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;
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-14 06:23:53 +0000
Seen: 10 times
Last updated: Jun 14 '23
Can the new position of a dynamically shifted control be saved in Delphi?
In Delphi, what is the method for formatting a Unix timestamp?
In Delphi, what is the method to obtain a numeric variant property?
How to display a form or a "please wait" panel while executing a task in FMX Delphi 10.2?
How can I show a checkmark in a Boolean field in Delphi's DBGrid?
How can memory leaks in UnicodeStrings be addressed in Delphi?