TIdMessage Content-ID not showing

Giganews Newsgroups
Subject: TIdMessage Content-ID not showing
Posted by:  Vandra_Ákos
Date: Sun, 20 Jul 2008

Hello people!

I have a problem (actually many problems, but these are the ones I
couldn't work around) using TIdMessage.
I have a multipart message containing another multipart message (the
attachments), which should have a Content-ID, so the receiver can
identify which message part has the attachments, and which one the
request. (I don't know if I was clear enough here, but this isn't all
that important really).
My problem is, that I can't make TIdMessage put a Content-ID header for
the embedded multipart messagepart. It simply ignores it. Tried adding
to Header and Extraheaders too.

The other issue is that the generated boundary markers differ only by a
single character at the end (the second one is appended another
character), and the server doesn' like this, it gives internal server
error. If I append another character to the beginning too by hand, it's
solved. But I cannot change the Boundary property of the TIdMessage, it
ignores being given another value.

My code:

    XmlPart := TIdText.Create(Msg.MessageParts,sl);
    XmlPart.ContentType := 'text/xml; charset="utf-8"';
    XmlPart.ContentTransfer := '7bit';
    XmlPart.ContentID := '<soap_part>';

    // Second message part contains the attachments
    AttachmentPart := TIdText.Create(Msg.MessageParts, nil);
    AttachmentPart.ContentType := 'multipart/related';
    AttachmentPart.Boundary := 'MMS_PART';

    // Add attachments to the attachment part
    for i := 0 to Attachments.Count - 1 do
      begin
        AttachmentDesc := Attachments[i] as TMM7Attachment; //
Description of attachment
        with
TIdAttachmentFile.Create(Msg.MessageParts,AttachmentDesc.FileName) do
        begin
          ParentPart := AttachmentPart.Index; // Set parent part in the
hierarchy
          ContentType := AttachmentDesc.ContentType; // Set content
mime type
          ContentID := 'attachment_' + IntToStr(i); // Unique ID for
each attachment

          // if auto, determine MIME type from extension
          if ContentType = 'auto' then
            ContentType :=
MimeTable.GetFileMIMEType(AttachmentDesc.FileName);
        end;
      end;

So at the end XmlPart has it's Content-ID okay, but AttachmentPart has
nothing, only it's Conent-Type header.

Generated message looks like this:

--8tm0CZPZzpkBM=_NXoUrhKfpYU47TL9ply
Content-Type: text/xml; charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-ID: <soap_part>

XML COMES HERE (removed to be shorter)

--8tm0CZPZzpkBM=_NXoUrhKfpYU47TL9ply
Content-Type: multipart/related;
        boundary="8tm0CZPZzpkBM=_NXoUrhKfpYU47TL9plyA"

--8tm0CZPZzpkBM=_NXoUrhKfpYU47TL9plyA
Content-Type: text/plain;
        name="a1.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
        filename="a1.txt"
Content-ID: attachment_0

SGVsbG8gV29ybGQh

--8tm0CZPZzpkBM=_NXoUrhKfpYU47TL9plyA
Content-Type: image/jpeg;
        name="a2.jpg"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
        filename="a2.jpg"
Content-ID: attachment_1

JPEG DATA IS HERE (removed to be shorter)

--8tm0CZPZzpkBM=_NXoUrhKfpYU47TL9plyA--

--8tm0CZPZzpkBM=_NXoUrhKfpYU47TL9ply--

Thanks for your help,
        Vandra Ákos

Replies