PHPMailer\PHPMailer\PHPMailer::DKIM_HeaderC PHP Method

DKIM_HeaderC() public method

Uses the 'relaxed' algorithm from RFC6376 section 3.4.2
public DKIM_HeaderC ( string $signHeader ) : string
$signHeader string Header
return string
    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]
        //@link 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 CRLF, 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");
        }
        $signHeader = implode("\r\n", $lines);
        return $signHeader;
    }