wppaste
WordPress

PHPMailer::parseAddresses( string $addrstr, bool|null $useimap = null, string $charset = self::CHARSET_ISO88591 ): array

Source
wp-includes/PHPMailer/PHPMailer.php:1301
Parse and validate a string containing one or more RFC822-style comma-separated email addresses of the form "display name " into an array of name/address pairs.

Description

Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available and the deprecated $useimap argument is truthy.
Note that quotes in the name part are removed.

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

$addrstrstring
The address list string
$useimapbool|nulloptional
Deprecated in PHPMailer 6.11.0.
Truthy values request the deprecated IMAP parser and trigger a deprecation warning.Default: null
$charsetstringoptional
The charset to use when decoding the address list string.Default: self::CHARSET_ISO88591

Return value

array

Performance profile

How much work a call to PHPMailer::parseAddresses() 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
14–31

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

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 · 6 distinct outcomes

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

WhenInstructionsCalls it makes
$useimap != true14::parseSimplerAddresses()
$useimap != true && $useimap == true && !function_exists()18function_exists(), ::parseSimplerAddresses()
$useimap != true && $useimap == true && function_exists()22–23function_exists(), imap_rfc822_parse_adrlist(), imap_errors()
$useimap == true && $useimap != true22::lang(), trigger_error(), ::parseSimplerAddresses()
$useimap == true && !function_exists()26::lang(), trigger_error(), function_exists(), ::parseSimplerAddresses()
$useimap == true && function_exists()30–31::lang(), trigger_error(), function_exists(), imap_rfc822_parse_adrlist(), imap_errors()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7814–3111
8.57814–31112 more instructions than PHP 8.4
8.47612–29116 fewer instructions than PHP 8.3
8.38212–2911
8.28212–2911
8.18212–29111 fewer instruction than PHP 7.4
7.48312–2911

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 · 4

  • \PHPMailer\PHPMailer\PHPMailer::lang()
  • static::validateAddress()
  • static::decodeHeader()
  • static::parseSimplerAddresses()

Source code

    public static function parseAddresses($addrstr, $useimap = null, $charset = self::CHARSET_ISO88591)    {        if ($useimap == true) {            trigger_error(self::lang('deprecated_argument') . '$useimap', E_USER_DEPRECATED);        }        $addresses = [];        if ($useimap == true && function_exists('imap_rfc822_parse_adrlist')) {            //Use this built-in parser if it's available            // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.imap_rfc822_parse_adrlistRemoved -- wrapped in function_exists()            $list = imap_rfc822_parse_adrlist($addrstr, '');            // Clear any potential IMAP errors to get rid of notices being thrown at end of script.            // phpcs:ignore PHPCompatibility.FunctionUse.RemovedFunctions.imap_errorsRemoved -- wrapped in function_exists()            imap_errors();            foreach ($list as $address) {                if (                    '.SYNTAX-ERROR.' !== $address->host &&                    static::validateAddress($address->mailbox . '@' . $address->host)                ) {                    //Decode the name part if it's present and maybe encoded                    if (                        property_exists($address, 'personal')                        && is_string($address->personal)                        && $address->personal !== ''                    ) {                        $address->personal = static::decodeHeader($address->personal, $charset);                    }                     $addresses[] = [                        'name' => (property_exists($address, 'personal') ? $address->personal : ''),                        'address' => $address->mailbox . '@' . $address->host,                    ];                }            }        } else {            //Use this simpler parser            $addresses = static::parseSimplerAddresses($addrstr, $charset);        }         return $addresses;    }

Changelog

2 changes between 6.7.7 and 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.

7.1.0
Parameter $useimap retyped from null to bool|null.verified against source
6.9.7
Parameter $useimap retyped from bool to null.verified against source

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.