Ticket #21074: 21074-phpmailer-5.2.2-beta1.patch
| File 21074-phpmailer-5.2.2-beta1.patch, 48.3 KB (added by bpetty, 10 months ago) |
|---|
-
wp-includes/class-phpmailer.php
diff --git wp-includes/class-phpmailer.php wp-includes/class-phpmailer.php index df533c2..fabce41 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-beta1 | 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 { 235 247 public $Password = ''; 236 248 237 249 /** 238 * Sets the SMTP server timeout in seconds. 250 * Sets SMTP auth type. 251 * @var string 252 */ 253 public $AuthType = ''; 254 255 /** 256 * Sets SMTP realm. 257 * @var string 258 */ 259 public $Realm = ''; 260 261 /** 262 * Sets SMTP workstation. 263 * @var string 264 */ 265 public $Workstation = ''; 266 267 /** 268 * Sets the SMTP server in seconds. 239 269 * This function will not work with the win32 version. 240 270 * @var int 241 271 */ … … class PHPMailer { 248 278 public $SMTPDebug = false; 249 279 250 280 /** 281 * Sets the function/method to use for debugging output. 282 * Right now we only honor "echo" or "error_log" 283 * @var string 284 */ 285 public $Debugoutput = "echo"; 286 287 /** 251 288 * Prevents the SMTP connection from being closed after each mail 252 289 * sending. If this is set to true then to close the connection 253 290 * requires an explicit call to SmtpClose(). … … class PHPMailer { 269 306 public $SingleToArray = array(); 270 307 271 308 /** 272 * Provides the ability to change the line ending 309 * Provides the ability to change the generic line ending 310 * NOTE: The default is now the SMTP RFC line-ending sequence, 311 * however, we still allow for the end-user to reset to "\n" 312 * if need be. We force CRLF where we KNOW it must be used 313 * via self::CRLF 273 314 * @var string 274 315 */ 275 public $LE = "\ n";316 public $LE = "\r\n"; 276 317 277 /**318 /** 278 319 * Used with DKIM DNS Resource Record 279 320 * @var string 280 321 */ … … class PHPMailer { 308 349 public $DKIM_private = ''; 309 350 310 351 /** 311 * Callback Action function name 312 * the function that handles the result of the send email action. Parameters: 352 * Callback Action function name. 353 * The function that handles the result of the send email action. 354 * It is called out by Send() for each email sent. 355 * 356 * Value can be: 357 * - 'function_name' for function names 358 * - 'Class::Method' for static method calls 359 * - array($object, 'Method') for calling methods on $object 360 * See http://php.net/is_callable manual page for more details. 361 * 362 * Parameters: 313 363 * bool $result result of the send action 314 364 * string $to email address of the recipient 315 365 * string $cc cc email addresses … … class PHPMailer { 324 374 * Sets the PHPMailer Version number 325 375 * @var string 326 376 */ 327 public $Version = '5.2. 1';377 public $Version = '5.2.2-beta1'; 328 378 329 379 /** 330 380 * What to use in the X-Mailer header 331 * @var string 381 * @var string NULL for default, whitespace for None, or actual string to use 332 382 */ 333 383 public $XMailer = ''; 334 384 … … class PHPMailer { 360 410 const STOP_MESSAGE = 0; // message only, continue processing 361 411 const STOP_CONTINUE = 1; // message?, likely ok to continue processing 362 412 const STOP_CRITICAL = 2; // message, plus full stop, critical error reached 363 413 const CRLF = "\r\n"; // SMTP RFC specified EOL 414 364 415 ///////////////////////////////////////////////// 365 416 // METHODS, VARIABLES 366 417 ///////////////////////////////////////////////// 367 418 368 419 /** 420 * Calls actual mail() function, but in a safe_mode aware fashion 421 * Also, unless sendmail_path points to sendmail (or something that 422 * claims to be sendmail), don't pass params (not a perfect fix, 423 * but it will do) 424 * @param string $to To 425 * @param string $subject Subject 426 * @param string $body Message Body 427 * @param string $header Additional Header(s) 428 * @param string $params Params 429 * @access private 430 * @return bool 431 */ 432 private function mail_passthru($to, $subject, $body, $header, $params) { 433 if ( ini_get('safe_mode') || !strstr(ini_get("sendmail_path"), 'sendmail') ) { 434 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header); 435 } else { 436 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params); 437 } 438 return $rt; 439 } 440 441 /** 442 * Outputs debugging info via user-defined method 443 * @param string $str 444 */ 445 private function edebug($str) { 446 if ($this->Debugoutput == "error_log") { 447 error_log($str); 448 } else { 449 echo $str; 450 } 451 } 452 453 /** 369 454 * Constructor 370 455 * @param boolean $exceptions Should we throw external exceptions? 371 456 */ … … class PHPMailer { 485 570 if ($this->exceptions) { 486 571 throw new phpmailerException('Invalid recipient array: ' . $kind); 487 572 } 488 if ($this->SMTPDebug) {489 echo $this->Lang('Invalid recipient array').': '.$kind;573 if ($this->SMTPDebug) { 574 $this->edebug($this->Lang('Invalid recipient array').': '.$kind); 490 575 } 491 576 return false; 492 577 } … … class PHPMailer { 497 582 if ($this->exceptions) { 498 583 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 499 584 } 500 if ($this->SMTPDebug) {501 echo $this->Lang('invalid_address').': '.$address;585 if ($this->SMTPDebug) { 586 $this->edebug($this->Lang('invalid_address').': '.$address); 502 587 } 503 588 return false; 504 589 } … … class PHPMailer { 521 606 * Set the From and FromName properties 522 607 * @param string $address 523 608 * @param string $name 609 * @param int $auto Also set Reply-To and Sender 524 610 * @return boolean 525 611 */ 526 612 public function SetFrom($address, $name = '', $auto = 1) { … … class PHPMailer { 531 617 if ($this->exceptions) { 532 618 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 533 619 } 534 if ($this->SMTPDebug) {535 echo $this->Lang('invalid_address').': '.$address;620 if ($this->SMTPDebug) { 621 $this->edebug($this->Lang('invalid_address').': '.$address); 536 622 } 537 623 return false; 538 624 } … … class PHPMailer { 587 673 if(!$this->PreSend()) return false; 588 674 return $this->PostSend(); 589 675 } catch (phpmailerException $e) { 590 $this->SentMIMEMessage= '';676 $this->mailHeader = ''; 591 677 $this->SetError($e->getMessage()); 592 678 if ($this->exceptions) { 593 679 throw $e; … … class PHPMailer { 596 682 } 597 683 } 598 684 599 protected function PreSend() { 685 /** 686 * Prep mail by constructing all message entities 687 * @return bool 688 */ 689 public function PreSend() { 600 690 try { 601 $mailHeader = "";691 $this->mailHeader = ""; 602 692 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { 603 693 throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); 604 694 } … … class PHPMailer { 619 709 $this->MIMEBody = $this->CreateBody(); 620 710 621 711 // To capture the complete message when using mail(), create 622 // an extra header list which CreateHeader() doesn't fold in712 // an extra header list which CreateHeader() doesn't fold in 623 713 if ($this->Mailer == 'mail') { 624 714 if (count($this->to) > 0) { 625 $ mailHeader .= $this->AddrAppend("To", $this->to);715 $this->mailHeader .= $this->AddrAppend("To", $this->to); 626 716 } else { 627 $ mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");717 $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;"); 628 718 } 629 $ mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));719 $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject)))); 630 720 // if(count($this->cc) > 0) { 631 // $ mailHeader .= $this->AddrAppend("Cc", $this->cc);721 // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc); 632 722 // } 633 723 } 634 724 … … class PHPMailer { 638 728 $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader; 639 729 } 640 730 641 $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);642 731 return true; 643 732 644 733 } catch (phpmailerException $e) { … … class PHPMailer { 650 739 } 651 740 } 652 741 653 protected function PostSend() { 742 /** 743 * Actual Email transport function 744 * Send the email via the selected mechanism 745 * @return bool 746 */ 747 public function PostSend() { 748 $rtn = false; 654 749 try { 655 750 // Choose the mailer and send through it 656 751 switch($this->Mailer) { 657 752 case 'sendmail': 658 return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody); 753 $rtn = $this->SendmailSend($this->MIMEHeader, $this->MIMEBody); 754 break; 659 755 case 'smtp': 660 return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody); 756 $rtn = $this->SmtpSend($this->MIMEHeader, $this->MIMEBody); 757 break; 661 758 case 'mail': 662 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 759 $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody); 760 break; 663 761 default: 664 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 762 $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody); 763 break; 665 764 } 666 765 667 766 } catch (phpmailerException $e) { … … class PHPMailer { 669 768 if ($this->exceptions) { 670 769 throw $e; 671 770 } 672 if ($this->SMTPDebug) {673 echo $e->getMessage()."\n";771 if ($this->SMTPDebug) { 772 $this->edebug($e->getMessage()."\n"); 674 773 } 675 774 return false; 676 775 } 776 return $rtn; 677 777 } 678 778 679 779 /** … … class PHPMailer { 744 844 if ($this->Sender != '' and !ini_get('safe_mode')) { 745 845 $old_from = ini_get('sendmail_from'); 746 846 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); 847 } 848 if ($this->SingleTo === true && count($toArr) > 1) { 849 foreach ($toArr as $key => $val) { 850 $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params); 756 851 // implement call back function if it exists 757 852 $isSent = ($rt == 1) ? 1 : 0; 758 $this->doCallback($isSent, $ to, $this->cc, $this->bcc, $this->Subject, $body);853 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 759 854 } 760 855 } 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 } 856 $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params); 857 // implement call back function if it exists 858 $isSent = ($rt == 1) ? 1 : 0; 859 $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 774 860 } 775 861 if (isset($old_from)) { 776 862 ini_set('sendmail_from', $old_from); … … class PHPMailer { 791 877 * @return bool 792 878 */ 793 879 protected function SmtpSend($header, $body) { 794 require_once $this->PluginDir . 'class -smtp.php';880 require_once $this->PluginDir . 'class.smtp.php'; 795 881 $bad_rcpt = array(); 796 882 797 883 if(!$this->SmtpConnect()) { … … class PHPMailer { 866 952 $this->smtp = new SMTP(); 867 953 } 868 954 955 $this->smtp->Timeout = $this->Timeout; 869 956 $this->smtp->do_debug = $this->SMTPDebug; 870 957 $hosts = explode(';', $this->Host); 871 958 $index = 0; 872 959 $connection = $this->smtp->Connected(); 960 $rtn = true; 873 961 874 962 // Retry while there is no connection 875 963 try { … … class PHPMailer { 893 981 894 982 if ($tls) { 895 983 if (!$this->smtp->StartTLS()) { 984 $rtn = false; 896 985 throw new phpmailerException($this->Lang('tls')); 897 986 } 898 987 … … class PHPMailer { 902 991 903 992 $connection = true; 904 993 if ($this->SMTPAuth) { 905 if (!$this->smtp->Authenticate($this->Username, $this->Password)) { 994 if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType, 995 $this->Realm, $this->Workstation)) { 996 $rtn = false; 906 997 throw new phpmailerException($this->Lang('authenticate')); 907 998 } 908 999 } 909 1000 } 910 1001 $index++; 911 1002 if (!$connection) { 1003 $rtn = false; 912 1004 throw new phpmailerException($this->Lang('connect_host')); 913 1005 } 914 1006 } 915 1007 } catch (phpmailerException $e) { 916 1008 $this->smtp->Reset(); 917 if ($this->exceptions) {1009 if ($this->exceptions) { 918 1010 throw $e; 919 1011 } 1012 $rtn = false; 920 1013 } 921 return true;1014 return $rtn; 922 1015 } 923 1016 924 1017 /** … … class PHPMailer { 1028 1121 // If utf-8 encoding is used, we will need to make sure we don't 1029 1122 // split multibyte characters when we wrap 1030 1123 $is_utf8 = (strtolower($this->CharSet) == "utf-8"); 1124 $lelen = strlen($this->LE); 1125 $crlflen = strlen(self::CRLF); 1031 1126 1032 1127 $message = $this->FixEOL($message); 1033 if (substr($message, - 1) == $this->LE) {1034 $message = substr($message, 0, - 1);1128 if (substr($message, -$lelen) == $this->LE) { 1129 $message = substr($message, 0, -$lelen); 1035 1130 } 1036 1131 1037 $line = explode($this->LE, $message); 1132 $line = explode($this->LE, $message); // Magic. We know FixEOL uses $LE 1038 1133 $message = ''; 1039 1134 for ($i = 0 ;$i < count($line); $i++) { 1040 1135 $line_part = explode(' ', $line[$i]); … … class PHPMailer { 1042 1137 for ($e = 0; $e<count($line_part); $e++) { 1043 1138 $word = $line_part[$e]; 1044 1139 if ($qp_mode and (strlen($word) > $length)) { 1045 $space_left = $length - strlen($buf) - 1;1140 $space_left = $length - strlen($buf) - $crlflen; 1046 1141 if ($e != 0) { 1047 1142 if ($space_left > 20) { 1048 1143 $len = $space_left; … … class PHPMailer { 1056 1151 $part = substr($word, 0, $len); 1057 1152 $word = substr($word, $len); 1058 1153 $buf .= ' ' . $part; 1059 $message .= $buf . sprintf("=%s", $this->LE);1154 $message .= $buf . sprintf("=%s", self::CRLF); 1060 1155 } else { 1061 1156 $message .= $buf . $soft_break; 1062 1157 } … … class PHPMailer { 1075 1170 $word = substr($word, $len); 1076 1171 1077 1172 if (strlen($word) > 0) { 1078 $message .= $part . sprintf("=%s", $this->LE);1173 $message .= $part . sprintf("=%s", self::CRLF); 1079 1174 } else { 1080 1175 $buf = $part; 1081 1176 } … … class PHPMailer { 1090 1185 } 1091 1186 } 1092 1187 } 1093 $message .= $buf . $this->LE;1188 $message .= $buf . self::CRLF; 1094 1189 } 1095 1190 1096 1191 return $message; … … class PHPMailer { 1176 1271 $this->boundary[3] = 'b3_' . $uniq_id; 1177 1272 1178 1273 $result .= $this->HeaderLine('Date', self::RFCDate()); 1179 if($this->Sender == '') { 1274 if ($this->ReturnPath) { 1275 $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath)); 1276 } elseif ($this->Sender == '') { 1180 1277 $result .= $this->HeaderLine('Return-Path', trim($this->From)); 1181 1278 } else { 1182 1279 $result .= $this->HeaderLine('Return-Path', trim($this->Sender)); … … class PHPMailer { 1195 1292 $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); 1196 1293 } 1197 1294 } 1198 }1295 } 1199 1296 1200 1297 $from = array(); 1201 1298 $from[0][0] = trim($this->From); … … class PHPMailer { 1227 1324 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); 1228 1325 } 1229 1326 $result .= $this->HeaderLine('X-Priority', $this->Priority); 1230 if ($this->XMailer) {1231 $result .= $this->HeaderLine('X-Mailer', $this->XMailer);1327 if ($this->XMailer == '') { 1328 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1232 1329 } else { 1233 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1330 $myXmailer = trim($this->XMailer); 1331 if ($myXmailer) { 1332 $result .= $this->HeaderLine('X-Mailer', $myXmailer); 1333 } 1234 1334 } 1235 1335 1236 1336 if($this->ConfirmReadingTo != '') { … … class PHPMailer { 1257 1357 public function GetMailMIME() { 1258 1358 $result = ''; 1259 1359 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 1360 case 'inline': 1265 1361 $result .= $this->HeaderLine('Content-Type', 'multipart/related;'); 1266 1362 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); … … class PHPMailer { 1277 1373 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 1278 1374 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 1279 1375 break; 1376 default: 1377 // Catches case 'plain': and case '': 1378 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); 1379 $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet); 1380 break; 1280 1381 } 1281 1382 1282 1383 if($this->Mailer != 'mail') { … … class PHPMailer { 1292 1393 * @return string 1293 1394 */ 1294 1395 public function GetSentMIMEMessage() { 1295 return $this->SentMIMEMessage;1396 return sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$this->mailHeader,$this->MIMEBody); 1296 1397 } 1297 1398 1298 1399 … … class PHPMailer { 1305 1406 $body = ''; 1306 1407 1307 1408 if ($this->sign_key_file) { 1308 $body .= $this->GetMailMIME() ;1409 $body .= $this->GetMailMIME().$this->LE; 1309 1410 } 1310 1411 1311 1412 $this->SetWordWrap(); 1312 1413 1313 1414 switch($this->message_type) { 1314 case 'plain':1315 $body .= $this->EncodeString($this->Body, $this->Encoding);1316 break;1317 1415 case 'inline': 1318 1416 $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 1319 1417 $body .= $this->EncodeString($this->Body, $this->Encoding); … … class PHPMailer { 1321 1419 $body .= $this->AttachAll("inline", $this->boundary[1]); 1322 1420 break; 1323 1421 case 'attach': 1324 $body .= $this->GetBoundary($this->boundary[1], '', ' ', '');1422 $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); 1325 1423 $body .= $this->EncodeString($this->Body, $this->Encoding); 1326 1424 $body .= $this->LE.$this->LE; 1327 1425 $body .= $this->AttachAll("attachment", $this->boundary[1]); … … class PHPMailer { 1398 1496 $body .= $this->LE; 1399 1497 $body .= $this->AttachAll("attachment", $this->boundary[1]); 1400 1498 break; 1499 default: 1500 // catch case 'plain' and case '' 1501 $body .= $this->EncodeString($this->Body, $this->Encoding); 1502 break; 1401 1503 } 1402 1504 1403 1505 if ($this->IsError()) { … … class PHPMailer { 1444 1546 $encoding = $this->Encoding; 1445 1547 } 1446 1548 $result .= $this->TextLine('--' . $boundary); 1447 $result .= sprintf("Content-Type: %s; charset= \"%s\"", $contentType, $charSet);1549 $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet); 1448 1550 $result .= $this->LE; 1449 1551 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); 1450 1552 $result .= $this->LE; … … class PHPMailer { 1533 1635 if ($this->exceptions) { 1534 1636 throw $e; 1535 1637 } 1536 if ($this->SMTPDebug) {1537 echo $e->getMessage()."\n";1638 if ($this->SMTPDebug) { 1639 $this->edebug($e->getMessage()."\n"); 1538 1640 } 1539 1641 if ( $e->getCode() == self::STOP_CRITICAL ) { 1540 1642 return false; … … class PHPMailer { 1633 1735 if (!is_readable($path)) { 1634 1736 throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE); 1635 1737 } 1636 if (function_exists('get_magic_quotes')) {1637 function get_magic_quotes() {1638 return false;1639 }1640 }1641 $magic_quotes = get_magic_quotes_runtime();1642 if ($magic_quotes) {1738 // if (!function_exists('get_magic_quotes')) { 1739 // function get_magic_quotes() { 1740 // return false; 1741 // } 1742 // } 1743 $magic_quotes = get_magic_quotes_runtime(); 1744 if ($magic_quotes) { 1643 1745 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1644 1746 set_magic_quotes_runtime(0); 1645 1747 } else { 1646 ini_set('magic_quotes_runtime', 0); 1647 }1648 }1748 ini_set('magic_quotes_runtime', 0); 1749 } 1750 } 1649 1751 $file_buffer = file_get_contents($path); 1650 1752 $file_buffer = $this->EncodeString($file_buffer, $encoding); 1651 if ($magic_quotes) {1753 if ($magic_quotes) { 1652 1754 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1653 1755 set_magic_quotes_runtime($magic_quotes); 1654 1756 } else { 1655 ini_set('magic_quotes_runtime', $magic_quotes); 1656 }1657 }1757 ini_set('magic_quotes_runtime', $magic_quotes); 1758 } 1759 } 1658 1760 return $file_buffer; 1659 1761 } catch (Exception $e) { 1660 1762 $this->SetError($e->getMessage()); … … class PHPMailer { 2027 2129 } 2028 2130 2029 2131 public function AlternativeExists() { 2030 return strlen($this->AltBody)>0;2132 return !empty($this->AltBody); 2031 2133 } 2032 2134 2033 2135 ///////////////////////////////////////////////// … … class PHPMailer { 2184 2286 } 2185 2287 2186 2288 /** 2187 * Changes every end of line from CR or LF to CRLF.2289 * Changes every end of line from CR or LF to $this->LE. 2188 2290 * @access public 2189 2291 * @return string 2190 2292 */ 2191 2293 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; 2294 return str_replace(array("\r\n", "\r", "\n"), $this->LE, $str); 2196 2295 } 2197 2296 2198 2297 /** … … class PHPMailer { 2231 2330 } 2232 2331 $this->IsHTML(true); 2233 2332 $this->Body = $message; 2234 if (empty($this->AltBody)) {2235 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));2236 if (!empty($textMsg)) {2237 $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);2238 }2239 }2333 if (empty($this->AltBody)) { 2334 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); 2335 if (!empty($textMsg)) { 2336 $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet); 2337 } 2338 } 2240 2339 if (empty($this->AltBody)) { 2241 2340 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; 2242 2341 } 2243 return $message;2342 return $message; 2244 2343 } 2245 2344 2246 2345 /** … … class PHPMailer { 2252 2351 */ 2253 2352 public static function _mime_types($ext = '') { 2254 2353 $mimes = array( 2354 'xl' => 'application/excel', 2255 2355 'hqx' => 'application/mac-binhex40', 2256 2356 'cpt' => 'application/mac-compactpro', 2257 'doc' => 'application/msword',2258 2357 'bin' => 'application/macbinary', 2358 'doc' => 'application/msword', 2359 'doc' => 'application/msword', 2360 'word' => 'application/msword', 2361 'class' => 'application/octet-stream', 2362 'dll' => 'application/octet-stream', 2259 2363 'dms' => 'application/octet-stream', 2364 'exe' => 'application/octet-stream', 2260 2365 'lha' => 'application/octet-stream', 2261 2366 'lzh' => 'application/octet-stream', 2262 'exe' => 'application/octet-stream',2263 'class' => 'application/octet-stream',2264 2367 'psd' => 'application/octet-stream', 2265 'so' => 'application/octet-stream',2266 2368 'sea' => 'application/octet-stream', 2267 ' dll'=> 'application/octet-stream',2369 'so' => 'application/octet-stream', 2268 2370 'oda' => 'application/oda', 2269 2371 'pdf' => 'application/pdf', 2270 2372 'ai' => 'application/postscript', … … class PHPMailer { 2282 2384 'dxr' => 'application/x-director', 2283 2385 'dvi' => 'application/x-dvi', 2284 2386 'gtar' => 'application/x-gtar', 2285 'php' => 'application/x-httpd-php',2286 'php4' => 'application/x-httpd-php',2287 2387 'php3' => 'application/x-httpd-php', 2388 'php4' => 'application/x-httpd-php', 2389 'php' => 'application/x-httpd-php', 2288 2390 'phtml' => 'application/x-httpd-php', 2289 2391 'phps' => 'application/x-httpd-php-source', 2290 2392 'js' => 'application/x-javascript', … … class PHPMailer { 2292 2394 'sit' => 'application/x-stuffit', 2293 2395 'tar' => 'application/x-tar', 2294 2396 'tgz' => 'application/x-tar', 2295 'xhtml' => 'application/xhtml+xml',2296 2397 'xht' => 'application/xhtml+xml', 2398 'xhtml' => 'application/xhtml+xml', 2297 2399 'zip' => 'application/zip', 2298 2400 'mid' => 'audio/midi', 2299 2401 'midi' => 'audio/midi', 2300 'mpga' => 'audio/mpeg',2301 2402 'mp2' => 'audio/mpeg', 2302 2403 'mp3' => 'audio/mpeg', 2404 'mpga' => 'audio/mpeg', 2303 2405 'aif' => 'audio/x-aiff', 2304 'aiff' => 'audio/x-aiff',2305 2406 'aifc' => 'audio/x-aiff', 2407 'aiff' => 'audio/x-aiff', 2306 2408 'ram' => 'audio/x-pn-realaudio', 2307 2409 'rm' => 'audio/x-pn-realaudio', 2308 2410 'rpm' => 'audio/x-pn-realaudio-plugin', 2309 2411 'ra' => 'audio/x-realaudio', 2310 'rv' => 'video/vnd.rn-realvideo',2311 2412 'wav' => 'audio/x-wav', 2312 2413 'bmp' => 'image/bmp', 2313 2414 'gif' => 'image/gif', 2314 2415 'jpeg' => 'image/jpeg', 2315 'jpg' => 'image/jpeg',2316 2416 'jpe' => 'image/jpeg', 2417 'jpg' => 'image/jpeg', 2317 2418 'png' => 'image/png', 2318 2419 'tiff' => 'image/tiff', 2319 2420 'tif' => 'image/tiff', 2421 'eml' => 'message/rfc822', 2320 2422 'css' => 'text/css', 2321 2423 'html' => 'text/html', 2322 2424 'htm' => 'text/html', 2323 2425 'shtml' => 'text/html', 2324 'txt' => 'text/plain',2325 'text' => 'text/plain',2326 2426 'log' => 'text/plain', 2427 'text' => 'text/plain', 2428 'txt' => 'text/plain', 2327 2429 'rtx' => 'text/richtext', 2328 2430 'rtf' => 'text/rtf', 2329 2431 'xml' => 'text/xml', 2330 2432 'xsl' => 'text/xml', 2331 2433 'mpeg' => 'video/mpeg', 2332 'mpg' => 'video/mpeg',2333 2434 'mpe' => 'video/mpeg', 2334 ' qt' => 'video/quicktime',2435 'mpg' => 'video/mpeg', 2335 2436 'mov' => 'video/quicktime', 2437 'qt' => 'video/quicktime', 2438 'rv' => 'video/vnd.rn-realvideo', 2336 2439 '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' 2440 'movie' => 'video/x-sgi-movie' 2342 2441 ); 2343 2442 return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)]; 2344 2443 } … … class PHPMailer { 2378 2477 * @return string 2379 2478 */ 2380 2479 public function SecureHeader($str) { 2381 $str = str_replace("\r", '', $str); 2382 $str = str_replace("\n", '', $str); 2383 return trim($str); 2480 return trim(str_replace(array("\r", "\n"), '', $str)); 2384 2481 } 2385 2482 2386 2483 /** … … class PHPMailer { 2515 2612 return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n"; 2516 2613 } 2517 2614 2615 /** 2616 * Perform callback 2617 */ 2518 2618 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) { 2519 if (!empty($this->action_function) && function_exists($this->action_function)) {2619 if (!empty($this->action_function) && is_callable($this->action_function)) { 2520 2620 $params = array($isSent, $to, $cc, $bcc, $subject, $body); 2521 2621 call_user_func_array($this->action_function, $params); 2522 2622 } 2523 2623 } 2524 2624 } 2525 2625 2626 /** 2627 * Exception handling 2628 */ 2526 2629 class phpmailerException extends Exception { 2527 2630 public function errorMessage() { 2528 2631 $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..49331c3 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-beta1 | 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-beta1'; 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 { 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 = ""; 901 $endtime = 0; 902 stream_set_timeout($this->smtp_conn, $this->Timeout); 903 if ($this->Timelimit > 0) { 904 $endtime = time() + $this->Timelimit; 905 } 800 906 while(!feof($this->smtp_conn)) { 801 907 $str = @fgets($this->smtp_conn,515); 802 908 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 />';909 $this->edebug("SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />'); 910 $this->edebug("SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />'); 805 911 } 806 912 $data .= $str; 807 913 if($this->do_debug >= 4) { 808 echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';914 $this->edebug("SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />'); 809 915 } 810 916 // if 4th character is a space, we are done reading, break the loop 811 917 if(substr($str,3,1) == " ") { break; } 918 // Timed-out? Log and break 919 $info = stream_get_meta_data($this->smtp_conn); 920 if ($info['timed_out']) { 921 if($this->do_debug >= 4) { 922 $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " seconds) <br />"); 923 } 924 break; 925 } 926 // Now check if reads took too long 927 if ($endtime) { 928 if (time() > $endtime) { 929 if($this->do_debug >= 4) { 930 $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " seconds) <br />"); 931 } 932 break; 933 } 934 } 812 935 } 813 936 return $data; 814 937 }
