drupal_html_to_text inserts LF in subject causing outgoing e-mail to fail

Ken Knowles - April 19, 2009 - 05:17
Project:Mime Mail
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:fixed
Description

The encoding of the subject includes a call to drupal_html_to_text. This function is probably not necessary for the subject line since any HTML in the subject line would not be rendered (that I know of). Although it shouldn't cause a problem with the encoding, drupal_html_to_text occasionally inserts a linefeed. This corrupts the subject line and causes the call to the PHP mail function to fail.

Attached is a patch to eliminate the call to drupal_html_to_text for the subject only.

AttachmentSize
Patch to remove call to drupal_html_to_text673 bytes

#1

mhdg - May 6, 2009 - 09:57

Using Notifications module with mime mail, SpamAssasin was telling me that : "1.5 SUBJECT_ENCODED_TWICE Subject: MIME encoded twice"

Subject: =?UTF-8?B?dGVzdC5pbnRlcmZpbmFuY2Uub3JnIHN1YnNjcmlwdGlvbiB1cGRhdGUgZm9yIG0=?= =?UTF-8?B?aWNoZWxAaGRnLmJlCg==?=

After patching:

function mime_header_encode($string) {
  return $string; // added for test
  if (preg_match('/[^\x20-\x7E]/', $string)) {
    $chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75);
    $len = strlen($string);
    $output = '';
    while ($len > 0) {
      $chunk = drupal_truncate_bytes($string, $chunk_size);
      $output .= ' =?UTF-8?B?'. base64_encode($chunk) ."?=\n";
      $c = strlen($chunk);
      $string = substr($string, $c);
      $len -= $c;
    }
    return trim($output);
  }
  return $string;
}

I got:
Subject: =?UTF-8?B?Tm90aWZpY2F0aW9ucyBkaWdlc3QK?=

Then I revert the change in mime_header_encode and applying the patch (eliminate the call to drupal_html_to_text for the subject only)

I got a correct result:
Subject: Notifications digest

Conclusion: correct solution, no false spam anymore.

Michel

#2

a_c_m - June 5, 2009 - 00:19

We've noticed this too. We are using phpmailer as well, and outlook users are seeing a square char at the end of each subject line.

Will test this and report back.

#3

derjochenmeyer - June 29, 2009 - 11:02

Patch works. After patching the subject looks good in outlook.

AttachmentSize
square_char_bug.gif 3.45 KB

#4

Peter Bex - July 2, 2009 - 09:05

+1 on this bugfix. It removes the weird little square.

Actually, some versions of Outlook behave even worse; they think that the email body starts after that linefeed. So when the user opens his mail, all he sees is the raw message contents, starting with the header following "Subject:".
I see similar behaviour in mutt, only less extreme; it shows one or two headers (To and Date) as text contents of the mail, but it still shows the different mime parts as different attachments.

I didn't get the error described by the OP, though. Perhaps that depends on the particular MTA used?

It would be great if this patch could be integrated in the next release of MimeMail.

#5

muhleder - September 16, 2009 - 09:16

+1 on this, we're seeing this issue too.

#6

mrfelton - October 23, 2009 - 12:26

+ 1 from me too. Thanks

#7

Damien Tournoud - November 5, 2009 - 15:21
Status:active» fixed

This has been fixed by http://drupal.org/cvs?commit=214382 a while ago.

 
 

Drupal is a registered trademark of Dries Buytaert.