1 | initial version |
To extract the TextBody from an openpgp encoded message in Delphi using Idmessage, follow these steps:
var
IdMessage: TIdMessage;
begin
IdMessage:= TIdMessage.Create(nil);
IdMessage.LoadFromFile('C:\path\to\message.eml');
var
i: Integer;
Part: TIdMessagePart;
TextBody: TStringList;
begin
TextBody := TStringList.Create;
try
for i := 0 to IdMessage.MessageParts.Count - 1 do
begin
Part := IdMessage.MessageParts.Items[i];
if Part.ContentType = 'text/plain' then
begin
if Part.ContentTransfer = 'quoted-printable' then
IdDecoderQuotedPrintable.DecodeStream(Part.DecodedStream, TextBody)
else if Part.ContentTransfer = 'base64' then
IdDecoderMIME.DecodeStream(Part.DecodedStream, TextBody)
else
Part.DecodedStream.Seek(0, soBeginning); // Reset stream position
TextBody.LoadFromStream(Part.DecodedStream);
Break;
end;
end;
finally
TextBody.Free;
end;
Memo1.Lines := TextBody;