Home > Delphi, Indy > Fix: Indy Mail Attachment Filenames lost in D2009

Fix: Indy Mail Attachment Filenames lost in D2009

October 2nd, 2008

Hi,

probably you already discovered a bug in Indy & D2009 that when sending E-Mails with attachments you will loose the attachment filenames.

This is related to a small bug in the Indy Version shipped with the initial release of Delphi 2009. It has already been fixed in the Indy SVN.

See the QualityCentral report for it: http://qc.codegear.com/wc/qcmain.aspx?d=66867

Bug Report Background:
Without the line break fix (see below) the attachment filename is printed in the same line as “Content-Disposition” and so some mail clients ignore the filename. Without it the file will have random names regarding to the used client.

If you do not want to update the whole Indy version shipped with D2009 you can fix the bug on your own:

1) Copy the VCL source file for IdMessageClient.pas from your D2009 directory:
C:\Program Files\CodeGear\RAD Studio\6.0\source\Indy\Indy10\Protocols\IdMessageClient.pas
to your project’s directory
2) Edit the IdMesageClient.pas and change the lines given below:

procedure TIdMessageClient.SendBody(AMsg: TIdMessage):
begin
...
  if LFileName <> '' then begin
    IOHandler.WriteLn(';'); // inserted for QC 66867, between original line 1214/1215
    IOHandler.Write('        name="' + LFileName + '"'); {do not localize}
  end;
  IOHandler.WriteLn;
  IOHandler.WriteLn('Content-Transfer-Encoding: ' + LAttachment.ContentTransfer); {do not localize}
  // next line fixed for QC 66867, changed IOHandler.Write<strong>Ln</strong> to IOHandler.Write
  IOHandler.Write('Content-Disposition: ' + LAttachment.ContentDisposition); {do not localize}
  if LFileName <> '' then begin
    IOHandler.WriteLn(';'); // inserted QC 66867, line 1220/1221
    IOHandler.Write('        filename="' + LFileName + '"'); {do not localize}
  end;
...
end;

3) Save and do a full-rebuild on your project
4) Verify that IdMessageClient.dcu has been created in your project’s directory

You can also replace the existing files in the Delphi 2009 source
directory at:

C:\Program Files\CodeGear\RAD Studio\6.0\source\Indy\Indy10\Protocols\IdMessageClient.pas

If you are doing the latter, be sure to replace the DCUs at:

1) C:\Program Files\CodeGear\RAD Studio\6.0\lib\Indy10\IdMessageClient.dcu
2) C:\Program Files\CodeGear\RAD Studio\6.0\lib\debug\Indy10\IdMessageClient.dcu

You may create the needed DCUs with the earlier mentioned steps, one
time without and a second time with enabled “Build Debug DCU” option.

Arvid Delphi, Indy ,

  1. October 2nd, 2008 at 14:04 | #1

    Or, rather, delete the offending mail client from the face of the Internet.

    ‘filename’ has all the rights to live in the same line as ‘Content-Disposition:’.

  2. Arvid
    October 2nd, 2008 at 14:14 | #2

    gabr, I think you are right regarding the RFC 2183 specs. But what will this help if all major clients won’t work correctly without those line breaks?

    > Or, rather, delete the offending mail client from the
    > face of the Internet.
    ;)

    Cheers Arvid

  3. October 2nd, 2008 at 14:26 | #3

    I know, I know. We have to live in the world of broken and incompatible software :(

    I’m just mad as I spend lots of time battling such incompatibilities in mail, http, smtp …

  4. December 8th, 2008 at 21:58 | #4

    very nice post !

  5. Arvid
    December 9th, 2008 at 10:44 | #5

    Hi delphi :)

    You’re welcome.

    I just saw that the same fix applies for QC 69187.

    Best regards
    Arvid

  6. Hadschi
    February 28th, 2009 at 00:35 | #6

    Thank you very much, it was a little bit hard to compile everything the rigth way, but it worked.

  7. expresson
    October 27th, 2009 at 18:23 | #7

    It`s was rather interesting to read. Hope to see same more in future.

  1. November 5th, 2009 at 10:08 | #1