FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=12411&edit=1

ID: 12411
Comment by: alec@alec.pl
Reported By: bmdevelopment at gmail dot com
Summary: Support RFC 2047 standard for non-ascii characters as
attachment filename.
Status: Open
Type: Feature/Change Request
Package: Mail_Mime
Operating System: FreeBSD 6.2-RELEASE #0
Package Version: 1.5.2
PHP Version: 5.2.4
Roadmap Versions:
New Comment:

I've attached a bulk patch which addresses issues #12411, #12429,
#14232, #15320, #14529, #14779. Test script:
<?php

include('Mail/mime.php');

$text = '';
$crlf = "\n";
$file = 'empty.txt'; //some empty file
$files = array(
'empty.txt',
'with space.txt',
'with unicode &#380;&#261;&#347;&#378;&#263;.txt',
'long name with spaces, very long long long long long very very
long long.txt',
'long name with spaces, very long long long long long very very and
&#380;&#261;&#347;&#378;&#281;&#263;.txt',
);
$mime = new Mail_mime($crlf);

foreach ($files as $name) {
copy($file, '/tmp/'.$name);
$mime->addAttachment('/tmp/'.$name, 'text/plain', '', true,
'base64', 'attachment', 'UTF-8', '', '',
'quoted-printable');
}

$mime->setTXTBody($text);

echo $mime->getMessage();

?>

And result:

MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="=_8ea5f688b1cf8f2db7d4f37126f5ac3f"

--=_8ea5f688b1cf8f2db7d4f37126f5ac3f
Content-Transfer-Encoding: base64
Content-Type: text/plain charset=UTF-8;;
name=empty.txt;
Content-Disposition: attachment;
filename=empty.txt;


--=_8ea5f688b1cf8f2db7d4f37126f5ac3f
Content-Transfer-Encoding: base64
Content-Type: text/plain charset=UTF-8;;
name="with space.txt";
Content-Disposition: attachment;
filename="with space.txt";


--=_8ea5f688b1cf8f2db7d4f37126f5ac3f
Content-Transfer-Encoding: base64
Content-Type: text/plain charset=UTF-8;;
name="=?UTF-8?Q?with_unicode_=C5=BC=C4=85=C5=9B=C5=BA=C4=87.txt?=";
Content-Disposition: attachment;
filename*=UTF-8''with%20unicode%20%C5%BC%C4%85%C5%9B%C5%BA%C4%87.txt;


--=_8ea5f688b1cf8f2db7d4f37126f5ac3f
Content-Transfer-Encoding: base64
Content-Type: text/plain charset=UTF-8;;
name="long name with spaces, very long long long long long very very
lo.txt";
Content-Disposition: attachment;

filename*0*=UTF-8''long%20name%20with%20spaces,%20very%20long%20long%20long;
filename*1*=%20long%20long%20very%20very%20long%20long.txt;


--=_8ea5f688b1cf8f2db7d4f37126f5ac3f
Content-Transfer-Encoding: base64
Content-Type: text/plain charset=UTF-8;;

name="=?UTF-8?Q?long_name_with_spaces,_very_long_long_long_long_long_very_v.txt?=";

Content-Disposition: attachment;

filename*0*=UTF-8''long%20name%20with%20spaces,%20very%20long%20long%20long;

filename*1*=%20long%20long%20very%20very%20and%20%C5%BC%C4%85%C5%9B%C5%BA%C4;
filename*2*=%99%C4%87.txt;


--=_8ea5f688b1cf8f2db7d4f37126f5ac3f--


Previous Comments:
------------------------------------------------------------------------

[2009-06-17 11:54:36] alec

The following patch has been added/updated:

Patch Name: mime_bulk.patch
Revision: 1245236075
URL:
http://pear.php.net/bugs/patch-display.php?bug=12411&patch=mime_bulk.patch&revision=1245236075&display=1

------------------------------------------------------------------------

[2008-09-29 03:44:47] alec

mime_param.patch it's my patch for the same issue.

------------------------------------------------------------------------

[2007-11-18 14:23:40] cwiedmann
At the moment just some remarks:
OK, today I've had some time to rewrite the patch (against CVS). The
method Mail_mime::addAttachment() have now a tithe parameter:
@param bool $rfc2231 Allow the language to be used for
display the filename as well as
the character set.
Defaults to true
If you set this parameter to "false", the old behaviour is used. The
headers are encoded like e.g. "Subject" and respect the parameters
"head_encoding" and "head_charset" from Mail_mime::get().

In case of setting this parameter to "false", "$charset" and
"$language" is not used.

So you can now encode the "name" and "filename" with Q or B encoding
and with the same charset you have defined for the normal headers.

Long filenames are now also folded with the old style: no problems with
e.g. with Outlook Express or Outlook. (see Bug #12429)

I have changed the private method Mail_mime::_encodeHeaders(), to a
public static method Mail_mime::encodeHeaders(). So we can use this (the
same) function from the class Mail_mime and the class Mail_mimePart.

Regards,
Carsten

------------------------------------------------------------------------

[2007-11-17 03:36:09] cwiedmann
Outlook and Outlook Express will not correctly display
the filenames in the 2231 format, which is currently the
only format supported in Mail_mime.
Courios: Outlook have only a problem with 2231, if you are using POP or
IMAP. With an other connector like Exchange or Kerio, this works also
with 2231.

Outlook Express can only handle 2047/822.

I think that is about it. This patch is working fine
for me now. Please feel free to use, correct and
improve it and add it to the code base if necessary.
At the moment just some remarks:
- The attached patch is a reverse patch:
From your version to the original version.
- The patch does not work with folded headers.
- Does only use B-encoding. But Q-encoding should also work.

Thus, this patch is at the moment only half the way. I also would give
this request an other name: "Option: disabling RFC 2231 extension". Also
I'm +1 to have this feature.

Regards,
Carsten

------------------------------------------------------------------------

[2007-11-09 03:16:44] bmdevelopment

Apologies for my carelessness, but I left a private email address in
the test script. Is it possible to delete the test script and re-upload
or delete this bug and I will re-post. Again, I apologize for this.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://pear.php.net/bugs/bug.php?id=12411

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJun 17, '09 at 10:01a
activeJun 17, '09 at 10:01a
posts1
users1
websitepear.php.net

1 user in discussion

Alec: 1 post

People

Translate

site design / logo © 2022 Grokbase