Make WordPress Core

Ticket #51311: 51311.patch

File 51311.patch, 10.6 KB (added by ayeshrajans, 5 years ago)

Tests: https://travis-ci.com/github/Ayesh/wordpress-develop/builds/184375019

  • phpcompat.xml.dist

    diff --git a/phpcompat.xml.dist b/phpcompat.xml.dist
    index 5af8e2a503..2eedf7851b 100644
    a b  
    4040        -->
    4141        <exclude-pattern>/vendor/*</exclude-pattern>
    4242
     43        <!-- Exclude PHPMailer library from checks -->
     44        <exclude-pattern>/src/wp-includes/PHPMailer/*</exclude-pattern>
     45
    4346        <!--
    4447                PHPCompatibilityParagonieSodiumCompat prevents false positives in `sodium_compat`.
    4548                However, because these files are included in a non-standard path, false positives are triggered in WordPress Core.
  • src/wp-includes/PHPMailer/PHPMailer.php

    diff --git a/src/wp-includes/PHPMailer/PHPMailer.php b/src/wp-includes/PHPMailer/PHPMailer.php
    index 27af1a937b..2d4156f4e8 100644
    a b class PHPMailer 
    441441     * Only supported in `mail` and `sendmail` transports, not in SMTP.
    442442     *
    443443     * @var bool
     444     *
     445     * @deprecated 6.0.0 PHPMailer isn't a mailing list manager!
    444446     */
    445447    public $SingleTo = false;
    446448
    class PHPMailer 
    745747     *
    746748     * @var string
    747749     */
    748     const VERSION = '6.1.6';
     750    const VERSION = '6.1.7';
    749751
    750752    /**
    751753     * Error severity: message only, continue processing.
    public function __destruct() 
    853855    private function mailPassthru($to, $subject, $body, $header, $params)
    854856    {
    855857        //Check overloading of mail function to avoid double-encoding
    856         if (ini_get('mbstring.func_overload') & 1) { // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
     858        if (ini_get('mbstring.func_overload') & 1) {
    857859            $subject = $this->secureHeader($subject);
    858860        } else {
    859861            $subject = $this->encodeHeader($this->secureHeader($subject));
    public static function validateAddress($address, $patternselect = null) 
    13071309            $patternselect = static::$validator;
    13081310        }
    13091311        if (is_callable($patternselect)) {
    1310             return $patternselect($address);
     1312            return call_user_func($patternselect, $address);
    13111313        }
    13121314        //Reject line breaks in addresses; it's valid RFC5322, but not RFC5321
    13131315        if (strpos($address, "\n") !== false || strpos($address, "\r") !== false) {
    public function punyencodeAddress($address) 
    14011403                //Ignore IDE complaints about this line - method signature changed in PHP 5.4
    14021404                $errorcode = 0;
    14031405                if (defined('INTL_IDNA_VARIANT_UTS46')) {
    1404                     // phpcs:ignore PHPCompatibility.ParameterValues.NewIDNVariantDefault.NotSet
    14051406                    $punycode = idn_to_ascii($domain, $errorcode, INTL_IDNA_VARIANT_UTS46);
    14061407                } elseif (defined('INTL_IDNA_VARIANT_2003')) {
    1407                     // phpcs:ignore PHPCompatibility.Constants.RemovedConstants.intl_idna_variant_2003Deprecated
    14081408                    $punycode = idn_to_ascii($domain, $errorcode, INTL_IDNA_VARIANT_2003);
    14091409                } else {
    1410                     // phpcs:ignore PHPCompatibility.ParameterValues.NewIDNVariantDefault.NotSet
    14111410                    $punycode = idn_to_ascii($domain, $errorcode);
    14121411                }
    14131412                if (false !== $punycode) {
    public function addAttachment( 
    29782977            if ('' === $name) {
    29792978                $name = $filename;
    29802979            }
    2981 
    29822980            if (!$this->validateEncoding($encoding)) {
    29832981                throw new Exception($this->lang('encoding') . $encoding);
    29842982            }
    public function getCustomHeaders() 
    39933991     * @param string        $message  HTML message string
    39943992     * @param string        $basedir  Absolute path to a base directory to prepend to relative paths to images
    39953993     * @param bool|callable $advanced Whether to use the internal HTML to text converter
    3996      *                                or your own custom converter @return string $message The transformed message Body
     3994     *                                or your own custom converter
     3995     * @return string The transformed message body
    39973996     *
    39983997     * @throws Exception
    39993998     *
    public function msgHTML($message, $basedir = '', $advanced = false) 
    41174116    public function html2text($html, $advanced = false)
    41184117    {
    41194118        if (is_callable($advanced)) {
    4120             return $advanced($html);
     4119            return call_user_func($advanced, $html);
    41214120        }
    41224121
    41234122        return html_entity_decode(
  • src/wp-includes/PHPMailer/SMTP.php

    diff --git a/src/wp-includes/PHPMailer/SMTP.php b/src/wp-includes/PHPMailer/SMTP.php
    index aa5555149a..6b0b73ddd9 100644
    a b class SMTP 
    3434     *
    3535     * @var string
    3636     */
    37     const VERSION = '6.1.6';
     37    const VERSION = '6.1.7';
    3838
    3939    /**
    4040     * SMTP line break constant.
    protected function edebug($str, $level = 0) 
    311311     */
    312312    public function connect($host, $port = null, $timeout = 30, $options = [])
    313313    {
    314         static $streamok;
    315         //This is enabled by default since 5.0.0 but some providers disable it
    316         //Check this once and cache the result
    317         if (null === $streamok) {
    318             $streamok = function_exists('stream_socket_client');
    319         }
    320314        // Clear errors to avoid confusion
    321315        $this->setError('');
    322316        // Make sure we are __not__ connected
    public function connect($host, $port = null, $timeout = 30, $options = []) 
    335329            (count($options) > 0 ? var_export($options, true) : 'array()'),
    336330            self::DEBUG_CONNECTION
    337331        );
     332
     333        $this->smtp_conn = $this->getSMTPConnection($host, $port, $timeout, $options);
     334
     335        if ($this->smtp_conn === false) {
     336            //Error info already set inside `getSMTPConnection()`
     337            return false;
     338        }
     339
     340        $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
     341
     342        // Get any announcement
     343        $this->last_reply = $this->get_lines();
     344        $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
     345
     346        return true;
     347    }
     348
     349    /**
     350     * Create connection to the SMTP server.
     351     *
     352     * @param string $host    SMTP server IP or host name
     353     * @param int    $port    The port number to connect to
     354     * @param int    $timeout How long to wait for the connection to open
     355     * @param array  $options An array of options for stream_context_create()
     356     *
     357     * @return false|resource
     358     */
     359    protected function getSMTPConnection($host, $port = null, $timeout = 30, $options = [])
     360    {
     361        static $streamok;
     362        //This is enabled by default since 5.0.0 but some providers disable it
     363        //Check this once and cache the result
     364        if (null === $streamok) {
     365            $streamok = function_exists('stream_socket_client');
     366        }
     367
    338368        $errno = 0;
    339369        $errstr = '';
    340370        if ($streamok) {
    341371            $socket_context = stream_context_create($options);
    342372            set_error_handler([$this, 'errorHandler']);
    343             $this->smtp_conn = stream_socket_client(
     373            $connection = stream_socket_client(
    344374                $host . ':' . $port,
    345375                $errno,
    346376                $errstr,
    public function connect($host, $port = null, $timeout = 30, $options = []) 
    356386                self::DEBUG_CONNECTION
    357387            );
    358388            set_error_handler([$this, 'errorHandler']);
    359             $this->smtp_conn = fsockopen(
     389            $connection = fsockopen(
    360390                $host,
    361391                $port,
    362392                $errno,
    public function connect($host, $port = null, $timeout = 30, $options = []) 
    365395            );
    366396            restore_error_handler();
    367397        }
     398
    368399        // Verify we connected properly
    369         if (!is_resource($this->smtp_conn)) {
     400        if (!is_resource($connection)) {
    370401            $this->setError(
    371402                'Failed to connect to server',
    372403                '',
    public function connect($host, $port = null, $timeout = 30, $options = []) 
    381412
    382413            return false;
    383414        }
    384         $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
     415
    385416        // SMTP server can take longer to respond, give longer timeout for first read
    386417        // Windows does not have support for this timeout function
    387418        if (strpos(PHP_OS, 'WIN') !== 0) {
    388             $max = (int) ini_get('max_execution_time');
     419            $max = (int)ini_get('max_execution_time');
    389420            // Don't bother if unlimited
    390421            if (0 !== $max && $timeout > $max) {
    391422                @set_time_limit($timeout);
    392423            }
    393             stream_set_timeout($this->smtp_conn, $timeout, 0);
     424            stream_set_timeout($connection, $timeout, 0);
    394425        }
    395         // Get any announcement
    396         $announce = $this->get_lines();
    397         $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
    398426
    399         return true;
     427        return $connection;
    400428    }
    401429
    402430    /**
    protected function get_lines() 
    11661194        $selW = null;
    11671195        while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
    11681196            //Must pass vars in here as params are by reference
    1169             if (!stream_select($selR, $selW, $selW, $this->Timelimit)) {
     1197            //solution for signals inspired by https://github.com/symfony/symfony/pull/6540
     1198            set_error_handler([$this, 'errorHandler']);
     1199            $n = stream_select($selR, $selW, $selW, $this->Timelimit);
     1200            restore_error_handler();
     1201
     1202            if ($n === false) {
     1203                $message = $this->getError()['detail'];
     1204
     1205                $this->edebug(
     1206                    'SMTP -> get_lines(): select failed (' . $message . ')',
     1207                    self::DEBUG_LOWLEVEL
     1208                );
     1209
     1210                //stream_select returns false when the `select` system call is interrupted by an incoming signal, try the select again
     1211                if (stripos($message, 'interrupted system call') !== false) {
     1212                    $this->edebug(
     1213                        'SMTP -> get_lines(): retrying stream_select',
     1214                        self::DEBUG_LOWLEVEL
     1215                    );
     1216                    $this->setError('');
     1217                    continue;
     1218                }
     1219
     1220                break;
     1221            }
     1222
     1223            if (!$n) {
    11701224                $this->edebug(
    11711225                    'SMTP -> get_lines(): select timed-out in (' . $this->Timelimit . ' sec)',
    11721226                    self::DEBUG_LOWLEVEL
    11731227                );
    11741228                break;
    11751229            }
     1230
    11761231            //Deliberate noise suppression - errors are handled afterwards
    11771232            $str = @fgets($this->smtp_conn, self::MAX_REPLY_LENGTH);
    11781233            $this->edebug('SMTP INBOUND: "' . trim($str) . '"', self::DEBUG_LOWLEVEL);