UTF-8 Attachments

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
CoolWind
Forum Newbie
Posts: 2
Joined: Tue Jan 15, 2008 2:17 am

UTF-8 Attachments

Post by CoolWind »

Hi,

I contacted Chris via e-mail telling a problem I found using Swift Mailer.
He kindly replied me but as the forum is working now (it was several
days down, I think), I want to share what I found and ask for help.

I'm using the latest version (3.3.2). I have found a problem when
adding an attachment which has a name that needs utf8 charset.

I use the following sentence:

$message->attach(new Swift_Message_Attachment(new Swift_File($realpath), $realname));

Which I think is correct. The data is added fine to the raw email
body, but the name is encoded in a form that NO e-mail client can
read successfully, for example, the name of the attachment
"Presentación Congreso.doc" is encoded as:

Content-Type: application/octet-stream; name*=utf-8'en-us'Presentaci%C3%B3n%20Congreso.doc
Content-Transfer-Encoding: base64
Content-Description: =?utf-8?B?UHJlc2VudGFjacOzbiBDb25ncmVzby5kb2M=?=
Content-Disposition: attachment; filename*=utf-8'en-us'Presentaci%C3%B3n%20Congreso.doc

As the result, for example, GMail gives me as filename for that attachment:

utf-8'en-us'Presentaci%C3%B3n%20Congreso.doc

Same e-mail with Outlook Express does NOT allow to download the attachment, it even
renames the filename to: (note the ".dat" at the end)

Presentación Congreso.doc.dat
[greyed, unselectable]

Other webmails detect that there's an attachment but the name appears blank.
As I told you, I have yet to find a single e-mail client or webmail who knows
how to decode successfully this encoded filename or any other UTF-8 attachment
sent by Swift Mailer.

I am not saying the encoding method used is wrong, I just say that any popular e-mail
client I've checked doesn't show the attachment as it should.

To compare what the other e-mail clients do, see GMail:

Content-Disposition: attachment;
filename="=?UTF-8?Q?Presentaci=C3=B3n_Congreso.doc?="

So, is this a bug? can it be solved in any way I'm missing?

Thank you.

Marc LP
Last edited by CoolWind on Tue Jan 15, 2008 4:01 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: UTF-8 Attachments

Post by Chris Corbyn »

Gmail puts double quotes around the =?...?Q?....?= stuff? That's invalid according to RFC 2047.

RFC 2047, 5 (3):

Code: Select all

  + An 'encoded-word' MUST NOT appear within a 'quoted-string'.
 
   + An 'encoded-word' MUST NOT be used in a Received header field.
 
   + An 'encoded-word' MUST NOT be used in parameter of a MIME
     Content-Type or Content-Disposition field, or in any structured
     field body except within a 'comment' or 'phrase'.
http://www.ietf.org/rfc/rfc2047.txt

I'm not saying there's no bug in my implementation, but Gmail is *definitely* breaking the RFC if that's what they're doing.

I'm halfway through writing version 4 which is due out very soon so unfortunately no more 3.x releases are going to be made. The 4.x release is having it's entire MIME library rewritten; so much so it will be released as a separate standalone library. *Everything* in the 4.x release is spec-driven using the RFC's, to the word, exactly following the specified ABNF grammar. It will be better and worth the wait ;)

I'm a little behind schedule but I was aiming for a February release.
CoolWind
Forum Newbie
Posts: 2
Joined: Tue Jan 15, 2008 2:17 am

Re: UTF-8 Attachments

Post by CoolWind »

We'll have to wait to 4.0 then.
Post Reply