function _drupal_wrap_mail_line

Wraps words on a single line.

Callback for array_walk() winthin drupal_wrap_mail().

Note that we are skipping MIME content header 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., the attached file hello_drupal.docx will produce the following Content-Type: Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document; name="hello_drupal.docx"

1 call to _drupal_wrap_mail_line()
drupal_wrap_mail in drupal/core/includes/mail.inc
Performs format=flowed soft wrapping for mail (RFC 3676).
1 string reference to '_drupal_wrap_mail_line'
drupal_wrap_mail in drupal/core/includes/mail.inc
Performs format=flowed soft wrapping for mail (RFC 3676).

File

drupal/core/includes/mail.inc, line 538
API functions for processing and sending e-mail.

Code

function _drupal_wrap_mail_line(&$line, $key, $values) {
  $line_is_mime_header = FALSE;
  $mime_headers = array(
    'Content-Type',
    'Content-Transfer-Encoding',
    'Content-Disposition',
    'Content-Description',
  );

  // Do not break MIME headers which could be longer than 77 characters.
  foreach ($mime_headers as $header) {
    if (strpos($line, $header . ': ') === 0) {
      $line_is_mime_header = TRUE;
      break;
    }
  }
  if (!$line_is_mime_header) {

    // Use soft-breaks only for purely quoted or unindented text.
    $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");
}