Search code examples
delphiindy

Indy IdSMTP and attachments in Thunderbird


Using the latest snapshot of Indy tiburon on D2010. A very simple project like:

var
  stream: TFileStream; (s is TidSMTP and m is TidMessage)
begin
  s.Connect;
  Stream := TFileStream.Create('c:\Test.zip', fmOpenRead or fmShareExclusive);
  try
    with TIdAttachmentMemory.Create(m.MessageParts, Stream) do
    begin
      ContentType := 'application/x-zip-compressed';
      Name := ExtractFilePath('C:\'); //'
      FileName := 'Test.zip';
    end;
  finally
    FreeAndNil(Stream);
  end;
  s.Send(m);
  s.Disconnect();
end;

Everything works Ok in Outlook, The bat!, OE, yahoo, etc... but in Thunderbird the attachment is not shown. Looking at the source of the message in Thunderbird, the attachment is there. The only difference I can find between messages send by indy and other clients is that Indy messages have this order:

Content-Type: multipart/mixed; boundary="Z\=_7oeC98yIhktvxiwiDTVyhv9R9gwkwT1"
MIME-Version: 1.0

while any other clients have the order:

MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="Z\=_7oeC98yIhktvxiwiDTVyhv9R9gwkwT1"

Don't know if THAT is the source of the problem, but if so: is this a bug on Thunderbird or is this a problem with indy which "malforms" the headers of the messages? Is this order a problem? Does that matter anyway?


Solution

  • The latest version (as today) of Indy has a problem in the headers:

    The problem seems to be around the line in the mail header with:

    Content-Type: multipart/mixed; boundary="oIROJ8Yu4KsL8BbjOo0fc\=_O7oAqLVq97i"

    The "=" inside the boundary identifier is prepended with a "\" (probably to escape it), but in the body of the mail the boundary looks like this:

    --oIROJ8Yu4KsL8BbjOo0fc=_O7oAqLVq97i

    If you look at the source of Indy, in the file idGlobalProtocols, ReplaceHeaderSubItem calls QuoteString, which is the one that adds the backslash. You could carefully change the logic here and recompile Indy.