Re: TIdMessage.Headers lost with NoEncode

Giganews Newsgroups
Subject: Re: TIdMessage.Headers lost with NoEncode
Posted by:  Remy Lebeau (re…
Date: Fri, 4 Sep 2015

Boba wrote:

> Dear Reader; what is wrong with the following code?:
> The "msg.txt" file does not contain any headers.

When the TIdMessage::NoEncode property is true, the TIdMessage::SaveTo....()
methods save the TIdMessage::Headers and TIdMessage::Body properties as-is.
But you are not populating the TIdMessage:::Headers property with any data.
The various TIdMessage property setters do not write data to the TIdMessage::Headers
property, and the TIdMessage::GenerateHeader() populates the TIdMessage::LastGeneratedHeaders
property instead of the TIdMessage::Headers property.

For what you are attempting, you would need to do this:

IdMsg->NoEncode = true;
IdMsg->ContentType = "text/plain; charset=UTF-8";
IdMsg->ContentTransferEncoding = "quoted-printable";
IdMsg->GenerateHeader(); // <-- uncomment this
IdMsg->Headers->Assign(IdMsg->LastGeneratedHeader); // <-- add this
IdMsg->Body->Add("Jimmy, gimmy =E2=82=AC10 or $15.");
IdMsg->SaveToFile("msg.txt", true);

Remy Lebeau (Indy Team)



In response to

TIdMessage.Headers lost with NoEncode posted by Boba on Fri, 4 Sep 2015