mail-mime-parser icon indicating copy to clipboard operation
mail-mime-parser copied to clipboard

Attachment with special chars not added correctly.

Open miknaz opened this issue 5 years ago • 1 comments

When I add attachment to message and then convert message object to string, filename is broken.

$message->addAttachmentPartFromFile('imgæ÷ü.jpeg', $mimeType);
$mime = (string) $message;

And this is attachment headers from mime string:

Content-Transfer-Encoding: base64
Content-Type: image/jpeg;
	name="imgae??.jpeg"
Content-Disposition: attachment;
	filename="imgae??.jpeg"
0: base64

Filename is broken.. (

I use the last 1.2.3 version

miknaz avatar Oct 16 '20 19:10 miknaz

Hi @miknaz --

For now, mail-mime-parser has very basic 'write' functionality, and unfortunately the users are left responsible for ensuring that proper encoding, etc... has been applied. In this case, you'd need to follow RFC2231 encoding for parameter values, something like:

See Message::setRawHeader And Message::getPart

$message->addAttachmentPartFromFile('tmp-name.jpeg', $mimeType);
$part = $message->getAttachmentPart(0); // this may be enough depending on your use case, or you may need to use a different method like getPart() with a filter, I linked to the docs for that above
$part->setRawHeader("Content-Type: image/jpeg;\r\nname*=utf-8'en'" . urlencode('imgæ÷ü.jpeg'));

Edit: the attachment is a separate part.

All the best

zbateson avatar Oct 16 '20 20:10 zbateson