Problem with TIdMessage.LoadFromFile and MIME messages

Giganews Newsgroups
Subject: Problem with TIdMessage.LoadFromFile and MIME messages
Posted by:  Scott Bussinger (scot…@opto-pps.com)
Date: Mon, 15 Dec 2003

I'm stuck on a problem with the TIdMessage.LoadFromFile (LoadFromStream
does same thing) when loading in complex messages. In particular, the
message has a plain text section, an alternative html section and
finally an attachment. I can create the message with no problem and save
it to a file. Here's a sample:

      Subject: Test Message
      To: anyo…@anywhere.com
      Content-Type: multipart/mixed;
        boundary="=_MoreStuf_2zzz1234sadvnqw3nerasdf"
      MIME-Version: 1.0
      Date: Mon, 15 Dec 2003 17:20:27 -0800

      This is a multi-part message in MIME format

      --=_MoreStuf_2zzz1234sadvnqw3nerasdf
      Content-Type: multipart/alternative;
              boundary="=_MoreStuf_2altzzz1234sadvnqw3nerasdf"

      --=_MoreStuf_2altzzz1234sadvnqw3nerasdf
      Content-Type: text/plain
      Content-Transfer-Encoding: quoted-printable

      text stuff

      --=_MoreStuf_2altzzz1234sadvnqw3nerasdf
      Content-Type: text/html; charset=IBM850
      Content-Transfer-Encoding: quoted-printable

      <html><body>html stuff</body></html>

      --=_MoreStuf_2altzzz1234sadvnqw3nerasdf--

      --=_MoreStuf_2zzz1234sadvnqw3nerasdf
      Content-Type: application/octet-stream;
              name="OPTO.INI"
      Content-Transfer-Encoding: base64
      Content-Disposition: attachment;
              filename="OPTO.INI"

      W09QVE9dDQoNCltERVZFTE9QTUVOVF0NCkZVTExTQ1JFRU49Tg0KDQo=

      --=_MoreStuf_2zzz1234sadvnqw3nerasdf--
      .

This looks great. If I then read this message back in and save it again,
using simple code like this:

        var
          Msg: TIdMessage;
        begin
        Msg := TIdMessage.Create(nil);
        try
          Msg.LoadFromFile('v:\test.txt',false);
          Msg.SaveToFile('v:\
ew.txt');
        finally
          Msg.Free;
        end;

The new results are quite different in a couple of very important ways:

      Subject: Test Message
      To: anyo…@anywhere.com
      Content-Type: multipart/mixed;
        boundary="=_MoreStuf_2zzz1234sadvnqw3nerasdf"
      MIME-Version: 1.0
      Date: Mon, 15 Dec 2003 17:20:27 -0800

      This is a multi-part message in MIME format

      --=_MoreStuf_2zzz1234sadvnqw3nerasdf
      Content-Type: multipart/alternative;
        boundary="=_MoreStuf_2altzzz1234sadvnqw3nerasdf"

      --=_MoreStuf_2altzzz1234sadvnqw3nerasdf
      Content-Type: multipart/alternative;
        boundary="=_MoreStuf_2altzzz1234sadvnqw3nerasdf"
      Content-Transfer-Encoding: quoted-printable

      --=_MoreStuf_2altzzz1234sadvnqw3nerasdf
      Content-Type: text/plain
      Content-Transfer-Encoding: quoted-printable

      text stuff

      --=_MoreStuf_2altzzz1234sadvnqw3nerasdf
      Content-Type: text/html; charset=IBM850
      Content-Transfer-Encoding: quoted-printable

      <html><body>html stuff</body></html>

      --=_MoreStuf_2altzzz1234sadvnqw3nerasdf--

      --=_MoreStuf_2zzz1234sadvnqw3nerasdf
      Content-Type: application/octet-stream;        name="OPTO.INI";
              name="OPTO.INI"
      Content-Transfer-Encoding: base64
      Content-Disposition: attachment;        filename="OPTO.INI";
              filename="OPTO.INI"

      W09QVE9dDQoNCltERVZFTE9QTUVOVF0NCkZVTExTQ1JFRU49Tg0KDQo=

      --=_MoreStuf_2zzz1234sadvnqw3nerasdf--
      .

In particular, there are _two_ multipart/alternative headers one after
the other. Also, in the attachment filename, the NAME and FILENAME
attributes are doubled up.

There seems to be some parsing problems here with the Load routines --
anyone have any idea what's wrong? I grabbed the Indy 9.0.14 development
snapshot as of 2003/12/15 just to make sure I was current and the
problem is still there. When Outlook receives a malformed message like
this, it _really_ doesn't like it! Can anyone help me out?

Thanks! Be seeing you.

Replies