Re: TIdMessage.Headers lost with NoEncode

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

Boba wrote:

> Dear Reader; what is wrong with the following code?:
<snip>
> 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:

{code}
IdMsg->Clear();
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);
{code}

--
Remy Lebeau (Indy Team)

Replies

None

In response to

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