See 6x issue: http://drupal.org/node/1029134
User Agents, such as Thunderbird, Apple Mail or iOS Mail, encodes both subject and filenames using ISO-8859-1, UTF8 or other if a special caracter is present in it.
For example, a mail with subject "Fwd : boite à lettres' appears as : Fwd: boites =?ISO-8859-1?Q?=E0_lettres?= ... Ugly.
Here is my fix for 7.x
In mailhandler/plugins/commands_plugin/MailhandlerCommandsFiles.class.php in line 20, replace:
$filename = $attachment->filename;
with
$filename = mb_decode_mimeheader($attachment->filename);
In mailhandler/plugins/commands_plugin/MailhandlerCommandsHeaders.class.php in line 18, replace:
$message[$key] = $value;
with
if ( in_array($key, array('Subject', 'subject') )) {
$message[$key] = iconv_mime_decode($value,0,"UTF-8");
}
else
{
$message[$key] = $value;
} I used iconv_mime_decode(); because imap_utf8(); translatet everything in to UPPERCASE. This is a known bug: https://bugs.php.net/bug.php?id=44098
Comments
Comment #1
danepowell commentedThanks for contributing a fix, and also an example... I will have to try that. One question: why do you use
iconv_mime_decode()in one place andmb_decode_mimeheader()in the other? I see that in the patch in #1029134: A way to clean ISO-8859-1 embedded in mail subjects or filenames,mb_decode_mimeheader()is used in both places...Comment #2
danepowell commentedI've committed a variation of this. For the files parser, I replaced imap_utf8 with mb_decode_mimeheader. I chose to use mb_decode_mimeheader instead of iconv_mime_decode because mb_decode_mimeheader is supposedly more portable (see http://beeznest.wordpress.com/2008/04/22/mbstring-vs-iconv/). Please test and let me know if you have any suggestions.
Commit:
http://drupal.org/commitlog/commit/96/73225d7082e79895d584530d71a347b236...
Comment #4
kloewer commentedmb_decode_mimeheader() keeps underscores
mb_decode_mimeheader() leaves the underscores in the string. Thats OK or even perfect for filenames, but not so handy for email subjects or text strings in general.
iconv_mime_decode() on the other hand removes unnecessary underscores made by the ISO-8859-1, but keeps the ones the user set intentionally.
See comments:
http://php.net/manual/de/function.mb-decode-mimeheader.php
http://php.net/manual/en/function.iconv-mime-decode.php
Comment #5
danepowell commentedThanks for the tip. Please test the dev release tonight and let me know if it works for you.
http://drupal.org/commitlog/commit/96/378b21514075d3e5e5a6bf604a26c53881...
http://drupal.org/commitlog/commit/96/7622ca2edf13adbd8164726401330461c3...