Board index » delphi » Second try, Indy SMTP message non-US letters in filename problem

Second try, Indy SMTP message non-US letters in filename problem

No one answered my first post, so I'll try again.

I am using Indy 9.0.11 (TIdSMTP and TIdMessage) to send emails.
It works fine except for one thing: Attachments with non-US letters in the
filename.
If I send a mail with a filename containing danish letters such as "???.jpg"
then the filename in the mail becomes fubar.
The attachment itself is ok but the filename is trashed.
The strange thing is that it depends on the SMTP server that I use.
I use the exact same program written in Delphi 5 and using Indy 9.0.11 and
send the exact same file attached.
If I send the mail through my company's smtp server then the filename is
unharmed and ok.
If I send the mail through my private ISP's smtp server then the filename is
trashed.
This happens consistently.
The SMTP served used is the only difference.
It doesn't matter which program I use to receive the mail:
I have tried using Lotus Notes, Outlook Express and Indy TIdPOP3 to recieve
the mail.
This is driving me absolutely bonkers.

My question is simply:
How do I ensure that the filenames of attached files are written correctly
in the message,
nomatter which SMTP server I or my customers happens to use?

Further information:
When I look at the mail text it contains these linies:

Using Indy, sent through my company's SMTP server:
(non-US letters in filename, all is fine)

 - - = _ NextPart_2rfkindysadvnqw3nerasdf
C ontent-Type: application/octet-stream;        name="???.jpg";
        name="???.jpg"
C ontent-Transfer-Encoding: base64
C ontent-Disposition: attachment;        filename="???.jpg";
        filename="???.jpg"

Using Indy, sent through my private ISP's SMTP server:
(notice the non-US letters are removed from the filename???)

 - - = _ NextPart_2rfkindysadvnqw3nerasdf
C ontent-Type: application/octet-stream;        name=".jpg";
        name=".jpg"
C ontent-Transfer-Encoding: base64
C ontent-Disposition: attachment;        filename=".jpg";
        filename=".jpg"

Using Outlook Express, sent through my private ISP's SMTP server:
(non-US letters in filename, all is fine)

 - - = _ NextPart_2rfkindysadvnqw3nerasdf
C ontent-Type: image/jpeg; name="=?Windows-1252?B?5vjlLmpwZw==?=";
        name="???.jpg"
C ontent-Transfer-Encoding: base64
C ontent-Disposition: attachment;
filename="=?Windows-1252?B?5vjlLmpwZw==?=";
        filename="???.jpg"

Using Outlook Express, sent through my private ISP's SMTP server:
(only US letters in filename, all is fine)

 - - = _ NextPart_2rfkindysadvnqw3nerasdf
C ontent-Type: image/jpeg; name="tulips.jpg";
        name="tulips.jpg"
C ontent-Transfer-Encoding: base64
C ontent-Disposition: attachment; filename="tulips.jpg";
        filename="tulips.jpg"

(I inserted some blanks in the lines above otherwisw OE wouldn't send it)

Please help me.
--
Finn Tolderlund

 

Re:Second try, Indy SMTP message non-US letters in filename problem


Quote
Finn Tolderlund wrote:
> No one answered my first post, so I'll try again.

> I am using Indy 9.0.11 (TIdSMTP and TIdMessage) to send emails.
> It works fine except for one thing: Attachments with non-US letters in the
> filename.

As you can see, Indy cannot encode filenames in mail. It is looks as
stupid bug...

you can:

- patch Indy and add filename encoding yourself...
- use another library... ;-)

Good libary must do:
1. detect charset used by your system
2. detect proper charset for e-mail (in most cases it is different from
system charset!!!)
3. decode characters to trasport charset
4. use InLine Mime for encode filename to e-mail headers and mark it by
correct charset tag

For example, my Synapse can do all of this! :-)

-- Lukas Gebauer.
http://www.ararat.cz/synapse/ - Synapse Delphi and Kylix TCP/IP Lib.

Re:Second try, Indy SMTP message non-US letters in filename problem


In article <3e805ea...@newsgroups.borland.com>, n...@spam.dk says...

Quote
> No one answered my first post, so I'll try again.

Maybe nobody knows... :*)

Quote
> My question is simply:
> How do I ensure that the filenames of attached files are
> written correctly in the message, nomatter which SMTP server
> I or my customers happens to use?

Maybe you could try encoding the filename. You're using
8bit characters, and they might simply be stripped of the
top bit, or ignored.
So, instead of calling the file '???.jpg', try:
'=?ISO-8859-1?q?=E6=F8=E5.jpg?='

How to easily convert between the two is left as an
excercise to the reader... :*)

But here's an overview of the ISO-8859 charsets:
http://czyborra.com/charsets/iso8859.html

M.

Re:Second try, Indy SMTP message non-US letters in filename problem


Quote
On Wed, 26 Mar 2003 10:56:03 +0100, Martin wrote:
> Maybe you could try encoding the filename. You're using
> 8bit characters, and they might simply be stripped of the
> top bit, or ignored.
> So, instead of calling the file '???.jpg', try:
> '=?ISO-8859-1?q?=E6=F8=E5.jpg?='

> How to easily convert between the two is left as an
> excercise to the reader... :*)

Nowadays one would use ISO-8859-15 though ;)

johannes

Re:Second try, Indy SMTP message non-US letters in filename problem


Quote
"Martin" <LLOQPTJOD...@spammotel.com> wrote in message

news:MPG.18eb979d36c9f5de989684@forums.borland.com...

Quote
> > My question is simply:
> > How do I ensure that the filenames of attached files are
> > written correctly in the message, nomatter which SMTP server
> > I or my customers happens to use?

> Maybe you could try encoding the filename. You're using
> 8bit characters, and they might simply be stripped of the
> top bit, or ignored.
> So, instead of calling the file '???.jpg', try:
> '=?ISO-8859-1?q?=E6=F8=E5.jpg?='

I use this statement to attach a file:
  TIdAttachment.Create(IdMessage1.MessageParts, 'd:\???.jpg');
Where in this process do I encode the filename?
--
Finn Tolderlund

Re:Second try, Indy SMTP message non-US letters in filename problem


In article <3e81b...@newsgroups.borland.com>, n...@spam.dk says...

Quote
> I use this statement to attach a file:
>   TIdAttachment.Create(IdMessage1.MessageParts, 'd:\???.jpg');
> Where in this process do I encode the filename?

Right there:
TIdAttachment.Create(
       IdMessage1.MessageParts,
       'd:\=?ISO-8859-1?q?=E6=F8=E5?=.jpg');

Don't know if it will work, but it's worth a try, at least... :*)

M.

Re:Second try, Indy SMTP message non-US letters in filename problem


Quote
"Martin" <LLOQPTJOD...@spammotel.com> wrote in message

news:MPG.18ece3cb1b18e89989685@forums.borland.com...

Quote
> In article <3e81b...@newsgroups.borland.com>, n...@spam.dk says...
> > I use this statement to attach a file:
> >   TIdAttachment.Create(IdMessage1.MessageParts, 'd:\???.jpg');
> > Where in this process do I encode the filename?

> Right there:
> TIdAttachment.Create(
>        IdMessage1.MessageParts,
>        'd:\=?ISO-8859-1?q?=E6=F8=E5?=.jpg');

> Don't know if it will work, but it's worth a try, at least... :*)

I can tell you without trying that it won't work.
In procedure TIdMessageEncoder.Encode it tries to open the file specified.
And by actually trying it raises an exception "Cannot open file
d:\=?ISO-8859-1?q?=E6=F8=E5?=.jpg".
Which isn't surprising since there are no such file. And ? is not allowed
either in filenames.
--
Finn Tolderlund

Re:Second try, Indy SMTP message non-US letters in filename problem


Quote
> "Martin" <LLOQPTJOD...@spammotel.com> wrote in message
> news:MPG.18ece3cb1b18e89989685@forums.borland.com...
> > TIdAttachment.Create(
> >        IdMessage1.MessageParts,
> >        'd:\=?ISO-8859-1?q?=E6=F8=E5?=.jpg');

I think I found the solution.
By doing this:
  TIdAttachment.Create(IdMessage1.MessageParts, 'd:\???.jpg').FileName :=
'=?ISO-8859-1?q?=E6=F8=E5?=.jpg';
or
  with TIdAttachment.Create(IdMessage1.MessageParts, 'd:\???.jpg') do
    FileName := '=?ISO-8859-1?q?=E6=F8=E5?=.jpg';
which is the same thing, it seems to work correctly.

Now if only Indy did that automatically ...
Sigh ...

Thanks Martin, for pushing me in the right direction.
--
Finn Tolderlund

Other Threads