wppaste
WordPress

PHPMailer::DKIM_Add( string $headers_line, string $subject, string $body ): string

Source
wp-includes/PHPMailer/PHPMailer.php:5324
Create the DKIM header and body in a new message header.

Compatibility

WordPress
core
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$headers_linestring
Header lines
$subjectstring
Subject
$bodystring
Body

Return value

string

Performance profile

How much work a call to PHPMailer::DKIM_Add() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
115–138

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 273.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost PHPMailer::DKIM_Add() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always115–138time(), stripos(), explode(), ->DKIM_BodyC(), hash(), pack(), base64_encode(), ->DKIM_HeaderC(), ->DKIM_Sign(), chunk_split(), ::normalizeBreaks()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev273115–13823
8.5273115–13823
8.4273115–1382321 fewer instructions than PHP 8.3
8.3294124–14723
8.2294124–14723
8.1294124–14723
7.4294124–14723

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 6

  • stripos()
  • \PHPMailer\PHPMailer\PHPMailer::DKIM_QP()
  • \PHPMailer\PHPMailer\PHPMailer::DKIM_BodyC()
  • \PHPMailer\PHPMailer\PHPMailer::DKIM_HeaderC()
  • \PHPMailer\PHPMailer\PHPMailer::DKIM_Sign()
  • static::normalizeBreaks()

Source code

    public function DKIM_Add($headers_line, $subject, $body)    {        $DKIMsignatureType = 'rsa-sha256'; //Signature & hash algorithms        $DKIMcanonicalization = 'relaxed/simple'; //Canonicalization methods of header & body        $DKIMquery = 'dns/txt'; //Query method        $DKIMtime = time();        //Always sign these headers without being asked        //Recommended list from https://www.rfc-editor.org/rfc/rfc6376#section-5.4.1        $autoSignHeaders = [            'from',            'to',            'cc',            'date',            'subject',            'reply-to',            'message-id',            'content-type',            'mime-version',            'x-mailer',        ];        if (stripos($headers_line, 'Subject') === false) {            $headers_line .= 'Subject: ' . $subject . static::$LE;        }        $headerLines = explode(static::$LE, $headers_line);        $currentHeaderLabel = '';        $currentHeaderValue = '';        $parsedHeaders = [];        $headerLineIndex = 0;        $headerLineCount = count($headerLines);        foreach ($headerLines as $headerLine) {            $matches = [];            if (preg_match('/^([^ \t]*?)(?::[ \t]*)(.*)$/', $headerLine, $matches)) {                if ($currentHeaderLabel !== '') {                    //We were previously in another header; This is the start of a new header, so save the previous one                    $parsedHeaders[] = ['label' => $currentHeaderLabel, 'value' => $currentHeaderValue];                }                $currentHeaderLabel = $matches[1];                $currentHeaderValue = $matches[2];            } elseif (preg_match('/^[ \t]+(.*)$/', $headerLine, $matches)) {                //This is a folded continuation of the current header, so unfold it                $currentHeaderValue .= ' ' . $matches[1];            }            ++$headerLineIndex;            if ($headerLineIndex >= $headerLineCount) {                //This was the last line, so finish off this header                $parsedHeaders[] = ['label' => $currentHeaderLabel, 'value' => $currentHeaderValue];            }        }        $copiedHeaders = [];        $headersToSignKeys = [];        $headersToSign = [];        foreach ($parsedHeaders as $header) {            //Is this header one that must be included in the DKIM signature?            if (in_array(strtolower($header['label']), $autoSignHeaders, true)) {                $headersToSignKeys[] = $header['label'];                $headersToSign[] = $header['label'] . ': ' . $header['value'];                if ($this->DKIM_copyHeaderFields) {                    $copiedHeaders[] = $header['label'] . ':' . //Note no space after this, as per RFC                        str_replace('|', '=7C', $this->DKIM_QP($header['value']));                }                continue;            }            //Is this an extra custom header we've been asked to sign?            if (in_array($header['label'], $this->DKIM_extraHeaders, true)) {                //Find its value in custom headers                foreach ($this->CustomHeader as $customHeader) {                    if ($customHeader[0] === $header['label']) {                        $headersToSignKeys[] = $header['label'];                        $headersToSign[] = $header['label'] . ': ' . $header['value'];                        if ($this->DKIM_copyHeaderFields) {                            $copiedHeaders[] = $header['label'] . ':' . //Note no space after this, as per RFC                                str_replace('|', '=7C', $this->DKIM_QP($header['value']));                        }                        //Skip straight to the next header                        continue 2;                    }                }            }        }        $copiedHeaderFields = '';

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/PHPMailer/PHPMailer.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.