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

danepowell’s picture

Status: Needs review » Needs work

Thanks 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 and mb_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...

danepowell’s picture

Category: bug » feature
Status: Needs work » Fixed

I'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...

kloewer’s picture

Category: feature » bug
Status: Fixed » Needs review

mb_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

danepowell’s picture

Version: 7.x-2.0-beta2 » 7.x-2.0-rc1
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.