When TIdMessage
parses an email, by default it decodes transfer encodings (quoted printable, etc) to raw bytes and then charset-decodes those bytes to UTF-16 in memory. To avoid that, you would have to set TIdMessage::NoDecode
to true before loading the email, but then you will not be able to use the TIdMessage::MessageParts
anymore. And in either case, you will not get raw bytes anyway since TIdMessage
deals primarily in String
data.
Body->SaveToFile(...)
is calling the standard VCL TStrings::SaveToFile()
, which saves the TString
data using the OS default encoding unless you explicitly specify a different encoding in its Encoding
parameter, eg:
static_cast<TIdText*>(IdMsg->MessageParts->Items[0])->Body->SaveToFile("file.htm", Sysutils::TEncoding::UTF8);