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

Comments

cor3huis’s picture

Version: 6.x-2.x-dev » master
Status: Active » Needs review

Same 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

ilo’s picture

Status: Needs review » Needs work

nice catch, should go into the parser's scope.

laurent.lemercier’s picture

Version: master » 7.x-1.x-dev
Status: Needs work » Active
StatusFileSize
new4.04 KB

For 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 :

  public function parseExtensions(&$message) {
    // Populate $message with all values from 'header' object.
    $parts = (array) $message['header'];
    // drupal_set_message('<pre>'. print_r($parts, TRUE) .'</pre>');
    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 ( in_array($key, array('Subject', 'subject') )) {
				$message[$key] = mb_decode_mimeheader($value);		
			}	
			else
			{
				$message[$key] = $value;
			}

	    
		}
      
    }
  }
ilo’s picture

Any particular reason why you moved this to 7.x-1.x-dev?

laurent.lemercier’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev

Thank you for this point, I didn't notice it. I am still on 6.x-2.x-dev.

danepowell’s picture

Can someone roll a patch, test, and get this to RTBC?

laurent.lemercier’s picture

StatusFileSize
new1.88 KB

Here 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 !

danepowell’s picture

Status: Active » Needs review

Thanks for the patch, someone else will need to review it to get it to RTBC.

kloewer’s picture

danepowell’s picture

Category: bug » feature
Status: Needs review » Fixed

I've committed this, although I'd still appreciate further testing:
http://drupal.org/commitlog/commit/96/363a067d7e22af3e01eb68c919a4294b32...

Status: Fixed » Closed (fixed)

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