POP3 Attachment problems again

Giganews Newsgroups
Subject: POP3 Attachment problems again
Posted by:  E.-J. Parsch (joachim.pars…@contrast-ag.de)
Date: Tue, 6 Dec 2005

Hi,

with Delphi 5 and Indy 9.0.14 I'm trying to get the attachment out of
retrieved mails that look like the following (retrieved raw):

Return-Path: <xxx>
X-Original-To: xxx
Delivered-To: xxx
Received: xxxxxx
id 44DD4C1BF; Mon,  5 Dec 2005 17:03:54 +0100 (CET)
Delivered-To: xxxxxxxxxxxx
Received: xxxxxxxxxxxxxxxxxx
by xxxxxxxxxxxxxxx
for <xxxxxxxxx>; Mon,  5 Dec 2005 17:03:54 +0100 (CET)
MIME-Version: 1.0
Content-Type: application/octet-stream;
name="xxxx.ARJ"
Content-Transfer-Encoding: base64
Content-Description: xxxx.ARJ
Content-Disposition: attachment;
filename="xxxx.ARJ"
Subject: xyxyxyxyxyxyxyx
Date: Mon, 5 Dec 2005 17:03:51 +0100
Message-ID: <cxcxcxcxcxcxc>
From: =asasasasasas= <bvbvbvbvbvb>
To: <gdgdgdgdgdgdgdg>
X-UIDL: `*o"!+d~"!j/"#!\gb"!
Status: U

YOowACJlAQsQAAJCQoiFM0KIhTMAAAAAAAAAAAAAAAAAAAAAAABGUkUwOTAwNS5BUkoAAG+DAmsA
AGDqOAAuZQELEAEAQiaIhTPYBQAAGFcAAC7RRfUAACAAAAAAAAAAAACFM+KIOzEAAAAARlJFMDkw

(much more stuff like this ;-)

cPqvfy6658fw5L3CPYve+oq93n+JqveBfDTbTTxstwDGQnvMUKkq9SKVJYF3/myH8Odj3F9PRqfz
MunhUXXWG/L0nW7y7vpusH7/3sH6/V9wYOoAAA==

Since I read in another thread that I had to decode the message manually,
because Content-Transfer-Encoding is set to 'base64', i tried this by using:

<Code starts here>
var
    Decoder        : TIdDecoder;
    Strm              : TStream;
    Buf                : string;

begin
  Buf := EOL + '.' + EOL;

  Msg.NoDecode := False;
  POP.Retrieve(iSelMessage, Msg);

  showmessage(IntToStr(Msg.MessageParts.count));    // = 1

  if Msg.ContentTransferEncoding = 'base64' then begin
    Msg.Clear;
    Msg.NoDecode := True;

    POP.Retrieve(iSelMessage, Msg);
    Decoder := TIdDecoderMime.Create(nil);

    try
      Strm := TMemoryStream.Create;
      try
          Msg.Headers.SaveToStream(Strm);
          Strm.Write(Buf[1], length(Buf));

          Decoder.DecodeToStream(Msg.Body.Text, Strm);
          Strm.Position := 0;
          Msg.NoDecode := False;

          Msg.LoadFromStream(Strm);
      finally
        Strm.Free;
      end;

    finally
      Decoder.Free;
    end;

    showmessage(IntToStr(msg.MessageParts.count));    // = 0
  end;
end;
<Code ends here>

But after this code is executed, the message contains 0 (zero) messageparts,
though there was 1 before decoding.

Since I know, that there is one attachment (I can retrieve it with Outlook!)
I must be doing something wrong - or should it finally be a bug in
TIdMessage?

Btw. The sender might be using Lotus notes - if that should be a hint for
the experts.

TIA
Joachim

Replies