PHPMailer::DKIM_HeaderC PHP Method

DKIM_HeaderC() public method

Generate a DKIM canonicalization header.
public DKIM_HeaderC ( string $signHeader ) : string
$signHeader string Header
return string
    public function DKIM_HeaderC($signHeader)
    {
        $signHeader = preg_replace('/\\r\\n\\s+/', ' ', $signHeader);
        $lines = explode("\r\n", $signHeader);
        foreach ($lines as $key => $line) {
            list($heading, $value) = explode(':', $line, 2);
            $heading = strtolower($heading);
            $value = preg_replace('/\\s{2,}/', ' ', $value);
            // Compress useless spaces
            $lines[$key] = $heading . ':' . trim($value);
            // Don't forget to remove WSP around the value
        }
        $signHeader = implode("\r\n", $lines);
        return $signHeader;
    }

Usage Example

Example #1
0
 /**
  * DKIM header canonicalization tests.
  * @link https://tools.ietf.org/html/rfc6376#section-3.4.2
  */
 public function testDKIMHeaderCanonicalization()
 {
     //Example from https://tools.ietf.org/html/rfc6376#section-3.4.5
     $preheaders = "A: X\r\nB : Y\t\r\n\tZ  \r\n";
     $postheaders = "a:X\r\nb:Y Z\r\n";
     $this->assertEquals($this->Mail->DKIM_HeaderC($preheaders), $postheaders, 'DKIM header canonicalization incorrect');
 }