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

UTF8 in attachment filename is not encoded #75

Closed
tumapav opened this issue Oct 7, 2020 · 11 comments
Closed

UTF8 in attachment filename is not encoded #75

tumapav opened this issue Oct 7, 2020 · 11 comments

Comments

@tumapav
Copy link

tumapav commented Oct 7, 2020

Version: 3.1.4

Bug Description

If the attachment file name contains UTF8 characters, the header is not RFC 2047 encoded, which causes email to rely on support of SMTPUTF8 extension, making the email undeliverable to destinations servers that don't support it (gmail supports it, but e.g. email.cz does not).

Steps To Reproduce

$mail = new Nette\Mail\Message;
$mail->setFrom('John <john@example.com>')
        ->addTo('peter@example.com')
        ->setSubject('Kůň v příloze')
        ->setBody("Test")
        ->addAttachment("kůň.txt", "test");

die($mail->generateMessage());

See resulting Content-Disposition header:

Content-Disposition: attachment; filename="kůň.txt"

Expected Behavior

Content-Disposition: attachment; filename="=?UTF-8?B?a8WvxYgudHh0?="

Possible Solution

This worked in the previous version, the bug was introduced with this change 6f33373 which fixed #24, in this change, call to encodeHeader() has been removed. This call should be probably returned, but I'm not sure how exactly in order to not introduce back the issue #24.

I know a workaround is not to use utf8 in attachment file name with e.g. Strings::toAscii($filename), but as long as the encoding works well with other headers like Subject or From, I don't see a reason for this header to be an exception.

@milo
Copy link
Member

milo commented Oct 7, 2020

It is hard to find some RFC for such situation. So, to find some working solution, I use Thunderbird. So I sent attachment named jůůůžě.txt via Thunderbird and GMail SMTP and I got:

Content-Type: text/plain; charset=UTF-8;
 name="=?UTF-8?B?asWvxa/Fr8W+xJsudHh0?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename*=UTF-8''%6A%C5%AF%C5%AF%C5%AF%C5%BE%C4%9B%2E%74%78%74

@milo
Copy link
Member

milo commented Oct 7, 2020

And this is via. GMail web interface:

Content-Type: text/plain; charset="UTF-8"; name="=?UTF-8?B?asWvxa/Fr8W+xJsudHh0?="
Content-Disposition: attachment; filename="=?UTF-8?B?asWvxa/Fr8W+xJsudHh0?="
Content-Transfer-Encoding: base64
Content-ID: <f_kfz6pkr50>
X-Attachment-Id: f_kfz6pkr50

@dg
Copy link
Member

dg commented Oct 7, 2020

Milo, can you try to send files named ", \ and x? I am unable do it on Windows (except the third).

@milo
Copy link
Member

milo commented Oct 7, 2020

Third char sould be x? I tried ů"\?x.txt and this is a result of Thunderbird 78.3.1 on Debian 10:

Content-Type: text/plain; charset=UTF-8;
 name="=?UTF-8?B?xa8iXD94LnR4dA==?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename*=UTF-8''%C5%AF%22%5C%3F%78%2E%74%78%74

Correctly seen as ů"\?x.txt attachment in Thunderbird on Windows and when trying to save it, Thunderbird replaces name to ů___x.txt.

@milo
Copy link
Member

milo commented Oct 7, 2020

And how encoded by GMail webface:

Content-Type: text/plain; charset="US-ASCII"; name="=?UTF-8?B?xa8iXD94LnR4dA==?="
Content-Disposition: attachment; filename="=?UTF-8?B?xa8iXD94LnR4dA==?="
Content-Transfer-Encoding: base64
X-Attachment-Id: f_kfzgl8310
Content-ID: <f_kfzgl8310>

@milo
Copy link
Member

milo commented Oct 7, 2020

When sending ".txt.
Thunderbird

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

GMail

Content-Type: text/plain; charset="US-ASCII"; name="\".txt"
Content-Disposition: attachment; filename="\".txt"
Content-Transfer-Encoding: base64
Content-ID: <f_kfzgqenu0>
X-Attachment-Id: f_kfzgqenu0

@dg
Copy link
Member

dg commented Oct 7, 2020

Thanks!

@dg
Copy link
Member

dg commented Oct 7, 2020

Just to be sure, can you check also \ alone?

@dg dg closed this as completed in 95307ab Oct 7, 2020
@milo
Copy link
Member

milo commented Oct 8, 2020

Thunderbird "

Content-Type: text/plain; charset=UTF-8;
 name="\""
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="\""

\

Content-Type: text/plain; charset=UTF-8;
 name="\\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="\\"

@milo
Copy link
Member

milo commented Oct 8, 2020

And long ones (160 chars):
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
and
ž23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789ž

in Thunderbird:

Content-Type: text/plain; charset=UTF-8;
 name="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename*0="123456789012345678901234567890123456789012345678901234567890";
 filename*1="123456789012345678901234567890123456789012345678901234567890";
 filename*2="1234567890123456789012345678901234567890"
Content-Type: text/plain; charset=UTF-8;
 name="=?UTF-8?Q?=c5=be2345678901234567890123456789012345678901234567890123?=
 =?UTF-8?Q?45678901234567890123456789012345678901234567890123456789012?=
 =?UTF-8?Q?34567890123456789012345678901234567890123456789=c5=be?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename*0*=UTF-8''%C5%BE%32%33%34%35%36%37%38%39%30%31%32%33%34%35%36%37;
 filename*1*=%38%39%30%31%32%33%34%35%36%37%38%39%30%31%32%33%34%35%36%37;
 filename*2*=%38%39%30%31%32%33%34%35%36%37%38%39%30%31%32%33%34%35%36%37;
 filename*3*=%38%39%30%31%32%33%34%35%36%37%38%39%30%31%32%33%34%35%36%37;
 filename*4*=%38%39%30%31%32%33%34%35%36%37%38%39%30%31%32%33%34%35%36%37;
 filename*5*=%38%39%30%31%32%33%34%35%36%37%38%39%30%31%32%33%34%35%36%37;
 filename*6*=%38%39%30%31%32%33%34%35%36%37%38%39%30%31%32%33%34%35%36%37;
 filename*7*=%38%39%30%31%32%33%34%35%36%37%38%39%30%31%32%33%34%35%36%37;
 filename*8*=%38%39%C5%BE

via GMail webface

Content-Type: application/octet-stream; 
	name=1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Content-Disposition: attachment; 
	filename=1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
Content-Transfer-Encoding: base64
Content-ID: <f_kg0oa0110>
X-Attachment-Id: f_kg0oa0110
Content-Type: application/octet-stream; 
	name="=?UTF-8?Q?=C5=BE23456789012345678901234567890123456789012345678901234567?=
	=?UTF-8?Q?890123456789012345678901234567890123456789012345678901234567?=
	=?UTF-8?Q?890123456789012345678901234567890123456789=C5=BE?="
Content-Disposition: attachment; 
	filename="=?UTF-8?Q?=C5=BE23456789012345678901234567890123456789012345678901234567?=
	=?UTF-8?Q?890123456789012345678901234567890123456789012345678901234567?=
	=?UTF-8?Q?890123456789012345678901234567890123456789=C5=BE?="
Content-Transfer-Encoding: base64
Content-ID: <f_kg0oa04b1>
X-Attachment-Id: f_kg0oa04b1

@dg
Copy link
Member

dg commented Oct 8, 2020

Thanks! Now it should work correctly

@nette nette deleted a comment Apr 14, 2021
@nette nette deleted a comment Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants