Swift_Signers_DKIMSigner::addSignature PHP Method

addSignature() public method

Add the signature to the given Headers.
public addSignature ( Swift_Mime_HeaderSet $headers ) : Swift_Signers_DKIMSigner
$headers Swift_Mime_HeaderSet
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);
        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;
    }

Usage Example

Example #1
0
 public function addSignature(Swift_Mime_HeaderSet $headers)
 {
     if (!$this->_peclLoaded) {
         return parent::addSignature($headers);
     } else {
         dkim_eom($this->_dkimHandler);
         $headers->addTextHeader('DKIM-Signature: ', dkim_getsighdr($this->_dkimHandler));
     }
     return $this;
 }
All Usage Examples Of Swift_Signers_DKIMSigner::addSignature