unit Upop3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
pop =
class(Tobject)
Client: TClientSocket;
procedure ClientRead(Sender: TObject; Socket: TCustomWinSocket);
private
Status: integer;
ip:
String;
port:Integer;
user:
String;
password:
String;
procedure delay(time: integer);
procedure connect1();
public
constructor Create(
ip,user,pass:
string;port:integer);
procedure disconnect();
function getList():
String;
function connect():boolean;
function getmail(nr:integer):
String;
function delmail(nr:integer):
STring;
end;
var
Form1: pop;
implementation
{$R *.dfm}
constructor pop.create(
ip,user,pass:
string;port:integer);
begin
client.Active := false;
self.ip :=
ip;
self.user := user;
self.password := pass;
client.Address :=
ip;
client.Port := port;
self.status := 0;
end;
procedure pop.delay(time: integer);
var time1 : longint;
begin
time1 := gettickcount;
while ((time1+ time )> gettickcount)
do
application.processmessages;
end;
procedure pop.connect1();
begin
case status
of
0:
begin client.Open;
end;
1:
begin client.Socket.SendText('
USER ' + user + chr(10));
end;
2:
begin client.Socket.SendText('
PASS ' + password + chr(10));
end;
end;
end;
function pop.connect():boolean;
var check:integer;
begin
check := -2 ;
while ((status > -1)
and (status < 3))
do begin
delay(100);
if (check <> status)
then begin
check := status;
connect1();
delay(100);
//memo1.lines.add('test');
end
end;
delay(100);
showmessage(IntToStr(status));
if (status = -1)
then result := false
else result := true;
//status := 0;
end;
procedure pop.ClientRead(Sender: TObject; Socket: TCustomWinSocket);
var bra:
string;
begin
bra := socket.ReceiveText;
//showmessage(bra);
if pos(bra,'
+')=0
then begin
//memo1.lines.add(bra);
inc(status);
end else begin
//memo1.lines.add(bra );
status:= -1;
end;
end;
procedure pop.disconnect();
begin
client.Socket.SendText('
QUIT ' + chr(10));
end;
function pop.getList():
String;
begin
showmessage(IntToStr(status));
if status > 0
then begin
client.Socket.SendText('
LIST ' + chr(10));
delay(1000);
result := client.Socket.ReceiveText;
end else
result := '
nein'
end;
function pop.getmail(nr:integer):
String;
begin
if status > 0
then begin
client.Socket.SendText('
RETR ' + IntToStr(nr) + chr(10));
delay(1000);
result := client.Socket.ReceiveText;
end else
result := '
nein'
end;
function pop.delmail(nr:integer):
String;
begin
if status > 0
then begin
client.Socket.SendText('
DELE ' + IntToStr(nr) + chr(10));
delay(1000);
result := client.Socket.ReceiveText;
end else
result := '
nein'
end;
{procedure pop.Button1Click(Sender: TObject);
begin
self.ip := '213.165.64.22';
self.user := 'ich@du.de';
self.password := '*********';
port := 110;
client.Address := ip;
client.Port := port;
self.status := 0;
if connect() then memo1.Lines.add('es hat alles geklappt') else memo1.lines.add('Fehler bei der anmeldung');
end;}
{procedure pop.Button2Click(Sender: TObject);
begin
memo1.Lines.add(getmail(2));
end;}
end.