Changeset 23522
- Timestamp:
- 02/28/2013 06:33:13 PM (11 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-phpmailer.php
r21128 r23522 3 3 .---------------------------------------------------------------------------. 4 4 | Software: PHPMailer - PHP email class | 5 | Version: 5.2. 1|5 | Version: 5.2.4 | 6 6 | Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ | 7 7 | ------------------------------------------------------------------------- | … … 24 24 25 25 /** 26 * PHPMailer - PHP email transport class26 * PHPMailer - PHP email creation and transport class 27 27 * NOTE: Requires PHP version 5 or later 28 28 * @package PHPMailer … … 32 32 * @copyright 2010 - 2012 Jim Jagielski 33 33 * @copyright 2004 - 2009 Andy Prevost 34 * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $35 34 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License 36 35 */ … … 38 37 if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n"); 39 38 39 /** 40 * PHP email creation and transport class 41 * @package PHPMailer 42 */ 40 43 class PHPMailer { 41 44 … … 93 96 */ 94 97 public $Sender = ''; 98 99 /** 100 * Sets the Return-Path of the message. If empty, it will 101 * be set to either From or Sender. 102 * @var string 103 */ 104 public $ReturnPath = ''; 95 105 96 106 /** … … 131 141 132 142 /** 133 * Stores the complete sent MIME message (Body and Headers)143 * Stores the extra header list which CreateHeader() doesn't fold in 134 144 * @var string 135 145 * @access protected 136 146 */ 137 protected $ SentMIMEMessage= '';147 protected $mailHeader = ''; 138 148 139 149 /** … … 157 167 158 168 /** 169 * Determine if mail() uses a fully sendmail compatible MTA that 170 * supports sendmail's "-oi -f" options 171 * @var boolean 172 */ 173 public $UseSendmailOptions = true; 174 175 /** 159 176 * Path to PHPMailer plugins. Useful if the SMTP class 160 177 * is in a different directory than the PHP include path. … … 184 201 public $MessageID = ''; 185 202 203 /** 204 * Sets the message Date to be used in the Date header. 205 * If empty, the current date will be added. 206 * @var string 207 */ 208 public $MessageDate = ''; 209 186 210 ///////////////////////////////////////////////// 187 211 // PROPERTIES FOR SMTP … … 189 213 190 214 /** 191 * Sets the SMTP hosts. All hosts must be separated by a 215 * Sets the SMTP hosts. 216 * 217 * All hosts must be separated by a 192 218 * semicolon. You can also specify a different port 193 219 * for each host by using this format: [hostname:port] … … 211 237 212 238 /** 213 * Sets connection prefix. 214 * Options are "", "ssl" or "tls" 239 * Sets connection prefix. Options are "", "ssl" or "tls" 215 240 * @var string 216 241 */ … … 234 259 */ 235 260 public $Password = ''; 261 262 /** 263 * Sets SMTP auth type. Options are LOGIN | PLAIN | NTLM (default LOGIN) 264 * @var string 265 */ 266 public $AuthType = ''; 267 268 /** 269 * Sets SMTP realm. 270 * @var string 271 */ 272 public $Realm = ''; 273 274 /** 275 * Sets SMTP workstation. 276 * @var string 277 */ 278 public $Workstation = ''; 236 279 237 280 /** … … 247 290 */ 248 291 public $SMTPDebug = false; 292 293 /** 294 * Sets the function/method to use for debugging output. 295 * Right now we only honor "echo" or "error_log" 296 * @var string 297 */ 298 public $Debugoutput = "echo"; 249 299 250 300 /** … … 270 320 271 321 /** 272 * Provides the ability to change the line ending 322 * Provides the ability to change the generic line ending 323 * NOTE: The default remains '\n'. We force CRLF where we KNOW 324 * it must be used via self::CRLF 273 325 * @var string 274 326 */ 275 327 public $LE = "\n"; 276 328 277 /** 278 * Used with DKIM DNS Resource Record 279 * @var string 280 */ 281 public $DKIM_selector = 'phpmailer'; 282 283 /** 284 * Used with DKIM DNS Resource Record 285 * optional, in format of email address 'you@yourdomain.com' 329 /** 330 * Used with DKIM Signing 331 * required parameter if DKIM is enabled 332 * 333 * domain selector example domainkey 334 * @var string 335 */ 336 public $DKIM_selector = ''; 337 338 /** 339 * Used with DKIM Signing 340 * required if DKIM is enabled, in format of email address 'you@yourdomain.com' typically used as the source of the email 286 341 * @var string 287 342 */ … … 289 344 290 345 /** 291 * Used with DKIM DNS Resource Record 346 * Used with DKIM Signing 347 * optional parameter if your private key requires a passphras 292 348 * @var string 293 349 */ … … 295 351 296 352 /** 297 * Used with DKIM DNS Resource Record298 * optional, in format of email address 'you@yourdomain.com'353 * Used with DKIM Singing 354 * required if DKIM is enabled, in format of email address 'domain.com' 299 355 * @var string 300 356 */ … … 302 358 303 359 /** 304 * Used with DKIM DNS Resource Record305 * optional, in format of email address 'you@yourdomain.com'360 * Used with DKIM Signing 361 * required if DKIM is enabled, path to private key file 306 362 * @var string 307 363 */ … … 309 365 310 366 /** 311 * Callback Action function name 312 * the function that handles the result of the send email action. Parameters: 367 * Callback Action function name. 368 * The function that handles the result of the send email action. 369 * It is called out by Send() for each email sent. 370 * 371 * Value can be: 372 * - 'function_name' for function names 373 * - 'Class::Method' for static method calls 374 * - array($object, 'Method') for calling methods on $object 375 * See http://php.net/is_callable manual page for more details. 376 * 377 * Parameters: 313 378 * bool $result result of the send action 314 379 * string $to email address of the recipient … … 317 382 * string $subject the subject 318 383 * string $body the email body 384 * string $from email address of sender 319 385 * @var string 320 386 */ … … 325 391 * @var string 326 392 */ 327 public $Version = '5.2. 1';393 public $Version = '5.2.4'; 328 394 329 395 /** 330 396 * What to use in the X-Mailer header 331 * @var string 397 * @var string NULL for default, whitespace for None, or actual string to use 332 398 */ 333 399 public $XMailer = ''; … … 337 403 ///////////////////////////////////////////////// 338 404 339 protected $smtp = NULL; 405 /** 406 * @var SMTP An instance of the SMTP sender class 407 * @access protected 408 */ 409 protected $smtp = null; 410 /** 411 * @var array An array of 'to' addresses 412 * @access protected 413 */ 340 414 protected $to = array(); 415 /** 416 * @var array An array of 'cc' addresses 417 * @access protected 418 */ 341 419 protected $cc = array(); 420 /** 421 * @var array An array of 'bcc' addresses 422 * @access protected 423 */ 342 424 protected $bcc = array(); 425 /** 426 * @var array An array of reply-to name and address 427 * @access protected 428 */ 343 429 protected $ReplyTo = array(); 430 /** 431 * @var array An array of all kinds of addresses: to, cc, bcc, replyto 432 * @access protected 433 */ 344 434 protected $all_recipients = array(); 435 /** 436 * @var array An array of attachments 437 * @access protected 438 */ 345 439 protected $attachment = array(); 440 /** 441 * @var array An array of custom headers 442 * @access protected 443 */ 346 444 protected $CustomHeader = array(); 445 /** 446 * @var string The message's MIME type 447 * @access protected 448 */ 347 449 protected $message_type = ''; 450 /** 451 * @var array An array of MIME boundary strings 452 * @access protected 453 */ 348 454 protected $boundary = array(); 455 /** 456 * @var array An array of available languages 457 * @access protected 458 */ 349 459 protected $language = array(); 460 /** 461 * @var integer The number of errors encountered 462 * @access protected 463 */ 350 464 protected $error_count = 0; 465 /** 466 * @var string The filename of a DKIM certificate file 467 * @access protected 468 */ 351 469 protected $sign_cert_file = ''; 470 /** 471 * @var string The filename of a DKIM key file 472 * @access protected 473 */ 352 474 protected $sign_key_file = ''; 475 /** 476 * @var string The password of a DKIM key 477 * @access protected 478 */ 353 479 protected $sign_key_pass = ''; 480 /** 481 * @var boolean Whether to throw exceptions for errors 482 * @access protected 483 */ 354 484 protected $exceptions = false; 355 485 … … 361 491 const STOP_CONTINUE = 1; // message?, likely ok to continue processing 362 492 const STOP_CRITICAL = 2; // message, plus full stop, critical error reached 363 493 const CRLF = "\r\n"; // SMTP RFC specified EOL 494 364 495 ///////////////////////////////////////////////// 365 496 // METHODS, VARIABLES 366 497 ///////////////////////////////////////////////// 498 499 /** 500 * Calls actual mail() function, but in a safe_mode aware fashion 501 * Also, unless sendmail_path points to sendmail (or something that 502 * claims to be sendmail), don't pass params (not a perfect fix, 503 * but it will do) 504 * @param string $to To 505 * @param string $subject Subject 506 * @param string $body Message Body 507 * @param string $header Additional Header(s) 508 * @param string $params Params 509 * @access private 510 * @return bool 511 */ 512 private function mail_passthru($to, $subject, $body, $header, $params) { 513 if ( ini_get('safe_mode') || !($this->UseSendmailOptions) ) { 514 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header); 515 } else { 516 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params); 517 } 518 return $rt; 519 } 520 521 /** 522 * Outputs debugging info via user-defined method 523 * @param string $str 524 */ 525 private function edebug($str) { 526 if ($this->Debugoutput == "error_log") { 527 error_log($str); 528 } else { 529 echo $str; 530 } 531 } 367 532 368 533 /** … … 477 642 * @param string $address The email address to send to 478 643 * @param string $name 644 * @throws phpmailerException 479 645 * @return boolean true on success, false if address already used or invalid in some way 480 646 * @access protected … … 486 652 throw new phpmailerException('Invalid recipient array: ' . $kind); 487 653 } 488 489 echo $this->Lang('Invalid recipient array').': '.$kind;654 if ($this->SMTPDebug) { 655 $this->edebug($this->Lang('Invalid recipient array').': '.$kind); 490 656 } 491 657 return false; … … 493 659 $address = trim($address); 494 660 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 495 if (! self::ValidateAddress($address)) {661 if (!$this->ValidateAddress($address)) { 496 662 $this->SetError($this->Lang('invalid_address').': '. $address); 497 663 if ($this->exceptions) { 498 664 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 499 665 } 500 501 echo $this->Lang('invalid_address').': '.$address;666 if ($this->SMTPDebug) { 667 $this->edebug($this->Lang('invalid_address').': '.$address); 502 668 } 503 669 return false; … … 522 688 * @param string $address 523 689 * @param string $name 690 * @param int $auto Also set Reply-To and Sender 691 * @throws phpmailerException 524 692 * @return boolean 525 693 */ … … 527 695 $address = trim($address); 528 696 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 529 if (! self::ValidateAddress($address)) {697 if (!$this->ValidateAddress($address)) { 530 698 $this->SetError($this->Lang('invalid_address').': '. $address); 531 699 if ($this->exceptions) { 532 700 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 533 701 } 534 535 echo $this->Lang('invalid_address').': '.$address;702 if ($this->SMTPDebug) { 703 $this->edebug($this->Lang('invalid_address').': '.$address); 536 704 } 537 705 return false; … … 552 720 /** 553 721 * Check that a string looks roughly like an email address should 554 * Static so it can be used without instantiation 555 * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator 556 * Conforms approximately to RFC2822 557 * @link http://www.hexillion.com/samples/#Regex Original pattern found here 722 * Static so it can be used without instantiation, public so people can overload 723 * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is 724 * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to 725 * not allow a@b type valid addresses :( 726 * Some Versions of PHP break on the regex though, likely due to PCRE, so use 727 * the older validation method for those users. (http://php.net/manual/en/pcre.installation.php) 728 * @link http://squiloople.com/2009/12/20/email-address-validation/ 729 * @copyright regex Copyright Michael Rushton 2009-10 | http://squiloople.com/ | Feel free to use and redistribute this code. But please keep this copyright notice. 558 730 * @param string $address The email address to check 559 731 * @return boolean … … 562 734 */ 563 735 public static function ValidateAddress($address) { 564 if (function_exists('filter_var')) { //Introduced in PHP 5.2 565 if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { 566 return false; 567 } else { 568 return true; 569 } 736 if ((defined('PCRE_VERSION')) && (version_compare(PCRE_VERSION, '8.0') >= 0)) { 737 return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[ ])+|(?>[ ]*\x0D\x0A)?[ ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address); 738 } elseif (function_exists('filter_var')) { //Introduced in PHP 5.2 739 if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) { 740 return false; 741 } else { 742 return true; 743 } 570 744 } else { 571 return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);572 745 return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address); 746 } 573 747 } 574 748 … … 581 755 * not sent successfully then it returns false. Use the ErrorInfo 582 756 * variable to view description of the error. 757 * @throws phpmailerException 583 758 * @return bool 584 759 */ … … 588 763 return $this->PostSend(); 589 764 } catch (phpmailerException $e) { 590 $this->SentMIMEMessage= '';765 $this->mailHeader = ''; 591 766 $this->SetError($e->getMessage()); 592 767 if ($this->exceptions) { … … 597 772 } 598 773 599 protected function PreSend() { 774 /** 775 * Prep mail by constructing all message entities 776 * @throws phpmailerException 777 * @return bool 778 */ 779 public function PreSend() { 600 780 try { 601 $mailHeader = "";781 $this->mailHeader = ""; 602 782 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { 603 783 throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); … … 620 800 621 801 // To capture the complete message when using mail(), create 622 802 // an extra header list which CreateHeader() doesn't fold in 623 803 if ($this->Mailer == 'mail') { 624 804 if (count($this->to) > 0) { 625 $ mailHeader .= $this->AddrAppend("To", $this->to);805 $this->mailHeader .= $this->AddrAppend("To", $this->to); 626 806 } else { 627 $ mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");807 $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;"); 628 808 } 629 $ mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));809 $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject)))); 630 810 // if(count($this->cc) > 0) { 631 // $ mailHeader .= $this->AddrAppend("Cc", $this->cc);811 // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc); 632 812 // } 633 813 } 634 814 635 815 // digitally sign with DKIM if enabled 636 if ( $this->DKIM_domain && $this->DKIM_private) {816 if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) { 637 817 $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody); 638 818 $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader; 639 819 } 640 820 641 $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);642 821 return true; 643 822 … … 651 830 } 652 831 653 protected function PostSend() { 832 /** 833 * Actual Email transport function 834 * Send the email via the selected mechanism 835 * @throws phpmailerException 836 * @return bool 837 */ 838 public function PostSend() { 654 839 try { 655 840 // Choose the mailer and send through it … … 664 849 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 665 850 } 666 667 851 } catch (phpmailerException $e) { 668 852 $this->SetError($e->getMessage()); … … 670 854 throw $e; 671 855 } 672 673 echo $e->getMessage()."\n";674 } 675 return false;676 }856 if ($this->SMTPDebug) { 857 $this->edebug($e->getMessage()."\n"); 858 } 859 } 860 return false; 677 861 } 678 862 … … 681 865 * @param string $header The message headers 682 866 * @param string $body The message body 867 * @throws phpmailerException 683 868 * @access protected 684 869 * @return bool … … 686 871 protected function SendmailSend($header, $body) { 687 872 if ($this->Sender != '') { 688 $sendmail = sprintf("%s -oi -f 873 $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); 689 874 } else { 690 875 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); 691 876 } 692 877 if ($this->SingleTo === true) { 693 foreach ($this->SingleToArray as $ key => $val) {878 foreach ($this->SingleToArray as $val) { 694 879 if(!@$mail = popen($sendmail, 'w')) { 695 880 throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); … … 727 912 * @param string $header The message headers 728 913 * @param string $body The message body 914 * @throws phpmailerException 729 915 * @access protected 730 916 * @return bool … … 740 926 $params = "-oi "; 741 927 } else { 742 $params = sprintf("-oi -f 928 $params = sprintf("-oi -f%s", $this->Sender); 743 929 } 744 930 if ($this->Sender != '' and !ini_get('safe_mode')) { 745 931 $old_from = ini_get('sendmail_from'); 746 932 ini_set('sendmail_from', $this->Sender); 747 if ($this->SingleTo === true && count($toArr) > 1) { 748 foreach ($toArr as $key => $val) { 749 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); 750 // implement call back function if it exists 751 $isSent = ($rt == 1) ? 1 : 0; 752 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 753 } 754 } else { 755 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); 933 } 934 $rt = false; 935 if ($this->SingleTo === true && count($toArr) > 1) { 936 foreach ($toArr as $val) { 937 $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params); 756 938 // implement call back function if it exists 757 939 $isSent = ($rt == 1) ? 1 : 0; 758 $this->doCallback($isSent, $ to, $this->cc, $this->bcc, $this->Subject, $body);940 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 759 941 } 760 942 } else { 761 if ($this->SingleTo === true && count($toArr) > 1) { 762 foreach ($toArr as $key => $val) { 763 $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); 764 // implement call back function if it exists 765 $isSent = ($rt == 1) ? 1 : 0; 766 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 767 } 768 } else { 769 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header); 770 // implement call back function if it exists 771 $isSent = ($rt == 1) ? 1 : 0; 772 $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 773 } 943 $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params); 944 // implement call back function if it exists 945 $isSent = ($rt == 1) ? 1 : 0; 946 $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 774 947 } 775 948 if (isset($old_from)) { … … 787 960 * @param string $header The message headers 788 961 * @param string $body The message body 962 * @throws phpmailerException 789 963 * @uses SMTP 790 964 * @access protected … … 800 974 $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender; 801 975 if(!$this->smtp->Mail($smtp_from)) { 802 throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL); 976 $this->SetError($this->Lang('from_failed') . $smtp_from . " : " . implode(",",$this->smtp->getError())) ; 977 throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL); 803 978 } 804 979 … … 851 1026 if($this->SMTPKeepAlive == true) { 852 1027 $this->smtp->Reset(); 1028 } else { 1029 $this->smtp->Quit(); 1030 $this->smtp->Close(); 853 1031 } 854 1032 return true; … … 860 1038 * @uses SMTP 861 1039 * @access public 1040 * @throws phpmailerException 862 1041 * @return bool 863 1042 */ 864 1043 public function SmtpConnect() { 865 1044 if(is_null($this->smtp)) { 866 $this->smtp = new SMTP(); 867 } 868 1045 $this->smtp = new SMTP; 1046 } 1047 1048 $this->smtp->Timeout = $this->Timeout; 869 1049 $this->smtp->do_debug = $this->SMTPDebug; 870 1050 $hosts = explode(';', $this->Host); … … 894 1074 if ($tls) { 895 1075 if (!$this->smtp->StartTLS()) { 896 throw new phpmailerException($this->Lang(' tls'));1076 throw new phpmailerException($this->Lang('connect_host')); 897 1077 } 898 1078 … … 903 1083 $connection = true; 904 1084 if ($this->SMTPAuth) { 905 if (!$this->smtp->Authenticate($this->Username, $this->Password)) { 1085 if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType, 1086 $this->Realm, $this->Workstation)) { 906 1087 throw new phpmailerException($this->Lang('authenticate')); 907 1088 } … … 909 1090 } 910 1091 $index++; 911 912 913 1092 if (!$connection) { 1093 throw new phpmailerException($this->Lang('connect_host')); 1094 } 914 1095 } 915 1096 } catch (phpmailerException $e) { 916 1097 $this->smtp->Reset(); 917 1098 if ($this->exceptions) { 918 1099 throw $e; 919 1100 } … … 927 1108 */ 928 1109 public function SmtpClose() { 929 if (!is_null($this->smtp)) {1110 if ($this->smtp !== null) { 930 1111 if($this->smtp->Connected()) { 931 1112 $this->smtp->Quit(); … … 940 1121 * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br") 941 1122 * @param string $lang_path Path to the language file directory 1123 * @return bool 942 1124 * @access public 943 1125 */ … … 945 1127 //Define full set of translatable strings 946 1128 $PHPMAILER_LANG = array( 947 'provide_address' => 'You must provide at least one recipient email address.', 1129 'authenticate' => 'SMTP Error: Could not authenticate.', 1130 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 1131 'data_not_accepted' => 'SMTP Error: Data not accepted.', 1132 'empty_message' => 'Message body empty', 1133 'encoding' => 'Unknown encoding: ', 1134 'execute' => 'Could not execute: ', 1135 'file_access' => 'Could not access file: ', 1136 'file_open' => 'File Error: Could not open file: ', 1137 'from_failed' => 'The following From address failed: ', 1138 'instantiate' => 'Could not instantiate mail function.', 1139 'invalid_address' => 'Invalid address', 948 1140 'mailer_not_supported' => ' mailer is not supported.', 949 'execute' => 'Could not execute: ', 950 'instantiate' => 'Could not instantiate mail function.', 951 'authenticate' => 'SMTP Error: Could not authenticate.', 952 'from_failed' => 'The following From address failed: ', 953 'recipients_failed' => 'SMTP Error: The following recipients failed: ', 954 'data_not_accepted' => 'SMTP Error: Data not accepted.', 955 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 956 'file_access' => 'Could not access file: ', 957 'file_open' => 'File Error: Could not open file: ', 958 'encoding' => 'Unknown encoding: ', 959 'signing' => 'Signing Error: ', 960 'smtp_error' => 'SMTP server error: ', 961 'empty_message' => 'Message body empty', 962 'invalid_address' => 'Invalid address', 963 'variable_set' => 'Cannot set or reset variable: ' 1141 'provide_address' => 'You must provide at least one recipient email address.', 1142 'recipients_failed' => 'SMTP Error: The following recipients failed: ', 1143 'signing' => 'Signing Error: ', 1144 'smtp_connect_failed' => 'SMTP Connect() failed.', 1145 'smtp_error' => 'SMTP server error: ', 1146 'variable_set' => 'Cannot set or reset variable: ' 964 1147 ); 965 1148 //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"! … … 987 1170 * Creates recipient headers. 988 1171 * @access public 1172 * @param string $type 1173 * @param array $addr 989 1174 * @return string 990 1175 */ … … 1004 1189 * Formats an address correctly. 1005 1190 * @access public 1191 * @param string $addr 1006 1192 * @return string 1007 1193 */ … … 1029 1215 // split multibyte characters when we wrap 1030 1216 $is_utf8 = (strtolower($this->CharSet) == "utf-8"); 1217 $lelen = strlen($this->LE); 1218 $crlflen = strlen(self::CRLF); 1031 1219 1032 1220 $message = $this->FixEOL($message); 1033 if (substr($message, - 1) == $this->LE) {1034 $message = substr($message, 0, - 1);1035 } 1036 1037 $line = explode($this->LE, $message); 1221 if (substr($message, -$lelen) == $this->LE) { 1222 $message = substr($message, 0, -$lelen); 1223 } 1224 1225 $line = explode($this->LE, $message); // Magic. We know FixEOL uses $LE 1038 1226 $message = ''; 1039 1227 for ($i = 0 ;$i < count($line); $i++) { … … 1043 1231 $word = $line_part[$e]; 1044 1232 if ($qp_mode and (strlen($word) > $length)) { 1045 $space_left = $length - strlen($buf) - 1;1233 $space_left = $length - strlen($buf) - $crlflen; 1046 1234 if ($e != 0) { 1047 1235 if ($space_left > 20) { … … 1057 1245 $word = substr($word, $len); 1058 1246 $buf .= ' ' . $part; 1059 $message .= $buf . sprintf("=%s", $this->LE);1247 $message .= $buf . sprintf("=%s", self::CRLF); 1060 1248 } else { 1061 1249 $message .= $buf . $soft_break; … … 1076 1264 1077 1265 if (strlen($word) > 0) { 1078 $message .= $part . sprintf("=%s", $this->LE);1266 $message .= $part . sprintf("=%s", self::CRLF); 1079 1267 } else { 1080 1268 $buf = $part; … … 1091 1279 } 1092 1280 } 1093 $message .= $buf . $this->LE;1281 $message .= $buf . self::CRLF; 1094 1282 } 1095 1283 … … 1176 1364 $this->boundary[3] = 'b3_' . $uniq_id; 1177 1365 1178 $result .= $this->HeaderLine('Date', self::RFCDate()); 1179 if($this->Sender == '') { 1366 if ($this->MessageDate == '') { 1367 $result .= $this->HeaderLine('Date', self::RFCDate()); 1368 } else { 1369 $result .= $this->HeaderLine('Date', $this->MessageDate); 1370 } 1371 1372 if ($this->ReturnPath) { 1373 $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath)); 1374 } elseif ($this->Sender == '') { 1180 1375 $result .= $this->HeaderLine('Return-Path', trim($this->From)); 1181 1376 } else { … … 1196 1391 } 1197 1392 } 1198 1393 } 1199 1394 1200 1395 $from = array(); … … 1228 1423 } 1229 1424 $result .= $this->HeaderLine('X-Priority', $this->Priority); 1230 if ($this->XMailer) {1231 $result .= $this->HeaderLine('X-Mailer', $this->XMailer);1425 if ($this->XMailer == '') { 1426 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1232 1427 } else { 1233 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1428 $myXmailer = trim($this->XMailer); 1429 if ($myXmailer) { 1430 $result .= $this->HeaderLine('X-Mailer', $myXmailer); 1431 } 1234 1432 } 1235 1433 … … 1258 1456 $result = ''; 1259 1457 switch($this->message_type) { 1260 case 'plain':1261 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);1262 $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"');1263 break;1264 1458 case 'inline': 1265 1459 $result .= $this->HeaderLine('Content-Type', 'multipart/related;'); … … 1278 1472 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 1279 1473 break; 1474 default: 1475 // Catches case 'plain': and case '': 1476 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); 1477 $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet); 1478 break; 1280 1479 } 1281 1480 1282 1481 if($this->Mailer != 'mail') { 1283 $result .= $this->LE .$this->LE;1482 $result .= $this->LE; 1284 1483 } 1285 1484 … … 1293 1492 */ 1294 1493 public function GetSentMIMEMessage() { 1295 return $this-> SentMIMEMessage;1494 return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody; 1296 1495 } 1297 1496 … … 1300 1499 * Assembles the message body. Returns an empty string on failure. 1301 1500 * @access public 1501 * @throws phpmailerException 1302 1502 * @return string The assembled message body 1303 1503 */ … … 1306 1506 1307 1507 if ($this->sign_key_file) { 1308 $body .= $this->GetMailMIME() ;1508 $body .= $this->GetMailMIME().$this->LE; 1309 1509 } 1310 1510 … … 1312 1512 1313 1513 switch($this->message_type) { 1314 case 'plain':1315 $body .= $this->EncodeString($this->Body, $this->Encoding);1316 break;1317 1514 case 'inline': 1318 1515 $body .= $this->GetBoundary($this->boundary[1], '', '', ''); … … 1399 1596 $body .= $this->AttachAll("attachment", $this->boundary[1]); 1400 1597 break; 1598 default: 1599 // catch case 'plain' and case '' 1600 $body .= $this->EncodeString($this->Body, $this->Encoding); 1601 break; 1401 1602 } 1402 1603 … … 1431 1632 * Returns the start of a message boundary. 1432 1633 * @access protected 1634 * @param string $boundary 1635 * @param string $charSet 1636 * @param string $contentType 1637 * @param string $encoding 1433 1638 * @return string 1434 1639 */ … … 1445 1650 } 1446 1651 $result .= $this->TextLine('--' . $boundary); 1447 $result .= sprintf("Content-Type: %s; charset= \"%s\"", $contentType, $charSet);1652 $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet); 1448 1653 $result .= $this->LE; 1449 1654 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); … … 1456 1661 * Returns the end of a message boundary. 1457 1662 * @access protected 1663 * @param string $boundary 1458 1664 * @return string 1459 1665 */ … … 1479 1685 * Returns a formatted header line. 1480 1686 * @access public 1687 * @param string $name 1688 * @param string $value 1481 1689 * @return string 1482 1690 */ … … 1488 1696 * Returns a formatted mail line. 1489 1697 * @access public 1698 * @param string $value 1490 1699 * @return string 1491 1700 */ … … 1506 1715 * @param string $encoding File encoding (see $Encoding). 1507 1716 * @param string $type File extension (MIME) type. 1717 * @throws phpmailerException 1508 1718 * @return bool 1509 1719 */ … … 1534 1744 throw $e; 1535 1745 } 1536 1537 echo $e->getMessage()."\n";1746 if ($this->SMTPDebug) { 1747 $this->edebug($e->getMessage()."\n"); 1538 1748 } 1539 1749 if ( $e->getCode() == self::STOP_CRITICAL ) { … … 1556 1766 * Returns an empty string on failure. 1557 1767 * @access protected 1768 * @param string $disposition_type 1769 * @param string $boundary 1558 1770 * @return string 1559 1771 */ … … 1569 1781 if($attachment[6] == $disposition_type) { 1570 1782 // Check for string attachment 1783 $string = ''; 1784 $path = ''; 1571 1785 $bString = $attachment[5]; 1572 1786 if ($bString) { … … 1625 1839 * @param string $path The full path to the file 1626 1840 * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' 1841 * @throws phpmailerException 1627 1842 * @see EncodeFile() 1628 1843 * @access protected … … 1634 1849 throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); 1635 1850 } 1636 if (function_exists('get_magic_quotes')) {1637 function get_magic_quotes() {1638 return false;1639 }1640 }1641 1642 1851 // if (!function_exists('get_magic_quotes')) { 1852 // function get_magic_quotes() { 1853 // return false; 1854 // } 1855 // } 1856 $magic_quotes = get_magic_quotes_runtime(); 1857 if ($magic_quotes) { 1643 1858 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1644 1859 set_magic_quotes_runtime(0); 1645 1860 } else { 1646 ini_set('magic_quotes_runtime', 0); 1647 1648 1861 ini_set('magic_quotes_runtime', 0); 1862 } 1863 } 1649 1864 $file_buffer = file_get_contents($path); 1650 1865 $file_buffer = $this->EncodeString($file_buffer, $encoding); 1651 1866 if ($magic_quotes) { 1652 1867 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1653 1868 set_magic_quotes_runtime($magic_quotes); 1654 1869 } else { 1655 ini_set('magic_quotes_runtime', $magic_quotes); 1656 1657 1870 ini_set('magic_quotes_runtime', $magic_quotes); 1871 } 1872 } 1658 1873 return $file_buffer; 1659 1874 } catch (Exception $e) { … … 1700 1915 * Encode a header string to best (shortest) of Q, B, quoted or none. 1701 1916 * @access public 1917 * @param string $str 1918 * @param string $position 1702 1919 * @return string 1703 1920 */ … … 1738 1955 // Use a custom function which correctly encodes and wraps long 1739 1956 // multibyte strings without breaking lines within a character 1740 $encoded = $this->Base64EncodeWrapMB($str );1957 $encoded = $this->Base64EncodeWrapMB($str, "\n"); 1741 1958 } else { 1742 1959 $encoded = base64_encode($str); … … 1748 1965 $encoded = $this->EncodeQ($str, $position); 1749 1966 $encoded = $this->WrapText($encoded, $maxlen, true); 1750 $encoded = str_replace('='. $this->LE, "\n", trim($encoded));1967 $encoded = str_replace('='.self::CRLF, "\n", trim($encoded)); 1751 1968 } 1752 1969 … … 1777 1994 * @access public 1778 1995 * @param string $str multi-byte text to wrap encode 1996 * @param string $lf string to use as linefeed/end-of-line 1779 1997 * @return string 1780 1998 */ 1781 public function Base64EncodeWrapMB($str ) {1999 public function Base64EncodeWrapMB($str, $lf=null) { 1782 2000 $start = "=?".$this->CharSet."?B?"; 1783 2001 $end = "?="; 1784 2002 $encoded = ""; 2003 if ($lf === null) { 2004 $lf = $this->LE; 2005 } 1785 2006 1786 2007 $mb_length = mb_strlen($str, $this->CharSet); … … 1803 2024 while (strlen($chunk) > $length); 1804 2025 1805 $encoded .= $chunk . $ this->LE;2026 $encoded .= $chunk . $lf; 1806 2027 } 1807 2028 1808 2029 // Chomp the last linefeed 1809 $encoded = substr($encoded, 0, -strlen($ this->LE));2030 $encoded = substr($encoded, 0, -strlen($lf)); 1810 2031 return $encoded; 1811 2032 } … … 1815 2036 * Only uses standard PHP, slow, but will always work 1816 2037 * @access public 1817 * @param string $string the text to encode2038 * @param string $input 1818 2039 * @param integer $line_max Number of chars allowed on a line before wrapping 2040 * @param bool $space_conv 2041 * @internal param string $string the text to encode 1819 2042 * @return string 1820 2043 */ … … 1841 2064 } 1842 2065 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required 1843 $h2 = floor($dec/16);1844 $h1 = floor($dec%16);2066 $h2 = (integer)floor($dec/16); 2067 $h1 = (integer)floor($dec%16); 1845 2068 $c = $escape.$hex[$h2].$hex[$h1]; 1846 2069 } … … 1902 2125 */ 1903 2126 public function EncodeQ($str, $position = 'text') { 1904 // 1905 $encoded = preg_replace('/[\r\n]*/', '', $str);1906 2127 //There should not be any EOL in the string 2128 $pattern=""; 2129 $encoded = str_replace(array("\r", "\n"), '', $str); 1907 2130 switch (strtolower($position)) { 1908 2131 case 'phrase': 1909 $ encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);2132 $pattern = '^A-Za-z0-9!*+\/ -'; 1910 2133 break; 2134 1911 2135 case 'comment': 1912 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); 2136 $pattern = '\(\)"'; 2137 //note that we dont break here! 2138 //for this reason we build the $pattern withoud including delimiters and [] 2139 1913 2140 case 'text': 1914 2141 default: 1915 // Replace every high ascii, control =, ? and _ characters 1916 //TODO using /e (equivalent to eval()) is probably not a good idea 1917 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', 1918 "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded); 2142 //Replace every high ascii, control =, ? and _ characters 2143 //We put \075 (=) as first value to make sure it's the first one in being converted, preventing double encode 2144 $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern; 1919 2145 break; 1920 2146 } 1921 1922 // Replace every spaces to _ (more readable than =20) 1923 $encoded = str_replace(' ', '_', $encoded); 1924 1925 return $encoded; 1926 } 2147 2148 if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) { 2149 foreach (array_unique($matches[0]) as $char) { 2150 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded); 2151 } 2152 } 2153 2154 //Replace every spaces to _ (more readable than =20) 2155 return str_replace(' ', '_', $encoded); 2156 } 2157 1927 2158 1928 2159 /** … … 1990 2221 } 1991 2222 1992 public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') { 2223 /** 2224 * Adds an embedded stringified attachment. This can include images, sounds, and 2225 * just about any other document. Make sure to set the $type to an 2226 * image type. For JPEG images use "image/jpeg" and for GIF images 2227 * use "image/gif". 2228 * @param string $string The attachment. 2229 * @param string $cid Content ID of the attachment. Use this to identify 2230 * the Id for accessing the image in an HTML form. 2231 * @param string $name Overrides the attachment name. 2232 * @param string $encoding File encoding (see $Encoding). 2233 * @param string $type File extension (MIME) type. 2234 * @return bool 2235 */ 2236 public function AddStringEmbeddedImage($string, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { 1993 2237 // Append to $attachment array 1994 2238 $this->attachment[] = array( 1995 2239 0 => $string, 1996 1 => $ filename,1997 2 => basename($filename),2240 1 => $name, 2241 2 => $name, 1998 2242 3 => $encoding, 1999 2243 4 => $type, … … 2018 2262 } 2019 2263 2264 /** 2265 * Returns true if an attachment (non-inline) is present. 2266 * @return bool 2267 */ 2020 2268 public function AttachmentExists() { 2021 2269 foreach($this->attachment as $attachment) { … … 2027 2275 } 2028 2276 2277 /** 2278 * Does this message have an alternative body set? 2279 * @return bool 2280 */ 2029 2281 public function AlternativeExists() { 2030 return strlen($this->AltBody)>0;2282 return !empty($this->AltBody); 2031 2283 } 2032 2284 … … 2112 2364 * Adds the error message to the error container. 2113 2365 * @access protected 2366 * @param string $msg 2114 2367 * @return void 2115 2368 */ … … 2161 2414 * Returns a message in the appropriate language. 2162 2415 * @access protected 2416 * @param string $key 2163 2417 * @return string 2164 2418 */ … … 2185 2439 2186 2440 /** 2187 * Changes every end of line from CR or LF to CRLF. 2188 * @access public 2441 * Changes every end of line from CRLF, CR or LF to $this->LE. 2442 * @access public 2443 * @param string $str String to FixEOL 2189 2444 * @return string 2190 2445 */ 2191 2446 public function FixEOL($str) { 2192 $str = str_replace("\r\n", "\n", $str); 2193 $str = str_replace("\r", "\n", $str); 2194 $str = str_replace("\n", $this->LE, $str); 2195 return $str; 2196 } 2197 2198 /** 2199 * Adds a custom header. 2200 * @access public 2447 // condense down to \n 2448 $nstr = str_replace(array("\r\n", "\r"), "\n", $str); 2449 // Now convert LE as needed 2450 if ($this->LE !== "\n") { 2451 $nstr = str_replace("\n", $this->LE, $nstr); 2452 } 2453 return $nstr; 2454 } 2455 2456 /** 2457 * Adds a custom header. $name value can be overloaded to contain 2458 * both header name and value (name:value) 2459 * @access public 2460 * @param string $name custom header name 2461 * @param string $value header value 2201 2462 * @return void 2202 2463 */ 2203 public function AddCustomHeader($custom_header) { 2204 $this->CustomHeader[] = explode(':', $custom_header, 2); 2464 public function AddCustomHeader($name, $value=null) { 2465 if ($value === null) { 2466 // Value passed in as name:value 2467 $this->CustomHeader[] = explode(':', $name, 2); 2468 } else { 2469 $this->CustomHeader[] = array($name, $value); 2470 } 2205 2471 } 2206 2472 … … 2208 2474 * Evaluates the message and returns modifications for inline images and backgrounds 2209 2475 * @access public 2210 * @return $message 2476 * @param string $message Text to be HTML modified 2477 * @param string $basedir baseline directory for path 2478 * @return string $message 2211 2479 */ 2212 2480 public function MsgHTML($message, $basedir = '') { … … 2218 2486 $filename = basename($url); 2219 2487 $directory = dirname($url); 2220 ($directory == '.') ? $directory='': ''; 2221 $cid = 'cid:' . md5($filename); 2488 if ($directory == '.') { 2489 $directory = ''; 2490 } 2491 $cid = 'cid:' . md5($url); 2222 2492 $ext = pathinfo($filename, PATHINFO_EXTENSION); 2223 2493 $mimeType = self::_mime_types($ext); 2224 2494 if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; } 2225 2495 if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; } 2226 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($ filename), $filename, 'base64', $mimeType) ) {2496 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($url), $filename, 'base64', $mimeType) ) { 2227 2497 $message = preg_replace("/".$images[1][$i]."=[\"']".preg_quote($url, '/')."[\"']/Ui", $images[1][$i]."=\"".$cid."\"", $message); 2228 2498 } … … 2232 2502 $this->IsHTML(true); 2233 2503 $this->Body = $message; 2234 2235 2236 2237 2238 2239 2504 if (empty($this->AltBody)) { 2505 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); 2506 if (!empty($textMsg)) { 2507 $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet); 2508 } 2509 } 2240 2510 if (empty($this->AltBody)) { 2241 2511 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; 2242 2512 } 2243 2513 return $message; 2244 2514 } 2245 2515 2246 2516 /** 2247 2517 * Gets the MIME type of the embedded or inline image 2248 * @param string File extension2518 * @param string $ext File extension 2249 2519 * @access public 2250 2520 * @return string MIME type of ext … … 2253 2523 public static function _mime_types($ext = '') { 2254 2524 $mimes = array( 2525 'xl' => 'application/excel', 2255 2526 'hqx' => 'application/mac-binhex40', 2256 2527 'cpt' => 'application/mac-compactpro', 2528 'bin' => 'application/macbinary', 2257 2529 'doc' => 'application/msword', 2258 'bin' => 'application/macbinary', 2530 'word' => 'application/msword', 2531 'class' => 'application/octet-stream', 2532 'dll' => 'application/octet-stream', 2259 2533 'dms' => 'application/octet-stream', 2534 'exe' => 'application/octet-stream', 2260 2535 'lha' => 'application/octet-stream', 2261 2536 'lzh' => 'application/octet-stream', 2262 'exe' => 'application/octet-stream',2263 'class' => 'application/octet-stream',2264 2537 'psd' => 'application/octet-stream', 2538 'sea' => 'application/octet-stream', 2265 2539 'so' => 'application/octet-stream', 2266 'sea' => 'application/octet-stream',2267 'dll' => 'application/octet-stream',2268 2540 'oda' => 'application/oda', 2269 2541 'pdf' => 'application/pdf', … … 2283 2555 'dvi' => 'application/x-dvi', 2284 2556 'gtar' => 'application/x-gtar', 2557 'php3' => 'application/x-httpd-php', 2558 'php4' => 'application/x-httpd-php', 2285 2559 'php' => 'application/x-httpd-php', 2286 'php4' => 'application/x-httpd-php',2287 'php3' => 'application/x-httpd-php',2288 2560 'phtml' => 'application/x-httpd-php', 2289 2561 'phps' => 'application/x-httpd-php-source', … … 2293 2565 'tar' => 'application/x-tar', 2294 2566 'tgz' => 'application/x-tar', 2567 'xht' => 'application/xhtml+xml', 2295 2568 'xhtml' => 'application/xhtml+xml', 2296 'xht' => 'application/xhtml+xml',2297 2569 'zip' => 'application/zip', 2298 2570 'mid' => 'audio/midi', 2299 2571 'midi' => 'audio/midi', 2300 'mpga' => 'audio/mpeg',2301 2572 'mp2' => 'audio/mpeg', 2302 2573 'mp3' => 'audio/mpeg', 2574 'mpga' => 'audio/mpeg', 2303 2575 'aif' => 'audio/x-aiff', 2576 'aifc' => 'audio/x-aiff', 2304 2577 'aiff' => 'audio/x-aiff', 2305 'aifc' => 'audio/x-aiff',2306 2578 'ram' => 'audio/x-pn-realaudio', 2307 2579 'rm' => 'audio/x-pn-realaudio', 2308 2580 'rpm' => 'audio/x-pn-realaudio-plugin', 2309 2581 'ra' => 'audio/x-realaudio', 2310 'rv' => 'video/vnd.rn-realvideo',2311 2582 'wav' => 'audio/x-wav', 2312 2583 'bmp' => 'image/bmp', 2313 2584 'gif' => 'image/gif', 2314 2585 'jpeg' => 'image/jpeg', 2586 'jpe' => 'image/jpeg', 2315 2587 'jpg' => 'image/jpeg', 2316 'jpe' => 'image/jpeg',2317 2588 'png' => 'image/png', 2318 2589 'tiff' => 'image/tiff', 2319 2590 'tif' => 'image/tiff', 2591 'eml' => 'message/rfc822', 2320 2592 'css' => 'text/css', 2321 2593 'html' => 'text/html', 2322 2594 'htm' => 'text/html', 2323 2595 'shtml' => 'text/html', 2596 'log' => 'text/plain', 2597 'text' => 'text/plain', 2324 2598 'txt' => 'text/plain', 2325 'text' => 'text/plain',2326 'log' => 'text/plain',2327 2599 'rtx' => 'text/richtext', 2328 2600 'rtf' => 'text/rtf', … … 2330 2602 'xsl' => 'text/xml', 2331 2603 'mpeg' => 'video/mpeg', 2604 'mpe' => 'video/mpeg', 2332 2605 'mpg' => 'video/mpeg', 2333 'm pe' => 'video/mpeg',2606 'mov' => 'video/quicktime', 2334 2607 'qt' => 'video/quicktime', 2335 ' mov' => 'video/quicktime',2608 'rv' => 'video/vnd.rn-realvideo', 2336 2609 'avi' => 'video/x-msvideo', 2337 'movie' => 'video/x-sgi-movie', 2338 'doc' => 'application/msword', 2339 'word' => 'application/msword', 2340 'xl' => 'application/excel', 2341 'eml' => 'message/rfc822' 2610 'movie' => 'video/x-sgi-movie' 2342 2611 ); 2343 2612 return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; … … 2354 2623 * @param mixed $value Parameter Value 2355 2624 * NOTE: will not work with arrays, there are no arrays to set/reset 2625 * @throws phpmailerException 2626 * @return bool 2356 2627 * @todo Should this not be using __set() magic function? 2357 2628 */ … … 2379 2650 */ 2380 2651 public function SecureHeader($str) { 2381 $str = str_replace("\r", '', $str); 2382 $str = str_replace("\n", '', $str); 2383 return trim($str); 2652 return trim(str_replace(array("\r", "\n"), '', $str)); 2384 2653 } 2385 2654 … … 2388 2657 * 2389 2658 * @access public 2659 * @param $cert_filename 2390 2660 * @param string $key_filename Parameter File Name 2391 2661 * @param string $key_pass Password for private key … … 2401 2671 * 2402 2672 * @access public 2403 * @param string $ key_filename Parameter File Name2404 * @ param string $key_pass Password for private key2673 * @param string $txt 2674 * @return string 2405 2675 */ 2406 2676 public function DKIM_QP($txt) { 2407 $tmp = '';2408 2677 $line = ''; 2409 2678 for ($i = 0; $i < strlen($txt); $i++) { … … 2423 2692 * @access public 2424 2693 * @param string $s Header 2694 * @return string 2425 2695 */ 2426 2696 public function DKIM_Sign($s) { … … 2434 2704 return base64_encode($signature); 2435 2705 } 2706 return ''; 2436 2707 } 2437 2708 … … 2441 2712 * @access public 2442 2713 * @param string $s Header 2714 * @return string 2443 2715 */ 2444 2716 public function DKIM_HeaderC($s) { … … 2460 2732 * @access public 2461 2733 * @param string $body Message Body 2734 * @return string 2462 2735 */ 2463 2736 public function DKIM_BodyC($body) { … … 2480 2753 * @param string $subject Subject 2481 2754 * @param string $body Body 2755 * @return string 2482 2756 */ 2483 2757 public function DKIM_Add($headers_line, $subject, $body) { … … 2488 2762 $subject_header = "Subject: $subject"; 2489 2763 $headers = explode($this->LE, $headers_line); 2764 $from_header = ""; 2765 $to_header = ""; 2490 2766 foreach($headers as $header) { 2491 2767 if (strpos($header, 'From:') === 0) { … … 2513 2789 $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); 2514 2790 $signed = $this->DKIM_Sign($toSign); 2515 return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; 2516 } 2517 2518 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) { 2519 if (!empty($this->action_function) && function_exists($this->action_function)) { 2520 $params = array($isSent, $to, $cc, $bcc, $subject, $body); 2791 return "X-PHPMAILER-DKIM: code.google.com/a/apache-extras.org/p/phpmailer/\r\n".$dkimhdrs.$signed."\r\n"; 2792 } 2793 2794 /** 2795 * Perform callback 2796 * @param boolean $isSent 2797 * @param string $to 2798 * @param string $cc 2799 * @param string $bcc 2800 * @param string $subject 2801 * @param string $body 2802 * @param string $from 2803 */ 2804 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) { 2805 if (!empty($this->action_function) && is_callable($this->action_function)) { 2806 $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from); 2521 2807 call_user_func_array($this->action_function, $params); 2522 2808 } … … 2524 2810 } 2525 2811 2812 /** 2813 * Exception handler for PHPMailer 2814 * @package PHPMailer 2815 */ 2526 2816 class phpmailerException extends Exception { 2817 /** 2818 * Prettify error message output 2819 * @return string 2820 */ 2527 2821 public function errorMessage() { 2528 2822 $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; -
trunk/wp-includes/class-smtp.php
r19849 r23522 3 3 .---------------------------------------------------------------------------. 4 4 | Software: PHPMailer - PHP email class | 5 | Version: 5.2. 1|5 | Version: 5.2.4 | 6 6 | Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ | 7 7 | ------------------------------------------------------------------------- | … … 33 33 * @copyright 2010 - 2012 Jim Jagielski 34 34 * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL) 35 * @version $Id: class.smtp.php 450 2010-06-23 16:46:33Z coolbru $36 35 */ 37 36 38 37 /** 39 * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP 40 * commands except TURN which will always return a not implemented 41 * error. SMTP also provides some utility methods for sending mail 42 * to an SMTP server. 43 * original author: Chris Ryan 38 * PHP RFC821 SMTP client 39 * 40 * Implements all the RFC 821 SMTP commands except TURN which will always return a not implemented error. 41 * SMTP also provides some utility methods for sending mail to an SMTP server. 42 * @author Chris Ryan 43 * @package PHPMailer 44 44 */ 45 45 … … 52 52 53 53 /** 54 * SMTP reply line ending 54 * SMTP reply line ending (don't change) 55 55 * @var string 56 56 */ … … 64 64 65 65 /** 66 * Sets the function/method to use for debugging output. 67 * Right now we only honor "echo" or "error_log" 68 * @var string 69 */ 70 public $Debugoutput = "echo"; 71 72 /** 66 73 * Sets VERP use on/off (default is off) 67 74 * @var bool … … 70 77 71 78 /** 79 * Sets the SMTP timeout value for reads, in seconds 80 * @var int 81 */ 82 public $Timeout = 15; 83 84 /** 85 * Sets the SMTP timelimit value for reads, in seconds 86 * @var int 87 */ 88 public $Timelimit = 30; 89 90 /** 72 91 * Sets the SMTP PHPMailer Version number 73 92 * @var string 74 93 */ 75 public $Version = '5.2. 1';94 public $Version = '5.2.4'; 76 95 77 96 ///////////////////////////////////////////////// … … 79 98 ///////////////////////////////////////////////// 80 99 81 private $smtp_conn; // the socket to the server 82 private $error; // error if any on the last call 83 private $helo_rply; // the reply the server sent to us for HELO 100 /** 101 * @var resource The socket to the server 102 */ 103 private $smtp_conn; 104 /** 105 * @var string Error message, if any, for the last call 106 */ 107 private $error; 108 /** 109 * @var string The reply the server sent to us for HELO 110 */ 111 private $helo_rply; 112 113 /** 114 * Outputs debugging info via user-defined method 115 * @param string $str 116 */ 117 private function edebug($str) { 118 if ($this->Debugoutput == "error_log") { 119 error_log($str); 120 } else { 121 echo $str; 122 } 123 } 84 124 85 125 /** 86 126 * Initialize the class so that the data is in a known state. 87 127 * @access public 88 * @return void128 * @return SMTP 89 129 */ 90 130 public function __construct() { … … 111 151 * SMTP CODE FAILURE: 421 112 152 * @access public 153 * @param string $host 154 * @param int $port 155 * @param int $tval 113 156 * @return bool 114 157 */ … … 140 183 "errstr" => $errstr); 141 184 if($this->do_debug >= 1) { 142 echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';185 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />'); 143 186 } 144 187 return false; … … 147 190 // SMTP server can take longer to respond, give longer timeout for first read 148 191 // Windows does not have support for this timeout function 149 if(substr(PHP_OS, 0, 3) != "WIN") 150 socket_set_timeout($this->smtp_conn, $tval, 0); 192 if(substr(PHP_OS, 0, 3) != "WIN") { 193 $max = ini_get('max_execution_time'); 194 if ($max != 0 && $tval > $max) { // don't bother if unlimited 195 @set_time_limit($tval); 196 } 197 stream_set_timeout($this->smtp_conn, $tval, 0); 198 } 151 199 152 200 // get any announcement … … 154 202 155 203 if($this->do_debug >= 2) { 156 echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';204 $this->edebug("SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />'); 157 205 } 158 206 … … 183 231 184 232 if($this->do_debug >= 2) { 185 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';233 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 186 234 } 187 235 … … 192 240 "smtp_msg" => substr($rply,4)); 193 241 if($this->do_debug >= 1) { 194 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';242 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 195 243 } 196 244 return false; … … 209 257 * Hello() method. Returns true if successfully authenticated. 210 258 * @access public 211 * @return bool 212 */ 213 public function Authenticate($username, $password) { 214 // Start authentication 215 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); 216 217 $rply = $this->get_lines(); 218 $code = substr($rply,0,3); 219 220 if($code != 334) { 221 $this->error = 222 array("error" => "AUTH not accepted from server", 223 "smtp_code" => $code, 224 "smtp_msg" => substr($rply,4)); 225 if($this->do_debug >= 1) { 226 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 227 } 228 return false; 229 } 230 231 // Send encoded username 232 fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); 233 234 $rply = $this->get_lines(); 235 $code = substr($rply,0,3); 236 237 if($code != 334) { 238 $this->error = 239 array("error" => "Username not accepted from server", 240 "smtp_code" => $code, 241 "smtp_msg" => substr($rply,4)); 242 if($this->do_debug >= 1) { 243 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 244 } 245 return false; 246 } 247 248 // Send encoded password 249 fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); 250 251 $rply = $this->get_lines(); 252 $code = substr($rply,0,3); 253 254 if($code != 235) { 255 $this->error = 256 array("error" => "Password not accepted from server", 257 "smtp_code" => $code, 258 "smtp_msg" => substr($rply,4)); 259 if($this->do_debug >= 1) { 260 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'; 261 } 262 return false; 263 } 264 259 * @param string $username 260 * @param string $password 261 * @param string $authtype 262 * @param string $realm 263 * @param string $workstation 264 * @return bool 265 */ 266 public function Authenticate($username, $password, $authtype='LOGIN', $realm='', $workstation='') { 267 if (empty($authtype)) { 268 $authtype = 'LOGIN'; 269 } 270 271 switch ($authtype) { 272 case 'PLAIN': 273 // Start authentication 274 fputs($this->smtp_conn,"AUTH PLAIN" . $this->CRLF); 275 276 $rply = $this->get_lines(); 277 $code = substr($rply,0,3); 278 279 if($code != 334) { 280 $this->error = 281 array("error" => "AUTH not accepted from server", 282 "smtp_code" => $code, 283 "smtp_msg" => substr($rply,4)); 284 if($this->do_debug >= 1) { 285 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 286 } 287 return false; 288 } 289 // Send encoded username and password 290 fputs($this->smtp_conn, base64_encode("\0".$username."\0".$password) . $this->CRLF); 291 292 $rply = $this->get_lines(); 293 $code = substr($rply,0,3); 294 295 if($code != 235) { 296 $this->error = 297 array("error" => "Authentication not accepted from server", 298 "smtp_code" => $code, 299 "smtp_msg" => substr($rply,4)); 300 if($this->do_debug >= 1) { 301 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 302 } 303 return false; 304 } 305 break; 306 case 'LOGIN': 307 // Start authentication 308 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); 309 310 $rply = $this->get_lines(); 311 $code = substr($rply,0,3); 312 313 if($code != 334) { 314 $this->error = 315 array("error" => "AUTH not accepted from server", 316 "smtp_code" => $code, 317 "smtp_msg" => substr($rply,4)); 318 if($this->do_debug >= 1) { 319 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 320 } 321 return false; 322 } 323 324 // Send encoded username 325 fputs($this->smtp_conn, base64_encode($username) . $this->CRLF); 326 327 $rply = $this->get_lines(); 328 $code = substr($rply,0,3); 329 330 if($code != 334) { 331 $this->error = 332 array("error" => "Username not accepted from server", 333 "smtp_code" => $code, 334 "smtp_msg" => substr($rply,4)); 335 if($this->do_debug >= 1) { 336 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 337 } 338 return false; 339 } 340 341 // Send encoded password 342 fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); 343 344 $rply = $this->get_lines(); 345 $code = substr($rply,0,3); 346 347 if($code != 235) { 348 $this->error = 349 array("error" => "Password not accepted from server", 350 "smtp_code" => $code, 351 "smtp_msg" => substr($rply,4)); 352 if($this->do_debug >= 1) { 353 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 354 } 355 return false; 356 } 357 break; 358 case 'NTLM': 359 /* 360 * ntlm_sasl_client.php 361 ** Bundled with Permission 362 ** 363 ** How to telnet in windows: http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx 364 ** PROTOCOL Documentation http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication 365 */ 366 require_once('ntlm_sasl_client.php'); 367 $temp = new stdClass(); 368 $ntlm_client = new ntlm_sasl_client_class; 369 if(! $ntlm_client->Initialize($temp)){//let's test if every function its available 370 $this->error = array("error" => $temp->error); 371 if($this->do_debug >= 1) { 372 $this->edebug("You need to enable some modules in your php.ini file: " . $this->error["error"] . $this->CRLF); 373 } 374 return false; 375 } 376 $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);//msg1 377 378 fputs($this->smtp_conn,"AUTH NTLM " . base64_encode($msg1) . $this->CRLF); 379 380 $rply = $this->get_lines(); 381 $code = substr($rply,0,3); 382 383 384 if($code != 334) { 385 $this->error = 386 array("error" => "AUTH not accepted from server", 387 "smtp_code" => $code, 388 "smtp_msg" => substr($rply,4)); 389 if($this->do_debug >= 1) { 390 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF); 391 } 392 return false; 393 } 394 395 $challange = substr($rply,3);//though 0 based, there is a white space after the 3 digit number....//msg2 396 $challange = base64_decode($challange); 397 $ntlm_res = $ntlm_client->NTLMResponse(substr($challange,24,8),$password); 398 $msg3 = $ntlm_client->TypeMsg3($ntlm_res,$username,$realm,$workstation);//msg3 399 // Send encoded username 400 fputs($this->smtp_conn, base64_encode($msg3) . $this->CRLF); 401 402 $rply = $this->get_lines(); 403 $code = substr($rply,0,3); 404 405 if($code != 235) { 406 $this->error = 407 array("error" => "Could not authenticate", 408 "smtp_code" => $code, 409 "smtp_msg" => substr($rply,4)); 410 if($this->do_debug >= 1) { 411 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF); 412 } 413 return false; 414 } 415 break; 416 } 265 417 return true; 266 418 } … … 277 429 // the socket is valid but we are not connected 278 430 if($this->do_debug >= 1) { 279 echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";431 $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"); 280 432 } 281 433 $this->Close(); … … 325 477 * SMTP CODE ERROR : 500,501,503,421 326 478 * @access public 479 * @param string $msg_data 327 480 * @return bool 328 481 */ … … 342 495 343 496 if($this->do_debug >= 2) { 344 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';497 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 345 498 } 346 499 … … 351 504 "smtp_msg" => substr($rply,4)); 352 505 if($this->do_debug >= 1) { 353 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';506 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 354 507 } 355 508 return false; … … 436 589 437 590 if($this->do_debug >= 2) { 438 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';591 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 439 592 } 440 593 … … 445 598 "smtp_msg" => substr($rply,4)); 446 599 if($this->do_debug >= 1) { 447 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';600 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 448 601 } 449 602 return false; … … 462 615 * SMTP CODE ERROR : 500, 501, 504, 421 463 616 * @access public 617 * @param string $host 464 618 * @return bool 465 619 */ … … 492 646 * Sends a HELO/EHLO command. 493 647 * @access private 648 * @param string $hello 649 * @param string $host 494 650 * @return bool 495 651 */ … … 501 657 502 658 if($this->do_debug >= 2) { 503 echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';659 $this->edebug("SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />'); 504 660 } 505 661 … … 510 666 "smtp_msg" => substr($rply,4)); 511 667 if($this->do_debug >= 1) { 512 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';668 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 513 669 } 514 670 return false; … … 532 688 * SMTP CODE SUCCESS: 500,501,421 533 689 * @access public 690 * @param string $from 534 691 * @return bool 535 692 */ … … 543 700 } 544 701 545 $useVerp = ($this->do_verp ? " XVERP" : "");702 $useVerp = ($this->do_verp ? " XVERP" : ""); 546 703 fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); 547 704 … … 550 707 551 708 if($this->do_debug >= 2) { 552 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';709 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 553 710 } 554 711 … … 559 716 "smtp_msg" => substr($rply,4)); 560 717 if($this->do_debug >= 1) { 561 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';718 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 562 719 } 563 720 return false; … … 575 732 * SMTP CODE ERROR : 500 576 733 * @access public 734 * @param bool $close_on_error 577 735 * @return bool 578 736 */ … … 593 751 594 752 if($this->do_debug >= 2) { 595 echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';753 $this->edebug("SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />'); 596 754 } 597 755 … … 607 765 $rval = false; 608 766 if($this->do_debug >= 1) { 609 echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';767 $this->edebug("SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'); 610 768 } 611 769 } … … 628 786 * SMTP CODE ERROR : 500,501,503,421 629 787 * @access public 788 * @param string $to 630 789 * @return bool 631 790 */ … … 645 804 646 805 if($this->do_debug >= 2) { 647 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';806 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 648 807 } 649 808 … … 654 813 "smtp_msg" => substr($rply,4)); 655 814 if($this->do_debug >= 1) { 656 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';815 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 657 816 } 658 817 return false; … … 688 847 689 848 if($this->do_debug >= 2) { 690 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';849 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 691 850 } 692 851 … … 697 856 "smtp_msg" => substr($rply,4)); 698 857 if($this->do_debug >= 1) { 699 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';858 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 700 859 } 701 860 return false; … … 719 878 * SMTP CODE SUCCESS: 500,501,502,421 720 879 * @access public 880 * @param string $from 721 881 * @return bool 722 882 */ … … 736 896 737 897 if($this->do_debug >= 2) { 738 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';898 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 739 899 } 740 900 … … 745 905 "smtp_msg" => substr($rply,4)); 746 906 if($this->do_debug >= 1) { 747 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';907 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 748 908 } 749 909 return false; … … 769 929 "is not implemented"); 770 930 if($this->do_debug >= 1) { 771 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';931 $this->edebug("SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />'); 772 932 } 773 933 return false; … … 798 958 private function get_lines() { 799 959 $data = ""; 800 while(!feof($this->smtp_conn)) { 960 $endtime = 0; 961 /* If for some reason the fp is bad, don't inf loop */ 962 if (!is_resource($this->smtp_conn)) { 963 return $data; 964 } 965 stream_set_timeout($this->smtp_conn, $this->Timeout); 966 if ($this->Timelimit > 0) { 967 $endtime = time() + $this->Timelimit; 968 } 969 while(is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { 801 970 $str = @fgets($this->smtp_conn,515); 802 971 if($this->do_debug >= 4) { 803 echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';804 echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';972 $this->edebug("SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'); 973 $this->edebug("SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'); 805 974 } 806 975 $data .= $str; 807 976 if($this->do_debug >= 4) { 808 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';977 $this->edebug("SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'); 809 978 } 810 979 // if 4th character is a space, we are done reading, break the loop 811 980 if(substr($str,3,1) == " ") { break; } 981 // Timed-out? Log and break 982 $info = stream_get_meta_data($this->smtp_conn); 983 if ($info['timed_out']) { 984 if($this->do_debug >= 4) { 985 $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " seconds) <br />"); 986 } 987 break; 988 } 989 // Now check if reads took too long 990 if ($endtime) { 991 if (time() > $endtime) { 992 if($this->do_debug >= 4) { 993 $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " seconds) <br />"); 994 } 995 break; 996 } 997 } 812 998 } 813 999 return $data; … … 815 1001 816 1002 } 817 818 1003 ?>
Note: See TracChangeset
for help on using the changeset viewer.