1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdPOP3, IdIntercept, IdLogBase, IdLogStream, IdIOHandler, IdIOHandlerStream, IdMailBox, IdMessage, ComCtrls, ExtCtrls, Unit2, IdMessageParts, IdText, IdAttachment;
procedure POPREFRESH(); function FmtFileSize(Size: Integer): string;
type TForm1 = class(TForm) Button1: TButton; Button3: TButton; Edit1: TEdit; Label1: TLabel; Button4: TButton; Edit2: TEdit; Label2: TLabel; POP: TIdPOP3; IdMessage1: TIdMessage; ListView1: TListView; Label3: TLabel; Timer1: TTimer; Button2: TButton; Button5: TButton; Edithost: TEdit; Editusername: TEdit; Editpassword: TEdit; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button2Click(Sender: TObject);
private
public end;
var Form1: TForm1;
implementation
{$R *.dfm}
function FmtFileSize(Size: Integer): string; begin if Size >= $F4240 then Result := Format('%.2f', [Size / $F4240]) + ' Mb' else if Size < 1000 then Result := IntToStr(Size) + ' bytes' else Result := Format('%.2f', [Size / 1000]) + ' Kb'; end;
procedure POPREFRESH(); var intIndex : integer; itm : TListItem; begin Form1.idMessage1.Clear; Form1.ListView1.Clear;
Form1.Edit1.Text := inttostr(Form1.POP.CheckMessages); Form1.Edit2.Text := fmtFileSize(Form1.POP.RetrieveMailBoxSize);
for intIndex := 1 to strtoint(Form1.edit1.Text) do begin Form1.POP.RetrieveHeader(intIndex, Form1.IdMessage1); itm := Form1.ListView1.Items.Add; itm.Caption := Form1.IdMessage1.Subject; itm.SubItems.Add(Form1.IdMessage1.From.Text); itm.SubItems.Add(DateToStr(Form1.IdMessage1.Date)); itm.SubItems.Add(FmtFileSize(Form1.POP.RetrieveMsgSize(intIndex))); end; end;
procedure TForm1.Button1Click(Sender: TObject); begin POP.Username := Editusername.Text; POP.Host := Edithost.Text; POP.Password := EditPassword.Text; POP.Connect; POPREFRESH; end;
procedure TForm1.Button3Click(Sender: TObject); begin POPREFRESH; end;
procedure TForm1.Button4Click(Sender: TObject); begin POP.Disconnect; end;
procedure TForm1.Timer1Timer(Sender: TObject); begin if pop.Connected = True then begin Label3.Color := cllime; button3.Enabled := True; button4.Enabled := True; button1.Enabled := False; ListView1.Enabled := True; button2.Enabled := True; button5.Enabled := True; end else begin Label3.Color := clred; button3.Enabled := False; button4.Enabled := False; Button1.Enabled := True; ListView1.Enabled := False; button2.Enabled := False; button5.Enabled := False; end; end;
procedure TForm1.Button5Click(Sender: TObject); begin POP.Delete(ListView1.ItemIndex + 1); POPRefresh; end;
procedure TForm1.Button2Click(Sender: TObject); var intIndex : integer; li : TListItem; begin POP.Retrieve(ListView1.Selected.Index + 1, IdMessage1);
Form2.LabelFrom.Caption := IdMessage1.From.Text; Form2.LabelRecipients.Caption := IdMessage1.Recipients.EmailAddresses; Form2.LabelCc.Caption := IdMessage1.CCList.EMailAddresses; Form2.LabelSubject.Caption := IdMessage1.Subject; Form2.LabelDate.Caption := FormatDateTime('dd mmm yyyy hh:mm:ss', IdMessage1.Date); Form2.LabelReceipt.Caption := IdMessage1.ReceiptRecipient.Text; Form2.LabelOrganization.Caption := IdMessage1.Organization; Form2.LabelPriority.Caption := IntToStr(Ord(IdMessage1.Priority) + 1);
for intIndex := 0 to Pred(IdMessage1.MessageParts.Count) do begin if IdMessage1.MessageParts.Items[intIndex] is TIdAttachment then begin li := Form2.ListViewMessageParts.Items.Add; li.Caption := TIdAttachment(IdMessage1.MessageParts.Items[intIndex]).Filename; li.SubItems.Add(TIdAttachment(IdMessage1.MessageParts.Items[intIndex]).ContentType); end else begin if IdMessage1.MessageParts.Items[intIndex] is TIdText then begin Form2.Memo1.Clear; Form2.Memo1.Lines.AddStrings(TIdText(IdMessage1.MessageParts.Items[intIndex]).Body); end end; end; if Form2.Memo1.Lines.Count = 0 then begin Form2.Memo1.Clear; Form2.Memo1.Lines.AddStrings(IdMessage1.Body); end; Form2.show; end;
end. |