Advertisement
Gov_777

imap Скачать вложение, удалить все кроме последнего

Jun 18th, 2017
704
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.14 KB | None | 0 0
  1.   IdIMAP41.Host := 'imap.ukr.net';
  2.   IdIMAP41.Username := 'login@ukr.net';
  3.   IdIMAP41.Password := 'password';
  4.   IdIMAP41.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(IdIMAP41);
  5.   IdIMAP41.UseTLS := utUseImplicitTLS;
  6.   IdIMAP41.Connect();
  7.   try
  8.     IdIMAP41.SelectMailBox('INBOX');
  9.     idIMAP41.Retrieve(IdIMAP41.MailBox.TotalMsgs, idMessage1);
  10.     for i := 1 to IdIMAP41.MailBox.TotalMsgs - 1 do
  11.     begin
  12.       idIMAP41.DeleteMsgs(i);
  13.       idIMAP41.ExpungeMailBox;
  14.     end;
  15.   finally
  16.     IdIMAP41.Disconnect;
  17.     IdIMAP41.IOHandler.Free;
  18.   end;
  19.   for n := 0 to IdMessage1.MessageParts.Count - 1 do
  20.   begin
  21.     ttype := idMessage1.MessageParts[n].ClassName;
  22.     if (ttype = 'TIdText') and not (ttype = NULL) then
  23.     begin
  24.       messtext2 := TIdText(idMessage1.MessageParts.Items[n]).Body.Text;
  25.     end;
  26.     atype := idMessage1.MessageParts[n].ClassName;
  27.     if atype = 'TIdAttachmentFile' then
  28.     begin
  29.       aname := IdMessage1.MessageParts.Items[n].FileName;
  30.       if aname = '' then
  31.         aname := 'unknown_file';
  32.       attach := TIdAttachment(IdMessage1.MessageParts.Items[n]);
  33.       attach.SaveToFile(aname);
  34.     end;
  35.   end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement