procedure TfrmMain.RetrieveExecute(Sender: TObject);
var
stTemp:
string;
intIndex: Integer;
li: TListItem;
begin
stTemp := Statusbar1.Panels[1].text;
if lvHeaders.Selected =
nil then
begin
Exit;
end;
//initialise
Showbusy(true);
Msg.Clear;
Memo1.Clear;
lvMessageParts.Items.Clear;
From.Caption := '
';
Cc.Caption := '
';
Subject.Caption := '
';
Date.Caption := '
';
Receipt.Caption := '
';
Organization.Caption := '
';
Priority.Caption := '
';
pnlAttachments.visible := false;
WebBrowser1.Visible := false;
Memo1.Visible := true;
//get message and put into MSG
ShowStatus('
Retrieving message "' + lvHeaders.Selected.SubItems.Strings[3] + '
"');
POP.Retrieve(lvHeaders.Selected.
Index + 1, Msg);
statusbar1.Panels[0].text := lvHeaders.Selected.SubItems.Strings[3];
//Setup fields on screen from MSG
From.Caption := Msg.From.Text;
Recipients.Caption := Msg.Recipients.EmailAddresses;
Cc.Caption := Msg.CCList.EMailAddresses;
Subject.Caption := Msg.Subject;
Date.Caption := FormatDateTime('
dd mmm yyyy hh:mm:ss', Msg.Date);
Receipt.Caption := Msg.ReceiptRecipient.Text;
Organization.Caption := Msg.Organization;
Priority.Caption := IntToStr(Ord(Msg.Priority) + 1);
// Manchmal hat die Mail keine mehreren Parts, dann muss man sie komplett laden
If (Msg.ContentType = '
text/plain')
or
(Pos('
text/plain' + '
;', Msg.ContentType) = 1)
then
begin
Memo1.Lines.Clear;
Memo1.Lines.AddStrings(Msg.Body);
end
else
If not (Msg.MessageParts.Count > 0)
then
begin
Memo1.Lines.Clear;
Memo1.Lines.Add('
UNKNOWN CONTENT TYPE: ' + '
"' + Msg.ContentType + '
"');
Memo1.Lines.AddStrings(Msg.Body);
end;
//Setup attachments list
ShowStatus('
Decoding attachments (' + IntToStr(Msg.MessageParts.Count) + '
)');
//ShowMessage('uhu');
for intIndex := 0
to Pred(Msg.MessageParts.Count)
do
begin
if (Msg.MessageParts.Items[intIndex]
is TIdAttachment)
then
begin //general attachment
pnlAttachments.visible := true;
li := lvMessageParts.Items.Add;
li.ImageIndex := 8;
li.Caption := TIdAttachment(Msg.MessageParts.Items[intIndex]).Filename;
li.SubItems.Add(TIdAttachment(Msg.MessageParts.Items[intIndex]).ContentType);
end
else
begin //body text
if Msg.MessageParts.Items[intIndex]
is TIdText
then
begin
If (Msg.MessageParts.Items[intIndex].ContentType = '
text/html')
or
(Pos('
text/html' + '
;', Msg.MessageParts.Items[intIndex].ContentType) = 1)
then
begin
WebBrowser1.Visible := true;
Memo1.Visible := false;
TIdText(Msg.MessageParts.Items[intIndex]).Body.SaveToFile('
C:\_temp.htm');
WebBrowser1.Navigate('
C:\_temp.htm');
end
else
begin
Memo1.Lines.Clear;
Memo1.Lines.AddStrings(TIdText(Msg.MessageParts.Items[intIndex]).Body);
end;
pnlAttachments.visible := true;
li := lvMessageParts.Items.Add;
li.ImageIndex := 8;
If (Msg.MessageParts.Items[intIndex].ContentType = '
text/html')
or
(Pos('
text/html' + '
;', Msg.MessageParts.Items[intIndex].ContentType) = 1)
then
begin
li.Caption := '
[HTML]';
end
else
begin
li.Caption := '
[Text]';
end;
li.SubItems.Add(Msg.MessageParts.Items[intIndex].ContentType);
end
else
begin
pnlAttachments.visible := true;
li := lvMessageParts.Items.Add;
li.ImageIndex := 8;
li.Caption := '
[Other]';
li.SubItems.Add(Msg.MessageParts.Items[intIndex].ContentType);
end;
end;
end;
ShowStatus(stTemp);
Showbusy(false);
end;