public function PHPMailer::DKIM_HeaderC
Search API
5.x PHPMailer.php | public PHPMailer::DKIM_HeaderC($signHeader) |
Generate a DKIM canonicalization header. Uses the 'relaxed' algorithm from RFC6376 section 3.4.2. Canonicalized headers should *always* use CRLF, regardless of mailer setting.
Parameters
string $signHeader Header:
Return value
string
See also
https://tools.ietf.org/html/rfc6376#section-3.4.2
1 call to PHPMailer::DKIM_HeaderC()
- PHPMailer::DKIM_Add in inc/
PHPMailer/ src/ PHPMailer.php - Create the DKIM header and body in a new message header.
File
- inc/
PHPMailer/ src/ PHPMailer.php, line 4351
Class
- PHPMailer
- PHPMailer - PHP email creation and transport class.
Namespace
PHPMailer\PHPMailerCode
public function DKIM_HeaderC($signHeader)
{
//Unfold all header continuation lines
//Also collapses folded whitespace.
//Note PCRE \s is too broad a definition of whitespace; RFC5322 defines it as `[ \t]`
//@see https://tools.ietf.org/html/rfc5322#section-2.2
//That means this may break if you do something daft like put vertical tabs in your headers.
$signHeader = preg_replace('/\r\n[ \t]+/', ' ', $signHeader);
$lines = explode("\r\n", $signHeader);
foreach ($lines as $key => $line) {
//If the header is missing a :, skip it as it's invalid
//This is likely to happen because the explode() above will also split
//on the trailing LE, leaving an empty line
if (strpos($line, ':') === false) {
continue;
}
list($heading, $value) = explode(':', $line, 2);
//Lower-case header name
$heading = strtolower($heading);
//Collapse white space within the value
$value = preg_replace('/[ \t]{2,}/', ' ', $value);
//RFC6376 is slightly unclear here - it says to delete space at the *end* of each value
//But then says to delete space before and after the colon.
//Net result is the same as trimming both ends of the value.
//by elimination, the same applies to the field name
$lines [$key] = trim($heading, " \t") . ':' . trim($value, " \t");
}
return implode("\r\n", $lines);
}