Ticket #21074: 21074-phpmailer-5.2.2-beta2.patch
File 21074-phpmailer-5.2.2-beta2.patch, 53.9 KB (added by , 12 years ago) |
---|
-
wp-includes/class-phpmailer.php
diff --git wp-includes/class-phpmailer.php wp-includes/class-phpmailer.php index df533c2..1530258 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-beta2 | 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 { 235 254 public $Password = ''; 236 255 237 256 /** 238 * Sets the SMTP server timeout in seconds. 257 * Sets SMTP auth type. 258 * @var string 259 */ 260 public $AuthType = ''; 261 262 /** 263 * Sets SMTP realm. 264 * @var string 265 */ 266 public $Realm = ''; 267 268 /** 269 * Sets SMTP workstation. 270 * @var string 271 */ 272 public $Workstation = ''; 273 274 /** 275 * Sets the SMTP server in seconds. 239 276 * This function will not work with the win32 version. 240 277 * @var int 241 278 */ … … class PHPMailer { 248 285 public $SMTPDebug = false; 249 286 250 287 /** 288 * Sets the function/method to use for debugging output. 289 * Right now we only honor "echo" or "error_log" 290 * @var string 291 */ 292 public $Debugoutput = "echo"; 293 294 /** 251 295 * Prevents the SMTP connection from being closed after each mail 252 296 * sending. If this is set to true then to close the connection 253 297 * requires an explicit call to SmtpClose(). … … class PHPMailer { 269 313 public $SingleToArray = array(); 270 314 271 315 /** 272 * Provides the ability to change the line ending 316 * Provides the ability to change the generic line ending 317 * NOTE: The default remains '\n'. We force CRLF where we KNOW 318 * it must be used via self::CRLF 273 319 * @var string 274 320 */ 275 321 public $LE = "\n"; 276 322 277 /**323 /** 278 324 * Used with DKIM DNS Resource Record 279 325 * @var string 280 326 */ … … class PHPMailer { 308 354 public $DKIM_private = ''; 309 355 310 356 /** 311 * Callback Action function name 312 * the function that handles the result of the send email action. Parameters: 357 * Callback Action function name. 358 * The function that handles the result of the send email action. 359 * It is called out by Send() for each email sent. 360 * 361 * Value can be: 362 * - 'function_name' for function names 363 * - 'Class::Method' for static method calls 364 * - array($object, 'Method') for calling methods on $object 365 * See http://php.net/is_callable manual page for more details. 366 * 367 * Parameters: 313 368 * bool $result result of the send action 314 369 * string $to email address of the recipient 315 370 * string $cc cc email addresses 316 371 * string $bcc bcc email addresses 317 372 * string $subject the subject 318 373 * string $body the email body 374 * string $from email address of sender 319 375 * @var string 320 376 */ 321 377 public $action_function = ''; //'callbackAction'; … … class PHPMailer { 324 380 * Sets the PHPMailer Version number 325 381 * @var string 326 382 */ 327 public $Version = '5.2. 1';383 public $Version = '5.2.2-beta2'; 328 384 329 385 /** 330 386 * What to use in the X-Mailer header 331 * @var string 387 * @var string NULL for default, whitespace for None, or actual string to use 332 388 */ 333 389 public $XMailer = ''; 334 390 … … class PHPMailer { 360 416 const STOP_MESSAGE = 0; // message only, continue processing 361 417 const STOP_CONTINUE = 1; // message?, likely ok to continue processing 362 418 const STOP_CRITICAL = 2; // message, plus full stop, critical error reached 363 419 const CRLF = "\r\n"; // SMTP RFC specified EOL 420 364 421 ///////////////////////////////////////////////// 365 422 // METHODS, VARIABLES 366 423 ///////////////////////////////////////////////// 367 424 368 425 /** 426 * Calls actual mail() function, but in a safe_mode aware fashion 427 * Also, unless sendmail_path points to sendmail (or something that 428 * claims to be sendmail), don't pass params (not a perfect fix, 429 * but it will do) 430 * @param string $to To 431 * @param string $subject Subject 432 * @param string $body Message Body 433 * @param string $header Additional Header(s) 434 * @param string $params Params 435 * @access private 436 * @return bool 437 */ 438 private function mail_passthru($to, $subject, $body, $header, $params) { 439 if ( ini_get('safe_mode') || !($this->UseSendmailOptions) ) { 440 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header); 441 } else { 442 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params); 443 } 444 return $rt; 445 } 446 447 /** 448 * Outputs debugging info via user-defined method 449 * @param string $str 450 */ 451 private function edebug($str) { 452 if ($this->Debugoutput == "error_log") { 453 error_log($str); 454 } else { 455 echo $str; 456 } 457 } 458 459 /** 369 460 * Constructor 370 461 * @param boolean $exceptions Should we throw external exceptions? 371 462 */ … … class PHPMailer { 389 480 /** 390 481 * Sets Mailer to send message using SMTP. 391 482 * @return void 483 * @deprecated 392 484 */ 393 485 public function IsSMTP() { 394 486 $this->Mailer = 'smtp'; … … class PHPMailer { 397 489 /** 398 490 * Sets Mailer to send message using PHP mail() function. 399 491 * @return void 492 * @deprecated 400 493 */ 401 494 public function IsMail() { 402 495 $this->Mailer = 'mail'; … … class PHPMailer { 405 498 /** 406 499 * Sets Mailer to send message using the $Sendmail program. 407 500 * @return void 501 * @deprecated 408 502 */ 409 503 public function IsSendmail() { 410 504 if (!stristr(ini_get('sendmail_path'), 'sendmail')) { … … class PHPMailer { 416 510 /** 417 511 * Sets Mailer to send message using the qmail MTA. 418 512 * @return void 513 * @deprecated 419 514 */ 420 515 public function IsQmail() { 421 516 if (stristr(ini_get('sendmail_path'), 'qmail')) { … … class PHPMailer { 485 580 if ($this->exceptions) { 486 581 throw new phpmailerException('Invalid recipient array: ' . $kind); 487 582 } 488 489 echo $this->Lang('Invalid recipient array').': '.$kind;583 if ($this->SMTPDebug) { 584 $this->edebug($this->Lang('Invalid recipient array').': '.$kind); 490 585 } 491 586 return false; 492 587 } … … class PHPMailer { 497 592 if ($this->exceptions) { 498 593 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 499 594 } 500 501 echo $this->Lang('invalid_address').': '.$address;595 if ($this->SMTPDebug) { 596 $this->edebug($this->Lang('invalid_address').': '.$address); 502 597 } 503 598 return false; 504 599 } … … class PHPMailer { 521 616 * Set the From and FromName properties 522 617 * @param string $address 523 618 * @param string $name 619 * @param int $auto Also set Reply-To and Sender 524 620 * @return boolean 525 621 */ 526 622 public function SetFrom($address, $name = '', $auto = 1) { … … class PHPMailer { 531 627 if ($this->exceptions) { 532 628 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 533 629 } 534 535 echo $this->Lang('invalid_address').': '.$address;630 if ($this->SMTPDebug) { 631 $this->edebug($this->Lang('invalid_address').': '.$address); 536 632 } 537 633 return false; 538 634 } … … class PHPMailer { 587 683 if(!$this->PreSend()) return false; 588 684 return $this->PostSend(); 589 685 } catch (phpmailerException $e) { 590 $this->SentMIMEMessage= '';686 $this->mailHeader = ''; 591 687 $this->SetError($e->getMessage()); 592 688 if ($this->exceptions) { 593 689 throw $e; … … class PHPMailer { 596 692 } 597 693 } 598 694 599 protected function PreSend() { 695 /** 696 * Prep mail by constructing all message entities 697 * @return bool 698 */ 699 public function PreSend() { 600 700 try { 601 $mailHeader = "";701 $this->mailHeader = ""; 602 702 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { 603 703 throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); 604 704 } … … class PHPMailer { 619 719 $this->MIMEBody = $this->CreateBody(); 620 720 621 721 // To capture the complete message when using mail(), create 622 722 // an extra header list which CreateHeader() doesn't fold in 623 723 if ($this->Mailer == 'mail') { 624 724 if (count($this->to) > 0) { 625 $ mailHeader .= $this->AddrAppend("To", $this->to);725 $this->mailHeader .= $this->AddrAppend("To", $this->to); 626 726 } else { 627 $ mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");727 $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;"); 628 728 } 629 $ mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));729 $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject)))); 630 730 // if(count($this->cc) > 0) { 631 // $ mailHeader .= $this->AddrAppend("Cc", $this->cc);731 // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc); 632 732 // } 633 733 } 634 734 … … class PHPMailer { 638 738 $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader; 639 739 } 640 740 641 $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);642 741 return true; 643 742 644 743 } catch (phpmailerException $e) { … … class PHPMailer { 650 749 } 651 750 } 652 751 653 protected function PostSend() { 752 /** 753 * Actual Email transport function 754 * Send the email via the selected mechanism 755 * @return bool 756 */ 757 public function PostSend() { 758 $rtn = false; 654 759 try { 655 760 // Choose the mailer and send through it 656 761 switch($this->Mailer) { 657 762 case 'sendmail': 658 return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody); 763 $rtn = $this->SendmailSend($this->MIMEHeader, $this->MIMEBody); 764 break; 659 765 case 'smtp': 660 return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody); 766 $rtn = $this->SmtpSend($this->MIMEHeader, $this->MIMEBody); 767 break; 661 768 case 'mail': 662 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 769 $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody); 770 break; 663 771 default: 664 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 772 $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody); 773 break; 665 774 } 666 775 667 776 } catch (phpmailerException $e) { … … class PHPMailer { 669 778 if ($this->exceptions) { 670 779 throw $e; 671 780 } 672 673 echo $e->getMessage()."\n";781 if ($this->SMTPDebug) { 782 $this->edebug($e->getMessage()."\n"); 674 783 } 675 784 return false; 676 785 } 786 return $rtn; 677 787 } 678 788 679 789 /** … … class PHPMailer { 744 854 if ($this->Sender != '' and !ini_get('safe_mode')) { 745 855 $old_from = ini_get('sendmail_from'); 746 856 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); 857 } 858 if ($this->SingleTo === true && count($toArr) > 1) { 859 foreach ($toArr as $key => $val) { 860 $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params); 756 861 // implement call back function if it exists 757 862 $isSent = ($rt == 1) ? 1 : 0; 758 $this->doCallback($isSent, $ to, $this->cc, $this->bcc, $this->Subject, $body);863 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 759 864 } 760 865 } 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 } 866 $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params); 867 // implement call back function if it exists 868 $isSent = ($rt == 1) ? 1 : 0; 869 $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 774 870 } 775 871 if (isset($old_from)) { 776 872 ini_set('sendmail_from', $old_from); … … class PHPMailer { 791 887 * @return bool 792 888 */ 793 889 protected function SmtpSend($header, $body) { 794 require_once $this->PluginDir . 'class -smtp.php';890 require_once $this->PluginDir . 'class.smtp.php'; 795 891 $bad_rcpt = array(); 796 892 797 893 if(!$this->SmtpConnect()) { … … class PHPMailer { 866 962 $this->smtp = new SMTP(); 867 963 } 868 964 965 $this->smtp->Timeout = $this->Timeout; 869 966 $this->smtp->do_debug = $this->SMTPDebug; 870 967 $hosts = explode(';', $this->Host); 871 968 $index = 0; 872 969 $connection = $this->smtp->Connected(); 970 $rtn = true; 873 971 874 972 // Retry while there is no connection 875 973 try { … … class PHPMailer { 893 991 894 992 if ($tls) { 895 993 if (!$this->smtp->StartTLS()) { 994 $rtn = false; 896 995 throw new phpmailerException($this->Lang('tls')); 897 996 } 898 997 … … class PHPMailer { 902 1001 903 1002 $connection = true; 904 1003 if ($this->SMTPAuth) { 905 if (!$this->smtp->Authenticate($this->Username, $this->Password)) { 1004 if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType, 1005 $this->Realm, $this->Workstation)) { 1006 $rtn = false; 906 1007 throw new phpmailerException($this->Lang('authenticate')); 907 1008 } 908 1009 } 909 1010 } 910 1011 $index++; 911 1012 if (!$connection) { 1013 $rtn = false; 912 1014 throw new phpmailerException($this->Lang('connect_host')); 913 1015 } 914 1016 } 915 1017 } catch (phpmailerException $e) { 916 1018 $this->smtp->Reset(); 917 1019 if ($this->exceptions) { 918 1020 throw $e; 919 1021 } 1022 $rtn = false; 920 1023 } 921 return true;1024 return $rtn; 922 1025 } 923 1026 924 1027 /** … … class PHPMailer { 1028 1131 // If utf-8 encoding is used, we will need to make sure we don't 1029 1132 // split multibyte characters when we wrap 1030 1133 $is_utf8 = (strtolower($this->CharSet) == "utf-8"); 1134 $lelen = strlen($this->LE); 1135 $crlflen = strlen(self::CRLF); 1031 1136 1032 1137 $message = $this->FixEOL($message); 1033 if (substr($message, - 1) == $this->LE) {1034 $message = substr($message, 0, - 1);1138 if (substr($message, -$lelen) == $this->LE) { 1139 $message = substr($message, 0, -$lelen); 1035 1140 } 1036 1141 1037 $line = explode($this->LE, $message); 1142 $line = explode($this->LE, $message); // Magic. We know FixEOL uses $LE 1038 1143 $message = ''; 1039 1144 for ($i = 0 ;$i < count($line); $i++) { 1040 1145 $line_part = explode(' ', $line[$i]); … … class PHPMailer { 1042 1147 for ($e = 0; $e<count($line_part); $e++) { 1043 1148 $word = $line_part[$e]; 1044 1149 if ($qp_mode and (strlen($word) > $length)) { 1045 $space_left = $length - strlen($buf) - 1;1150 $space_left = $length - strlen($buf) - $crlflen; 1046 1151 if ($e != 0) { 1047 1152 if ($space_left > 20) { 1048 1153 $len = $space_left; … … class PHPMailer { 1056 1161 $part = substr($word, 0, $len); 1057 1162 $word = substr($word, $len); 1058 1163 $buf .= ' ' . $part; 1059 $message .= $buf . sprintf("=%s", $this->LE);1164 $message .= $buf . sprintf("=%s", self::CRLF); 1060 1165 } else { 1061 1166 $message .= $buf . $soft_break; 1062 1167 } … … class PHPMailer { 1075 1180 $word = substr($word, $len); 1076 1181 1077 1182 if (strlen($word) > 0) { 1078 $message .= $part . sprintf("=%s", $this->LE);1183 $message .= $part . sprintf("=%s", self::CRLF); 1079 1184 } else { 1080 1185 $buf = $part; 1081 1186 } … … class PHPMailer { 1090 1195 } 1091 1196 } 1092 1197 } 1093 $message .= $buf . $this->LE;1198 $message .= $buf . self::CRLF; 1094 1199 } 1095 1200 1096 1201 return $message; … … class PHPMailer { 1176 1281 $this->boundary[3] = 'b3_' . $uniq_id; 1177 1282 1178 1283 $result .= $this->HeaderLine('Date', self::RFCDate()); 1179 if($this->Sender == '') { 1284 if ($this->ReturnPath) { 1285 $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath)); 1286 } elseif ($this->Sender == '') { 1180 1287 $result .= $this->HeaderLine('Return-Path', trim($this->From)); 1181 1288 } else { 1182 1289 $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); … … class PHPMailer { 1195 1302 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); 1196 1303 } 1197 1304 } 1198 1305 } 1199 1306 1200 1307 $from = array(); 1201 1308 $from[0][0] = trim($this->From); … … class PHPMailer { 1227 1334 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); 1228 1335 } 1229 1336 $result .= $this->HeaderLine('X-Priority', $this->Priority); 1230 if ($this->XMailer) {1231 $result .= $this->HeaderLine('X-Mailer', $this->XMailer);1337 if ($this->XMailer == '') { 1338 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1232 1339 } else { 1233 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1340 $myXmailer = trim($this->XMailer); 1341 if ($myXmailer) { 1342 $result .= $this->HeaderLine('X-Mailer', $myXmailer); 1343 } 1234 1344 } 1235 1345 1236 1346 if($this->ConfirmReadingTo != '') { … … class PHPMailer { 1257 1367 public function GetMailMIME() { 1258 1368 $result = ''; 1259 1369 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 1370 case 'inline': 1265 1371 $result .= $this->HeaderLine('Content-Type', 'multipart/related;'); 1266 1372 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); … … class PHPMailer { 1277 1383 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 1278 1384 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 1279 1385 break; 1386 default: 1387 // Catches case 'plain': and case '': 1388 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); 1389 $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet); 1390 break; 1280 1391 } 1281 1392 1282 1393 if($this->Mailer != 'mail') { … … class PHPMailer { 1292 1403 * @return string 1293 1404 */ 1294 1405 public function GetSentMIMEMessage() { 1295 return $this->SentMIMEMessage;1406 return sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$this->mailHeader,$this->MIMEBody); 1296 1407 } 1297 1408 1298 1409 … … class PHPMailer { 1305 1416 $body = ''; 1306 1417 1307 1418 if ($this->sign_key_file) { 1308 $body .= $this->GetMailMIME() ;1419 $body .= $this->GetMailMIME().$this->LE; 1309 1420 } 1310 1421 1311 1422 $this->SetWordWrap(); 1312 1423 1313 1424 switch($this->message_type) { 1314 case 'plain':1315 $body .= $this->EncodeString($this->Body, $this->Encoding);1316 break;1317 1425 case 'inline': 1318 1426 $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 1319 1427 $body .= $this->EncodeString($this->Body, $this->Encoding); … … class PHPMailer { 1321 1429 $body .= $this->AttachAll("inline", $this->boundary[1]); 1322 1430 break; 1323 1431 case 'attach': 1324 $body .= $this->GetBoundary($this->boundary[1], '', ' ', '');1432 $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); 1325 1433 $body .= $this->EncodeString($this->Body, $this->Encoding); 1326 1434 $body .= $this->LE.$this->LE; 1327 1435 $body .= $this->AttachAll("attachment", $this->boundary[1]); … … class PHPMailer { 1398 1506 $body .= $this->LE; 1399 1507 $body .= $this->AttachAll("attachment", $this->boundary[1]); 1400 1508 break; 1509 default: 1510 // catch case 'plain' and case '' 1511 $body .= $this->EncodeString($this->Body, $this->Encoding); 1512 break; 1401 1513 } 1402 1514 1403 1515 if ($this->IsError()) { … … class PHPMailer { 1444 1556 $encoding = $this->Encoding; 1445 1557 } 1446 1558 $result .= $this->TextLine('--' . $boundary); 1447 $result .= sprintf("Content-Type: %s; charset= \"%s\"", $contentType, $charSet);1559 $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet); 1448 1560 $result .= $this->LE; 1449 1561 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); 1450 1562 $result .= $this->LE; … … class PHPMailer { 1533 1645 if ($this->exceptions) { 1534 1646 throw $e; 1535 1647 } 1536 1537 echo $e->getMessage()."\n";1648 if ($this->SMTPDebug) { 1649 $this->edebug($e->getMessage()."\n"); 1538 1650 } 1539 1651 if ( $e->getCode() == self::STOP_CRITICAL ) { 1540 1652 return false; … … class PHPMailer { 1633 1745 if (!is_readable($path)) { 1634 1746 throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); 1635 1747 } 1636 if (function_exists('get_magic_quotes')) {1637 function get_magic_quotes() {1638 return false;1639 }1640 }1641 1642 1748 // if (!function_exists('get_magic_quotes')) { 1749 // function get_magic_quotes() { 1750 // return false; 1751 // } 1752 // } 1753 $magic_quotes = get_magic_quotes_runtime(); 1754 if ($magic_quotes) { 1643 1755 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1644 1756 set_magic_quotes_runtime(0); 1645 1757 } else { 1646 ini_set('magic_quotes_runtime', 0); 1647 1648 1758 ini_set('magic_quotes_runtime', 0); 1759 } 1760 } 1649 1761 $file_buffer = file_get_contents($path); 1650 1762 $file_buffer = $this->EncodeString($file_buffer, $encoding); 1651 1763 if ($magic_quotes) { 1652 1764 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1653 1765 set_magic_quotes_runtime($magic_quotes); 1654 1766 } else { 1655 ini_set('magic_quotes_runtime', $magic_quotes); 1656 1657 1767 ini_set('magic_quotes_runtime', $magic_quotes); 1768 } 1769 } 1658 1770 return $file_buffer; 1659 1771 } catch (Exception $e) { 1660 1772 $this->SetError($e->getMessage()); … … class PHPMailer { 1747 1859 $encoding = 'Q'; 1748 1860 $encoded = $this->EncodeQ($str, $position); 1749 1861 $encoded = $this->WrapText($encoded, $maxlen, true); 1750 $encoded = str_replace('='. $this->LE, "\n", trim($encoded));1862 $encoded = str_replace('='.self::CRLF, "\n", trim($encoded)); 1751 1863 } 1752 1864 1753 1865 $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded); … … class PHPMailer { 1901 2013 * @return string 1902 2014 */ 1903 2015 public function EncodeQ($str, $position = 'text') { 1904 // There should not be any EOL in the string 1905 $encoded = preg_replace('/[\r\n]*/', '', $str); 1906 2016 //There should not be any EOL in the string 2017 $encoded = str_replace(array("\r", "\n"), '', $str); 1907 2018 switch (strtolower($position)) { 1908 2019 case 'phrase': 1909 $ encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);2020 $pattern = '^A-Za-z0-9!*+\/ -'; 1910 2021 break; 2022 1911 2023 case 'comment': 1912 $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded); 2024 $pattern = '\(\)"'; 2025 //note that we dont break here! 2026 //for this reason we build the $pattern withoud including delimiters and [] 2027 1913 2028 case 'text': 1914 2029 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); 2030 //Replace every high ascii, control =, ? and _ characters 2031 //We put \075 (=) as first value to make sure it's the first one in being converted, preventing double encode 2032 $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern; 1919 2033 break; 1920 2034 } 2035 2036 if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) { 2037 foreach (array_unique($matches[0]) as $char) { 2038 $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded); 2039 } 2040 } 2041 2042 //Replace every spaces to _ (more readable than =20) 2043 return str_replace(' ', '_', $encoded); 2044 } 1921 2045 1922 // Replace every spaces to _ (more readable than =20)1923 $encoded = str_replace(' ', '_', $encoded);1924 1925 return $encoded;1926 }1927 2046 1928 2047 /** 1929 2048 * Adds a string or binary attachment (non-filesystem) to the list. … … class PHPMailer { 2027 2146 } 2028 2147 2029 2148 public function AlternativeExists() { 2030 return strlen($this->AltBody)>0;2149 return !empty($this->AltBody); 2031 2150 } 2032 2151 2033 2152 ///////////////////////////////////////////////// … … class PHPMailer { 2184 2303 } 2185 2304 2186 2305 /** 2187 * Changes every end of line from CR or LF to CRLF.2306 * Changes every end of line from CRLF, CR or LF to $this->LE. 2188 2307 * @access public 2308 * @param string $str String to FixEOL 2189 2309 * @return string 2190 2310 */ 2191 2311 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; 2312 // condense down to \n 2313 $nstr = str_replace(array("\r\n", "\r"), "\n", $str); 2314 // Now convert LE as needed 2315 if ($this->LE !== "\n") { 2316 $nstr = str_replace("\n", $this->LE, $nstr); 2317 } 2318 return $nstr; 2196 2319 } 2197 2320 2198 2321 /** 2199 * Adds a custom header. 2322 * Adds a custom header. $name value can be overloaded to contain 2323 * both header name and value (name:value) 2200 2324 * @access public 2325 * @param string $name custom header name 2326 * @param string $value header value 2201 2327 * @return void 2202 2328 */ 2203 public function AddCustomHeader($custom_header) { 2204 $this->CustomHeader[] = explode(':', $custom_header, 2); 2329 public function AddCustomHeader($name, $value=null) { 2330 if ($value === null) { 2331 // Value passed in as name:value 2332 $this->CustomHeader[] = explode(':', $name, 2); 2333 } else { 2334 $this->CustomHeader[] = array($name, $value); 2335 } 2205 2336 } 2206 2337 2207 2338 /** 2208 2339 * Evaluates the message and returns modifications for inline images and backgrounds 2209 2340 * @access public 2341 * @param string $message Text to be HTML modified 2342 * @param string $basedir baseline directory for path 2210 2343 * @return $message 2211 2344 */ 2212 2345 public function MsgHTML($message, $basedir = '') { … … class PHPMailer { 2231 2364 } 2232 2365 $this->IsHTML(true); 2233 2366 $this->Body = $message; 2234 2235 2236 2237 2238 2239 2367 if (empty($this->AltBody)) { 2368 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); 2369 if (!empty($textMsg)) { 2370 $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet); 2371 } 2372 } 2240 2373 if (empty($this->AltBody)) { 2241 2374 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; 2242 2375 } 2243 2376 return $message; 2244 2377 } 2245 2378 2246 2379 /** 2247 2380 * Gets the MIME type of the embedded or inline image 2248 * @param string File extension2381 * @param string $ext File extension 2249 2382 * @access public 2250 2383 * @return string MIME type of ext 2251 2384 * @static 2252 2385 */ 2253 2386 public static function _mime_types($ext = '') { 2254 2387 $mimes = array( 2388 'xl' => 'application/excel', 2255 2389 'hqx' => 'application/mac-binhex40', 2256 2390 'cpt' => 'application/mac-compactpro', 2257 'doc' => 'application/msword',2258 2391 'bin' => 'application/macbinary', 2392 'doc' => 'application/msword', 2393 'doc' => 'application/msword', 2394 'word' => 'application/msword', 2395 'class' => 'application/octet-stream', 2396 'dll' => 'application/octet-stream', 2259 2397 'dms' => 'application/octet-stream', 2398 'exe' => 'application/octet-stream', 2260 2399 'lha' => 'application/octet-stream', 2261 2400 'lzh' => 'application/octet-stream', 2262 'exe' => 'application/octet-stream',2263 'class' => 'application/octet-stream',2264 2401 'psd' => 'application/octet-stream', 2265 'so' => 'application/octet-stream',2266 2402 'sea' => 'application/octet-stream', 2267 ' dll'=> 'application/octet-stream',2403 'so' => 'application/octet-stream', 2268 2404 'oda' => 'application/oda', 2269 2405 'pdf' => 'application/pdf', 2270 2406 'ai' => 'application/postscript', … … class PHPMailer { 2282 2418 'dxr' => 'application/x-director', 2283 2419 'dvi' => 'application/x-dvi', 2284 2420 'gtar' => 'application/x-gtar', 2285 'php' => 'application/x-httpd-php',2286 'php4' => 'application/x-httpd-php',2287 2421 'php3' => 'application/x-httpd-php', 2422 'php4' => 'application/x-httpd-php', 2423 'php' => 'application/x-httpd-php', 2288 2424 'phtml' => 'application/x-httpd-php', 2289 2425 'phps' => 'application/x-httpd-php-source', 2290 2426 'js' => 'application/x-javascript', … … class PHPMailer { 2292 2428 'sit' => 'application/x-stuffit', 2293 2429 'tar' => 'application/x-tar', 2294 2430 'tgz' => 'application/x-tar', 2295 'xhtml' => 'application/xhtml+xml',2296 2431 'xht' => 'application/xhtml+xml', 2432 'xhtml' => 'application/xhtml+xml', 2297 2433 'zip' => 'application/zip', 2298 2434 'mid' => 'audio/midi', 2299 2435 'midi' => 'audio/midi', 2300 'mpga' => 'audio/mpeg',2301 2436 'mp2' => 'audio/mpeg', 2302 2437 'mp3' => 'audio/mpeg', 2438 'mpga' => 'audio/mpeg', 2303 2439 'aif' => 'audio/x-aiff', 2304 'aiff' => 'audio/x-aiff',2305 2440 'aifc' => 'audio/x-aiff', 2441 'aiff' => 'audio/x-aiff', 2306 2442 'ram' => 'audio/x-pn-realaudio', 2307 2443 'rm' => 'audio/x-pn-realaudio', 2308 2444 'rpm' => 'audio/x-pn-realaudio-plugin', 2309 2445 'ra' => 'audio/x-realaudio', 2310 'rv' => 'video/vnd.rn-realvideo',2311 2446 'wav' => 'audio/x-wav', 2312 2447 'bmp' => 'image/bmp', 2313 2448 'gif' => 'image/gif', 2314 2449 'jpeg' => 'image/jpeg', 2315 'jpg' => 'image/jpeg',2316 2450 'jpe' => 'image/jpeg', 2451 'jpg' => 'image/jpeg', 2317 2452 'png' => 'image/png', 2318 2453 'tiff' => 'image/tiff', 2319 2454 'tif' => 'image/tiff', 2455 'eml' => 'message/rfc822', 2320 2456 'css' => 'text/css', 2321 2457 'html' => 'text/html', 2322 2458 'htm' => 'text/html', 2323 2459 'shtml' => 'text/html', 2324 'txt' => 'text/plain',2325 'text' => 'text/plain',2326 2460 'log' => 'text/plain', 2461 'text' => 'text/plain', 2462 'txt' => 'text/plain', 2327 2463 'rtx' => 'text/richtext', 2328 2464 'rtf' => 'text/rtf', 2329 2465 'xml' => 'text/xml', 2330 2466 'xsl' => 'text/xml', 2331 2467 'mpeg' => 'video/mpeg', 2332 'mpg' => 'video/mpeg',2333 2468 'mpe' => 'video/mpeg', 2334 ' qt' => 'video/quicktime',2469 'mpg' => 'video/mpeg', 2335 2470 'mov' => 'video/quicktime', 2471 'qt' => 'video/quicktime', 2472 'rv' => 'video/vnd.rn-realvideo', 2336 2473 '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' 2474 'movie' => 'video/x-sgi-movie' 2342 2475 ); 2343 2476 return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; 2344 2477 } … … class PHPMailer { 2378 2511 * @return string 2379 2512 */ 2380 2513 public function SecureHeader($str) { 2381 $str = str_replace("\r", '', $str); 2382 $str = str_replace("\n", '', $str); 2383 return trim($str); 2514 return trim(str_replace(array("\r", "\n"), '', $str)); 2384 2515 } 2385 2516 2386 2517 /** … … class PHPMailer { 2515 2646 return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; 2516 2647 } 2517 2648 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); 2649 /** 2650 * Perform callback 2651 */ 2652 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) { 2653 if (!empty($this->action_function) && is_callable($this->action_function)) { 2654 $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from); 2521 2655 call_user_func_array($this->action_function, $params); 2522 2656 } 2523 2657 } 2524 2658 } 2525 2659 2660 /** 2661 * Exception handling 2662 */ 2526 2663 class phpmailerException extends Exception { 2527 2664 public function errorMessage() { 2528 2665 $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..78dbe0b 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-beta2 | 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 { 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-beta2'; 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 'LOGIN': 256 // Start authentication 257 fputs($this->smtp_conn,"AUTH LOGIN" . $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 273 // Send encoded username 274 fputs($this->smtp_conn, base64_encode($username) . $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" => "Username 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 290 // Send encoded password 291 fputs($this->smtp_conn, base64_encode($password) . $this->CRLF); 292 293 $rply = $this->get_lines(); 294 $code = substr($rply,0,3); 295 296 if($code != 235) { 297 $this->error = 298 array("error" => "Password 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 break; 307 case 'NTLM': 308 /* 309 * ntlm_sasl_client.php 310 ** Bundled with Permission 311 ** 312 ** How to telnet in windows: http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx 313 ** PROTOCOL Documentation http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication 314 */ 315 require_once('ntlm_sasl_client.php'); 316 $temp = new stdClass(); 317 $ntlm_client = new ntlm_sasl_client_class; 318 if(! $ntlm_client->Initialize($temp)){//let's test if every function its available 319 $this->error = array("error" => $temp->error); 320 if($this->do_debug >= 1) { 321 $this->edebug("You need to enable some modules in your php.ini file: " . $this->error["error"] . $this->CRLF); 322 } 323 return false; 324 } 325 $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);//msg1 326 327 fputs($this->smtp_conn,"AUTH NTLM " . base64_encode($msg1) . $this->CRLF); 328 329 $rply = $this->get_lines(); 330 $code = substr($rply,0,3); 331 332 333 if($code != 334) { 334 $this->error = 335 array("error" => "AUTH not accepted from server", 336 "smtp_code" => $code, 337 "smtp_msg" => substr($rply,4)); 338 if($this->do_debug >= 1) { 339 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF); 340 } 341 return false; 342 } 343 344 $challange = substr($rply,3);//though 0 based, there is a white space after the 3 digit number....//msg2 345 $challange = base64_decode($challange); 346 $ntlm_res = $ntlm_client->NTLMResponse(substr($challange,24,8),$password); 347 $msg3 = $ntlm_client->TypeMsg3($ntlm_res,$username,$realm,$workstation);//msg3 348 // Send encoded username 349 fputs($this->smtp_conn, base64_encode($msg3) . $this->CRLF); 350 351 $rply = $this->get_lines(); 352 $code = substr($rply,0,3); 353 354 if($code != 235) { 355 $this->error = 356 array("error" => "Could not authenticate", 357 "smtp_code" => $code, 358 "smtp_msg" => substr($rply,4)); 359 if($this->do_debug >= 1) { 360 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF); 361 } 362 return false; 363 } 364 break; 263 365 } 264 265 366 return true; 266 367 } 267 368 … … class SMTP { 276 377 if($sock_status["eof"]) { 277 378 // the socket is valid but we are not connected 278 379 if($this->do_debug >= 1) { 279 echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";380 $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"); 280 381 } 281 382 $this->Close(); 282 383 return false; … … class SMTP { 341 442 $code = substr($rply,0,3); 342 443 343 444 if($this->do_debug >= 2) { 344 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';445 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 345 446 } 346 447 347 448 if($code != 354) { … … class SMTP { 350 451 "smtp_code" => $code, 351 452 "smtp_msg" => substr($rply,4)); 352 453 if($this->do_debug >= 1) { 353 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';454 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 354 455 } 355 456 return false; 356 457 } … … class SMTP { 435 536 $code = substr($rply,0,3); 436 537 437 538 if($this->do_debug >= 2) { 438 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';539 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 439 540 } 440 541 441 542 if($code != 250) { … … class SMTP { 444 545 "smtp_code" => $code, 445 546 "smtp_msg" => substr($rply,4)); 446 547 if($this->do_debug >= 1) { 447 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';548 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 448 549 } 449 550 return false; 450 551 } … … class SMTP { 500 601 $code = substr($rply,0,3); 501 602 502 603 if($this->do_debug >= 2) { 503 echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';604 $this->edebug("SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />'); 504 605 } 505 606 506 607 if($code != 250) { … … class SMTP { 509 610 "smtp_code" => $code, 510 611 "smtp_msg" => substr($rply,4)); 511 612 if($this->do_debug >= 1) { 512 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';613 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 513 614 } 514 615 return false; 515 616 } … … class SMTP { 542 643 return false; 543 644 } 544 645 545 $useVerp = ($this->do_verp ? " XVERP" : "");646 $useVerp = ($this->do_verp ? " XVERP" : ""); 546 647 fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF); 547 648 548 649 $rply = $this->get_lines(); 549 650 $code = substr($rply,0,3); 550 651 551 652 if($this->do_debug >= 2) { 552 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';653 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 553 654 } 554 655 555 656 if($code != 250) { … … class SMTP { 558 659 "smtp_code" => $code, 559 660 "smtp_msg" => substr($rply,4)); 560 661 if($this->do_debug >= 1) { 561 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';662 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 562 663 } 563 664 return false; 564 665 } … … class SMTP { 592 693 $byemsg = $this->get_lines(); 593 694 594 695 if($this->do_debug >= 2) { 595 echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';696 $this->edebug("SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />'); 596 697 } 597 698 598 699 $rval = true; … … class SMTP { 606 707 "smtp_rply" => substr($byemsg,4)); 607 708 $rval = false; 608 709 if($this->do_debug >= 1) { 609 echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';710 $this->edebug("SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />'); 610 711 } 611 712 } 612 713 … … class SMTP { 644 745 $code = substr($rply,0,3); 645 746 646 747 if($this->do_debug >= 2) { 647 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';748 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 648 749 } 649 750 650 751 if($code != 250 && $code != 251) { … … class SMTP { 653 754 "smtp_code" => $code, 654 755 "smtp_msg" => substr($rply,4)); 655 756 if($this->do_debug >= 1) { 656 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';757 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 657 758 } 658 759 return false; 659 760 } … … class SMTP { 687 788 $code = substr($rply,0,3); 688 789 689 790 if($this->do_debug >= 2) { 690 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';791 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 691 792 } 692 793 693 794 if($code != 250) { … … class SMTP { 696 797 "smtp_code" => $code, 697 798 "smtp_msg" => substr($rply,4)); 698 799 if($this->do_debug >= 1) { 699 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';800 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 700 801 } 701 802 return false; 702 803 } … … class SMTP { 735 836 $code = substr($rply,0,3); 736 837 737 838 if($this->do_debug >= 2) { 738 echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';839 $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />'); 739 840 } 740 841 741 842 if($code != 250) { … … class SMTP { 744 845 "smtp_code" => $code, 745 846 "smtp_msg" => substr($rply,4)); 746 847 if($this->do_debug >= 1) { 747 echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';848 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />'); 748 849 } 749 850 return false; 750 851 } … … class SMTP { 768 869 $this->error = array("error" => "This method, TURN, of the SMTP ". 769 870 "is not implemented"); 770 871 if($this->do_debug >= 1) { 771 echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';872 $this->edebug("SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />'); 772 873 } 773 874 return false; 774 875 } … … class SMTP { 797 898 */ 798 899 private function get_lines() { 799 900 $data = ""; 800 while(!feof($this->smtp_conn)) { 901 $endtime = 0; 902 /* If for some reason the fp is bad, don't inf loop */ 903 if (!is_resource($this->smtp_conn)) { 904 return $data; 905 } 906 stream_set_timeout($this->smtp_conn, $this->Timeout); 907 if ($this->Timelimit > 0) { 908 $endtime = time() + $this->Timelimit; 909 } 910 while(is_resource($this->smtp_conn) && !feof($this->smtp_conn)) { 801 911 $str = @fgets($this->smtp_conn,515); 802 912 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 />';913 $this->edebug("SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'); 914 $this->edebug("SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'); 805 915 } 806 916 $data .= $str; 807 917 if($this->do_debug >= 4) { 808 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';918 $this->edebug("SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'); 809 919 } 810 920 // if 4th character is a space, we are done reading, break the loop 811 921 if(substr($str,3,1) == " ") { break; } 922 // Timed-out? Log and break 923 $info = stream_get_meta_data($this->smtp_conn); 924 if ($info['timed_out']) { 925 if($this->do_debug >= 4) { 926 $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " seconds) <br />"); 927 } 928 break; 929 } 930 // Now check if reads took too long 931 if ($endtime) { 932 if (time() > $endtime) { 933 if($this->do_debug >= 4) { 934 $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " seconds) <br />"); 935 } 936 break; 937 } 938 } 812 939 } 813 940 return $data; 814 941 }