Primero creamos un nuevo proyecto en Delphi
y modificamos las propiedades que deseemos cambiar de nuestra forma.
Agregamos los siguientes controles
- 3 Cajas de texto
- 5 Etiquetas
- 1 Control Memo
- 1 Socket
En este caso agregamos una estructura
que será en la que se agregaran los datos decodificados de
los correos.
type Mail = record
MFecha: String;
MFrom: String;
MSubject: String;
MTo: String;
MessageID: String;
Mensage: String;
end;
Con las siguientes procedimientos decodificamos los mensages y
los agregamos a la lista de correo.
procedure TForm1.BtnCheacarClick(Sender: TObject);
begin
if Skt.Active then
Skt.Close;
Skt.Host := EdtServidor.Text;
Skt.Open;
Contador := 1;
Status.Caption := 'Conectando';
end;
procedure TForm1.SktRead(Sender: TObject; Socket: TCustomWinSocket);
var
Cadena: String;
i: Integer;
begin
Cadena := Socket.ReceiveText;
case Contador of
1:
begin//Usuario
Delay(100);
Status.Caption := 'Enviando usuario';
Skt.Socket.SendText('user ' + EdtUsuario.Text
+ crlf);
inc(Contador);
ContMail := 0;
end;
2:
begin//contraseña
Delay(100);
Status.Caption := 'Enviando password';
Skt.Socket.SendText('pass ' + EdtPass.Text
+ crlf);
inc(Contador);
end;
3:
begin//Obtengo el numero de mensages que hay en el correo
Delay(200);
Status.Caption := 'Trayendo No. de mensajes';
Skt.Socket.SendText('stat' + crlf);
inc(Contador);
end;
4:
begin
Delay(1000);
Status.Caption := 'Obteniedo mensages';
NoMensages := Lista(Cadena);
SetLength(Correos, NoMensages);
ContMail := 0;
Caption := Caption + IntToStr(NoMensages);
if NoMensages > 0 then
begin
skt.Socket.SendText('retr 1'
+ crlf);
Inc(Contador);
end
else
begin
inc(Contador, 2);
skt.Socket.SendText('noop' +
crlf)
end;
end;
5:
begin
Delay(15000);
Status.Caption := 'Decodificando mensajes';
if Cadena[1] <> '+' then
Decodificar(Cadena);//Decodifico
el correo
Inc(ContMail);
if ContMail < NoMensages then
begin
Skt.Socket.SendText('retr '
+ IntToStr(ContMail + 1) + crlf);
end
else
begin
Inc(Contador);
skt.Socket.SendText('noop '
+ crlf);
end;
end;
6:
begin
LstCorreo.Clear;
Status.Caption := 'Desconectando';
Skt.Socket.SendText('quit');
if NoMensages = 0 then
ShowMessage('No hay correos')
else
begin
for i := 0 to NoMensages - 1
do
LstCorreo.Items.Add(Correos[i].MFrom
+ ' [' + Correos[i].MSubject + ']');
end;
inc(Contador);
Contador := 0;
Skt.Socket.Close;
end;
end;
end;
|