/** * Add the signature to the given Headers * * @param Swift_Mime_HeaderSet $headers * @return Swift_Signers_DKIMSigner */ 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); $this->_endOfHeaders(); 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; }
/** * Create a new ParameterizedHeader with $name, $value and $params. * @param string $name * @param string $value * @param array $params * @return Swift_Mime_ParameterizedHeader */ public function createParameterizedHeader($name, $value = null, $params = array()) { $header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->_encoder, strtolower($name) == 'content-disposition' ? $this->_paramEncoder : null); if (isset($value)) { $header->setFieldBodyModel($value); } foreach ($params as $k => $v) { $header->setParameter($k, $v); } $this->_setHeaderCharset($header); return $header; }
private function _getHeader($name, $encoder, $paramEncoder) { $header = new Swift_Mime_Headers_ParameterizedHeader($name, $encoder, $paramEncoder, new Swift_Mime_Grammar()); $header->setCharset($this->_charset); return $header; }