Fix: Indy Mail Attachment Filenames lost in D2009

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 FilesCodeGearRAD Studio6.0sourceIndyIndy10ProtocolsIdMessageClient.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.

Advertisements

10 thoughts on “Fix: Indy Mail Attachment Filenames lost in D2009

  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. 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. 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. Pingback: WordPress .RC » Blog Archive

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s