Changeset 39725 for branches/4.3/src/wp-includes/class-smtp.php
- Timestamp:
- 01/06/2017 05:42:02 AM (7 years ago)
- Location:
- branches/4.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.3
- Property svn:mergeinfo changed
/trunk merged: 36083,39645
- Property svn:mergeinfo changed
-
branches/4.3/src/wp-includes/class-smtp.php
r33124 r39725 29 29 /** 30 30 * The PHPMailer SMTP version number. 31 * @ typestring32 */ 33 const VERSION = '5.2. 10';31 * @var string 32 */ 33 const VERSION = '5.2.21'; 34 34 35 35 /** 36 36 * SMTP line break constant. 37 * @ typestring37 * @var string 38 38 */ 39 39 const CRLF = "\r\n"; … … 41 41 /** 42 42 * The SMTP port to use if one is not specified. 43 * @ typeinteger43 * @var integer 44 44 */ 45 45 const DEFAULT_SMTP_PORT = 25; … … 47 47 /** 48 48 * The maximum line length allowed by RFC 2822 section 2.1.1 49 * @ typeinteger49 * @var integer 50 50 */ 51 51 const MAX_LINE_LENGTH = 998; … … 78 78 /** 79 79 * The PHPMailer SMTP Version number. 80 * @ typestring80 * @var string 81 81 * @deprecated Use the `VERSION` constant instead 82 82 * @see SMTP::VERSION 83 83 */ 84 public $Version = '5.2. 10';84 public $Version = '5.2.21'; 85 85 86 86 /** 87 87 * SMTP server port number. 88 * @ typeinteger88 * @var integer 89 89 * @deprecated This is only ever used as a default value, so use the `DEFAULT_SMTP_PORT` constant instead 90 90 * @see SMTP::DEFAULT_SMTP_PORT … … 94 94 /** 95 95 * SMTP reply line ending. 96 * @ typestring96 * @var string 97 97 * @deprecated Use the `CRLF` constant instead 98 98 * @see SMTP::CRLF … … 108 108 * * self::DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status 109 109 * * self::DEBUG_LOWLEVEL (`4`) Low-level data output, all messages 110 * @ typeinteger110 * @var integer 111 111 */ 112 112 public $do_debug = self::DEBUG_OFF; … … 123 123 * $smtp->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; 124 124 * </code> 125 * @ typestring|callable125 * @var string|callable 126 126 */ 127 127 public $Debugoutput = 'echo'; … … 131 131 * @link http://en.wikipedia.org/wiki/Variable_envelope_return_path 132 132 * @link http://www.postfix.org/VERP_README.html Info on VERP 133 * @ typeboolean133 * @var boolean 134 134 */ 135 135 public $do_verp = false; … … 140 140 * This needs to be quite high to function correctly with hosts using greetdelay as an anti-spam measure. 141 141 * @link http://tools.ietf.org/html/rfc2821#section-4.5.3.2 142 * @ typeinteger142 * @var integer 143 143 */ 144 144 public $Timeout = 300; … … 147 147 * How long to wait for commands to complete, in seconds. 148 148 * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 149 * @ typeinteger149 * @var integer 150 150 */ 151 151 public $Timelimit = 300; 152 152 153 /** 154 * @var array patterns to extract smtp transaction id from smtp reply 155 * Only first capture group will be use, use non-capturing group to deal with it 156 * Extend this class to override this property to fulfil your needs. 157 */ 158 protected $smtp_transaction_id_patterns = array( 159 'exim' => '/[0-9]{3} OK id=(.*)/', 160 'sendmail' => '/[0-9]{3} 2.0.0 (.*) Message/', 161 'postfix' => '/[0-9]{3} 2.0.0 Ok: queued as (.*)/' 162 ); 163 153 164 /** 154 165 * The socket for the server connection. 155 * @ typeresource166 * @var resource 156 167 */ 157 168 protected $smtp_conn; … … 159 170 /** 160 171 * Error information, if any, for the last SMTP command. 161 * @ typearray172 * @var array 162 173 */ 163 174 protected $error = array( … … 171 182 * The reply the server sent to us for HELO. 172 183 * If null, no HELO string has yet been received. 173 * @ typestring|null184 * @var string|null 174 185 */ 175 186 protected $helo_rply = null; … … 182 193 * Other values can be boolean TRUE or an array containing extension options. 183 194 * If null, no HELO/EHLO string has yet been received. 184 * @ typearray|null195 * @var array|null 185 196 */ 186 197 protected $server_caps = null; … … 188 199 /** 189 200 * The most recent reply received from the server. 190 * @ typestring201 * @var string 191 202 */ 192 203 protected $last_reply = ''; … … 207 218 //Avoid clash with built-in function names 208 219 if (!in_array($this->Debugoutput, array('error_log', 'html', 'echo')) and is_callable($this->Debugoutput)) { 209 call_user_func($this->Debugoutput, $str, $ this->do_debug);220 call_user_func($this->Debugoutput, $str, $level); 210 221 return; 211 222 } … … 273 284 if ($streamok) { 274 285 $socket_context = stream_context_create($options); 275 //Suppress errors; connection failures are handled at a higher level276 $this->smtp_conn = @stream_socket_client(286 set_error_handler(array($this, 'errorHandler')); 287 $this->smtp_conn = stream_socket_client( 277 288 $host . ":" . $port, 278 289 $errno, … … 282 293 $socket_context 283 294 ); 295 restore_error_handler(); 284 296 } else { 285 297 //Fall back to fsockopen which should work in more places, but is missing some features … … 288 300 self::DEBUG_CONNECTION 289 301 ); 302 set_error_handler(array($this, 'errorHandler')); 290 303 $this->smtp_conn = fsockopen( 291 304 $host, … … 295 308 $timeout 296 309 ); 310 restore_error_handler(); 297 311 } 298 312 // Verify we connected properly … … 337 351 return false; 338 352 } 353 354 //Allow the best TLS version(s) we can 355 $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; 356 357 //PHP 5.6.7 dropped inclusion of TLS 1.1 and 1.2 in STREAM_CRYPTO_METHOD_TLS_CLIENT 358 //so add them back in manually if we can 359 if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) { 360 $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; 361 $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT; 362 } 363 339 364 // Begin encrypted connection 340 365 if (!stream_socket_enable_crypto( 341 366 $this->smtp_conn, 342 367 true, 343 STREAM_CRYPTO_METHOD_TLS_CLIENT368 $crypto_method 344 369 )) { 345 370 return false; … … 352 377 * Must be run after hello(). 353 378 * @see hello() 354 * @param string $username 355 * @param string $password 356 * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5)357 * @param string $realm 379 * @param string $username The user name 380 * @param string $password The password 381 * @param string $authtype The auth type (PLAIN, LOGIN, CRAM-MD5) 382 * @param string $realm The auth realm for NTLM 358 383 * @param string $workstation The auth workstation for NTLM 359 * @ access public360 * @return bool ean True if successfully authenticated.384 * @param null|OAuth $OAuth An optional OAuth instance (@see PHPMailerOAuth) 385 * @return bool True if successfully authenticated.* @access public 361 386 */ 362 387 public function authenticate( … … 365 390 $authtype = null, 366 391 $realm = '', 367 $workstation = '' 392 $workstation = '', 393 $OAuth = null 368 394 ) { 369 395 if (!$this->server_caps) { … … 389 415 390 416 if (empty($authtype)) { 391 foreach (array(' LOGIN', 'CRAM-MD5', 'PLAIN') as $method) {417 foreach (array('CRAM-MD5', 'LOGIN', 'PLAIN') as $method) { 392 418 if (in_array($method, $this->server_caps['AUTH'])) { 393 419 $authtype = $method; … … 673 699 { 674 700 $this->server_caps = array(); 675 $lines = explode("\n", $this->last_reply); 701 $lines = explode("\n", $this->helo_rply); 702 676 703 foreach ($lines as $n => $s) { 704 //First 4 chars contain response code followed by - or space 677 705 $s = trim(substr($s, 4)); 678 if ( !$s) {706 if (empty($s)) { 679 707 continue; 680 708 } … … 686 714 } else { 687 715 $name = array_shift($fields); 688 if ($name == 'SIZE') { 689 $fields = ($fields) ? $fields[0] : 0; 716 switch ($name) { 717 case 'SIZE': 718 $fields = ($fields ? $fields[0] : 0); 719 break; 720 case 'AUTH': 721 if (!is_array($fields)) { 722 $fields = array(); 723 } 724 break; 725 default: 726 $fields = true; 690 727 } 691 728 } 692 $this->server_caps[$name] = ($fields ? $fields : true);729 $this->server_caps[$name] = $fields; 693 730 } 694 731 } … … 740 777 * Returns true if the recipient was accepted false if it was rejected. 741 778 * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF> 742 * @param string $ toaddrThe address the message is being sent to743 * @access public 744 * @return boolean 745 */ 746 public function recipient($ toaddr)779 * @param string $address The address the message is being sent to 780 * @access public 781 * @return boolean 782 */ 783 public function recipient($address) 747 784 { 748 785 return $this->sendCommand( 749 786 'RCPT TO', 750 'RCPT TO:<' . $ toaddr. '>',787 'RCPT TO:<' . $address . '>', 751 788 array(250, 251) 752 789 ); … … 767 804 /** 768 805 * Send a command to an SMTP server and check its return code. 769 * @param string $command 806 * @param string $command The command name - not sent to the server 770 807 * @param string $commandstring The actual command to send 771 * @param integer|array $expect 808 * @param integer|array $expect One or more expected integer success codes 772 809 * @access protected 773 810 * @return boolean True on success. … … 777 814 if (!$this->connected()) { 778 815 $this->setError("Called $command without being connected"); 816 return false; 817 } 818 //Reject line breaks in all commands 819 if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) { 820 $this->setError("Command '$command' contained line breaks"); 779 821 return false; 780 822 } … … 982 1024 while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { 983 1025 $str = @fgets($this->smtp_conn, 515); 984 $this->edebug("SMTP -> get_lines(): \$data was \"$data\"", self::DEBUG_LOWLEVEL);985 $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL);1026 $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL); 1027 $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL); 986 1028 $data .= $str; 987 $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);988 1029 // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen 989 1030 if ((isset($str[3]) and $str[3] == ' ')) { … … 1100 1141 return $this->Timeout; 1101 1142 } 1143 1144 /** 1145 * Reports an error number and string. 1146 * @param integer $errno The error number returned by PHP. 1147 * @param string $errmsg The error message returned by PHP. 1148 */ 1149 protected function errorHandler($errno, $errmsg) 1150 { 1151 $notice = 'Connection: Failed to connect to server.'; 1152 $this->setError( 1153 $notice, 1154 $errno, 1155 $errmsg 1156 ); 1157 $this->edebug( 1158 $notice . ' Error number ' . $errno . '. "Error notice: ' . $errmsg, 1159 self::DEBUG_CONNECTION 1160 ); 1161 } 1162 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(); 1173 1174 if (empty($reply)) { 1175 return null; 1176 } 1177 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 } 1183 1184 return false; 1185 } 1102 1186 }
Note: See TracChangeset
for help on using the changeset viewer.