diff --git a/includes/mail.inc b/includes/mail.inc index a778ac5..a0b53d6 100644 --- a/includes/mail.inc +++ b/includes/mail.inc @@ -418,10 +418,24 @@ function drupal_html_to_text($string, $allowed_tags = NULL) { * Helper function for array_walk in drupal_wrap_mail(). * * Wraps words on a single line. + * + * Note that we are skipping MIME content headers lines, because attached files, + * especially applications, could have long MIME types or long filenames which + * result in line length longer than the 77 characters limit and wrapping that + * line will break the e-mail format. E.g. attached file hello_drupal.docx will + * produce the following Content-Type: + * Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document; name="hello_drupal.docx" */ function _drupal_wrap_mail_line(&$line, $key, $values) { - // Use soft-breaks only for purely quoted or unindented text. - $line = wordwrap($line, 77 - $values['length'], $values['soft'] ? " \n" : "\n"); + // Use soft-breaks only for purely quoted or unindented text. Do not break + // MIME headers which could be longer than 77 characters. + $line_is_mime_header = strpos($line, 'Content-Type: ') === 0 + || strpos($line, 'Content-Transfer-Encoding: ') === 0 + || strpos($line, 'Content-Disposition: ') === 0 + || strpos($line, 'Content-Description: ') === 0; + if (!$line_is_mime_header) { + $line = wordwrap($line, 77 - $values['length'], $values['soft'] ? " \n" : "\n"); + } // Break really long words at the maximum width allowed. $line = wordwrap($line, 996 - $values['length'], $values['soft'] ? " \n" : "\n"); }