Mailhandler, non-latin encoding in attachments

When emails with non-latin encoding sent to script mail_handler.php it produce unreadable attachment names:


There is patch to fix this issue (diff to most recent version from https://secure.phabricator.com/source/phabricator/browse/master/scripts/mail/mail_handler.php):

--- /home/a.baznikin/mail_handler.php   2020-01-22 10:44:59.938357861 +0700
+++ mail_handler.php   2020-01-22 11:27:25.813930933 +0700
@@ -80,7 +80,7 @@
   $file = PhabricatorFile::newFromFileData(
     $attachment->getContent(),
     array(
-      'name' => $attachment->getFilename(),
+      'name' => phutil_decode_mime_header($attachment->getFilename()),
       'viewPolicy' => PhabricatorPolicies::POLICY_NOONE,
     ));
   $attachments[] = $file->getPHID();

Reproduction Instructions
Send file with non-latin characters in its name to to mail handler. See how it looks like.

Phabricator/Arcanist Version
My version isn’t most recent, BUT mail_handler is standalone script:
https://secure.phabricator.com/source/phabricator/browse/master/scripts/mail/mail_handler.php
Only difference - we use iconv_mime_decode not phutil_decode_mime_header (it’s the same under hood - https://secure.phabricator.com/source/libphutil/browse/master/src/utils/utils.php$1746 )

phabricator 5bcaa0f557ded7347fb17047d583f06c19be4a52 (Aug 19 2018) (branched from 75a5dd8d8cc0ba8cdf274ab509284ab4f7c0577c on origin)

arcanist 9dfa68d739ee05e806018821cd4d997307ae54f1 (Aug 7 2018) (branched from d9a4293ae734756823b4a3ca202f185c57f3e834 on origin)

phutil a16485ffb2551334027b16e7bcec86643c630fbe (Aug 19 2018) (branched from 5b341cc09ca9bb707be469c7f23bbf6a961bc593 on origin)

diff 2.8.1 at /usr/bin/diff

git 2.16.3 at /usr/bin/git

hg 2.2.2 at /usr/bin/hg

pygmentize 2.0.2 at /usr/bin/pygmentize

svn Not Available
1 Like