public function addSignature(Swift_Mime_HeaderSet $headers)
{
// Prepare the DKIM-Signature
$params = array('v' => '1', 'a' => $this->hashAlgorithm, 'bh' => base64_encode($this->bodyHash), 'd' => $this->domainName, 'h' => implode(': ', $this->signedHeaders), 'i' => $this->signerIdentity, 's' => $this->selector);
if ($this->bodyCanon != 'simple') {
$params['c'] = $this->headerCanon . '/' . $this->bodyCanon;
} elseif ($this->headerCanon != 'simple') {
$params['c'] = $this->headerCanon;
}
if ($this->showLen) {
$params['l'] = $this->bodyLen;
}
if ($this->signatureTimestamp === true) {
$params['t'] = time();
if ($this->signatureExpiration !== false) {
$params['x'] = $params['t'] + $this->signatureExpiration;
}
} else {
if ($this->signatureTimestamp !== false) {
$params['t'] = $this->signatureTimestamp;
}
if ($this->signatureExpiration !== false) {
$params['x'] = $this->signatureExpiration;
}
}
if ($this->debugHeaders) {
$params['z'] = implode('|', $this->debugHeadersData);
}
$string = '';
foreach ($params as $k => $v) {
$string .= $k . '=' . $v . '; ';
}
$string = trim($string);
$headers->addTextHeader('DKIM-Signature', $string);
// Add the last DKIM-Signature
$tmp = $headers->getAll('DKIM-Signature');
$this->dkimHeader = end($tmp);
$this->addHeader(trim($this->dkimHeader->toString()) . "\r\n b=", true);
if ($this->debugHeaders) {
$headers->addTextHeader('X-DebugHash', base64_encode($this->headerHash));
}
$this->dkimHeader->setValue($string . ' b=' . trim(chunk_split(base64_encode($this->getEncryptedHash()), 73, ' ')));
return $this;
}