Ticket #21074: 21074-phpmailer-5.2.2-r23022.patch
File 21074-phpmailer-5.2.2-r23022.patch, 81.5 KB (added by , 11 years ago) |
---|
-
wp-includes/class-phpmailer.php
diff --git wp-includes/class-phpmailer.php wp-includes/class-phpmailer.php index df533c2..146bc52 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) | … … 23 23 */ 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 29 29 * @author Andy Prevost … … 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 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 42 45 ///////////////////////////////////////////////// … … class PHPMailer { 94 97 public $Sender = ''; 95 98 96 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 = ''; 105 106 /** 97 107 * Sets the Subject of the message. 98 108 * @var string 99 109 */ … … class PHPMailer { 130 140 protected $MIMEHeader = ''; 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 /** 140 150 * Sets word wrapping on the body of the message to a given number of … … class PHPMailer { 156 166 public $Sendmail = '/usr/sbin/sendmail'; 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. 161 178 * @var string … … class PHPMailer { 183 200 */ 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 188 212 ///////////////////////////////////////////////// 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] 194 220 * (e.g. "smtp1.example.com:25;smtp2.example.com"). … … class PHPMailer { 210 236 public $Helo = ''; 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 */ 217 242 public $SMTPSecure = ''; … … class PHPMailer { 235 260 public $Password = ''; 236 261 237 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 = ''; 279 280 /** 238 281 * Sets the SMTP server timeout in seconds. 239 282 * This function will not work with the win32 version. 240 283 * @var int … … class PHPMailer { 248 291 public $SMTPDebug = false; 249 292 250 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"; 299 300 /** 251 301 * Prevents the SMTP connection from being closed after each mail 252 302 * sending. If this is set to true then to close the connection 253 303 * requires an explicit call to SmtpClose(). … … class PHPMailer { 269 319 public $SingleToArray = array(); 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 329 /** 330 * Used with DKIM Signing 331 * required parameter if DKIM is enabled 332 * 333 * domain selector example domainkey 279 334 * @var string 280 335 */ 281 public $DKIM_selector = ' phpmailer';336 public $DKIM_selector = ''; 282 337 283 338 /** 284 * Used with DKIM DNS Resource Record285 * optional, in format of email address 'you@yourdomain.com'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 */ 288 343 public $DKIM_identity = ''; 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 */ 294 350 public $DKIM_passphrase = ''; 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 */ 301 357 public $DKIM_domain = ''; 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 */ 308 364 public $DKIM_private = ''; 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 315 380 * string $cc cc email addresses 316 381 * string $bcc bcc email addresses 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 */ 321 387 public $action_function = ''; //'callbackAction'; … … class PHPMailer { 324 390 * Sets the PHPMailer Version number 325 391 * @var string 326 392 */ 327 public $Version = '5.2. 1';393 public $Version = '5.2.2'; 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 = ''; 334 400 … … class PHPMailer { 336 402 // PROPERTIES, PRIVATE AND PROTECTED 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 356 486 ///////////////////////////////////////////////// … … class PHPMailer { 360 490 const STOP_MESSAGE = 0; // message only, continue processing 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 ///////////////////////////////////////////////// 367 498 368 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 } 532 533 /** 369 534 * Constructor 370 535 * @param boolean $exceptions Should we throw external exceptions? 371 536 */ … … class PHPMailer { 389 554 /** 390 555 * Sets Mailer to send message using SMTP. 391 556 * @return void 557 * @deprecated 392 558 */ 393 559 public function IsSMTP() { 394 560 $this->Mailer = 'smtp'; … … class PHPMailer { 397 563 /** 398 564 * Sets Mailer to send message using PHP mail() function. 399 565 * @return void 566 * @deprecated 400 567 */ 401 568 public function IsMail() { 402 569 $this->Mailer = 'mail'; … … class PHPMailer { 405 572 /** 406 573 * Sets Mailer to send message using the $Sendmail program. 407 574 * @return void 575 * @deprecated 408 576 */ 409 577 public function IsSendmail() { 410 578 if (!stristr(ini_get('sendmail_path'), 'sendmail')) { … … class PHPMailer { 416 584 /** 417 585 * Sets Mailer to send message using the qmail MTA. 418 586 * @return void 587 * @deprecated 419 588 */ 420 589 public function IsQmail() { 421 590 if (stristr(ini_get('sendmail_path'), 'qmail')) { … … class PHPMailer { 476 645 * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo' 477 646 * @param string $address The email address to send to 478 647 * @param string $name 648 * @throws phpmailerException 479 649 * @return boolean true on success, false if address already used or invalid in some way 480 650 * @access protected 481 651 */ … … class PHPMailer { 485 655 if ($this->exceptions) { 486 656 throw new phpmailerException('Invalid recipient array: ' . $kind); 487 657 } 488 489 echo $this->Lang('Invalid recipient array').': '.$kind;658 if ($this->SMTPDebug) { 659 $this->edebug($this->Lang('Invalid recipient array').': '.$kind); 490 660 } 491 661 return false; 492 662 } 493 663 $address = trim($address); 494 664 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 495 if (! self::ValidateAddress($address)) {665 if (!$this->ValidateAddress($address)) { 496 666 $this->SetError($this->Lang('invalid_address').': '. $address); 497 667 if ($this->exceptions) { 498 668 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 499 669 } 500 501 echo $this->Lang('invalid_address').': '.$address;670 if ($this->SMTPDebug) { 671 $this->edebug($this->Lang('invalid_address').': '.$address); 502 672 } 503 673 return false; 504 674 } … … class PHPMailer { 521 691 * Set the From and FromName properties 522 692 * @param string $address 523 693 * @param string $name 694 * @param int $auto Also set Reply-To and Sender 695 * @throws phpmailerException 524 696 * @return boolean 525 697 */ 526 698 public function SetFrom($address, $name = '', $auto = 1) { 527 699 $address = trim($address); 528 700 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 529 if (! self::ValidateAddress($address)) {701 if (!$this->ValidateAddress($address)) { 530 702 $this->SetError($this->Lang('invalid_address').': '. $address); 531 703 if ($this->exceptions) { 532 704 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 533 705 } 534 535 echo $this->Lang('invalid_address').': '.$address;706 if ($this->SMTPDebug) { 707 $this->edebug($this->Lang('invalid_address').': '.$address); 536 708 } 537 709 return false; 538 710 } … … class PHPMailer { 551 723 552 724 /** 553 725 * 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 726 * Static so it can be used without instantiation, public so people can overload 727 * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is 728 * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to 729 * not allow a@b type valid addresses :( 730 * @link http://squiloople.com/2009/12/20/email-address-validation/ 731 * @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 732 * @param string $address The email address to check 559 733 * @return boolean 560 734 * @static 561 735 * @access public 562 736 */ 563 737 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 } 738 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 739 } 574 740 575 741 ///////////////////////////////////////////////// … … class PHPMailer { 580 746 * Creates message and assigns Mailer. If the message is 581 747 * not sent successfully then it returns false. Use the ErrorInfo 582 748 * variable to view description of the error. 749 * @throws phpmailerException 583 750 * @return bool 584 751 */ 585 752 public function Send() { … … class PHPMailer { 587 754 if(!$this->PreSend()) return false; 588 755 return $this->PostSend(); 589 756 } catch (phpmailerException $e) { 590 $this->SentMIMEMessage= '';757 $this->mailHeader = ''; 591 758 $this->SetError($e->getMessage()); 592 759 if ($this->exceptions) { 593 760 throw $e; … … class PHPMailer { 596 763 } 597 764 } 598 765 599 protected function PreSend() { 766 /** 767 * Prep mail by constructing all message entities 768 * @throws phpmailerException 769 * @return bool 770 */ 771 public function PreSend() { 600 772 try { 601 $mailHeader = "";773 $this->mailHeader = ""; 602 774 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { 603 775 throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); 604 776 } … … class PHPMailer { 619 791 $this->MIMEBody = $this->CreateBody(); 620 792 621 793 // To capture the complete message when using mail(), create 622 794 // an extra header list which CreateHeader() doesn't fold in 623 795 if ($this->Mailer == 'mail') { 624 796 if (count($this->to) > 0) { 625 $ mailHeader .= $this->AddrAppend("To", $this->to);797 $this->mailHeader .= $this->AddrAppend("To", $this->to); 626 798 } else { 627 $ mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");799 $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;"); 628 800 } 629 $ mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));801 $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject)))); 630 802 // if(count($this->cc) > 0) { 631 // $ mailHeader .= $this->AddrAppend("Cc", $this->cc);803 // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc); 632 804 // } 633 805 } 634 806 635 807 // digitally sign with DKIM if enabled 636 if ( $this->DKIM_domain && $this->DKIM_private) {808 if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) { 637 809 $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody); 638 810 $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader; 639 811 } 640 812 641 $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);642 813 return true; 643 814 644 815 } catch (phpmailerException $e) { … … class PHPMailer { 650 821 } 651 822 } 652 823 653 protected function PostSend() { 824 /** 825 * Actual Email transport function 826 * Send the email via the selected mechanism 827 * @throws phpmailerException 828 * @return bool 829 */ 830 public function PostSend() { 654 831 try { 655 832 // Choose the mailer and send through it 656 833 switch($this->Mailer) { … … class PHPMailer { 663 840 default: 664 841 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 665 842 } 666 667 843 } catch (phpmailerException $e) { 668 844 $this->SetError($e->getMessage()); 669 845 if ($this->exceptions) { 670 846 throw $e; 671 847 } 672 673 echo $e->getMessage()."\n";848 if ($this->SMTPDebug) { 849 $this->edebug($e->getMessage()."\n"); 674 850 } 675 return false;676 851 } 852 return false; 677 853 } 678 854 679 855 /** 680 856 * Sends mail using the $Sendmail program. 681 857 * @param string $header The message headers 682 858 * @param string $body The message body 859 * @throws phpmailerException 683 860 * @access protected 684 861 * @return bool 685 862 */ 686 863 protected function SendmailSend($header, $body) { 687 864 if ($this->Sender != '') { 688 $sendmail = sprintf("%s -oi -f 865 $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender)); 689 866 } else { 690 867 $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail)); 691 868 } 692 869 if ($this->SingleTo === true) { 693 foreach ($this->SingleToArray as $ key => $val) {870 foreach ($this->SingleToArray as $val) { 694 871 if(!@$mail = popen($sendmail, 'w')) { 695 872 throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 696 873 } … … class PHPMailer { 726 903 * Sends mail using the PHP mail() function. 727 904 * @param string $header The message headers 728 905 * @param string $body The message body 906 * @throws phpmailerException 729 907 * @access protected 730 908 * @return bool 731 909 */ … … class PHPMailer { 739 917 if (empty($this->Sender)) { 740 918 $params = "-oi "; 741 919 } else { 742 $params = sprintf("-oi -f 920 $params = sprintf("-oi -f%s", $this->Sender); 743 921 } 744 922 if ($this->Sender != '' and !ini_get('safe_mode')) { 745 923 $old_from = ini_get('sendmail_from'); 746 924 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); 925 } 926 $rt = false; 927 if ($this->SingleTo === true && count($toArr) > 1) { 928 foreach ($toArr as $val) { 929 $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params); 756 930 // implement call back function if it exists 757 931 $isSent = ($rt == 1) ? 1 : 0; 758 $this->doCallback($isSent, $ to, $this->cc, $this->bcc, $this->Subject, $body);932 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 759 933 } 760 934 } 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 } 935 $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params); 936 // implement call back function if it exists 937 $isSent = ($rt == 1) ? 1 : 0; 938 $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 774 939 } 775 940 if (isset($old_from)) { 776 941 ini_set('sendmail_from', $old_from); … … class PHPMailer { 786 951 * Returns false if there is a bad MAIL FROM, RCPT, or DATA input. 787 952 * @param string $header The message headers 788 953 * @param string $body The message body 954 * @throws phpmailerException 789 955 * @uses SMTP 790 956 * @access protected 791 957 * @return bool … … class PHPMailer { 850 1016 } 851 1017 if($this->SMTPKeepAlive == true) { 852 1018 $this->smtp->Reset(); 1019 } else { 1020 $this->smtp->Quit(); 1021 $this->smtp->Close(); 853 1022 } 854 1023 return true; 855 1024 } … … class PHPMailer { 859 1028 * Returns false if the operation failed. 860 1029 * @uses SMTP 861 1030 * @access public 1031 * @throws phpmailerException 862 1032 * @return bool 863 1033 */ 864 1034 public function SmtpConnect() { 865 1035 if(is_null($this->smtp)) { 866 $this->smtp = new SMTP ();1036 $this->smtp = new SMTP; 867 1037 } 868 1038 1039 $this->smtp->Timeout = $this->Timeout; 869 1040 $this->smtp->do_debug = $this->SMTPDebug; 870 1041 $hosts = explode(';', $this->Host); 871 1042 $index = 0; … … class PHPMailer { 902 1073 903 1074 $connection = true; 904 1075 if ($this->SMTPAuth) { 905 if (!$this->smtp->Authenticate($this->Username, $this->Password)) { 1076 if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType, 1077 $this->Realm, $this->Workstation)) { 906 1078 throw new phpmailerException($this->Lang('authenticate')); 907 1079 } 908 1080 } 909 1081 } 910 1082 $index++; 911 912 913 1083 if (!$connection) { 1084 throw new phpmailerException($this->Lang('connect_host')); 1085 } 914 1086 } 915 1087 } catch (phpmailerException $e) { 916 1088 $this->smtp->Reset(); 917 1089 if ($this->exceptions) { 918 1090 throw $e; 919 1091 } 920 1092 } … … class PHPMailer { 926 1098 * @return void 927 1099 */ 928 1100 public function SmtpClose() { 929 if (!is_null($this->smtp)) {1101 if ($this->smtp !== null) { 930 1102 if($this->smtp->Connected()) { 931 1103 $this->smtp->Quit(); 932 1104 $this->smtp->Close(); … … class PHPMailer { 939 1111 * Returns false if it cannot load the language file. The default language is English. 940 1112 * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br") 941 1113 * @param string $lang_path Path to the language file directory 1114 * @return bool 942 1115 * @access public 943 1116 */ 944 1117 function SetLanguage($langcode = 'en', $lang_path = 'language/') { 945 1118 //Define full set of translatable strings 946 1119 $PHPMAILER_LANG = array( 947 'provide_address' => 'You must provide at least one recipient email address.', 1120 'authenticate' => 'SMTP Error: Could not authenticate.', 1121 'connect_host' => 'SMTP Error: Could not connect to SMTP host.', 1122 'data_not_accepted' => 'SMTP Error: Data not accepted.', 1123 'empty_message' => 'Message body empty', 1124 'encoding' => 'Unknown encoding: ', 1125 'execute' => 'Could not execute: ', 1126 'file_access' => 'Could not access file: ', 1127 'file_open' => 'File Error: Could not open file: ', 1128 'from_failed' => 'The following From address failed: ', 1129 'instantiate' => 'Could not instantiate mail function.', 1130 'invalid_address' => 'Invalid address', 948 1131 '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: ' 1132 'provide_address' => 'You must provide at least one recipient email address.', 1133 'recipients_failed' => 'SMTP Error: The following recipients failed: ', 1134 'signing' => 'Signing Error: ', 1135 'smtp_connect_failed' => 'SMTP Connect() failed.', 1136 'smtp_error' => 'SMTP server error: ', 1137 'variable_set' => 'Cannot set or reset variable: ' 964 1138 ); 965 1139 //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"! 966 1140 $l = true; … … class PHPMailer { 986 1160 /** 987 1161 * Creates recipient headers. 988 1162 * @access public 1163 * @param string $type 1164 * @param array $addr 989 1165 * @return string 990 1166 */ 991 1167 public function AddrAppend($type, $addr) { … … class PHPMailer { 1003 1179 /** 1004 1180 * Formats an address correctly. 1005 1181 * @access public 1182 * @param string $addr 1006 1183 * @return string 1007 1184 */ 1008 1185 public function AddrFormat($addr) { … … class PHPMailer { 1028 1205 // If utf-8 encoding is used, we will need to make sure we don't 1029 1206 // split multibyte characters when we wrap 1030 1207 $is_utf8 = (strtolower($this->CharSet) == "utf-8"); 1208 $lelen = strlen($this->LE); 1209 $crlflen = strlen(self::CRLF); 1031 1210 1032 1211 $message = $this->FixEOL($message); 1033 if (substr($message, - 1) == $this->LE) {1034 $message = substr($message, 0, - 1);1212 if (substr($message, -$lelen) == $this->LE) { 1213 $message = substr($message, 0, -$lelen); 1035 1214 } 1036 1215 1037 $line = explode($this->LE, $message); 1216 $line = explode($this->LE, $message); // Magic. We know FixEOL uses $LE 1038 1217 $message = ''; 1039 1218 for ($i = 0 ;$i < count($line); $i++) { 1040 1219 $line_part = explode(' ', $line[$i]); … … class PHPMailer { 1042 1221 for ($e = 0; $e<count($line_part); $e++) { 1043 1222 $word = $line_part[$e]; 1044 1223 if ($qp_mode and (strlen($word) > $length)) { 1045 $space_left = $length - strlen($buf) - 1;1224 $space_left = $length - strlen($buf) - $crlflen; 1046 1225 if ($e != 0) { 1047 1226 if ($space_left > 20) { 1048 1227 $len = $space_left; … … class PHPMailer { 1056 1235 $part = substr($word, 0, $len); 1057 1236 $word = substr($word, $len); 1058 1237 $buf .= ' ' . $part; 1059 $message .= $buf . sprintf("=%s", $this->LE);1238 $message .= $buf . sprintf("=%s", self::CRLF); 1060 1239 } else { 1061 1240 $message .= $buf . $soft_break; 1062 1241 } … … class PHPMailer { 1075 1254 $word = substr($word, $len); 1076 1255 1077 1256 if (strlen($word) > 0) { 1078 $message .= $part . sprintf("=%s", $this->LE);1257 $message .= $part . sprintf("=%s", self::CRLF); 1079 1258 } else { 1080 1259 $buf = $part; 1081 1260 } … … class PHPMailer { 1090 1269 } 1091 1270 } 1092 1271 } 1093 $message .= $buf . $this->LE;1272 $message .= $buf . self::CRLF; 1094 1273 } 1095 1274 1096 1275 return $message; … … class PHPMailer { 1175 1354 $this->boundary[2] = 'b2_' . $uniq_id; 1176 1355 $this->boundary[3] = 'b3_' . $uniq_id; 1177 1356 1178 $result .= $this->HeaderLine('Date', self::RFCDate()); 1179 if($this->Sender == '') { 1357 if ($this->MessageDate == '') { 1358 $result .= $this->HeaderLine('Date', self::RFCDate()); 1359 } else { 1360 $result .= $this->HeaderLine('Date', $this->MessageDate); 1361 } 1362 1363 if ($this->ReturnPath) { 1364 $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath)); 1365 } elseif ($this->Sender == '') { 1180 1366 $result .= $this->HeaderLine('Return-Path', trim($this->From)); 1181 1367 } else { 1182 1368 $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); … … class PHPMailer { 1195 1381 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); 1196 1382 } 1197 1383 } 1198 1384 } 1199 1385 1200 1386 $from = array(); 1201 1387 $from[0][0] = trim($this->From); … … class PHPMailer { 1227 1413 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); 1228 1414 } 1229 1415 $result .= $this->HeaderLine('X-Priority', $this->Priority); 1230 if ($this->XMailer) {1231 $result .= $this->HeaderLine('X-Mailer', $this->XMailer);1416 if ($this->XMailer == '') { 1417 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1232 1418 } else { 1233 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1419 $myXmailer = trim($this->XMailer); 1420 if ($myXmailer) { 1421 $result .= $this->HeaderLine('X-Mailer', $myXmailer); 1422 } 1234 1423 } 1235 1424 1236 1425 if($this->ConfirmReadingTo != '') { … … class PHPMailer { 1257 1446 public function GetMailMIME() { 1258 1447 $result = ''; 1259 1448 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 1449 case 'inline': 1265 1450 $result .= $this->HeaderLine('Content-Type', 'multipart/related;'); 1266 1451 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); … … class PHPMailer { 1277 1462 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 1278 1463 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 1279 1464 break; 1465 default: 1466 // Catches case 'plain': and case '': 1467 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); 1468 $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet); 1469 break; 1280 1470 } 1281 1471 1282 1472 if($this->Mailer != 'mail') { 1283 $result .= $this->LE .$this->LE;1473 $result .= $this->LE; 1284 1474 } 1285 1475 1286 1476 return $result; … … class PHPMailer { 1292 1482 * @return string 1293 1483 */ 1294 1484 public function GetSentMIMEMessage() { 1295 return $this-> SentMIMEMessage;1485 return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody; 1296 1486 } 1297 1487 1298 1488 1299 1489 /** 1300 1490 * Assembles the message body. Returns an empty string on failure. 1301 1491 * @access public 1492 * @throws phpmailerException 1302 1493 * @return string The assembled message body 1303 1494 */ 1304 1495 public function CreateBody() { 1305 1496 $body = ''; 1306 1497 1307 1498 if ($this->sign_key_file) { 1308 $body .= $this->GetMailMIME() ;1499 $body .= $this->GetMailMIME().$this->LE; 1309 1500 } 1310 1501 1311 1502 $this->SetWordWrap(); 1312 1503 1313 1504 switch($this->message_type) { 1314 case 'plain':1315 $body .= $this->EncodeString($this->Body, $this->Encoding);1316 break;1317 1505 case 'inline': 1318 1506 $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 1319 1507 $body .= $this->EncodeString($this->Body, $this->Encoding); … … class PHPMailer { 1398 1586 $body .= $this->LE; 1399 1587 $body .= $this->AttachAll("attachment", $this->boundary[1]); 1400 1588 break; 1589 default: 1590 // catch case 'plain' and case '' 1591 $body .= $this->EncodeString($this->Body, $this->Encoding); 1592 break; 1401 1593 } 1402 1594 1403 1595 if ($this->IsError()) { … … class PHPMailer { 1430 1622 /** 1431 1623 * Returns the start of a message boundary. 1432 1624 * @access protected 1625 * @param string $boundary 1626 * @param string $charSet 1627 * @param string $contentType 1628 * @param string $encoding 1433 1629 * @return string 1434 1630 */ 1435 1631 protected function GetBoundary($boundary, $charSet, $contentType, $encoding) { … … class PHPMailer { 1444 1640 $encoding = $this->Encoding; 1445 1641 } 1446 1642 $result .= $this->TextLine('--' . $boundary); 1447 $result .= sprintf("Content-Type: %s; charset= \"%s\"", $contentType, $charSet);1643 $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet); 1448 1644 $result .= $this->LE; 1449 1645 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); 1450 1646 $result .= $this->LE; … … class PHPMailer { 1455 1651 /** 1456 1652 * Returns the end of a message boundary. 1457 1653 * @access protected 1654 * @param string $boundary 1458 1655 * @return string 1459 1656 */ 1460 1657 protected function EndBoundary($boundary) { … … class PHPMailer { 1478 1675 /** 1479 1676 * Returns a formatted header line. 1480 1677 * @access public 1678 * @param string $name 1679 * @param string $value 1481 1680 * @return string 1482 1681 */ 1483 1682 public function HeaderLine($name, $value) { … … class PHPMailer { 1487 1686 /** 1488 1687 * Returns a formatted mail line. 1489 1688 * @access public 1689 * @param string $value 1490 1690 * @return string 1491 1691 */ 1492 1692 public function TextLine($value) { … … class PHPMailer { 1505 1705 * @param string $name Overrides the attachment name. 1506 1706 * @param string $encoding File encoding (see $Encoding). 1507 1707 * @param string $type File extension (MIME) type. 1708 * @throws phpmailerException 1508 1709 * @return bool 1509 1710 */ 1510 1711 public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { … … class PHPMailer { 1533 1734 if ($this->exceptions) { 1534 1735 throw $e; 1535 1736 } 1536 1537 echo $e->getMessage()."\n";1737 if ($this->SMTPDebug) { 1738 $this->edebug($e->getMessage()."\n"); 1538 1739 } 1539 1740 if ( $e->getCode() == self::STOP_CRITICAL ) { 1540 1741 return false; … … class PHPMailer { 1555 1756 * Attaches all fs, string, and binary attachments to the message. 1556 1757 * Returns an empty string on failure. 1557 1758 * @access protected 1759 * @param string $disposition_type 1760 * @param string $boundary 1558 1761 * @return string 1559 1762 */ 1560 1763 protected function AttachAll($disposition_type, $boundary) { … … class PHPMailer { 1568 1771 // CHECK IF IT IS A VALID DISPOSITION_FILTER 1569 1772 if($attachment[6] == $disposition_type) { 1570 1773 // Check for string attachment 1774 $string = ''; 1775 $path = ''; 1571 1776 $bString = $attachment[5]; 1572 1777 if ($bString) { 1573 1778 $string = $attachment[0]; … … class PHPMailer { 1624 1829 * Returns an empty string on failure. 1625 1830 * @param string $path The full path to the file 1626 1831 * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' 1832 * @throws phpmailerException 1627 1833 * @see EncodeFile() 1628 1834 * @access protected 1629 1835 * @return string … … class PHPMailer { 1633 1839 if (!is_readable($path)) { 1634 1840 throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); 1635 1841 } 1636 if (function_exists('get_magic_quotes')) {1637 function get_magic_quotes() {1638 return false;1639 }1640 }1641 1642 1842 // if (!function_exists('get_magic_quotes')) { 1843 // function get_magic_quotes() { 1844 // return false; 1845 // } 1846 // } 1847 $magic_quotes = get_magic_quotes_runtime(); 1848 if ($magic_quotes) { 1643 1849 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1644 1850 set_magic_quotes_runtime(0); 1645 1851 } else { 1646 ini_set('magic_quotes_runtime', 0); 1647 1648 1852 ini_set('magic_quotes_runtime', 0); 1853 } 1854 } 1649 1855 $file_buffer = file_get_contents($path); 1650 1856 $file_buffer = $this->EncodeString($file_buffer, $encoding); 1651 1857 if ($magic_quotes) { 1652 1858 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1653 1859 set_magic_quotes_runtime($magic_quotes); 1654 1860 } else { 1655 ini_set('magic_quotes_runtime', $magic_quotes); 1656 1657 1861 ini_set('magic_quotes_runtime', $magic_quotes); 1862 } 1863 } 1658 1864 return $file_buffer; 1659 1865 } catch (Exception $e) { 1660 1866 $this->SetError($e->getMessage()); … … class PHPMailer { 1699 1905 /** 1700 1906 * Encode a header string to best (shortest) of Q, B, quoted or none. 1701 1907 * @access public 1908 * @param string $str 1909 * @param string $position 1702 1910 * @return string 1703 1911 */ 1704 1912 public function EncodeHeader($str, $position = 'text') { … … class PHPMailer { 1737 1945 if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) { 1738 1946 // Use a custom function which correctly encodes and wraps long 1739 1947 // multibyte strings without breaking lines within a character 1740 $encoded = $this->Base64EncodeWrapMB($str );1948 $encoded = $this->Base64EncodeWrapMB($str, "\n"); 1741 1949 } else { 1742 1950 $encoded = base64_encode($str); 1743 1951 $maxlen -= $maxlen % 4; … … class PHPMailer { 1747 1955 $encoding = 'Q'; 1748 1956 $encoded = $this->EncodeQ($str, $position); 1749 1957 $encoded = $this->WrapText($encoded, $maxlen, true); 1750 $encoded = str_replace('='. $this->LE, "\n", trim($encoded));1958 $encoded = str_replace('='.self::CRLF, "\n", trim($encoded)); 1751 1959 } 1752 1960 1753 1961 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); … … class PHPMailer { 1776 1984 * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php 1777 1985 * @access public 1778 1986 * @param string $str multi-byte text to wrap encode 1987 * @param string $lf string to use as linefeed/end-of-line 1779 1988 * @return string 1780 1989 */ 1781 public function Base64EncodeWrapMB($str ) {1990 public function Base64EncodeWrapMB($str, $lf=null) { 1782 1991 $start = "=?".$this->CharSet."?B?"; 1783 1992 $end = "?="; 1784 1993 $encoded = ""; 1994 if ($lf === null) { 1995 $lf = $this->LE; 1996 } 1785 1997 1786 1998 $mb_length = mb_strlen($str, $this->CharSet); 1787 1999 // Each line must have length <= 75, including $start and $end … … class PHPMailer { 1802 2014 } 1803 2015 while (strlen($chunk) > $length); 1804 2016 1805 $encoded .= $chunk . $ this->LE;2017 $encoded .= $chunk . $lf; 1806 2018 } 1807 2019 1808 2020 // Chomp the last linefeed 1809 $encoded = substr($encoded, 0, -strlen($ this->LE));2021 $encoded = substr($encoded, 0, -strlen($lf)); 1810 2022 return $encoded; 1811 2023 } 1812 2024 … … class PHPMailer { 1814 2026 * Encode string to quoted-printable. 1815 2027 * Only uses standard PHP, slow, but will always work 1816 2028 * @access public 1817 * @param string $string the text to encode2029 * @param string $input 1818 2030 * @param integer $line_max Number of chars allowed on a line before wrapping 2031 * @param bool $space_conv 2032 * @internal param string $string the text to encode 1819 2033 * @return string 1820 2034 */ 1821 2035 public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) { … … class PHPMailer { 1840 2054 $c = '=20'; 1841 2055 } 1842 2056 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required 1843 $h2 = floor($dec/16);1844 $h1 = floor($dec%16);2057 $h2 = (integer)floor($dec/16); 2058 $h1 = (integer)floor($dec%16); 1845 2059 $c = $escape.$hex[$h2].$hex[$h1]; 1846 2060 } 1847 2061 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted … … class PHPMailer { 1901 2115 * @return string 1902 2116 */ 1903 2117 public function EncodeQ($str, $position = 'text') { 1904 // 1905 $encoded = preg_replace('/[\r\n]*/', '', $str);1906 2118 //There should not be any EOL in the string 2119 $pattern=""; 2120 $encoded = str_replace(array("\r", "\n"), '', $str); 1907 2121 switch (strtolower($position)) { 1908 2122 case 'phrase': 1909 $ encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);2123 $pattern = '^A-Za-z0-9!*+\/ -'; 1910 2124 break; 2125 1911 2126 case 'comment': 1912 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); 2127 $pattern = '\(\)"'; 2128 //note that we dont break here! 2129 //for this reason we build the $pattern withoud including delimiters and [] 2130 1913 2131 case 'text': 1914 2132 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); 2133 //Replace every high ascii, control =, ? and _ characters 2134 //We put \075 (=) as first value to make sure it's the first one in being converted, preventing double encode 2135 $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern; 1919 2136 break; 1920 2137 } 2138 2139 if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) { 2140 foreach (array_unique($matches[0]) as $char) { 2141 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded); 2142 } 2143 } 2144 2145 //Replace every spaces to _ (more readable than =20) 2146 return str_replace(' ', '_', $encoded); 2147 } 1921 2148 1922 // Replace every spaces to _ (more readable than =20)1923 $encoded = str_replace(' ', '_', $encoded);1924 1925 return $encoded;1926 }1927 2149 1928 2150 /** 1929 2151 * Adds a string or binary attachment (non-filesystem) to the list. … … class PHPMailer { 1989 2211 return true; 1990 2212 } 1991 2213 1992 public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') { 2214 /** 2215 * Adds an embedded stringified attachment. This can include images, sounds, and 2216 * just about any other document. Make sure to set the $type to an 2217 * image type. For JPEG images use "image/jpeg" and for GIF images 2218 * use "image/gif". 2219 * @param string $string The attachment. 2220 * @param string $cid Content ID of the attachment. Use this to identify 2221 * the Id for accessing the image in an HTML form. 2222 * @param string $name Overrides the attachment name. 2223 * @param string $encoding File encoding (see $Encoding). 2224 * @param string $type File extension (MIME) type. 2225 * @return bool 2226 */ 2227 public function AddStringEmbeddedImage($string, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { 1993 2228 // Append to $attachment array 1994 2229 $this->attachment[] = array( 1995 2230 0 => $string, 1996 1 => $ filename,1997 2 => basename($filename),2231 1 => $name, 2232 2 => $name, 1998 2233 3 => $encoding, 1999 2234 4 => $type, 2000 2235 5 => true, // isStringAttachment … … class PHPMailer { 2017 2252 return false; 2018 2253 } 2019 2254 2255 /** 2256 * Returns true if an attachment (non-inline) is present. 2257 * @return bool 2258 */ 2020 2259 public function AttachmentExists() { 2021 2260 foreach($this->attachment as $attachment) { 2022 2261 if ($attachment[6] == 'attachment') { … … class PHPMailer { 2026 2265 return false; 2027 2266 } 2028 2267 2268 /** 2269 * Does this message have an alternative body set? 2270 * @return bool 2271 */ 2029 2272 public function AlternativeExists() { 2030 return strlen($this->AltBody)>0;2273 return !empty($this->AltBody); 2031 2274 } 2032 2275 2033 2276 ///////////////////////////////////////////////// … … class PHPMailer { 2111 2354 /** 2112 2355 * Adds the error message to the error container. 2113 2356 * @access protected 2357 * @param string $msg 2114 2358 * @return void 2115 2359 */ 2116 2360 protected function SetError($msg) { … … class PHPMailer { 2160 2404 /** 2161 2405 * Returns a message in the appropriate language. 2162 2406 * @access protected 2407 * @param string $key 2163 2408 * @return string 2164 2409 */ 2165 2410 protected function Lang($key) { … … class PHPMailer { 2184 2429 } 2185 2430 2186 2431 /** 2187 * Changes every end of line from CR or LF to CRLF.2432 * Changes every end of line from CRLF, CR or LF to $this->LE. 2188 2433 * @access public 2434 * @param string $str String to FixEOL 2189 2435 * @return string 2190 2436 */ 2191 2437 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; 2438 // condense down to \n 2439 $nstr = str_replace(array("\r\n", "\r"), "\n", $str); 2440 // Now convert LE as needed 2441 if ($this->LE !== "\n") { 2442 $nstr = str_replace("\n", $this->LE, $nstr); 2443 } 2444 return $nstr; 2196 2445 } 2197 2446 2198 2447 /** 2199 * Adds a custom header. 2448 * Adds a custom header. $name value can be overloaded to contain 2449 * both header name and value (name:value) 2200 2450 * @access public 2451 * @param string $name custom header name 2452 * @param string $value header value 2201 2453 * @return void 2202 2454 */ 2203 public function AddCustomHeader($custom_header) { 2204 $this->CustomHeader[] = explode(':', $custom_header, 2); 2455 public function AddCustomHeader($name, $value=null) { 2456 if ($value === null) { 2457 // Value passed in as name:value 2458 $this->CustomHeader[] = explode(':', $name, 2); 2459 } else { 2460 $this->CustomHeader[] = array($name, $value); 2461 } 2205 2462 } 2206 2463 2207 2464 /** 2208 2465 * Evaluates the message and returns modifications for inline images and backgrounds 2209 2466 * @access public 2210 * @return $message 2467 * @param string $message Text to be HTML modified 2468 * @param string $basedir baseline directory for path 2469 * @return string $message 2211 2470 */ 2212 2471 public function MsgHTML($message, $basedir = '') { 2213 2472 preg_match_all("/(src|background)=[\"'](.*)[\"']/Ui", $message, $images); … … class PHPMailer { 2217 2476 if (!preg_match('#^[A-z]+://#', $url)) { 2218 2477 $filename = basename($url); 2219 2478 $directory = dirname($url); 2220 ($directory == '.') ? $directory='': ''; 2479 if ($directory == '.') { 2480 $directory = ''; 2481 } 2221 2482 $cid = 'cid:' . md5($filename); 2222 2483 $ext = pathinfo($filename, PATHINFO_EXTENSION); 2223 2484 $mimeType = self::_mime_types($ext); … … class PHPMailer { 2231 2492 } 2232 2493 $this->IsHTML(true); 2233 2494 $this->Body = $message; 2234 2235 2236 2237 2238 2239 2495 if (empty($this->AltBody)) { 2496 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); 2497 if (!empty($textMsg)) { 2498 $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet); 2499 } 2500 } 2240 2501 if (empty($this->AltBody)) { 2241 2502 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; 2242 2503 } 2243 2504 return $message; 2244 2505 } 2245 2506 2246 2507 /** 2247 2508 * Gets the MIME type of the embedded or inline image 2248 * @param string File extension2509 * @param string $ext File extension 2249 2510 * @access public 2250 2511 * @return string MIME type of ext 2251 2512 * @static 2252 2513 */ 2253 2514 public static function _mime_types($ext = '') { 2254 2515 $mimes = array( 2516 'xl' => 'application/excel', 2255 2517 'hqx' => 'application/mac-binhex40', 2256 2518 'cpt' => 'application/mac-compactpro', 2257 'doc' => 'application/msword',2258 2519 'bin' => 'application/macbinary', 2520 'doc' => 'application/msword', 2521 'word' => 'application/msword', 2522 'class' => 'application/octet-stream', 2523 'dll' => 'application/octet-stream', 2259 2524 'dms' => 'application/octet-stream', 2525 'exe' => 'application/octet-stream', 2260 2526 'lha' => 'application/octet-stream', 2261 2527 'lzh' => 'application/octet-stream', 2262 'exe' => 'application/octet-stream',2263 'class' => 'application/octet-stream',2264 2528 'psd' => 'application/octet-stream', 2265 'so' => 'application/octet-stream',2266 2529 'sea' => 'application/octet-stream', 2267 ' dll'=> 'application/octet-stream',2530 'so' => 'application/octet-stream', 2268 2531 'oda' => 'application/oda', 2269 2532 'pdf' => 'application/pdf', 2270 2533 'ai' => 'application/postscript', … … class PHPMailer { 2282 2545 'dxr' => 'application/x-director', 2283 2546 'dvi' => 'application/x-dvi', 2284 2547 'gtar' => 'application/x-gtar', 2285 'php' => 'application/x-httpd-php',2286 'php4' => 'application/x-httpd-php',2287 2548 'php3' => 'application/x-httpd-php', 2549 'php4' => 'application/x-httpd-php', 2550 'php' => 'application/x-httpd-php', 2288 2551 'phtml' => 'application/x-httpd-php', 2289 2552 'phps' => 'application/x-httpd-php-source', 2290 2553 'js' => 'application/x-javascript', … … class PHPMailer { 2292 2555 'sit' => 'application/x-stuffit', 2293 2556 'tar' => 'application/x-tar', 2294 2557 'tgz' => 'application/x-tar', 2295 'xhtml' => 'application/xhtml+xml',2296 2558 'xht' => 'application/xhtml+xml', 2559 'xhtml' => 'application/xhtml+xml', 2297 2560 'zip' => 'application/zip', 2298 2561 'mid' => 'audio/midi', 2299 2562 'midi' => 'audio/midi', 2300 'mpga' => 'audio/mpeg',2301 2563 'mp2' => 'audio/mpeg', 2302 2564 'mp3' => 'audio/mpeg', 2565 'mpga' => 'audio/mpeg', 2303 2566 'aif' => 'audio/x-aiff', 2304 'aiff' => 'audio/x-aiff',2305 2567 'aifc' => 'audio/x-aiff', 2568 'aiff' => 'audio/x-aiff', 2306 2569 'ram' => 'audio/x-pn-realaudio', 2307 2570 'rm' => 'audio/x-pn-realaudio', 2308 2571 'rpm' => 'audio/x-pn-realaudio-plugin', 2309 2572 'ra' => 'audio/x-realaudio', 2310 'rv' => 'video/vnd.rn-realvideo',2311 2573 'wav' => 'audio/x-wav', 2312 2574 'bmp' => 'image/bmp', 2313 2575 'gif' => 'image/gif', 2314 2576 'jpeg' => 'image/jpeg', 2315 'jpg' => 'image/jpeg',2316 2577 'jpe' => 'image/jpeg', 2578 'jpg' => 'image/jpeg', 2317 2579 'png' => 'image/png', 2318 2580 'tiff' => 'image/tiff', 2319 2581 'tif' => 'image/tiff', 2582 'eml' => 'message/rfc822', 2320 2583 'css' => 'text/css', 2321 2584 'html' => 'text/html', 2322 2585 'htm' => 'text/html', 2323 2586 'shtml' => 'text/html', 2324 'txt' => 'text/plain',2325 'text' => 'text/plain',2326 2587 'log' => 'text/plain', 2588 'text' => 'text/plain', 2589 'txt' => 'text/plain', 2327 2590 'rtx' => 'text/richtext', 2328 2591 'rtf' => 'text/rtf', 2329 2592 'xml' => 'text/xml', 2330 2593 'xsl' => 'text/xml', 2331 2594 'mpeg' => 'video/mpeg', 2332 'mpg' => 'video/mpeg',2333 2595 'mpe' => 'video/mpeg', 2334 ' qt' => 'video/quicktime',2596 'mpg' => 'video/mpeg', 2335 2597 'mov' => 'video/quicktime', 2598 'qt' => 'video/quicktime', 2599 'rv' => 'video/vnd.rn-realvideo', 2336 2600 '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' 2601 'movie' => 'video/x-sgi-movie' 2342 2602 ); 2343 2603 return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; 2344 2604 } … … class PHPMailer { 2353 2613 * @param string $name Parameter Name 2354 2614 * @param mixed $value Parameter Value 2355 2615 * NOTE: will not work with arrays, there are no arrays to set/reset 2616 * @throws phpmailerException 2617 * @return bool 2356 2618 * @todo Should this not be using __set() magic function? 2357 2619 */ 2358 2620 public function set($name, $value = '') { … … class PHPMailer { 2378 2640 * @return string 2379 2641 */ 2380 2642 public function SecureHeader($str) { 2381 $str = str_replace("\r", '', $str); 2382 $str = str_replace("\n", '', $str); 2383 return trim($str); 2643 return trim(str_replace(array("\r", "\n"), '', $str)); 2384 2644 } 2385 2645 2386 2646 /** 2387 2647 * Set the private key file and password to sign the message. 2388 2648 * 2389 2649 * @access public 2650 * @param $cert_filename 2390 2651 * @param string $key_filename Parameter File Name 2391 2652 * @param string $key_pass Password for private key 2392 2653 */ … … class PHPMailer { 2400 2661 * Set the private key file and password to sign the message. 2401 2662 * 2402 2663 * @access public 2403 * @param string $ key_filename Parameter File Name2404 * @ param string $key_pass Password for private key2664 * @param string $txt 2665 * @return string 2405 2666 */ 2406 2667 public function DKIM_QP($txt) { 2407 $tmp = '';2408 2668 $line = ''; 2409 2669 for ($i = 0; $i < strlen($txt); $i++) { 2410 2670 $ord = ord($txt[$i]); … … class PHPMailer { 2422 2682 * 2423 2683 * @access public 2424 2684 * @param string $s Header 2685 * @return string 2425 2686 */ 2426 2687 public function DKIM_Sign($s) { 2427 2688 $privKeyStr = file_get_contents($this->DKIM_private); … … class PHPMailer { 2433 2694 if (openssl_sign($s, $signature, $privKey)) { 2434 2695 return base64_encode($signature); 2435 2696 } 2697 return ''; 2436 2698 } 2437 2699 2438 2700 /** … … class PHPMailer { 2440 2702 * 2441 2703 * @access public 2442 2704 * @param string $s Header 2705 * @return string 2443 2706 */ 2444 2707 public function DKIM_HeaderC($s) { 2445 2708 $s = preg_replace("/\r\n\s+/", " ", $s); … … class PHPMailer { 2459 2722 * 2460 2723 * @access public 2461 2724 * @param string $body Message Body 2725 * @return string 2462 2726 */ 2463 2727 public function DKIM_BodyC($body) { 2464 2728 if ($body == '') return "\r\n"; … … class PHPMailer { 2479 2743 * @param string $headers_line Header lines 2480 2744 * @param string $subject Subject 2481 2745 * @param string $body Body 2746 * @return string 2482 2747 */ 2483 2748 public function DKIM_Add($headers_line, $subject, $body) { 2484 2749 $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms … … class PHPMailer { 2487 2752 $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) 2488 2753 $subject_header = "Subject: $subject"; 2489 2754 $headers = explode($this->LE, $headers_line); 2755 $from_header = ""; 2756 $to_header = ""; 2490 2757 foreach($headers as $header) { 2491 2758 if (strpos($header, 'From:') === 0) { 2492 2759 $from_header = $header; … … class PHPMailer { 2512 2779 "\tb="; 2513 2780 $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs); 2514 2781 $signed = $this->DKIM_Sign($toSign); 2515 return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";2782 return "X-PHPMAILER-DKIM: code.google.com/a/apache-extras.org/p/phpmailer/\r\n".$dkimhdrs.$signed."\r\n"; 2516 2783 } 2517 2784 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); 2785 /** 2786 * Perform callback 2787 * @param boolean $isSent 2788 * @param string $to 2789 * @param string $cc 2790 * @param string $bcc 2791 * @param string $subject 2792 * @param string $body 2793 * @param string $from 2794 */ 2795 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) { 2796 if (!empty($this->action_function) && is_callable($this->action_function)) { 2797 $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from); 2521 2798 call_user_func_array($this->action_function, $params); 2522 2799 } 2523 2800 } 2524 2801 } 2525 2802 2803 /** 2804 * Exception handler for PHPMailer 2805 * @package PHPMailer 2806 */ 2526 2807 class phpmailerException extends Exception { 2808 /** 2809 * Prettify error message output 2810 * @return string 2811 */ 2527 2812 public function errorMessage() { 2528 2813 $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n"; 2529 2814 return $errorMsg; -
wp-includes/class-smtp.php
diff --git wp-includes/class-smtp.php wp-includes/class-smtp.php index 6977bff..8d9cd7d 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 /** 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 46 46 class SMTP { … … class SMTP { 51 51 public $SMTP_PORT = 25; 52 52 53 53 /** 54 * SMTP reply line ending 54 * SMTP reply line ending (don't change) 55 55 * @var string 56 56 */ 57 57 public $CRLF = "\r\n"; … … class SMTP { 63 63 public $do_debug; // the level of debug to perform 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 68 75 */ 69 76 public $do_verp = false; 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.2'; 76 95 77 96 ///////////////////////////////////////////////// 78 97 // PROPERTIES, PRIVATE AND PROTECTED 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() { 91 131 $this->smtp_conn = 0; … … class SMTP { 110 150 * SMTP CODE SUCCESS: 220 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 */ 115 158 public function Connect($host, $port = 0, $tval = 30) { … … class SMTP { 139 182 "errno" => $errno, 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; 145 188 } 146 189 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 153 201 $announce = $this->get_lines(); 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 159 207 return true; … … class SMTP { 182 230 $code = substr($rply,0,3); 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 188 236 if($code != 220) { … … class SMTP { 191 239 "smtp_code" => $code, 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; 197 245 } … … class SMTP { 208 256 * Performs SMTP authentication. Must be run after running the 209 257 * Hello() method. Returns true if successfully authenticated. 210 258 * @access public 259 * @param string $username 260 * @param string $password 261 * @param string $authtype 262 * @param string $realm 263 * @param string $workstation 211 264 * @return bool 212 265 */ 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; 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; 263 416 } 264 265 417 return true; 266 418 } 267 419 … … class SMTP { 276 428 if($sock_status["eof"]) { 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(); 282 434 return false; … … class SMTP { 324 476 * SMTP CODE FAILURE: 451,554 325 477 * SMTP CODE ERROR : 500,501,503,421 326 478 * @access public 479 * @param string $msg_data 327 480 * @return bool 328 481 */ 329 482 public function Data($msg_data) { … … class SMTP { 341 494 $code = substr($rply,0,3); 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 347 500 if($code != 354) { … … class SMTP { 350 503 "smtp_code" => $code, 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; 356 509 } … … class SMTP { 435 588 $code = substr($rply,0,3); 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 441 594 if($code != 250) { … … class SMTP { 444 597 "smtp_code" => $code, 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; 450 603 } … … class SMTP { 461 614 * SMTP CODE SUCCESS: 250 462 615 * SMTP CODE ERROR : 500, 501, 504, 421 463 616 * @access public 617 * @param string $host 464 618 * @return bool 465 619 */ 466 620 public function Hello($host = '') { … … class SMTP { 491 645 /** 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 */ 496 652 private function SendHello($hello, $host) { … … class SMTP { 500 656 $code = substr($rply,0,3); 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 506 662 if($code != 250) { … … class SMTP { 509 665 "smtp_code" => $code, 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; 515 671 } … … class SMTP { 531 687 * SMTP CODE SUCCESS: 552,451,452 532 688 * SMTP CODE SUCCESS: 500,501,421 533 689 * @access public 690 * @param string $from 534 691 * @return bool 535 692 */ 536 693 public function Mail($from) { … … class SMTP { 542 699 return false; 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 548 705 $rply = $this->get_lines(); 549 706 $code = substr($rply,0,3); 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 555 712 if($code != 250) { … … class SMTP { 558 715 "smtp_code" => $code, 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; 564 721 } … … class SMTP { 574 731 * SMTP CODE SUCCESS: 221 575 732 * SMTP CODE ERROR : 500 576 733 * @access public 734 * @param bool $close_on_error 577 735 * @return bool 578 736 */ 579 737 public function Quit($close_on_error = true) { … … class SMTP { 592 750 $byemsg = $this->get_lines(); 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 598 756 $rval = true; … … class SMTP { 606 764 "smtp_rply" => substr($byemsg,4)); 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 } 612 770 … … class SMTP { 627 785 * SMTP CODE FAILURE: 550,551,552,553,450,451,452 628 786 * SMTP CODE ERROR : 500,501,503,421 629 787 * @access public 788 * @param string $to 630 789 * @return bool 631 790 */ 632 791 public function Recipient($to) { … … class SMTP { 644 803 $code = substr($rply,0,3); 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 650 809 if($code != 250 && $code != 251) { … … class SMTP { 653 812 "smtp_code" => $code, 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; 659 818 } … … class SMTP { 687 846 $code = substr($rply,0,3); 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 693 852 if($code != 250) { … … class SMTP { 696 855 "smtp_code" => $code, 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; 702 861 } … … class SMTP { 718 877 * SMTP CODE SUCCESS: 552,451,452 719 878 * SMTP CODE SUCCESS: 500,501,502,421 720 879 * @access public 880 * @param string $from 721 881 * @return bool 722 882 */ 723 883 public function SendAndMail($from) { … … class SMTP { 735 895 $code = substr($rply,0,3); 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 741 901 if($code != 250) { … … class SMTP { 744 904 "smtp_code" => $code, 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; 750 910 } … … class SMTP { 768 928 $this->error = array("error" => "This method, TURN, of the SMTP ". 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; 774 934 } … … class SMTP { 797 957 */ 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; 814 1000 } 815 1001 816 1002 } 817 818 1003 ?>