Changeset 36083
- Timestamp:
- 12/24/2015 01:58:33 AM (9 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-phpmailer.php
r33142 r36083 30 30 /** 31 31 * The PHPMailer Version number. 32 * @ typestring33 */ 34 public $Version = '5.2.1 0';32 * @var string 33 */ 34 public $Version = '5.2.14'; 35 35 36 36 /** 37 37 * Email priority. 38 * Options: 1 = High, 3 = Normal, 5 = low. 39 * @type integer 40 */ 41 public $Priority = 3; 38 * Options: null (default), 1 = High, 3 = Normal, 5 = low. 39 * When null, the header is not set at all. 40 * @var integer 41 */ 42 public $Priority = null; 42 43 43 44 /** 44 45 * The character set of the message. 45 * @ typestring46 * @var string 46 47 */ 47 48 public $CharSet = 'iso-8859-1'; … … 49 50 /** 50 51 * The MIME Content-type of the message. 51 * @ typestring52 * @var string 52 53 */ 53 54 public $ContentType = 'text/plain'; … … 56 57 * The message encoding. 57 58 * Options: "8bit", "7bit", "binary", "base64", and "quoted-printable". 58 * @ typestring59 * @var string 59 60 */ 60 61 public $Encoding = '8bit'; … … 62 63 /** 63 64 * Holds the most recent mailer error message. 64 * @ typestring65 * @var string 65 66 */ 66 67 public $ErrorInfo = ''; … … 68 69 /** 69 70 * The From email address for the message. 70 * @ typestring71 * @var string 71 72 */ 72 73 public $From = 'root@localhost'; … … 74 75 /** 75 76 * The From name of the message. 76 * @ typestring77 * @var string 77 78 */ 78 79 public $FromName = 'Root User'; … … 81 82 * The Sender email (Return-Path) of the message. 82 83 * If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. 83 * @ typestring84 * @var string 84 85 */ 85 86 public $Sender = ''; … … 88 89 * The Return-Path of the message. 89 90 * If empty, it will be set to either From or Sender. 90 * @ typestring91 * @var string 91 92 * @deprecated Email senders should never set a return-path header; 92 93 * it's the receiver's job (RFC5321 section 4.4), so this no longer does anything. … … 97 98 /** 98 99 * The Subject of the message. 99 * @ typestring100 * @var string 100 101 */ 101 102 public $Subject = ''; … … 104 105 * An HTML or plain text message body. 105 106 * If HTML then call isHTML(true). 106 * @ typestring107 * @var string 107 108 */ 108 109 public $Body = ''; … … 113 114 * capability such as mutt & Eudora. 114 115 * Clients that can read HTML will view the normal Body. 115 * @ typestring116 * @var string 116 117 */ 117 118 public $AltBody = ''; … … 123 124 * @link http://sprain.ch/blog/downloads/php-class-easypeasyics-create-ical-files-with-php/ 124 125 * @link http://kigkonsult.se/iCalcreator/ 125 * @ typestring126 * @var string 126 127 */ 127 128 public $Ical = ''; … … 130 131 * The complete compiled MIME message body. 131 132 * @access protected 132 * @ typestring133 * @var string 133 134 */ 134 135 protected $MIMEBody = ''; … … 136 137 /** 137 138 * The complete compiled MIME message headers. 138 * @ typestring139 * @var string 139 140 * @access protected 140 141 */ … … 143 144 /** 144 145 * Extra headers that createHeader() doesn't fold in. 145 * @ typestring146 * @var string 146 147 * @access protected 147 148 */ … … 151 152 * Word-wrap the message body to this number of chars. 152 153 * Set to 0 to not wrap. A useful value here is 78, for RFC2822 section 2.1.1 compliance. 153 * @ typeinteger154 * @var integer 154 155 */ 155 156 public $WordWrap = 0; … … 158 159 * Which method to use to send mail. 159 160 * Options: "mail", "sendmail", or "smtp". 160 * @ typestring161 * @var string 161 162 */ 162 163 public $Mailer = 'mail'; … … 164 165 /** 165 166 * The path to the sendmail program. 166 * @ typestring167 * @var string 167 168 */ 168 169 public $Sendmail = '/usr/sbin/sendmail'; … … 171 172 * Whether mail() uses a fully sendmail-compatible MTA. 172 173 * One which supports sendmail's "-oi -f" options. 173 * @ typeboolean174 * @var boolean 174 175 */ 175 176 public $UseSendmailOptions = true; … … 178 179 * Path to PHPMailer plugins. 179 180 * Useful if the SMTP class is not in the PHP include path. 180 * @ typestring181 * @var string 181 182 * @deprecated Should not be needed now there is an autoloader. 182 183 */ … … 184 185 185 186 /** 186 * The email address that a reading confirmation should be sent to .187 * @ typestring187 * The email address that a reading confirmation should be sent to, also known as read receipt. 188 * @var string 188 189 */ 189 190 public $ConfirmReadingTo = ''; 190 191 191 192 /** 192 * The hostname to use in Message-Id and Received headers193 * and as default HELO string.194 * If empty, the value returned195 * by SERVER_NAME is used or'localhost.localdomain'.196 * @ typestring193 * The hostname to use in the Message-ID header and as default HELO string. 194 * If empty, PHPMailer attempts to find one with, in order, 195 * $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value 196 * 'localhost.localdomain'. 197 * @var string 197 198 */ 198 199 public $Hostname = ''; 199 200 200 201 /** 201 * An ID to be used in the Message-I dheader.202 * An ID to be used in the Message-ID header. 202 203 * If empty, a unique id will be generated. 203 * @ typestring204 * @var string 204 205 */ 205 206 public $MessageID = ''; … … 208 209 * The message Date to be used in the Date header. 209 210 * If empty, the current date will be added. 210 * @ typestring211 * @var string 211 212 */ 212 213 public $MessageDate = ''; … … 221 222 * (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465"). 222 223 * Hosts will be tried in order. 223 * @ typestring224 * @var string 224 225 */ 225 226 public $Host = 'localhost'; … … 227 228 /** 228 229 * The default SMTP server port. 229 * @ typeinteger230 * @var integer 230 231 * @TODO Why is this needed when the SMTP class takes care of it? 231 232 */ … … 234 235 /** 235 236 * The SMTP HELO of the message. 236 * Default is $Hostname. 237 * @type string 237 * Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find 238 * one with the same method described above for $Hostname. 239 * @var string 238 240 * @see PHPMailer::$Hostname 239 241 */ … … 243 245 * What kind of encryption to use on the SMTP connection. 244 246 * Options: '', 'ssl' or 'tls' 245 * @ typestring247 * @var string 246 248 */ 247 249 public $SMTPSecure = ''; … … 251 253 * even if `SMTPSecure` is not set to 'tls'. 252 254 * Be aware that in PHP >= 5.6 this requires that the server's certificates are valid. 253 * @ typeboolean255 * @var boolean 254 256 */ 255 257 public $SMTPAutoTLS = true; … … 258 260 * Whether to use SMTP authentication. 259 261 * Uses the Username and Password properties. 260 * @ typeboolean262 * @var boolean 261 263 * @see PHPMailer::$Username 262 264 * @see PHPMailer::$Password … … 266 268 /** 267 269 * Options array passed to stream_context_create when connecting via SMTP. 268 * @ typearray270 * @var array 269 271 */ 270 272 public $SMTPOptions = array(); … … 272 274 /** 273 275 * SMTP username. 274 * @ typestring276 * @var string 275 277 */ 276 278 public $Username = ''; … … 278 280 /** 279 281 * SMTP password. 280 * @ typestring282 * @var string 281 283 */ 282 284 public $Password = ''; … … 285 287 * SMTP auth type. 286 288 * Options are LOGIN (default), PLAIN, NTLM, CRAM-MD5 287 * @ typestring289 * @var string 288 290 */ 289 291 public $AuthType = ''; … … 292 294 * SMTP realm. 293 295 * Used for NTLM auth 294 * @ typestring296 * @var string 295 297 */ 296 298 public $Realm = ''; … … 299 301 * SMTP workstation. 300 302 * Used for NTLM auth 301 * @ typestring303 * @var string 302 304 */ 303 305 public $Workstation = ''; … … 306 308 * The SMTP server timeout in seconds. 307 309 * Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2 308 * @ typeinteger310 * @var integer 309 311 */ 310 312 public $Timeout = 300; … … 319 321 * * `3` As 2 plus connection status 320 322 * * `4` Low-level data output 321 * @ typeinteger323 * @var integer 322 324 * @see SMTP::$do_debug 323 325 */ … … 335 337 * $mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; 336 338 * </code> 337 * @ typestring|callable339 * @var string|callable 338 340 * @see SMTP::$Debugoutput 339 341 */ … … 344 346 * If this is set to true then to close the connection 345 347 * requires an explicit call to smtpClose(). 346 * @ typeboolean348 * @var boolean 347 349 */ 348 350 public $SMTPKeepAlive = false; … … 351 353 * Whether to split multiple to addresses into multiple messages 352 354 * or send them all in one message. 353 * @ typeboolean355 * @var boolean 354 356 */ 355 357 public $SingleTo = false; … … 357 359 /** 358 360 * Storage for addresses when SingleTo is enabled. 359 * @ typearray361 * @var array 360 362 * @TODO This should really not be public 361 363 */ … … 365 367 * Whether to generate VERP addresses on send. 366 368 * Only applicable when sending via SMTP. 367 * @link http ://en.wikipedia.org/wiki/Variable_envelope_return_path369 * @link https://en.wikipedia.org/wiki/Variable_envelope_return_path 368 370 * @link http://www.postfix.org/VERP_README.html Postfix VERP info 369 * @ typeboolean371 * @var boolean 370 372 */ 371 373 public $do_verp = false; … … 373 375 /** 374 376 * Whether to allow sending messages with an empty body. 375 * @ typeboolean377 * @var boolean 376 378 */ 377 379 public $AllowEmpty = false; … … 381 383 * @note The default remains "\n". We force CRLF where we know 382 384 * it must be used via self::CRLF. 383 * @ typestring385 * @var string 384 386 */ 385 387 public $LE = "\n"; … … 387 389 /** 388 390 * DKIM selector. 389 * @ typestring391 * @var string 390 392 */ 391 393 public $DKIM_selector = ''; … … 394 396 * DKIM Identity. 395 397 * Usually the email address used as the source of the email 396 * @ typestring398 * @var string 397 399 */ 398 400 public $DKIM_identity = ''; … … 401 403 * DKIM passphrase. 402 404 * Used if your key is encrypted. 403 * @ typestring405 * @var string 404 406 */ 405 407 public $DKIM_passphrase = ''; … … 408 410 * DKIM signing domain name. 409 411 * @example 'example.com' 410 * @ typestring412 * @var string 411 413 */ 412 414 public $DKIM_domain = ''; … … 414 416 /** 415 417 * DKIM private key file path. 416 * @ typestring418 * @var string 417 419 */ 418 420 public $DKIM_private = ''; … … 434 436 * string $body the email body 435 437 * string $from email address of sender 436 * @ typestring438 * @var string 437 439 */ 438 440 public $action_function = ''; … … 441 443 * What to put in the X-Mailer header. 442 444 * Options: An empty string for PHPMailer default, whitespace for none, or a string to use 443 * @ typestring445 * @var string 444 446 */ 445 447 public $XMailer = ''; … … 447 449 /** 448 450 * An instance of the SMTP sender class. 449 * @ typeSMTP451 * @var SMTP 450 452 * @access protected 451 453 */ … … 453 455 454 456 /** 455 * The array of 'to' addresses.456 * @ typearray457 * The array of 'to' names and addresses. 458 * @var array 457 459 * @access protected 458 460 */ … … 460 462 461 463 /** 462 * The array of 'cc' addresses.463 * @ typearray464 * The array of 'cc' names and addresses. 465 * @var array 464 466 * @access protected 465 467 */ … … 467 469 468 470 /** 469 * The array of 'bcc' addresses.470 * @ typearray471 * The array of 'bcc' names and addresses. 472 * @var array 471 473 * @access protected 472 474 */ … … 475 477 /** 476 478 * The array of reply-to names and addresses. 477 * @ typearray479 * @var array 478 480 * @access protected 479 481 */ … … 483 485 * An array of all kinds of addresses. 484 486 * Includes all of $to, $cc, $bcc 485 * @ typearray487 * @var array 486 488 * @access protected 489 * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc 487 490 */ 488 491 protected $all_recipients = array(); 489 492 490 493 /** 494 * An array of names and addresses queued for validation. 495 * In send(), valid and non duplicate entries are moved to $all_recipients 496 * and one of $to, $cc, or $bcc. 497 * This array is used only for addresses with IDN. 498 * @var array 499 * @access protected 500 * @see PHPMailer::$to @see PHPMailer::$cc @see PHPMailer::$bcc 501 * @see PHPMailer::$all_recipients 502 */ 503 protected $RecipientsQueue = array(); 504 505 /** 506 * An array of reply-to names and addresses queued for validation. 507 * In send(), valid and non duplicate entries are moved to $ReplyTo. 508 * This array is used only for addresses with IDN. 509 * @var array 510 * @access protected 511 * @see PHPMailer::$ReplyTo 512 */ 513 protected $ReplyToQueue = array(); 514 515 /** 491 516 * The array of attachments. 492 * @ typearray517 * @var array 493 518 * @access protected 494 519 */ … … 497 522 /** 498 523 * The array of custom headers. 499 * @ typearray524 * @var array 500 525 * @access protected 501 526 */ … … 504 529 /** 505 530 * The most recent Message-ID (including angular brackets). 506 * @ typestring531 * @var string 507 532 * @access protected 508 533 */ … … 511 536 /** 512 537 * The message's MIME type. 513 * @ typestring538 * @var string 514 539 * @access protected 515 540 */ … … 518 543 /** 519 544 * The array of MIME boundary strings. 520 * @ typearray545 * @var array 521 546 * @access protected 522 547 */ … … 525 550 /** 526 551 * The array of available languages. 527 * @ typearray552 * @var array 528 553 * @access protected 529 554 */ … … 532 557 /** 533 558 * The number of errors encountered. 534 * @ typeinteger559 * @var integer 535 560 * @access protected 536 561 */ … … 539 564 /** 540 565 * The S/MIME certificate file path. 541 * @ typestring566 * @var string 542 567 * @access protected 543 568 */ … … 546 571 /** 547 572 * The S/MIME key file path. 548 * @ typestring573 * @var string 549 574 * @access protected 550 575 */ … … 553 578 /** 554 579 * The optional S/MIME extra certificates ("CA Chain") file path. 555 * @ typestring580 * @var string 556 581 * @access protected 557 582 */ … … 561 586 * The S/MIME password for the key. 562 587 * Used only if the key is encrypted. 563 * @ typestring588 * @var string 564 589 * @access protected 565 590 */ … … 568 593 /** 569 594 * Whether to throw exceptions for errors. 570 * @ typeboolean595 * @var boolean 571 596 * @access protected 572 597 */ … … 575 600 /** 576 601 * Unique ID used for message ID and boundaries. 577 * @ typestring602 * @var string 578 603 * @access protected 579 604 */ … … 602 627 /** 603 628 * The maximum line length allowed by RFC 2822 section 2.1.1 604 * @ typeinteger629 * @var integer 605 630 */ 606 631 const MAX_LINE_LENGTH = 998; … … 764 789 /** 765 790 * Add a "To" address. 766 * @param string $address 791 * @param string $address The email address to send to 767 792 * @param string $name 768 * @return boolean true on success, false if address already used 793 * @return boolean true on success, false if address already used or invalid in some way 769 794 */ 770 795 public function addAddress($address, $name = '') 771 796 { 772 return $this->add AnAddress('to', $address, $name);797 return $this->addOrEnqueueAnAddress('to', $address, $name); 773 798 } 774 799 … … 776 801 * Add a "CC" address. 777 802 * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer. 778 * @param string $address 803 * @param string $address The email address to send to 779 804 * @param string $name 780 * @return boolean true on success, false if address already used 805 * @return boolean true on success, false if address already used or invalid in some way 781 806 */ 782 807 public function addCC($address, $name = '') 783 808 { 784 return $this->add AnAddress('cc', $address, $name);809 return $this->addOrEnqueueAnAddress('cc', $address, $name); 785 810 } 786 811 … … 788 813 * Add a "BCC" address. 789 814 * @note: This function works with the SMTP mailer on win32, not with the "mail" mailer. 790 * @param string $address 815 * @param string $address The email address to send to 791 816 * @param string $name 792 * @return boolean true on success, false if address already used 817 * @return boolean true on success, false if address already used or invalid in some way 793 818 */ 794 819 public function addBCC($address, $name = '') 795 820 { 796 return $this->add AnAddress('bcc', $address, $name);797 } 798 799 /** 800 * Add a "Reply- to" address.801 * @param string $address 821 return $this->addOrEnqueueAnAddress('bcc', $address, $name); 822 } 823 824 /** 825 * Add a "Reply-To" address. 826 * @param string $address The email address to reply to 802 827 * @param string $name 803 * @return boolean 828 * @return boolean true on success, false if address already used or invalid in some way 804 829 */ 805 830 public function addReplyTo($address, $name = '') 806 831 { 807 return $this->addAnAddress('Reply-To', $address, $name); 808 } 809 810 /** 811 * Add an address to one of the recipient arrays. 812 * Addresses that have been added already return false, but do not throw exceptions 813 * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo' 814 * @param string $address The email address to send to 832 return $this->addOrEnqueueAnAddress('Reply-To', $address, $name); 833 } 834 835 /** 836 * Add an address to one of the recipient arrays or to the ReplyTo array. Because PHPMailer 837 * can't validate addresses with an IDN without knowing the PHPMailer::$CharSet (that can still 838 * be modified after calling this function), addition of such addresses is delayed until send(). 839 * Addresses that have been added already return false, but do not throw exceptions. 840 * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo' 841 * @param string $address The email address to send, resp. to reply to 815 842 * @param string $name 816 843 * @throws phpmailerException … … 818 845 * @access protected 819 846 */ 820 protected function addAnAddress($kind, $address, $name = '') 821 { 822 if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) { 823 $this->setError($this->lang('Invalid recipient array') . ': ' . $kind); 824 $this->edebug($this->lang('Invalid recipient array') . ': ' . $kind); 825 if ($this->exceptions) { 826 throw new phpmailerException('Invalid recipient array: ' . $kind); 827 } 828 return false; 829 } 847 protected function addOrEnqueueAnAddress($kind, $address, $name) 848 { 830 849 $address = trim($address); 831 850 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 851 if (($pos = strrpos($address, '@')) === false) { 852 // At-sign is misssing. 853 $error_message = $this->lang('invalid_address') . $address; 854 $this->setError($error_message); 855 $this->edebug($error_message); 856 if ($this->exceptions) { 857 throw new phpmailerException($error_message); 858 } 859 return false; 860 } 861 $params = array($kind, $address, $name); 862 // Enqueue addresses with IDN until we know the PHPMailer::$CharSet. 863 if ($this->has8bitChars(substr($address, ++$pos)) and $this->idnSupported()) { 864 if ($kind != 'Reply-To') { 865 if (!array_key_exists($address, $this->RecipientsQueue)) { 866 $this->RecipientsQueue[$address] = $params; 867 return true; 868 } 869 } else { 870 if (!array_key_exists($address, $this->ReplyToQueue)) { 871 $this->ReplyToQueue[$address] = $params; 872 return true; 873 } 874 } 875 return false; 876 } 877 // Immediately add standard addresses without IDN. 878 return call_user_func_array(array($this, 'addAnAddress'), $params); 879 } 880 881 /** 882 * Add an address to one of the recipient arrays or to the ReplyTo array. 883 * Addresses that have been added already return false, but do not throw exceptions. 884 * @param string $kind One of 'to', 'cc', 'bcc', or 'ReplyTo' 885 * @param string $address The email address to send, resp. to reply to 886 * @param string $name 887 * @throws phpmailerException 888 * @return boolean true on success, false if address already used or invalid in some way 889 * @access protected 890 */ 891 protected function addAnAddress($kind, $address, $name = '') 892 { 893 if (!in_array($kind, array('to', 'cc', 'bcc', 'Reply-To'))) { 894 $error_message = $this->lang('Invalid recipient kind: ') . $kind; 895 $this->setError($error_message); 896 $this->edebug($error_message); 897 if ($this->exceptions) { 898 throw new phpmailerException($error_message); 899 } 900 return false; 901 } 832 902 if (!$this->validateAddress($address)) { 833 $this->setError($this->lang('invalid_address') . ': ' . $address); 834 $this->edebug($this->lang('invalid_address') . ': ' . $address); 903 $error_message = $this->lang('invalid_address') . $address; 904 $this->setError($error_message); 905 $this->edebug($error_message); 835 906 if ($this->exceptions) { 836 throw new phpmailerException($ this->lang('invalid_address') . ': ' . $address);907 throw new phpmailerException($error_message); 837 908 } 838 909 return false; 839 910 } 840 911 if ($kind != 'Reply-To') { 841 if (! isset($this->all_recipients[strtolower($address)])) {912 if (!array_key_exists(strtolower($address), $this->all_recipients)) { 842 913 array_push($this->$kind, array($address, $name)); 843 914 $this->all_recipients[strtolower($address)] = true; … … 865 936 $address = trim($address); 866 937 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 867 if (!$this->validateAddress($address)) { 868 $this->setError($this->lang('invalid_address') . ': ' . $address); 869 $this->edebug($this->lang('invalid_address') . ': ' . $address); 938 // Don't validate now addresses with IDN. Will be done in send(). 939 if (($pos = strrpos($address, '@')) === false or 940 (!$this->has8bitChars(substr($address, ++$pos)) or !$this->idnSupported()) and 941 !$this->validateAddress($address)) { 942 $error_message = $this->lang('invalid_address') . $address; 943 $this->setError($error_message); 944 $this->edebug($error_message); 870 945 if ($this->exceptions) { 871 throw new phpmailerException($ this->lang('invalid_address') . ': ' . $address);946 throw new phpmailerException($error_message); 872 947 } 873 948 return false; … … 899 974 * @param string $address The email address to check 900 975 * @param string $patternselect A selector for the validation pattern to use : 901 * * `auto` Pick strictest oneautomatically;976 * * `auto` Pick best pattern automatically; 902 977 * * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14; 903 978 * * `pcre` Use old PCRE implementation; 904 * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; same as pcre8 but does not allow 'dotless' domains;979 * * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; 905 980 * * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements. 906 981 * * `noregex` Don't use a regex: super fast, really dumb. … … 911 986 public static function validateAddress($address, $patternselect = 'auto') 912 987 { 988 //Reject line breaks in addresses; it's valid RFC5322, but not RFC5321 989 if (strpos($address, "\n") !== false or strpos($address, "\r") !== false) { 990 return false; 991 } 913 992 if (!$patternselect or $patternselect == 'auto') { 914 993 //Check this constant first so it works when extension_loaded() is disabled by safe mode … … 991 1070 992 1071 /** 1072 * Tells whether IDNs (Internationalized Domain Names) are supported or not. This requires the 1073 * "intl" and "mbstring" PHP extensions. 1074 * @return bool "true" if required functions for IDN support are present 1075 */ 1076 public function idnSupported() 1077 { 1078 // @TODO: Write our own "idn_to_ascii" function for PHP <= 5.2. 1079 return function_exists('idn_to_ascii') and function_exists('mb_convert_encoding'); 1080 } 1081 1082 /** 1083 * Converts IDN in given email address to its ASCII form, also known as punycode, if possible. 1084 * Important: Address must be passed in same encoding as currently set in PHPMailer::$CharSet. 1085 * This function silently returns unmodified address if: 1086 * - No conversion is necessary (i.e. domain name is not an IDN, or is already in ASCII form) 1087 * - Conversion to punycode is impossible (e.g. required PHP functions are not available) 1088 * or fails for any reason (e.g. domain has characters not allowed in an IDN) 1089 * @see PHPMailer::$CharSet 1090 * @param string $address The email address to convert 1091 * @return string The encoded address in ASCII form 1092 */ 1093 public function punyencodeAddress($address) 1094 { 1095 // Verify we have required functions, CharSet, and at-sign. 1096 if ($this->idnSupported() and 1097 !empty($this->CharSet) and 1098 ($pos = strrpos($address, '@')) !== false) { 1099 $domain = substr($address, ++$pos); 1100 // Verify CharSet string is a valid one, and domain properly encoded in this CharSet. 1101 if ($this->has8bitChars($domain) and @mb_check_encoding($domain, $this->CharSet)) { 1102 $domain = mb_convert_encoding($domain, 'UTF-8', $this->CharSet); 1103 if (($punycode = defined('INTL_IDNA_VARIANT_UTS46') ? 1104 idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46) : 1105 idn_to_ascii($domain)) !== false) { 1106 return substr($address, 0, $pos) . $punycode; 1107 } 1108 } 1109 } 1110 return $address; 1111 } 1112 1113 /** 993 1114 * Create a message and send it. 994 1115 * Uses the sending method specified by $Mailer. … … 1021 1142 { 1022 1143 try { 1144 $this->error_count = 0; // Reset errors 1023 1145 $this->mailHeader = ''; 1146 1147 // Dequeue recipient and Reply-To addresses with IDN 1148 foreach (array_merge($this->RecipientsQueue, $this->ReplyToQueue) as $params) { 1149 $params[1] = $this->punyencodeAddress($params[1]); 1150 call_user_func_array(array($this, 'addAnAddress'), $params); 1151 } 1024 1152 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { 1025 1153 throw new phpmailerException($this->lang('provide_address'), self::STOP_CRITICAL); 1154 } 1155 1156 // Validate From, Sender, and ConfirmReadingTo addresses 1157 foreach (array('From', 'Sender', 'ConfirmReadingTo') as $address_kind) { 1158 $this->$address_kind = trim($this->$address_kind); 1159 if (empty($this->$address_kind)) { 1160 continue; 1161 } 1162 $this->$address_kind = $this->punyencodeAddress($this->$address_kind); 1163 if (!$this->validateAddress($this->$address_kind)) { 1164 $error_message = $this->lang('invalid_address') . $this->$address_kind; 1165 $this->setError($error_message); 1166 $this->edebug($error_message); 1167 if ($this->exceptions) { 1168 throw new phpmailerException($error_message); 1169 } 1170 return false; 1171 } 1026 1172 } 1027 1173 … … 1031 1177 } 1032 1178 1033 $this->error_count = 0; // Reset errors1034 1179 $this->setMessageType(); 1035 1180 // Refuse to send an empty message unless we are specifically allowing it … … 1172 1317 fputs($mail, $body); 1173 1318 $result = pclose($mail); 1174 $this->doCallback(($result == 0), $this->to, $this->cc, $this->bcc, $this->Subject, $body, $this->From); 1319 $this->doCallback( 1320 ($result == 0), 1321 $this->to, 1322 $this->cc, 1323 $this->bcc, 1324 $this->Subject, 1325 $body, 1326 $this->From 1327 ); 1175 1328 if ($result != 0) { 1176 1329 throw new phpmailerException($this->lang('execute') . $this->Sendmail, self::STOP_CRITICAL); … … 1459 1612 'from_failed' => 'The following From address failed: ', 1460 1613 'instantiate' => 'Could not instantiate mail function.', 1461 'invalid_address' => 'Invalid address ',1614 'invalid_address' => 'Invalid address: ', 1462 1615 'mailer_not_supported' => ' mailer is not supported.', 1463 1616 'provide_address' => 'You must provide at least one recipient email address.', … … 1724 1877 $result .= $this->headerLine('Date', $this->MessageDate); 1725 1878 1726 1727 1879 // To be created automatically by mail() 1728 1880 if ($this->SingleTo) { … … 1770 1922 $this->lastMessageID = $this->MessageID; 1771 1923 } else { 1772 $this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this-> ServerHostname());1924 $this->lastMessageID = sprintf('<%s@%s>', $this->uniqueid, $this->serverHostname()); 1773 1925 } 1774 1926 $result .= $this->headerLine('Message-ID', $this->lastMessageID); 1775 $result .= $this->headerLine('X-Priority', $this->Priority); 1927 if (!is_null($this->Priority)) { 1928 $result .= $this->headerLine('X-Priority', $this->Priority); 1929 } 1776 1930 if ($this->XMailer == '') { 1777 1931 $result .= $this->headerLine( 1778 1932 'X-Mailer', 1779 'PHPMailer ' . $this->Version . ' (https://github.com/PHPMailer/PHPMailer /)'1933 'PHPMailer ' . $this->Version . ' (https://github.com/PHPMailer/PHPMailer)' 1780 1934 ); 1781 1935 } else { … … 1787 1941 1788 1942 if ($this->ConfirmReadingTo != '') { 1789 $result .= $this->headerLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo). '>');1943 $result .= $this->headerLine('Disposition-Notification-To', '<' . $this->ConfirmReadingTo . '>'); 1790 1944 } 1791 1945 … … 2267 2421 $disposition = $attachment[6]; 2268 2422 $cid = $attachment[7]; 2269 if ($disposition == 'inline' && isset($cidUniq[$cid])) {2423 if ($disposition == 'inline' && array_key_exists($cid, $cidUniq)) { 2270 2424 continue; 2271 2425 } … … 2273 2427 2274 2428 $mime[] = sprintf('--%s%s', $boundary, $this->LE); 2275 $mime[] = sprintf( 2276 'Content-Type: %s; name="%s"%s', 2277 $type, 2278 $this->encodeHeader($this->secureHeader($name)), 2279 $this->LE 2280 ); 2429 //Only include a filename property if we have one 2430 if (!empty($name)) { 2431 $mime[] = sprintf( 2432 'Content-Type: %s; name="%s"%s', 2433 $type, 2434 $this->encodeHeader($this->secureHeader($name)), 2435 $this->LE 2436 ); 2437 } else { 2438 $mime[] = sprintf( 2439 'Content-Type: %s%s', 2440 $type, 2441 $this->LE 2442 ); 2443 } 2281 2444 // RFC1341 part 5 says 7bit is assumed if not specified 2282 2445 if ($encoding != '7bit') { … … 2302 2465 ); 2303 2466 } else { 2304 $mime[] = sprintf( 2305 'Content-Disposition: %s; filename=%s%s', 2306 $disposition, 2307 $encoded_name, 2308 $this->LE . $this->LE 2309 ); 2467 if (!empty($encoded_name)) { 2468 $mime[] = sprintf( 2469 'Content-Disposition: %s; filename=%s%s', 2470 $disposition, 2471 $encoded_name, 2472 $this->LE . $this->LE 2473 ); 2474 } else { 2475 $mime[] = sprintf( 2476 'Content-Disposition: %s%s', 2477 $disposition, 2478 $this->LE . $this->LE 2479 ); 2480 } 2310 2481 } 2311 2482 } else { … … 2341 2512 * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' 2342 2513 * @throws phpmailerException 2343 * @see EncodeFile(encodeFile2344 2514 * @access protected 2345 2515 * @return string … … 2561 2731 // Use native function if it's available (>= PHP5.3) 2562 2732 if (function_exists('quoted_printable_encode')) { 2563 return $this->fixEOL(quoted_printable_encode($string));2733 return quoted_printable_encode($string); 2564 2734 } 2565 2735 // Fall back to a pure PHP implementation … … 2569 2739 rawurlencode($string) 2570 2740 ); 2571 $string = preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string); 2572 return $this->fixEOL($string); 2741 return preg_replace('/[^\r\n]{' . ($line_max - 3) . '}[^=\r\n]{2}/', "$0=\r\n", $string); 2573 2742 } 2574 2743 … … 2639 2808 } 2640 2809 2641 2642 2810 /** 2643 2811 * Add a string or binary attachment (non-filesystem). … … 2745 2913 ) { 2746 2914 // If a MIME type is not specified, try to work it out from the name 2747 if ($type == '' ) {2915 if ($type == '' and !empty($name)) { 2748 2916 $type = self::filenameToType($name); 2749 2917 } … … 2802 2970 2803 2971 /** 2972 * Clear queued addresses of given kind. 2973 * @access protected 2974 * @param string $kind 'to', 'cc', or 'bcc' 2975 * @return void 2976 */ 2977 public function clearQueuedAddresses($kind) 2978 { 2979 $RecipientsQueue = $this->RecipientsQueue; 2980 foreach ($RecipientsQueue as $address => $params) { 2981 if ($params[0] == $kind) { 2982 unset($this->RecipientsQueue[$address]); 2983 } 2984 } 2985 } 2986 2987 /** 2804 2988 * Clear all To recipients. 2805 2989 * @return void … … 2811 2995 } 2812 2996 $this->to = array(); 2997 $this->clearQueuedAddresses('to'); 2813 2998 } 2814 2999 … … 2823 3008 } 2824 3009 $this->cc = array(); 3010 $this->clearQueuedAddresses('cc'); 2825 3011 } 2826 3012 … … 2835 3021 } 2836 3022 $this->bcc = array(); 3023 $this->clearQueuedAddresses('bcc'); 2837 3024 } 2838 3025 … … 2844 3031 { 2845 3032 $this->ReplyTo = array(); 3033 $this->ReplyToQueue = array(); 2846 3034 } 2847 3035 … … 2856 3044 $this->bcc = array(); 2857 3045 $this->all_recipients = array(); 3046 $this->RecipientsQueue = array(); 2858 3047 } 2859 3048 … … 3012 3201 3013 3202 /** 3014 * Returns all custom headers 3015 * 3203 * Returns all custom headers. 3016 3204 * @return array 3017 3205 */ … … 3030 3218 * @param string $basedir baseline directory for path 3031 3219 * @param boolean|callable $advanced Whether to use the internal HTML to text converter 3032 * or your own custom converter @see html2text()3220 * or your own custom converter @see PHPMailer::html2text() 3033 3221 * @return string $message 3034 3222 */ … … 3036 3224 { 3037 3225 preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images); 3038 if ( isset($images[2])) {3226 if (array_key_exists(2, $images)) { 3039 3227 foreach ($images[2] as $imgindex => $url) { 3040 3228 // Convert data URIs into embedded images … … 3047 3235 } 3048 3236 $cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2 3049 if ($this->addStringEmbeddedImage($data, $cid, ' ', 'base64', $match[1])) {3237 if ($this->addStringEmbeddedImage($data, $cid, 'embed' . $imgindex, 'base64', $match[1])) { 3050 3238 $message = str_replace( 3051 3239 $images[0][$imgindex], … … 3054 3242 ); 3055 3243 } 3056 } elseif ( !preg_match('#^[A-z]+://#', $url)) {3244 } elseif (substr($url, 0, 4) !== 'cid:' && !preg_match('#^[A-z]+://#', $url)) { 3057 3245 // Do not change urls for absolute images (thanks to corvuscorax) 3246 // Do not change urls that are already inline images 3058 3247 $filename = basename($url); 3059 3248 $directory = dirname($url); … … 3145 3334 'doc' => 'application/msword', 3146 3335 'word' => 'application/msword', 3336 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 3337 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', 3338 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', 3339 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', 3340 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 3341 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', 3342 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 3343 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 3344 'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12', 3345 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', 3147 3346 'class' => 'application/octet-stream', 3148 3347 'dll' => 'application/octet-stream', … … 3349 3548 } 3350 3549 3351 3352 3550 /** 3353 3551 * Set the public and private key files and password for S/MIME signing. … … 3518 3716 "\tb="; 3519 3717 $toSign = $this->DKIM_HeaderC( 3520 $from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs 3718 $from_header . "\r\n" . 3719 $to_header . "\r\n" . 3720 $subject_header . "\r\n" . 3721 $dkimhdrs 3521 3722 ); 3522 3723 $signed = $this->DKIM_Sign($toSign); … … 3538 3739 /** 3539 3740 * Allows for public read access to 'to' property. 3741 * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included. 3540 3742 * @access public 3541 3743 * @return array … … 3548 3750 /** 3549 3751 * Allows for public read access to 'cc' property. 3752 * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included. 3550 3753 * @access public 3551 3754 * @return array … … 3558 3761 /** 3559 3762 * Allows for public read access to 'bcc' property. 3763 * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included. 3560 3764 * @access public 3561 3765 * @return array … … 3568 3772 /** 3569 3773 * Allows for public read access to 'ReplyTo' property. 3774 * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included. 3570 3775 * @access public 3571 3776 * @return array … … 3578 3783 /** 3579 3784 * Allows for public read access to 'all_recipients' property. 3785 * @note: Before the send() call, queued addresses (i.e. with IDN) are not yet included. 3580 3786 * @access public 3581 3787 * @return array -
trunk/src/wp-includes/class-smtp.php
r33124 r36083 29 29 /** 30 30 * The PHPMailer SMTP version number. 31 * @ typestring32 */ 33 const VERSION = '5.2.1 0';31 * @var string 32 */ 33 const VERSION = '5.2.14'; 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.1 0';84 public $Version = '5.2.14'; 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; … … 153 153 /** 154 154 * The socket for the server connection. 155 * @ typeresource155 * @var resource 156 156 */ 157 157 protected $smtp_conn; … … 159 159 /** 160 160 * Error information, if any, for the last SMTP command. 161 * @ typearray161 * @var array 162 162 */ 163 163 protected $error = array( … … 171 171 * The reply the server sent to us for HELO. 172 172 * If null, no HELO string has yet been received. 173 * @ typestring|null173 * @var string|null 174 174 */ 175 175 protected $helo_rply = null; … … 182 182 * Other values can be boolean TRUE or an array containing extension options. 183 183 * If null, no HELO/EHLO string has yet been received. 184 * @ typearray|null184 * @var array|null 185 185 */ 186 186 protected $server_caps = null; … … 188 188 /** 189 189 * The most recent reply received from the server. 190 * @ typestring190 * @var string 191 191 */ 192 192 protected $last_reply = ''; … … 352 352 * Must be run after hello(). 353 353 * @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 354 * @param string $username The user name 355 * @param string $password The password 356 * @param string $authtype The auth type (PLAIN, LOGIN, NTLM, CRAM-MD5, XOAUTH2) 357 * @param string $realm The auth realm for NTLM 358 358 * @param string $workstation The auth workstation for NTLM 359 * @ access public360 * @return bool ean True if successfully authenticated.359 * @param null|OAuth $OAuth An optional OAuth instance (@see PHPMailerOAuth) 360 * @return bool True if successfully authenticated.* @access public 361 361 */ 362 362 public function authenticate( … … 365 365 $authtype = null, 366 366 $realm = '', 367 $workstation = '' 367 $workstation = '', 368 $OAuth = null 368 369 ) { 369 370 if (!$this->server_caps) { … … 674 675 $this->server_caps = array(); 675 676 $lines = explode("\n", $this->last_reply); 677 676 678 foreach ($lines as $n => $s) { 679 //First 4 chars contain response code followed by - or space 677 680 $s = trim(substr($s, 4)); 678 if ( !$s) {681 if (empty($s)) { 679 682 continue; 680 683 } … … 686 689 } else { 687 690 $name = array_shift($fields); 688 if ($name == 'SIZE') { 689 $fields = ($fields) ? $fields[0] : 0; 691 switch ($name) { 692 case 'SIZE': 693 $fields = ($fields ? $fields[0] : 0); 694 break; 695 case 'AUTH': 696 if (!is_array($fields)) { 697 $fields = array(); 698 } 699 break; 700 default: 701 $fields = true; 690 702 } 691 703 } 692 $this->server_caps[$name] = ($fields ? $fields : true);704 $this->server_caps[$name] = $fields; 693 705 } 694 706 } … … 740 752 * Returns true if the recipient was accepted false if it was rejected. 741 753 * 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)754 * @param string $address The address the message is being sent to 755 * @access public 756 * @return boolean 757 */ 758 public function recipient($address) 747 759 { 748 760 return $this->sendCommand( 749 761 'RCPT TO', 750 'RCPT TO:<' . $ toaddr. '>',762 'RCPT TO:<' . $address . '>', 751 763 array(250, 251) 752 764 ); … … 767 779 /** 768 780 * Send a command to an SMTP server and check its return code. 769 * @param string $command 781 * @param string $command The command name - not sent to the server 770 782 * @param string $commandstring The actual command to send 771 * @param integer|array $expect 783 * @param integer|array $expect One or more expected integer success codes 772 784 * @access protected 773 785 * @return boolean True on success. … … 777 789 if (!$this->connected()) { 778 790 $this->setError("Called $command without being connected"); 791 return false; 792 } 793 //Reject line breaks in all commands 794 if (strpos($commandstring, "\n") !== false or strpos($commandstring, "\r") !== false) { 795 $this->setError("Command '$command' contained line breaks"); 779 796 return false; 780 797 } … … 982 999 while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { 983 1000 $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);1001 $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL); 1002 $this->edebug("SMTP -> get_lines(): \$str is \"$str\"", self::DEBUG_LOWLEVEL); 986 1003 $data .= $str; 987 $this->edebug("SMTP -> get_lines(): \$data is \"$data\"", self::DEBUG_LOWLEVEL);988 1004 // If 4th character is a space, we are done reading, break the loop, micro-optimisation over strlen 989 1005 if ((isset($str[3]) and $str[3] == ' ')) {
Note: See TracChangeset
for help on using the changeset viewer.