Thanks for this splendid module...
The problem :
User Agents, such as Thunderbird, 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.
The issue :
Maybe this is not the right way to address the problem, I am a newbie into Drupal... but this hack works for me...
I have changed Mailhandlerparser.inc to run mb_decode_mimeheader before sending back the result :
public function parseAttachments(&$message) {
$message['attachments'] = array();
foreach ($message['mimeparts'] as $attachment) {
// 'unnamed_attachment' files are not really attachments, but mimeparts like HTML or Plain Text.
// We only want to save real attachments, like images and files.
if ($attachment->filename !== 'unnamed_attachment') {
$cleanfilename = mb_decode_mimeheader($attachment->filename);
$file = file_save_data($attachment->data, file_directory_temp() . '/' . $cleanfilename);
$message['attachments'][] = new FeedsEnclosure($file, $attachment->filemime);
}
}
and
public function parseExtensions(&$message) {
// Populate $message with all values from 'header' object.
$parts = (array) $message['header'];
foreach ($parts as $key => $value) {
// Some keys are already taken, so do not overwrite them.
if (!in_array($key, array('header', 'origbody', 'mimeparts', 'mailbox', 'attachments'))) {
if ( $key == array('subject') ) {
$message[$key] = $value;
}
else
{
$message[$key] = mb_decode_mimeheader($value);
}
}
}
}
This way, filenames and subjects are now nice....
Attached the file (built on the version of january 14th 2011). Sorry, I don't know how to create a patch file ...
Hope this helps... I spent hours finding a solution, after trying to set up lots of input filters ...
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | Iso88591.patch | 1.88 KB | laurent.lemercier |
| #3 | MailhandlerParser2.txt | 4.04 KB | laurent.lemercier |
| MailhandlerParser.inc | 3.95 KB | laurent.lemercier |
Comments
Comment #1
cor3huis commentedSame unwanted side-effect seen for the D6 1.x version as I recall from top of my head.
Do not know if solution is correct way, but someone who can test this and look into the issue, that would be appreciated
Comment #2
ilo commentednice catch, should go into the parser's scope.
Comment #3
laurent.lemercier commentedFor those who are interested by this issue.
The first correction seems to be completely OK.
The second one, depending on the entry, throws an error : mb_decode_mimeheader() expects parameter 1 to be string, array given dans ROOTDIR/sites/all/modules/mailhandler/plugins/MailhandlerParser.inc à la ligne 79
I changed the treatment to the following, and it runs better :
Comment #4
ilo commentedAny particular reason why you moved this to 7.x-1.x-dev?
Comment #5
laurent.lemercier commentedThank you for this point, I didn't notice it. I am still on 6.x-2.x-dev.
Comment #6
danepowell commentedCan someone roll a patch, test, and get this to RTBC?
Comment #7
laurent.lemercier commentedHere you are (made against the latest version of 6x.2x of 2011-May-19, with Eclipse and EGit).
Hope it works, I have not time to test at the moment.
This is my first patch in Drupal environment... Keep cool if it doesn't !
Comment #8
danepowell commentedThanks for the patch, someone else will need to review it to get it to RTBC.
Comment #9
kloewer commentedSee fix for 7.x: http://drupal.org/node/1312694
Comment #10
danepowell commentedI've committed this, although I'd still appreciate further testing:
http://drupal.org/commitlog/commit/96/363a067d7e22af3e01eb68c919a4294b32...