Ticket #21074: 21074-phpmailer-5.2.2-rc2-r22509.patch
| File 21074-phpmailer-5.2.2-rc2-r22509.patch, 66.4 KB (added by bpetty, 6 months ago) |
|---|
-
wp-includes/class-phpmailer.php
diff --git wp-includes/class-phpmailer.php wp-includes/class-phpmailer.php index df533c2..bb66770 100644
2 2 /*~ class.phpmailer.php 3 3 .---------------------------------------------------------------------------. 4 4 | Software: PHPMailer - PHP email class | 5 | Version: 5.2. 1|5 | Version: 5.2.2 | 6 6 | Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ | 7 7 | ------------------------------------------------------------------------- | 8 8 | Admin: Jim Jagielski (project admininistrator) | … … 31 31 * @author Jim Jagielski 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 */ 37 36 37 38 38 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 39 40 /** 41 * Main PHPMailer class definition 42 */ 40 43 class PHPMailer { 41 44 42 45 ///////////////////////////////////////////////// … … class PHPMailer { 87 90 public $FromName = 'Root User'; 88 91 89 92 /** 90 * Sets the Sender email (Return-Path)of the message. If not empty,93 * Sets the Sender email of the message. If not empty, 91 94 * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. 95 * If not empty, and ReturnPath is empty, will also be the 96 * Return-Path header. 92 97 * @var string 93 98 */ 94 99 public $Sender = ''; 95 100 96 101 /** 102 * Sets the Return-Path of the message. If empty, it will 103 * be set to either From or Sender. 104 * @var string 105 */ 106 public $ReturnPath = ''; 107 108 /** 97 109 * Sets the Subject of the message. 98 110 * @var string 99 111 */ … … class PHPMailer { 130 142 protected $MIMEHeader = ''; 131 143 132 144 /** 133 * Stores the complete sent MIME message (Body and Headers)145 * Stores the extra header list which CreateHeader() doesn't fold in 134 146 * @var string 135 147 * @access protected 136 148 */ 137 protected $ SentMIMEMessage= '';149 protected $mailHeader = ''; 138 150 139 151 /** 140 152 * Sets word wrapping on the body of the message to a given number of … … class PHPMailer { 156 168 public $Sendmail = '/usr/sbin/sendmail'; 157 169 158 170 /** 171 * Determine if mail() uses a fully sendmail compatible MTA that 172 * supports sendmail's "-oi -f" options 173 * @var boolean 174 */ 175 public $UseSendmailOptions = true; 176 177 /** 159 178 * Path to PHPMailer plugins. Useful if the SMTP class 160 179 * is in a different directory than the PHP include path. 161 180 * @var string … … class PHPMailer { 183 202 */ 184 203 public $MessageID = ''; 185 204 205 /** 206 * Sets the message Date to be used in the Date header. 207 * If empty, the current date will be added. 208 * @var string 209 */ 210 public $MessageDate = ''; 211 186 212 ///////////////////////////////////////////////// 187 213 // PROPERTIES FOR SMTP 188 214 ///////////////////////////////////////////////// 189 215 190 216 /** 191 * Sets the SMTP hosts. All hosts must be separated by a 217 * Sets the SMTP hosts. 218 * 219 * All hosts must be separated by a 192 220 * semicolon. You can also specify a different port 193 221 * for each host by using this format: [hostname:port] 194 222 * (e.g. "smtp1.example.com:25;smtp2.example.com"). … … class PHPMailer { 210 238 public $Helo = ''; 211 239 212 240 /** 213 * Sets connection prefix. 214 * Options are "", "ssl" or "tls" 241 * Sets connection prefix. Options are "", "ssl" or "tls" 215 242 * @var string 216 243 */ 217 244 public $SMTPSecure = ''; … … class PHPMailer { 235 262 public $Password = ''; 236 263 237 264 /** 238 * Sets the SMTP server timeout in seconds. 265 * Sets SMTP auth type. Options are LOGIN | PLAIN | NTLM (default LOGIN) 266 * @var string 267 */ 268 public $AuthType = ''; 269 270 /** 271 * Sets SMTP realm. 272 * @var string 273 */ 274 public $Realm = ''; 275 276 /** 277 * Sets SMTP workstation. 278 * @var string 279 */ 280 public $Workstation = ''; 281 282 /** 283 * Sets the SMTP server in seconds. 239 284 * This function will not work with the win32 version. 240 285 * @var int 241 286 */ … … class PHPMailer { 248 293 public $SMTPDebug = false; 249 294 250 295 /** 296 * Sets the function/method to use for debugging output. 297 * Right now we only honor "echo" or "error_log" 298 * @var string 299 */ 300 public $Debugoutput = "echo"; 301 302 /** 251 303 * Prevents the SMTP connection from being closed after each mail 252 304 * sending. If this is set to true then to close the connection 253 305 * requires an explicit call to SmtpClose(). … … class PHPMailer { 269 321 public $SingleToArray = array(); 270 322 271 323 /** 272 * Provides the ability to change the line ending 324 * Provides the ability to change the generic line ending 325 * NOTE: The default remains '\n'. We force CRLF where we KNOW 326 * it must be used via self::CRLF 273 327 * @var string 274 328 */ 275 329 public $LE = "\n"; 276 330 277 /** 278 * Used with DKIM DNS Resource Record 331 /** 332 * Used with DKIM Signing 333 * required parameter if DKIM is enabled 334 * 335 * domain selector example domainkey 279 336 * @var string 280 337 */ 281 public $DKIM_selector = ' phpmailer';338 public $DKIM_selector = ''; 282 339 283 340 /** 284 * Used with DKIM DNS Resource Record285 * optional, in format of email address 'you@yourdomain.com'341 * Used with DKIM Signing 342 * required if DKIM is enabled, in format of email address 'you@yourdomain.com' typically used as the source of the email 286 343 * @var string 287 344 */ 288 345 public $DKIM_identity = ''; 289 346 290 347 /** 291 * Used with DKIM DNS Resource Record 348 * Used with DKIM Signing 349 * optional parameter if your private key requires a passphras 292 350 * @var string 293 351 */ 294 352 public $DKIM_passphrase = ''; 295 353 296 354 /** 297 * Used with DKIM DNS Resource Record298 * optional, in format of email address 'you@yourdomain.com'355 * Used with DKIM Singing 356 * required if DKIM is enabled, in format of email address 'domain.com' 299 357 * @var string 300 358 */ 301 359 public $DKIM_domain = ''; 302 360 303 361 /** 304 * Used with DKIM DNS Resource Record305 * optional, in format of email address 'you@yourdomain.com'362 * Used with DKIM Signing 363 * required if DKIM is enabled, path to private key file 306 364 * @var string 307 365 */ 308 366 public $DKIM_private = ''; 309 367 310 368 /** 311 * Callback Action function name 312 * the function that handles the result of the send email action. Parameters: 369 * Callback Action function name. 370 * The function that handles the result of the send email action. 371 * It is called out by Send() for each email sent. 372 * 373 * Value can be: 374 * - 'function_name' for function names 375 * - 'Class::Method' for static method calls 376 * - array($object, 'Method') for calling methods on $object 377 * See http://php.net/is_callable manual page for more details. 378 * 379 * Parameters: 313 380 * bool $result result of the send action 314 381 * string $to email address of the recipient 315 382 * string $cc cc email addresses 316 383 * string $bcc bcc email addresses 317 384 * string $subject the subject 318 385 * string $body the email body 386 * string $from email address of sender 319 387 * @var string 320 388 */ 321 389 public $action_function = ''; //'callbackAction'; … … class PHPMailer { 324 392 * Sets the PHPMailer Version number 325 393 * @var string 326 394 */ 327 public $Version = '5.2. 1';395 public $Version = '5.2.2-rc2'; 328 396 329 397 /** 330 398 * What to use in the X-Mailer header 331 * @var string 399 * @var string NULL for default, whitespace for None, or actual string to use 332 400 */ 333 401 public $XMailer = ''; 334 402 … … class PHPMailer { 360 428 const STOP_MESSAGE = 0; // message only, continue processing 361 429 const STOP_CONTINUE = 1; // message?, likely ok to continue processing 362 430 const STOP_CRITICAL = 2; // message, plus full stop, critical error reached 363 431 const CRLF = "\r\n"; // SMTP RFC specified EOL 432 364 433 ///////////////////////////////////////////////// 365 434 // METHODS, VARIABLES 366 435 ///////////////////////////////////////////////// 367 436 368 437 /** 438 * Calls actual mail() function, but in a safe_mode aware fashion 439 * Also, unless sendmail_path points to sendmail (or something that 440 * claims to be sendmail), don't pass params (not a perfect fix, 441 * but it will do) 442 * @param string $to To 443 * @param string $subject Subject 444 * @param string $body Message Body 445 * @param string $header Additional Header(s) 446 * @param string $params Params 447 * @access private 448 * @return bool 449 */ 450 private function mail_passthru($to, $subject, $body, $header, $params) { 451 if ( ini_get('safe_mode') || !($this->UseSendmailOptions) ) { 452 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header); 453 } else { 454 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params); 455 } 456 return $rt; 457 } 458 459 /** 460 * Outputs debugging info via user-defined method 461 * @param string $str 462 */ 463 private function edebug($str) { 464 if ($this->Debugoutput == "error_log") { 465 error_log($str); 466 } else { 467 echo $str; 468 } 469 } 470 471 /** 369 472 * Constructor 370 473 * @param boolean $exceptions Should we throw external exceptions? 371 474 */ … … class PHPMailer { 389 492 /** 390 493 * Sets Mailer to send message using SMTP. 391 494 * @return void 495 * @deprecated 392 496 */ 393 497 public function IsSMTP() { 394 498 $this->Mailer = 'smtp'; … … class PHPMailer { 397 501 /** 398 502 * Sets Mailer to send message using PHP mail() function. 399 503 * @return void 504 * @deprecated 400 505 */ 401 506 public function IsMail() { 402 507 $this->Mailer = 'mail'; … … class PHPMailer { 405 510 /** 406 511 * Sets Mailer to send message using the $Sendmail program. 407 512 * @return void 513 * @deprecated 408 514 */ 409 515 public function IsSendmail() { 410 516 if (!stristr(ini_get('sendmail_path'), 'sendmail')) { … … class PHPMailer { 416 522 /** 417 523 * Sets Mailer to send message using the qmail MTA. 418 524 * @return void 525 * @deprecated 419 526 */ 420 527 public function IsQmail() { 421 528 if (stristr(ini_get('sendmail_path'), 'qmail')) { … … class PHPMailer { 485 592 if ($this->exceptions) { 486 593 throw new phpmailerException('Invalid recipient array: ' . $kind); 487 594 } 488 if ($this->SMTPDebug) {489 echo $this->Lang('Invalid recipient array').': '.$kind;595 if ($this->SMTPDebug) { 596 $this->edebug($this->Lang('Invalid recipient array').': '.$kind); 490 597 } 491 598 return false; 492 599 } 493 600 $address = trim($address); 494 601 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 495 if (! self::ValidateAddress($address)) {602 if (!$this->ValidateAddress($address)) { 496 603 $this->SetError($this->Lang('invalid_address').': '. $address); 497 604 if ($this->exceptions) { 498 605 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 499 606 } 500 if ($this->SMTPDebug) {501 echo $this->Lang('invalid_address').': '.$address;607 if ($this->SMTPDebug) { 608 $this->edebug($this->Lang('invalid_address').': '.$address); 502 609 } 503 610 return false; 504 611 } … … class PHPMailer { 521 628 * Set the From and FromName properties 522 629 * @param string $address 523 630 * @param string $name 631 * @param int $auto Also set Reply-To and Sender 524 632 * @return boolean 525 633 */ 526 634 public function SetFrom($address, $name = '', $auto = 1) { 527 635 $address = trim($address); 528 636 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 529 if (! self::ValidateAddress($address)) {637 if (!$this->ValidateAddress($address)) { 530 638 $this->SetError($this->Lang('invalid_address').': '. $address); 531 639 if ($this->exceptions) { 532 640 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 533 641 } 534 if ($this->SMTPDebug) {535 echo $this->Lang('invalid_address').': '.$address;642 if ($this->SMTPDebug) { 643 $this->edebug($this->Lang('invalid_address').': '.$address); 536 644 } 537 645 return false; 538 646 } … … class PHPMailer { 551 659 552 660 /** 553 661 * 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 662 * Static so it can be used without instantiation, public so people can overload 663 * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is 664 * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to 665 * not allow a@b type valid addresses :( 666 * @link http://squiloople.com/2009/12/20/email-address-validation/ 667 * @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 668 * @param string $address The email address to check 559 669 * @return boolean 560 670 * @static 561 671 * @access public 562 672 */ 563 673 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 } 570 } 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 } 674 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); 573 675 } 574 676 575 677 ///////////////////////////////////////////////// … … class PHPMailer { 587 689 if(!$this->PreSend()) return false; 588 690 return $this->PostSend(); 589 691 } catch (phpmailerException $e) { 590 $this->SentMIMEMessage= '';692 $this->mailHeader = ''; 591 693 $this->SetError($e->getMessage()); 592 694 if ($this->exceptions) { 593 695 throw $e; … … class PHPMailer { 596 698 } 597 699 } 598 700 599 protected function PreSend() { 701 /** 702 * Prep mail by constructing all message entities 703 * @return bool 704 */ 705 public function PreSend() { 600 706 try { 601 $mailHeader = "";707 $this->mailHeader = ""; 602 708 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { 603 709 throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); 604 710 } … … class PHPMailer { 619 725 $this->MIMEBody = $this->CreateBody(); 620 726 621 727 // To capture the complete message when using mail(), create 622 // an extra header list which CreateHeader() doesn't fold in728 // an extra header list which CreateHeader() doesn't fold in 623 729 if ($this->Mailer == 'mail') { 624 730 if (count($this->to) > 0) { 625 $ mailHeader .= $this->AddrAppend("To", $this->to);731 $this->mailHeader .= $this->AddrAppend("To", $this->to); 626 732 } else { 627 $ mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");733 $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;"); 628 734 } 629 $ mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));735 $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject)))); 630 736 // if(count($this->cc) > 0) { 631 // $ mailHeader .= $this->AddrAppend("Cc", $this->cc);737 // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc); 632 738 // } 633 739 } 634 740 635 741 // digitally sign with DKIM if enabled 636 if ( $this->DKIM_domain && $this->DKIM_private) {742 if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) { 637 743 $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody); 638 744 $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader; 639 745 } 640 746 641 $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);642 747 return true; 643 748 644 749 } catch (phpmailerException $e) { … … class PHPMailer { 650 755 } 651 756 } 652 757 653 protected function PostSend() { 758 /** 759 * Actual Email transport function 760 * Send the email via the selected mechanism 761 * @return bool 762 */ 763 public function PostSend() { 764 $rtn = false; 654 765 try { 655 766 // Choose the mailer and send through it 656 767 switch($this->Mailer) { 657 768 case 'sendmail': 658 return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody); 769 $rtn = $this->SendmailSend($this->MIMEHeader, $this->MIMEBody); 770 break; 659 771 case 'smtp': 660 return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody); 772 $rtn = $this->SmtpSend($this->MIMEHeader, $this->MIMEBody); 773 break; 661 774 case 'mail': 662 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 775 $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody); 776 break; 663 777 default: 664 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 778 $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody); 779 break; 665 780 } 666 781 667 782 } catch (phpmailerException $e) { … … class PHPMailer { 669 784 if ($this->exceptions) { 670 785 throw $e; 671 786 } 672 if ($this->SMTPDebug) {673 echo $e->getMessage()."\n";787 if ($this->SMTPDebug) { 788 $this->edebug($e->getMessage()."\n"); 674 789 } 675 790 return false; 676 791 } 792 return $rtn; 677 793 } 678 794 679 795 /** … … class PHPMailer { 685 801 */ 686 802 protected function SendmailSend($header, $body) { 687 803 if ($this->Sender != '') { 688 $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));804 $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); 689 805 } else { 690 806 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); 691 807 } … … class PHPMailer { 739 855 if (empty($this->Sender)) { 740 856 $params = "-oi "; 741 857 } else { 742 $params = sprintf("-oi -f %s", $this->Sender);858 $params = sprintf("-oi -f%s", $this->Sender); 743 859 } 744 860 if ($this->Sender != '' and !ini_get('safe_mode')) { 745 861 $old_from = ini_get('sendmail_from'); 746 862 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); 863 } 864 if ($this->SingleTo === true && count($toArr) > 1) { 865 foreach ($toArr as $key => $val) { 866 $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params); 756 867 // implement call back function if it exists 757 868 $isSent = ($rt == 1) ? 1 : 0; 758 $this->doCallback($isSent, $ to, $this->cc, $this->bcc, $this->Subject, $body);869 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 759 870 } 760 871 } 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 } 872 $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params); 873 // implement call back function if it exists 874 $isSent = ($rt == 1) ? 1 : 0; 875 $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 774 876 } 775 877 if (isset($old_from)) { 776 878 ini_set('sendmail_from', $old_from); … … class PHPMailer { 862 964 * @return bool 863 965 */ 864 966 public function SmtpConnect() { 865 if (is_null($this->smtp)) {967 if ($this->smtp === null) { 866 968 $this->smtp = new SMTP(); 867 969 } 868 970 971 $this->smtp->Timeout = $this->Timeout; 869 972 $this->smtp->do_debug = $this->SMTPDebug; 870 973 $hosts = explode(';', $this->Host); 871 974 $index = 0; 872 975 $connection = $this->smtp->Connected(); 976 $rtn = true; 873 977 874 978 // Retry while there is no connection 875 979 try { … … class PHPMailer { 893 997 894 998 if ($tls) { 895 999 if (!$this->smtp->StartTLS()) { 1000 $rtn = false; 896 1001 throw new phpmailerException($this->Lang('tls')); 897 1002 } 898 1003 … … class PHPMailer { 902 1007 903 1008 $connection = true; 904 1009 if ($this->SMTPAuth) { 905 if (!$this->smtp->Authenticate($this->Username, $this->Password)) { 1010 if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType, 1011 $this->Realm, $this->Workstation)) { 1012 $rtn = false; 906 1013 throw new phpmailerException($this->Lang('authenticate')); 907 1014 } 908 1015 } 909 1016 } 910 1017 $index++; 911 if (!$connection) { 912 throw new phpmailerException($this->Lang('connect_host')); 913 } 1018 } 1019 if (!$connection) { 1020 $rtn = false; 1021 throw new phpmailerException($this->Lang('connect_host')); 914 1022 } 915 1023 } catch (phpmailerException $e) { 916 1024 $this->smtp->Reset(); 917 if ($this->exceptions) {1025 if ($this->exceptions) { 918 1026 throw $e; 919 1027 } 1028 $rtn = false; 920 1029 } 921 return true;1030 return $rtn; 922 1031 } 923 1032 924 1033 /** … … class PHPMailer { 926 1035 * @return void 927 1036 */ 928 1037 public function SmtpClose() { 929 if (!is_null($this->smtp)) {1038 if ($this->smtp !== null) { 930 1039 if($this->smtp->Connected()) { 931 1040 $this->smtp->Quit(); 932 1041 $this->smtp->Close(); … … class PHPMailer { 944 1053 function SetLanguage($langcode = 'en', $lang_path = 'language/') { 945 1054 //Define full set of translatable strings 946 1055 $PHPMAILER_LANG = array( 947 'provide_address' => 'You must provide at least one recipient email address.', 1056 'authenticate' => 'SMTP Error: Could not authenticate.', 1057 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 1058 'data_not_accepted' => 'SMTP Error: Data not accepted.', 1059 'empty_message' => 'Message body empty', 1060 'encoding' => 'Unknown encoding: ', 1061 'execute' => 'Could not execute: ', 1062 'file_access' => 'Could not access file: ', 1063 'file_open' => 'File Error: Could not open file: ', 1064 'from_failed' => 'The following From address failed: ', 1065 'instantiate' => 'Could not instantiate mail function.', 1066 'invalid_address' => 'Invalid address', 948 1067 '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: ' 1068 'provide_address' => 'You must provide at least one recipient email address.', 1069 'recipients_failed' => 'SMTP Error: The following recipients failed: ', 1070 'signing' => 'Signing Error: ', 1071 'smtp_connect_failed' => 'SMTP Connect() failed.', 1072 'smtp_error' => 'SMTP server error: ', 1073 'variable_set' => 'Cannot set or reset variable: ' 964 1074 ); 965 1075 //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"! 966 1076 $l = true; … … class PHPMailer { 1028 1138 // If utf-8 encoding is used, we will need to make sure we don't 1029 1139 // split multibyte characters when we wrap 1030 1140 $is_utf8 = (strtolower($this->CharSet) == "utf-8"); 1141 $lelen = strlen($this->LE); 1142 $crlflen = strlen(self::CRLF); 1031 1143 1032 1144 $message = $this->FixEOL($message); 1033 if (substr($message, - 1) == $this->LE) {1034 $message = substr($message, 0, - 1);1145 if (substr($message, -$lelen) == $this->LE) { 1146 $message = substr($message, 0, -$lelen); 1035 1147 } 1036 1148 1037 $line = explode($this->LE, $message); 1149 $line = explode($this->LE, $message); // Magic. We know FixEOL uses $LE 1038 1150 $message = ''; 1039 1151 for ($i = 0 ;$i < count($line); $i++) { 1040 1152 $line_part = explode(' ', $line[$i]); … … class PHPMailer { 1042 1154 for ($e = 0; $e<count($line_part); $e++) { 1043 1155 $word = $line_part[$e]; 1044 1156 if ($qp_mode and (strlen($word) > $length)) { 1045 $space_left = $length - strlen($buf) - 1;1157 $space_left = $length - strlen($buf) - $crlflen; 1046 1158 if ($e != 0) { 1047 1159 if ($space_left > 20) { 1048 1160 $len = $space_left; … … class PHPMailer { 1056 1168 $part = substr($word, 0, $len); 1057 1169 $word = substr($word, $len); 1058 1170 $buf .= ' ' . $part; 1059 $message .= $buf . sprintf("=%s", $this->LE);1171 $message .= $buf . sprintf("=%s", self::CRLF); 1060 1172 } else { 1061 1173 $message .= $buf . $soft_break; 1062 1174 } … … class PHPMailer { 1075 1187 $word = substr($word, $len); 1076 1188 1077 1189 if (strlen($word) > 0) { 1078 $message .= $part . sprintf("=%s", $this->LE);1190 $message .= $part . sprintf("=%s", self::CRLF); 1079 1191 } else { 1080 1192 $buf = $part; 1081 1193 } … … class PHPMailer { 1090 1202 } 1091 1203 } 1092 1204 } 1093 $message .= $buf . $this->LE;1205 $message .= $buf . self::CRLF; 1094 1206 } 1095 1207 1096 1208 return $message; … … class PHPMailer { 1175 1287 $this->boundary[2] = 'b2_' . $uniq_id; 1176 1288 $this->boundary[3] = 'b3_' . $uniq_id; 1177 1289 1178 $result .= $this->HeaderLine('Date', self::RFCDate()); 1179 if($this->Sender == '') { 1290 if ($this->MessageDate == '') { 1291 $result .= $this->HeaderLine('Date', self::RFCDate()); 1292 } else { 1293 $result .= $this->HeaderLine('Date', $this->MessageDate); 1294 } 1295 1296 if ($this->ReturnPath) { 1297 $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath)); 1298 } elseif ($this->Sender == '') { 1180 1299 $result .= $this->HeaderLine('Return-Path', trim($this->From)); 1181 1300 } else { 1182 1301 $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); … … class PHPMailer { 1195 1314 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); 1196 1315 } 1197 1316 } 1198 }1317 } 1199 1318 1200 1319 $from = array(); 1201 1320 $from[0][0] = trim($this->From); … … class PHPMailer { 1227 1346 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); 1228 1347 } 1229 1348 $result .= $this->HeaderLine('X-Priority', $this->Priority); 1230 if ($this->XMailer) {1231 $result .= $this->HeaderLine('X-Mailer', $this->XMailer);1349 if ($this->XMailer == '') { 1350 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1232 1351 } else { 1233 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1352 $myXmailer = trim($this->XMailer); 1353 if ($myXmailer) { 1354 $result .= $this->HeaderLine('X-Mailer', $myXmailer); 1355 } 1234 1356 } 1235 1357 1236 1358 if($this->ConfirmReadingTo != '') { … … class PHPMailer { 1257 1379 public function GetMailMIME() { 1258 1380 $result = ''; 1259 1381 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 1382 case 'inline': 1265 1383 $result .= $this->HeaderLine('Content-Type', 'multipart/related;'); 1266 1384 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); … … class PHPMailer { 1277 1395 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 1278 1396 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 1279 1397 break; 1398 default: 1399 // Catches case 'plain': and case '': 1400 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); 1401 $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet); 1402 break; 1280 1403 } 1281 1404 1282 1405 if($this->Mailer != 'mail') { 1283 $result .= $this->LE .$this->LE;1406 $result .= $this->LE; 1284 1407 } 1285 1408 1286 1409 return $result; … … class PHPMailer { 1292 1415 * @return string 1293 1416 */ 1294 1417 public function GetSentMIMEMessage() { 1295 return $this-> SentMIMEMessage;1418 return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody; 1296 1419 } 1297 1420 1298 1421 … … class PHPMailer { 1305 1428 $body = ''; 1306 1429 1307 1430 if ($this->sign_key_file) { 1308 $body .= $this->GetMailMIME() ;1431 $body .= $this->GetMailMIME().$this->LE; 1309 1432 } 1310 1433 1311 1434 $this->SetWordWrap(); 1312 1435 1313 1436 switch($this->message_type) { 1314 case 'plain':1315 $body .= $this->EncodeString($this->Body, $this->Encoding);1316 break;1317 1437 case 'inline': 1318 1438 $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 1319 1439 $body .= $this->EncodeString($this->Body, $this->Encoding); … … class PHPMailer { 1398 1518 $body .= $this->LE; 1399 1519 $body .= $this->AttachAll("attachment", $this->boundary[1]); 1400 1520 break; 1521 default: 1522 // catch case 'plain' and case '' 1523 $body .= $this->EncodeString($this->Body, $this->Encoding); 1524 break; 1401 1525 } 1402 1526 1403 1527 if ($this->IsError()) { … … class PHPMailer { 1444 1568 $encoding = $this->Encoding; 1445 1569 } 1446 1570 $result .= $this->TextLine('--' . $boundary); 1447 $result .= sprintf("Content-Type: %s; charset= \"%s\"", $contentType, $charSet);1571 $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet); 1448 1572 $result .= $this->LE; 1449 1573 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); 1450 1574 $result .= $this->LE; … … class PHPMailer { 1533 1657 if ($this->exceptions) { 1534 1658 throw $e; 1535 1659 } 1536 if ($this->SMTPDebug) {1537 echo $e->getMessage()."\n";1660 if ($this->SMTPDebug) { 1661 $this->edebug($e->getMessage()."\n"); 1538 1662 } 1539 1663 if ( $e->getCode() == self::STOP_CRITICAL ) { 1540 1664 return false; … … class PHPMailer { 1633 1757 if (!is_readable($path)) { 1634 1758 throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); 1635 1759 } 1636 if (function_exists('get_magic_quotes')) {1637 function get_magic_quotes() {1638 return false;1639 }1640 }1641 $magic_quotes = get_magic_quotes_runtime();1642 if ($magic_quotes) {1760 // if (!function_exists('get_magic_quotes')) { 1761 // function get_magic_quotes() { 1762 // return false; 1763 // } 1764 // } 1765 $magic_quotes = get_magic_quotes_runtime(); 1766 if ($magic_quotes) { 1643 1767 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1644 1768 set_magic_quotes_runtime(0); 1645 1769 } else { 1646 ini_set('magic_quotes_runtime', 0); 1647 }1648 }1770 ini_set('magic_quotes_runtime', 0); 1771 } 1772 } 1649 1773 $file_buffer = file_get_contents($path); 1650 1774 $file_buffer = $this->EncodeString($file_buffer, $encoding); 1651 if ($magic_quotes) {1775 if ($magic_quotes) { 1652 1776 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1653 1777 set_magic_quotes_runtime($magic_quotes); 1654 1778 } else { 1655 ini_set('magic_quotes_runtime', $magic_quotes); 1656 }1657 }1779 ini_set('magic_quotes_runtime', $magic_quotes); 1780 } 1781 } 1658 1782 return $file_buffer; 1659 1783 } catch (Exception $e) { 1660 1784 $this->SetError($e->getMessage()); … … class PHPMailer { 1737 1861 if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { 1738 1862 // Use a custom function which correctly encodes and wraps long 1739 1863 // multibyte strings without breaking lines within a character 1740 $encoded = $this->Base64EncodeWrapMB($str );1864 $encoded = $this->Base64EncodeWrapMB($str, "\n"); 1741 1865 } else { 1742 1866 $encoded = base64_encode($str); 1743 1867 $maxlen -= $maxlen % 4; … … class PHPMailer { 1747 1871 $encoding = 'Q'; 1748 1872 $encoded = $this->EncodeQ($str, $position); 1749 1873 $encoded = $this->WrapText($encoded, $maxlen, true); 1750 $encoded = str_replace('='. $this->LE, "\n", trim($encoded));1874 $encoded = str_replace('='.self::CRLF, "\n", trim($encoded)); 1751 1875 } 1752 1876 1753 1877 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); … … class PHPMailer { 1776 1900 * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php 1777 1901 * @access public 1778 1902 * @param string $str multi-byte text to wrap encode 1903 * @param string $lf string to use as linefeed/end-of-line 1779 1904 * @return string 1780 1905 */ 1781 public function Base64EncodeWrapMB($str ) {1906 public function Base64EncodeWrapMB($str, $lf=null) { 1782 1907 $start = "=?".$this->CharSet."?B?"; 1783 1908 $end = "?="; 1784 1909 $encoded = ""; 1910 if ($lf === null) { 1911 $lf = $this->LE; 1912 } 1785 1913 1786 1914 $mb_length = mb_strlen($str, $this->CharSet); 1787 1915 // Each line must have length <= 75, including $start and $end … … class PHPMailer { 1802 1930 } 1803 1931 while (strlen($chunk) > $length); 1804 1932 1805 $encoded .= $chunk . $ this->LE;1933 $encoded .= $chunk . $lf; 1806 1934 } 1807 1935 1808 1936 // Chomp the last linefeed 1809 $encoded = substr($encoded, 0, -strlen($ this->LE));1937 $encoded = substr($encoded, 0, -strlen($lf)); 1810 1938 return $encoded; 1811 1939 } 1812 1940 … … class PHPMailer { 1901 2029 * @return string 1902 2030 */ 1903 2031 public function EncodeQ($str, $position = 'text') { 1904 // There should not be any EOL in the string1905 $encoded = preg_replace('/[\r\n]*/', '', $str);1906 2032 //There should not be any EOL in the string 2033 $pattern=""; 2034 $encoded = str_replace(array("\r", "\n"), '', $str); 1907 2035 switch (strtolower($position)) { 1908 2036 case 'phrase': 1909 $ encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);2037 $pattern = '^A-Za-z0-9!*+\/ -'; 1910 2038 break; 2039 1911 2040 case 'comment': 1912 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); 2041 $pattern = '\(\)"'; 2042 //note that we dont break here! 2043 //for this reason we build the $pattern withoud including delimiters and [] 2044 1913 2045 case 'text': 1914 2046 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); 2047 //Replace every high ascii, control =, ? and _ characters 2048 //We put \075 (=) as first value to make sure it's the first one in being converted, preventing double encode 2049 $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern; 1919 2050 break; 1920 2051 } 2052 2053 if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) { 2054 foreach (array_unique($matches[0]) as $char) { 2055 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded); 2056 } 2057 } 2058 2059 //Replace every spaces to _ (more readable than =20) 2060 return str_replace(' ', '_', $encoded); 2061 } 1921 2062 1922 // Replace every spaces to _ (more readable than =20)1923 $encoded = str_replace(' ', '_', $encoded);1924 1925 return $encoded;1926 }1927 2063 1928 2064 /** 1929 2065 * Adds a string or binary attachment (non-filesystem) to the list. … … class PHPMailer { 2027 2163 } 2028 2164 2029 2165 public function AlternativeExists() { 2030 return strlen($this->AltBody)>0;2166 return !empty($this->AltBody); 2031 2167 } 2032 2168 2033 2169 ///////////////////////////////////////////////// … … class PHPMailer { 2115 2251 */ 2116 2252 protected function SetError($msg) { 2117 2253 $this->error_count++; 2118 if ( $this->Mailer == 'smtp' and !is_null($this->smtp)) {2254 if (($this->Mailer == 'smtp') and ($this->smtp !== null)) { 2119 2255 $lasterror = $this->smtp->getError(); 2120 2256 if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) { 2121 2257 $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n"; … … class PHPMailer { 2184 2320 } 2185 2321 2186 2322 /** 2187 * Changes every end of line from CR or LF to CRLF.2323 * Changes every end of line from CRLF, CR or LF to $this->LE. 2188 2324 * @access public 2325 * @param string $str String to FixEOL 2189 2326 * @return string 2190 2327 */ 2191 2328 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; 2329 // condense down to \n 2330 $nstr = str_replace(array("\r\n", "\r"), "\n", $str); 2331 // Now convert LE as needed 2332 if ($this->LE !== "\n") { 2333 $nstr = str_replace("\n", $this->LE, $nstr); 2334 } 2335 return $nstr; 2196 2336 } 2197 2337 2198 2338 /** 2199 * Adds a custom header. 2339 * Adds a custom header. $name value can be overloaded to contain 2340 * both header name and value (name:value) 2200 2341 * @access public 2342 * @param string $name custom header name 2343 * @param string $value header value 2201 2344 * @return void 2202 2345 */ 2203 public function AddCustomHeader($custom_header) { 2204 $this->CustomHeader[] = explode(':', $custom_header, 2); 2346 public function AddCustomHeader($name, $value=null) { 2347 if ($value === null) { 2348 // Value passed in as name:value 2349 $this->CustomHeader[] = explode(':', $name, 2); 2350 } else { 2351 $this->CustomHeader[] = array($name, $value); 2352 } 2205 2353 } 2206 2354 2207 2355 /** 2208 2356 * Evaluates the message and returns modifications for inline images and backgrounds 2209 2357 * @access public 2358 * @param string $message Text to be HTML modified 2359 * @param string $basedir baseline directory for path 2210 2360 * @return $message 2211 2361 */ 2212 2362 public function MsgHTML($message, $basedir = '') { … … class PHPMailer { 2231 2381 } 2232 2382 $this->IsHTML(true); 2233 2383 $this->Body = $message; 2234 if (empty($this->AltBody)) {2235 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));2236 if (!empty($textMsg)) {2237 $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);2238 }2239 }2384 if (empty($this->AltBody)) { 2385 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); 2386 if (!empty($textMsg)) { 2387 $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet); 2388 } 2389 } 2240 2390 if (empty($this->AltBody)) { 2241 2391 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; 2242 2392 } 2243 return $message;2393 return $message; 2244 2394 } 2245 2395 2246 2396 /** 2247 2397 * Gets the MIME type of the embedded or inline image 2248 * @param string File extension2398 * @param string $ext File extension 2249 2399 * @access public 2250 2400 * @return string MIME type of ext 2251 2401 * @static 2252 2402 */ 2253 2403 public static function _mime_types($ext = '') { 2254 2404 $mimes = array( 2405 'xl' => 'application/excel', 2255 2406 'hqx' => 'application/mac-binhex40', 2256 2407 'cpt' => 'application/mac-compactpro', 2257 'doc' => 'application/msword',2258 2408 'bin' => 'application/macbinary', 2409 'doc' => 'application/msword', 2410 'doc' => 'application/msword', 2411 'word' => 'application/msword', 2412 'class' => 'application/octet-stream', 2413 'dll' => 'application/octet-stream', 2259 2414 'dms' => 'application/octet-stream', 2415 'exe' => 'application/octet-stream', 2260 2416 'lha' => 'application/octet-stream', 2261 2417 'lzh' => 'application/octet-stream', 2262 'exe' => 'application/octet-stream',2263 'class' => 'application/octet-stream',2264 2418 'psd' => 'application/octet-stream', 2265 'so' => 'application/octet-stream',2266 2419 'sea' => 'application/octet-stream', 2267 ' dll'=> 'application/octet-stream',2420 'so' => 'application/octet-stream', 2268 2421 'oda' => 'application/oda', 2269 2422 'pdf' => 'application/pdf', 2270 2423 'ai' => 'application/postscript', … … class PHPMailer { 2282 2435 'dxr' => 'application/x-director', 2283 2436 'dvi' => 'application/x-dvi', 2284 2437 'gtar' => 'application/x-gtar', 2285 'php' => 'application/x-httpd-php',2286 'php4' => 'application/x-httpd-php',2287 2438 'php3' => 'application/x-httpd-php', 2439 'php4' => 'application/x-httpd-php', 2440 'php' => 'application/x-httpd-php', 2288 2441 'phtml' => 'application/x-httpd-php', 2289 2442 'phps' => 'application/x-httpd-php-source', 2290 2443 'js' => 'application/x-javascript', … … class PHPMailer { 2292 2445 'sit' => 'application/x-stuffit', 2293 2446 'tar' => 'application/x-tar', 2294 2447 'tgz' => 'application/x-tar', 2295 'xhtml' => 'application/xhtml+xml',2296 2448 'xht' => 'application/xhtml+xml', 2449 'xhtml' => 'application/xhtml+xml', 2297 2450 'zip' => 'application/zip', 2298 2451 'mid' => 'audio/midi', 2299 2452 'midi' => 'audio/midi', 2300 'mpga' => 'audio/mpeg',2301 2453 'mp2' => 'audio/mpeg', 2302 2454 'mp3' => 'audio/mpeg', 2455 'mpga' => 'audio/mpeg', 2303 2456 'aif' => 'audio/x-aiff', 2304 'aiff' => 'audio/x-aiff',2305 2457 'aifc' => 'audio/x-aiff', 2458 'aiff' => 'audio/x-aiff', 2306 2459 'ram' => 'audio/x-pn-realaudio', 2307 2460 'rm' => 'audio/x-pn-realaudio', 2308 2461 'rpm' => 'audio/x-pn-realaudio-plugin', 2309 2462 'ra' => 'audio/x-realaudio', 2310 'rv' => 'video/vnd.rn-realvideo',2311 2463 'wav' => 'audio/x-wav', 2312 2464 'bmp' => 'image/bmp', 2313 2465 'gif' => 'image/gif', 2314 2466 'jpeg' => 'image/jpeg', 2315 'jpg' => 'image/jpeg',2316 2467 'jpe' => 'image/jpeg', 2468 'jpg' => 'image/jpeg', 2317 2469 'png' => 'image/png', 2318 2470 'tiff' => 'image/tiff', 2319 2471 'tif' => 'image/tiff', 2472 'eml' => 'message/rfc822', 2320 2473 'css' => 'text/css', 2321 2474 'html' => 'text/html', 2322 2475 'htm' => 'text/html', 2323 2476 'shtml' => 'text/html', 2324 'txt' => 'text/plain',2325 'text' => 'text/plain',2326 2477 'log' => 'text/plain', 2478 'text' => 'text/plain', 2479 'txt' => 'text/plain', 2327 2480 'rtx' => 'text/richtext', 2328 2481 'rtf' => 'text/rtf', 2329 2482 'xml' => 'text/xml', 2330 2483 'xsl' => 'text/xml', 2331 2484 'mpeg' => 'video/mpeg', 2332 'mpg' => 'video/mpeg',2333 2485 'mpe' => 'video/mpeg', 2334 ' qt' => 'video/quicktime',2486 'mpg' => 'video/mpeg', 2335 2487 'mov' => 'video/quicktime', 2488 'qt' => 'video/quicktime', 2489 'rv' => 'video/vnd.rn-realvideo', 2336 2490 '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' 2491 'movie' => 'video/x-sgi-movie' 2342 2492 ); 2343 2493 return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; 2344 2494 } … … class PHPMailer { 2378 2528 * @return string 2379 2529 */ 2380 2530 public function SecureHeader($str) { 2381 $str = str_replace("\r", '', $str); 2382 $str = str_replace("\n", '', $str); 2383 return trim($str); 2531 return trim(str_replace(array("\r", "\n"), '', $str)); 2384 2532 } 2385 2533 2386 2534 /** … … class PHPMailer { 2487 2635 $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) 2488 2636 $subject_header = "Subject: $subject"; 2489 2637 $headers = explode($this->LE, $headers_line); 2638 $from_header = ""; 2639 $to_header = ""; 2490 2640 foreach($headers as $header) { 2491 2641 if (strpos($header, 'From:') === 0) { 2492 2642 $from_header = $header; … … class PHPMailer { 2512 2662 "\tb="; 2513 2663 $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); 2514 2664 $signed = $this->DKIM_Sign($toSign); 2515 return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";2665 return "X-PHPMAILER-DKIM: code.google.com/a/apache-extras.org/p/phpmailer/\r\n".$dkimhdrs.$signed."\r\n"; 2516 2666 } 2517 2667 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); 2668 /** 2669 * Perform callback 2670 */ 2671 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) { 2672 if (!empty($this->action_function) && is_callable($this->action_function)) { 2673 $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from); 2521 2674 call_user_func_array($this->action_function, $params); 2522 2675 } 2523 2676 } 2524 2677 } 2525 2678 2679 /** 2680 * Exception handling 2681 */ 2526 2682 class phpmailerException extends Exception { 2527 2683 public function errorMessage() { 2528 2684 $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; -
wp-includes/class-smtp.php
diff --git wp-includes/class-smtp.php wp-includes/class-smtp.php index 6977bff..cccaeae 100644
2 2 /*~ class.smtp.php 3 3 .---------------------------------------------------------------------------. 4 4 | Software: PHPMailer - PHP email class | 5 | Version: 5.2. 1|5 | Version: 5.2.2 | 6 6 | Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ | 7 7 | ------------------------------------------------------------------------- | 8 8 | Admin: Jim Jagielski (project admininistrator) | … … 32 32 * @author Jim Jagielski 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 /** … … class SMTP { 51 50 public $SMTP_PORT = 25; 52 51 53 52 /** 54 * SMTP reply line ending 53 * SMTP reply line ending (don't change) 55 54 * @var string 56 55 */ 57 56 public $CRLF = "\r\n"; … … class SMTP { 63 62 public $do_debug; // the level of debug to perform 64 63 65 64 /** 65 * Sets the function/method to use for debugging output. 66 * Right now we only honor "echo" or "error_log" 67 * @var string 68 */ 69 public $Debugoutput = "echo"; 70 71 /** 66 72 * Sets VERP use on/off (default is off) 67 73 * @var bool 68 74 */ 69 75 public $do_verp = false; 70 76 71 77 /** 78 * Sets the SMTP timeout value for reads, in seconds 79 * @var int 80 */ 81 public $Timeout = 15; 82 83 /** 84 * Sets the SMTP timelimit value for reads, in seconds 85 * @var int 86 */ 87 public $Timelimit = 30; 88 89 /** 72 90 * Sets the SMTP PHPMailer Version number 73 91 * @var string 74 92 */ 75 public $Version = '5.2. 1';93 public $Version = '5.2.2-rc2'; 76 94 77 95 ///////////////////////////////////////////////// 78 96 // PROPERTIES, PRIVATE AND PROTECTED … … class SMTP { 83 101 private $helo_rply; // the reply the server sent to us for HELO 84 102 85 103 /** 104 * Outputs debugging info via user-defined method 105 * @param string $str 106 */ 107 private function edebug($str) { 108 if ($this->Debugoutput == "error_log") { 109 error_log($str); 110 } else { 111 echo $str; 112 } 113 } 114 115 /** 86 116 * Initialize the class so that the data is in a known state. 87 117 * @access public 88 118 * @return void … … class SMTP { 139 169 "errno" => $errno, 140 170 "errstr" => $errstr); 141 171 if($this->do_debug >= 1) { 142 echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';172 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />'); 143 173 } 144 174 return false; 145 175 } 146 176 147 177 // SMTP server can take longer to respond, give longer timeout for first read 148 178 // 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); 179 if(substr(PHP_OS, 0, 3) != "WIN") { 180 $max = ini_get('max_execution_time'); 181 if ($max != 0 && $tval > $max) { // don't bother if unlimited 182 @set_time_limit($tval); 183 } 184 stream_set_timeout($this->smtp_conn, $tval, 0); 185 } 151 186 152 187 // get any announcement 153 188 $announce = $this->get_lines(); 154 189 155 190 if($this->do_debug >= 2) { 156 echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';191 $this->edebug("SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />'); 157 192 } 158 193 159 194 return true; … … class SMTP { 182 217 $code = substr($rply,0,3); 183 218 184 219 if($this->do_debug >= 2) { 185 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';220 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 186 221 } 187 222 188 223 if($code != 220) { … … class SMTP { 191 226 "smtp_code" => $code, 192 227 "smtp_msg" => substr($rply,4)); 193 228 if($this->do_debug >= 1) { 194 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';229 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 195 230 } 196 231 return false; 197 232 } … … class SMTP { 210 245 * @access public 211 246 * @return bool 212 247 */ 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; 248 public function Authenticate($username, $password, $authtype='LOGIN', $realm='', 249 $workstation='') { 250 if (empty($authtype)) { 251 $authtype = 'LOGIN'; 252 } 253 254 switch ($authtype) { 255 case 'PLAIN': 256 // Start authentication 257 fputs($this->smtp_conn,"AUTH PLAIN" . $this->CRLF); 258 259 $rply = $this->get_lines(); 260 $code = substr($rply,0,3); 261 262 if($code != 334) { 263 $this->error = 264 array("error" => "AUTH not accepted from server", 265 "smtp_code" => $code, 266 "smtp_msg" => substr($rply,4)); 267 if($this->do_debug >= 1) { 268 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 269 } 270 return false; 271 } 272 // Send encoded username and password 273 fputs($this->smtp_conn, base64_encode("\0".$username."\0".$password) . $this->CRLF); 274 275 $rply = $this->get_lines(); 276 $code = substr($rply,0,3); 277 278 if($code != 235) { 279 $this->error = 280 array("error" => "Authentication not accepted from server", 281 "smtp_code" => $code, 282 "smtp_msg" => substr($rply,4)); 283 if($this->do_debug >= 1) { 284 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 285 } 286 return false; 287 } 288 break; 289 case 'LOGIN': 290 // Start authentication 291 fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF); 292 293 $rply = $this->get_lines(); 294 $code = substr($rply,0,3); 295 296 if($code != 334) { 297 $this->error = 298 array("error" => "AUTH not accepted from server", 299 "smtp_code" => $code, 300 "smtp_msg" => substr($rply,4)); 301 if($this->do_debug >= 1) { 302 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 303 } 304 return false; 305 } 306 307 // Send encoded username 308 fputs($this->smtp_conn, base64_encode($username) . $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" => "Username 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 password 325 fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); 326 327 $rply = $this->get_lines(); 328 $code = substr($rply,0,3); 329 330 if($code != 235) { 331 $this->error = 332 array("error" => "Password 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 break; 341 case 'NTLM': 342 /* 343 * ntlm_sasl_client.php 344 ** Bundled with Permission 345 ** 346 ** How to telnet in windows: http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx 347 ** PROTOCOL Documentation http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication 348 */ 349 require_once('ntlm_sasl_client.php'); 350 $temp = new stdClass(); 351 $ntlm_client = new ntlm_sasl_client_class; 352 if(! $ntlm_client->Initialize($temp)){//let's test if every function its available 353 $this->error = array("error" => $temp->error); 354 if($this->do_debug >= 1) { 355 $this->edebug("You need to enable some modules in your php.ini file: " . $this->error["error"] . $this->CRLF); 356 } 357 return false; 358 } 359 $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);//msg1 360 361 fputs($this->smtp_conn,"AUTH NTLM " . base64_encode($msg1) . $this->CRLF); 362 363 $rply = $this->get_lines(); 364 $code = substr($rply,0,3); 365 366 367 if($code != 334) { 368 $this->error = 369 array("error" => "AUTH not accepted from server", 370 "smtp_code" => $code, 371 "smtp_msg" => substr($rply,4)); 372 if($this->do_debug >= 1) { 373 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF); 374 } 375 return false; 376 } 377 378 $challange = substr($rply,3);//though 0 based, there is a white space after the 3 digit number....//msg2 379 $challange = base64_decode($challange); 380 $ntlm_res = $ntlm_client->NTLMResponse(substr($challange,24,8),$password); 381 $msg3 = $ntlm_client->TypeMsg3($ntlm_res,$username,$realm,$workstation);//msg3 382 // Send encoded username 383 fputs($this->smtp_conn, base64_encode($msg3) . $this->CRLF); 384 385 $rply = $this->get_lines(); 386 $code = substr($rply,0,3); 387 388 if($code != 235) { 389 $this->error = 390 array("error" => "Could not authenticate", 391 "smtp_code" => $code, 392 "smtp_msg" => substr($rply,4)); 393 if($this->do_debug >= 1) { 394 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF); 395 } 396 return false; 397 } 398 break; 263 399 } 264 265 400 return true; 266 401 } 267 402 … … class SMTP { 276 411 if($sock_status["eof"]) { 277 412 // the socket is valid but we are not connected 278 413 if($this->do_debug >= 1) { 279 echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";414 $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"); 280 415 } 281 416 $this->Close(); 282 417 return false; … … class SMTP { 341 476 $code = substr($rply,0,3); 342 477 343 478 if($this->do_debug >= 2) { 344 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';479 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 345 480 } 346 481 347 482 if($code != 354) { … … class SMTP { 350 485 "smtp_code" => $code, 351 486 "smtp_msg" => substr($rply,4)); 352 487 if($this->do_debug >= 1) { 353 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';488 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 354 489 } 355 490 return false; 356 491 } … … class SMTP { 435 570 $code = substr($rply,0,3); 436 571 437 572 if($this->do_debug >= 2) { 438 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';573 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 439 574 } 440 575 441 576 if($code != 250) { … … class SMTP { 444 579 "smtp_code" => $code, 445 580 "smtp_msg" => substr($rply,4)); 446 581 if($this->do_debug >= 1) { 447 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';582 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 448 583 } 449 584 return false; 450 585 } … … class SMTP { 500 635 $code = substr($rply,0,3); 501 636 502 637 if($this->do_debug >= 2) { 503 echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';638 $this->edebug("SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />'); 504 639 } 505 640 506 641 if($code != 250) { … … class SMTP { 509 644 "smtp_code" => $code, 510 645 "smtp_msg" => substr($rply,4)); 511 646 if($this->do_debug >= 1) { 512 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';647 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 513 648 } 514 649 return false; 515 650 } … … class SMTP { 542 677 return false; 543 678 } 544 679 545 $useVerp = ($this->do_verp ? " XVERP" : "");680 $useVerp = ($this->do_verp ? " XVERP" : ""); 546 681 fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); 547 682 548 683 $rply = $this->get_lines(); 549 684 $code = substr($rply,0,3); 550 685 551 686 if($this->do_debug >= 2) { 552 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';687 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 553 688 } 554 689 555 690 if($code != 250) { … … class SMTP { 558 693 "smtp_code" => $code, 559 694 "smtp_msg" => substr($rply,4)); 560 695 if($this->do_debug >= 1) { 561 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';696 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 562 697 } 563 698 return false; 564 699 } … … class SMTP { 592 727 $byemsg = $this->get_lines(); 593 728 594 729 if($this->do_debug >= 2) { 595 echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';730 $this->edebug("SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />'); 596 731 } 597 732 598 733 $rval = true; … … class SMTP { 606 741 "smtp_rply" => substr($byemsg,4)); 607 742 $rval = false; 608 743 if($this->do_debug >= 1) { 609 echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';744 $this->edebug("SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'); 610 745 } 611 746 } 612 747 … … class SMTP { 644 779 $code = substr($rply,0,3); 645 780 646 781 if($this->do_debug >= 2) { 647 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';782 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 648 783 } 649 784 650 785 if($code != 250 && $code != 251) { … … class SMTP { 653 788 "smtp_code" => $code, 654 789 "smtp_msg" => substr($rply,4)); 655 790 if($this->do_debug >= 1) { 656 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';791 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 657 792 } 658 793 return false; 659 794 } … … class SMTP { 687 822 $code = substr($rply,0,3); 688 823 689 824 if($this->do_debug >= 2) { 690 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';825 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 691 826 } 692 827 693 828 if($code != 250) { … … class SMTP { 696 831 "smtp_code" => $code, 697 832 "smtp_msg" => substr($rply,4)); 698 833 if($this->do_debug >= 1) { 699 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';834 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 700 835 } 701 836 return false; 702 837 } … … class SMTP { 735 870 $code = substr($rply,0,3); 736 871 737 872 if($this->do_debug >= 2) { 738 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';873 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 739 874 } 740 875 741 876 if($code != 250) { … … class SMTP { 744 879 "smtp_code" => $code, 745 880 "smtp_msg" => substr($rply,4)); 746 881 if($this->do_debug >= 1) { 747 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';882 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 748 883 } 749 884 return false; 750 885 } … … class SMTP { 768 903 $this->error = array("error" => "This method, TURN, of the SMTP ". 769 904 "is not implemented"); 770 905 if($this->do_debug >= 1) { 771 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';906 $this->edebug("SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />'); 772 907 } 773 908 return false; 774 909 } … … class SMTP { 797 932 */ 798 933 private function get_lines() { 799 934 $data = ""; 800 while(!feof($this->smtp_conn)) { 935 $endtime = 0; 936 /* If for some reason the fp is bad, don't inf loop */ 937 if (!is_resource($this->smtp_conn)) { 938 return $data; 939 } 940 stream_set_timeout($this->smtp_conn, $this->Timeout); 941 if ($this->Timelimit > 0) { 942 $endtime = time() + $this->Timelimit; 943 } 944 while(is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { 801 945 $str = @fgets($this->smtp_conn,515); 802 946 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 />';947 $this->edebug("SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'); 948 $this->edebug("SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'); 805 949 } 806 950 $data .= $str; 807 951 if($this->do_debug >= 4) { 808 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';952 $this->edebug("SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'); 809 953 } 810 954 // if 4th character is a space, we are done reading, break the loop 811 955 if(substr($str,3,1) == " ") { break; } 956 // Timed-out? Log and break 957 $info = stream_get_meta_data($this->smtp_conn); 958 if ($info['timed_out']) { 959 if($this->do_debug >= 4) { 960 $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " seconds) <br />"); 961 } 962 break; 963 } 964 // Now check if reads took too long 965 if ($endtime) { 966 if (time() > $endtime) { 967 if($this->do_debug >= 4) { 968 $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " seconds) <br />"); 969 } 970 break; 971 } 972 } 812 973 } 813 974 return $data; 814 975 }
