function mimemail_rfc_headers in Mime Mail 6
Same name and namespace in other branches
- 5 mimemail.inc \mimemail_rfc_headers()
- 7 mimemail.inc \mimemail_rfc_headers()
Attempts to RFC822-compliant headers for the mail message or its MIME parts.
@todo Could use some enhancement and stress testing.
Parameters
$headers: An array of headers.
Return value
A string containing the header.
2 calls to mimemail_rfc_headers()
- mimemail_mailengine in ./
mimemail.module - The default mailengine.
- mimemail_multipart_body in ./
mimemail.inc - Helper function to build multipart messages.
File
- ./
mimemail.inc, line 21 - Common mail functions for sending e-mail. Originally written by Gerhard.
Code
function mimemail_rfc_headers($headers) {
$header = '';
$crlf = variable_get('mimemail_crlf', "\n");
foreach ($headers as $key => $value) {
$key = trim($key);
// Collapse spaces and get rid of newline characters.
$value = preg_replace('/(\\s+|\\n|\\r|^\\s|\\s$)/', ' ', $value);
// Fold headers if they're too long.
if (drupal_strlen($value) > 60) {
// If there's a semicolon, use that to separate.
if (count($array = preg_split('/;\\s*/', $value)) > 1) {
$value = trim(join(";{$crlf} ", $array));
}
else {
$value = wordwrap($value, 50, "{$crlf} ", FALSE);
}
}
$header .= "{$key}: {$value}{$crlf}";
}
return trim($header);
}