| Project: | Mime Mail |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
I'm getting an extra space in the mail subject when the subject has many characters. One such instance is when receiving the password reset email. It ends up being "Subject: Replacement login information for Some User Name at Some Long Site Name ((two spaces here)Secondary Name Here)".
I traced the extra space in the subject to mimemail.module where drupal_html_to_text is run. I then traced the point where the extra space was being introduced and it is in drupal/includes/mail.inc in function _drupal_wrap_mail_line. As the subject is longer than the 77 characters for the wordwrap call, two extra spaces and a newline are added as a string break character. As it is necessary to rewrite any HTML that might happen to end up in the subject (see: #369983: Plain text Email subject shows & as _amp; and " as _quot; ), the drupal_html_to_text call can't be eliminated.
It seems to me from #438058: Remove line feeds in subject that people were experiencing mail client breakage from the subject newlines, even though RFC 2822 says they should be OK. To fix this, the str_replace call was then added to remove the newlines.
An extra space would still exist in long subjects even after the str_replace. A quick fix is to replace in the mimemail.module for mimemail_prepare_message:$subject = str_replace("\n", '', trim(drupal_html_to_text($subject)));
with:$subject = str_replace("\n", '', str_replace(" \n", '', trim(drupal_html_to_text($subject))));
I'm not sure if this has any undesirable side-effects, however. Obviously my change could be refactored to look better as well. After the change, my email subjects look like they should without the extra space.
Comments
#1
There is no need to call str_replace twice, since we can use an array to designate multiple needles. Please test the attached patch and report back.
#2
Committed to both branches.
#3
Automatically closed -- issue fixed for 2 weeks with no activity.