Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachment with special chars not added correctly. #145

Open
miknaz opened this issue Oct 16, 2020 · 1 comment
Open

Attachment with special chars not added correctly. #145

miknaz opened this issue Oct 16, 2020 · 1 comment

Comments

@miknaz
Copy link

miknaz commented Oct 16, 2020

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

@zbateson
Copy link
Owner

zbateson commented Oct 16, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants