Make WordPress Core

Ticket #40472: 40472v2.diff

File 40472v2.diff, 10.2 KB (added by MattyRob, 8 years ago)
  • src/wp-includes/class-phpmailer.php

     
    3131     * The PHPMailer Version number.
    3232     * @var string
    3333     */
    34     public $Version = '5.2.22';
     34    public $Version = '5.2.24';
    3535
    3636    /**
    3737     * Email priority.
     
    440440     *
    441441     * Parameters:
    442442     *   boolean $result        result of the send action
    443      *   string  $to            email address of the recipient
    444      *   string  $cc            cc email addresses
    445      *   string  $bcc           bcc email addresses
     443     *   array   $to            email addresses of the recipients
     444     *   array   $cc            cc email addresses
     445     *   array   $bcc           bcc email addresses
    446446     *   string  $subject       the subject
    447447     *   string  $body          the email body
    448448     *   string  $from          email address of sender
     
    16231623
    16241624        foreach ($hosts as $hostentry) {
    16251625            $hostinfo = array();
    1626             if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) {
     1626            if (!preg_match(
     1627                '/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*|\[[a-fA-F0-9:]+\]):?([0-9]*)$/',
     1628                trim($hostentry),
     1629                $hostinfo
     1630            )) {
    16271631                // Not a valid host entry
     1632                $this->edebug('Ignoring invalid host: ' . $hostentry);
    16281633                continue;
    16291634            }
    16301635            // $hostinfo[2]: optional ssl or tls prefix
     
    17431748            'dk' => 'da',
    17441749            'no' => 'nb',
    17451750            'se' => 'sv',
     1751            'sr' => 'rs'
    17461752        );
    17471753
    17481754        if (isset($renamed_langcodes[$langcode])) {
     
    20252031    {
    20262032        $result = '';
    20272033
    2028         if ($this->MessageDate == '') {
    2029             $this->MessageDate = self::rfcDate();
    2030         }
    2031         $result .= $this->headerLine('Date', $this->MessageDate);
     2034        $result .= $this->headerLine('Date', $this->MessageDate == '' ? self::rfcDate() : $this->MessageDate);
    20322035
    20332036        // To be created automatically by mail()
    20342037        if ($this->SingleTo) {
     
    40344037     */
    40354038    public function errorMessage()
    40364039    {
    4037         $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
     4040        $errorMsg = '<strong>' . htmlspecialchars($this->getMessage()) . "</strong><br />\n";
    40384041        return $errorMsg;
    40394042    }
    40404043}
  • src/wp-includes/class-smtp.php

     
    3030     * The PHPMailer SMTP version number.
    3131     * @var string
    3232     */
    33     const VERSION = '5.2.22';
     33    const VERSION = '5.2.24';
    3434
    3535    /**
    3636     * SMTP line break constant.
     
    8181     * @deprecated Use the `VERSION` constant instead
    8282     * @see SMTP::VERSION
    8383     */
    84     public $Version = '5.2.22';
     84    public $Version = '5.2.24';
    8585
    8686    /**
    8787     * SMTP server port number.
     
    227227                break;
    228228            case 'html':
    229229                //Cleans up output a bit for a better looking, HTML-safe output
    230                 echo htmlentities(
     230                echo gmdate('Y-m-d H:i:s') . ' ' . htmlentities(
    231231                    preg_replace('/[\r\n]+/', '', $str),
    232232                    ENT_QUOTES,
    233233                    'UTF-8'
    234                 )
    235                 . "<br>\n";
     234                ) . "<br>\n";
    236235                break;
    237236            case 'echo':
    238237            default:
     
    242241                    "\n",
    243242                    "\n                   \t                  ",
    244243                    trim($str)
    245                 )."\n";
     244                ) . "\n";
    246245        }
    247246    }
    248247
     
    276275        }
    277276        // Connect to the SMTP server
    278277        $this->edebug(
    279             "Connection: opening to $host:$port, timeout=$timeout, options=".var_export($options, true),
     278            "Connection: opening to $host:$port, timeout=$timeout, options=" .
     279            var_export($options, true),
    280280            self::DEBUG_CONNECTION
    281281        );
    282282        $errno = 0;
     
    362362        }
    363363
    364364        // Begin encrypted connection
    365         if (!stream_socket_enable_crypto(
     365        set_error_handler(array($this, 'errorHandler'));
     366        $crypto_ok = stream_socket_enable_crypto(
    366367            $this->smtp_conn,
    367368            true,
    368369            $crypto_method
    369         )) {
    370             return false;
    371         }
    372         return true;
     370        );
     371        restore_error_handler();
     372        return $crypto_ok;
    373373    }
    374374
    375375    /**
     
    398398        }
    399399
    400400        if (array_key_exists('EHLO', $this->server_caps)) {
    401         // SMTP extensions are available. Let's try to find a proper authentication method
    402 
     401            // SMTP extensions are available; try to find a proper authentication method
    403402            if (!array_key_exists('AUTH', $this->server_caps)) {
    404403                $this->setError('Authentication is not allowed at this stage');
    405404                // 'at this stage' means that auth may be allowed after the stage changes
     
    424423                    $this->setError('No supported authentication methods found');
    425424                    return false;
    426425                }
    427                 self::edebug('Auth method selected: '.$authtype, self::DEBUG_LOWLEVEL);
     426                self::edebug('Auth method selected: ' . $authtype, self::DEBUG_LOWLEVEL);
    428427            }
    429428
    430429            if (!in_array($authtype, $this->server_caps['AUTH'])) {
     
    487486     * Works like hash_hmac('md5', $data, $key)
    488487     * in case that function is not available
    489488     * @param string $data The data to hash
    490      * @param string $key  The key to hash with
     489     * @param string $key The key to hash with
    491490     * @access protected
    492491     * @return string
    493492     */
     
    830829            $code_ex = (count($matches) > 2 ? $matches[2] : null);
    831830            // Cut off error code from each response line
    832831            $detail = preg_replace(
    833                 "/{$code}[ -]".($code_ex ? str_replace('.', '\\.', $code_ex).' ' : '')."/m",
     832                "/{$code}[ -]" .
     833                ($code_ex ? str_replace('.', '\\.', $code_ex) . ' ' : '') . "/m",
    834834                '',
    835835                $this->last_reply
    836836            );
     
    926926    public function client_send($data)
    927927    {
    928928        $this->edebug("CLIENT -> SERVER: $data", self::DEBUG_CLIENT);
    929         return fwrite($this->smtp_conn, $data);
     929        set_error_handler(array($this, 'errorHandler'));
     930        $result = fwrite($this->smtp_conn, $data);
     931        restore_error_handler();
     932        return $result;
    930933    }
    931934
    932935    /**
     
    10261029            $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);
    10271030            $this->edebug("SMTP -> get_lines(): \$str is  \"$str\"", self::DEBUG_LOWLEVEL);
    10281031            $data .= $str;
    1029             // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen
    1030             if ((isset($str[3]) and $str[3] == ' ')) {
     1032            // If response is only 3 chars (not valid, but RFC5321 S4.2 says it must be handled),
     1033            // or 4th character is a space, we are done reading, break the loop,
     1034            // string array access is a micro-optimisation over strlen
     1035            if (!isset($str[3]) or (isset($str[3]) and $str[3] == ' ')) {
    10311036                break;
    10321037            }
    10331038            // Timed-out? Log and break
     
    10421047            // Now check if reads took too long
    10431048            if ($endtime and time() > $endtime) {
    10441049                $this->edebug(
    1045                     'SMTP -> get_lines(): timelimit reached ('.
     1050                    'SMTP -> get_lines(): timelimit reached (' .
    10461051                    $this->Timelimit . ' sec)',
    10471052                    self::DEBUG_LOWLEVEL
    10481053                );
     
    11451150     * Reports an error number and string.
    11461151     * @param integer $errno The error number returned by PHP.
    11471152     * @param string $errmsg The error message returned by PHP.
     1153     * @param string $errfile The file the error occurred in
     1154     * @param integer $errline The line number the error occurred on
    11481155     */
    1149     protected function errorHandler($errno, $errmsg)
     1156    protected function errorHandler($errno, $errmsg, $errfile = '', $errline = 0)
    11501157    {
    1151         $notice = 'Connection: Failed to connect to server.';
     1158        $notice = 'Connection failed.';
    11521159        $this->setError(
    11531160            $notice,
    11541161            $errno,
     
    11551162            $errmsg
    11561163        );
    11571164        $this->edebug(
    1158             $notice . ' Error number ' . $errno . '. "Error notice: ' . $errmsg,
     1165            $notice . ' Error #' . $errno . ': ' . $errmsg . " [$errfile line $errline]",
    11591166            self::DEBUG_CONNECTION
    11601167        );
    11611168    }
    11621169
    1163         /**
    1164         * Will return the ID of the last smtp transaction based on a list of patterns provided
    1165         * in SMTP::$smtp_transaction_id_patterns.
    1166         * If no reply has been received yet, it will return null.
    1167         * If no pattern has been matched, it will return false.
    1168         * @return bool|null|string
    1169         */
    1170         public function getLastTransactionID()
    1171         {
    1172                 $reply = $this->getLastReply();
     1170    /**
     1171    * Will return the ID of the last smtp transaction based on a list of patterns provided
     1172    * in SMTP::$smtp_transaction_id_patterns.
     1173    * If no reply has been received yet, it will return null.
     1174    * If no pattern has been matched, it will return false.
     1175    * @return bool|null|string
     1176    */
     1177    public function getLastTransactionID()
     1178    {
     1179        $reply = $this->getLastReply();
    11731180
    1174                 if (empty($reply)) {
    1175                         return null;
    1176                 }
     1181        if (empty($reply)) {
     1182            return null;
     1183        }
    11771184
    1178                 foreach($this->smtp_transaction_id_patterns as $smtp_transaction_id_pattern) {
    1179                         if(preg_match($smtp_transaction_id_pattern, $reply, $matches)) {
    1180                                 return $matches[1];
    1181                         }
    1182                 }
     1185        foreach ($this->smtp_transaction_id_patterns as $smtp_transaction_id_pattern) {
     1186            if (preg_match($smtp_transaction_id_pattern, $reply, $matches)) {
     1187                return $matches[1];
     1188            }
     1189        }
    11831190
    1184                 return false;
     1191        return false;
    11851192    }
    11861193}