- File:
-
- 1 edited
-
trunk/wp-includes/class-phpmailer.php (modified) (64 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-phpmailer.php
r18107 r20715 3 3 .---------------------------------------------------------------------------. 4 4 | Software: PHPMailer - PHP email class | 5 | Version: 5.1 | 6 | Contact: via sourceforge.net support pages (also www.worxware.com) | 7 | Info: http://phpmailer.sourceforge.net | 8 | Support: http://sourceforge.net/projects/phpmailer/ | 5 | Version: 5.2.1 | 6 | Site: https://code.google.com/a/apache-extras.org/p/phpmailer/ | 9 7 | ------------------------------------------------------------------------- | 10 | Admin: Andy Prevost (project admininistrator)|8 | Admin: Jim Jagielski (project admininistrator) | 11 9 | Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net | 12 10 | : Marcus Bointon (coolbru) coolbru@users.sourceforge.net | 11 | : Jim Jagielski (jimjag) jimjag@gmail.com | 13 12 | Founder: Brent R. Matzelle (original founder) | 13 | Copyright (c) 2010-2012, Jim Jagielski. All Rights Reserved. | 14 14 | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. | 15 15 | Copyright (c) 2001-2003, Brent R. Matzelle | … … 20 20 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 21 21 | FITNESS FOR A PARTICULAR PURPOSE. | 22 | ------------------------------------------------------------------------- |23 | We offer a number of paid services (www.worxware.com): |24 | - Web Hosting on highly optimized fast and secure servers |25 | - Technology Consulting |26 | - Oursourcing (highly qualified programmers and graphic designers) |27 22 '---------------------------------------------------------------------------' 28 23 */ … … 34 29 * @author Andy Prevost 35 30 * @author Marcus Bointon 31 * @author Jim Jagielski 32 * @copyright 2010 - 2012 Jim Jagielski 36 33 * @copyright 2004 - 2009 Andy Prevost 37 * @version $Id: class.phpmailer.php 4 47 2009-05-25 01:36:38Z codeworxtech$34 * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $ 38 35 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License 39 36 */ … … 118 115 */ 119 116 public $AltBody = ''; 117 118 /** 119 * Stores the complete compiled MIME message body. 120 * @var string 121 * @access protected 122 */ 123 protected $MIMEBody = ''; 124 125 /** 126 * Stores the complete compiled MIME message headers. 127 * @var string 128 * @access protected 129 */ 130 protected $MIMEHeader = ''; 131 132 /** 133 * Stores the complete sent MIME message (Body and Headers) 134 * @var string 135 * @access protected 136 */ 137 protected $SentMIMEMessage = ''; 120 138 121 139 /** … … 269 287 */ 270 288 public $DKIM_identity = ''; 289 290 /** 291 * Used with DKIM DNS Resource Record 292 * @var string 293 */ 294 public $DKIM_passphrase = ''; 271 295 272 296 /** … … 301 325 * @var string 302 326 */ 303 public $Version = '5.1'; 327 public $Version = '5.2.1'; 328 329 /** 330 * What to use in the X-Mailer header 331 * @var string 332 */ 333 public $XMailer = ''; 304 334 305 335 ///////////////////////////////////////////////// … … 307 337 ///////////////////////////////////////////////// 308 338 309 pr ivate$smtp = NULL;310 pr ivate$to = array();311 pr ivate$cc = array();312 pr ivate$bcc = array();313 pr ivate$ReplyTo = array();314 pr ivate$all_recipients = array();315 pr ivate$attachment = array();316 pr ivate$CustomHeader = array();317 pr ivate$message_type = '';318 pr ivate$boundary = array();319 protected $language = array();320 pr ivate$error_count = 0;321 pr ivate $sign_cert_file = "";322 pr ivate $sign_key_file = "";323 pr ivate $sign_key_pass = "";324 pr ivate$exceptions = false;339 protected $smtp = NULL; 340 protected $to = array(); 341 protected $cc = array(); 342 protected $bcc = array(); 343 protected $ReplyTo = array(); 344 protected $all_recipients = array(); 345 protected $attachment = array(); 346 protected $CustomHeader = array(); 347 protected $message_type = ''; 348 protected $boundary = array(); 349 protected $language = array(); 350 protected $error_count = 0; 351 protected $sign_cert_file = ''; 352 protected $sign_key_file = ''; 353 protected $sign_key_pass = ''; 354 protected $exceptions = false; 325 355 326 356 ///////////////////////////////////////////////// … … 438 468 */ 439 469 public function AddReplyTo($address, $name = '') { 440 return $this->AddAnAddress('Reply To', $address, $name);470 return $this->AddAnAddress('Reply-To', $address, $name); 441 471 } 442 472 … … 448 478 * @param string $name 449 479 * @return boolean true on success, false if address already used or invalid in some way 450 * @access private 451 */ 452 private function AddAnAddress($kind, $address, $name = '') { 453 if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) { 454 echo 'Invalid recipient array: ' . $kind; 480 * @access protected 481 */ 482 protected function AddAnAddress($kind, $address, $name = '') { 483 if (!preg_match('/^(to|cc|bcc|Reply-To)$/', $kind)) { 484 $this->SetError($this->Lang('Invalid recipient array').': '.$kind); 485 if ($this->exceptions) { 486 throw new phpmailerException('Invalid recipient array: ' . $kind); 487 } 488 if ($this->SMTPDebug) { 489 echo $this->Lang('Invalid recipient array').': '.$kind; 490 } 455 491 return false; 456 492 } … … 462 498 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 463 499 } 464 echo $this->Lang('invalid_address').': '.$address; 500 if ($this->SMTPDebug) { 501 echo $this->Lang('invalid_address').': '.$address; 502 } 465 503 return false; 466 504 } 467 if ($kind != 'Reply To') {505 if ($kind != 'Reply-To') { 468 506 if (!isset($this->all_recipients[strtolower($address)])) { 469 507 array_push($this->$kind, array($address, $name)); … … 486 524 * @return boolean 487 525 */ 488 public function SetFrom($address, $name = '', $auto=1) {526 public function SetFrom($address, $name = '', $auto = 1) { 489 527 $address = trim($address); 490 528 $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim … … 494 532 throw new phpmailerException($this->Lang('invalid_address').': '.$address); 495 533 } 496 echo $this->Lang('invalid_address').': '.$address; 534 if ($this->SMTPDebug) { 535 echo $this->Lang('invalid_address').': '.$address; 536 } 497 537 return false; 498 538 } … … 501 541 if ($auto) { 502 542 if (empty($this->ReplyTo)) { 503 $this->AddAnAddress('Reply To', $address, $name);543 $this->AddAnAddress('Reply-To', $address, $name); 504 544 } 505 545 if (empty($this->Sender)) { … … 545 585 public function Send() { 546 586 try { 587 if(!$this->PreSend()) return false; 588 return $this->PostSend(); 589 } catch (phpmailerException $e) { 590 $this->SentMIMEMessage = ''; 591 $this->SetError($e->getMessage()); 592 if ($this->exceptions) { 593 throw $e; 594 } 595 return false; 596 } 597 } 598 599 protected function PreSend() { 600 try { 601 $mailHeader = ""; 547 602 if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { 548 603 throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); … … 556 611 $this->error_count = 0; // reset errors 557 612 $this->SetMessageType(); 558 $header = $this->CreateHeader(); 559 $body = $this->CreateBody(); 560 613 //Refuse to send an empty message 561 614 if (empty($this->Body)) { 562 615 throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL); 563 616 } 564 617 618 $this->MIMEHeader = $this->CreateHeader(); 619 $this->MIMEBody = $this->CreateBody(); 620 621 // To capture the complete message when using mail(), create 622 // an extra header list which CreateHeader() doesn't fold in 623 if ($this->Mailer == 'mail') { 624 if (count($this->to) > 0) { 625 $mailHeader .= $this->AddrAppend("To", $this->to); 626 } else { 627 $mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;"); 628 } 629 $mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject)))); 630 // if(count($this->cc) > 0) { 631 // $mailHeader .= $this->AddrAppend("Cc", $this->cc); 632 // } 633 } 634 565 635 // digitally sign with DKIM if enabled 566 636 if ($this->DKIM_domain && $this->DKIM_private) { 567 $header_dkim = $this->DKIM_Add($header,$this->Subject,$body); 568 $header = str_replace("\r\n","\n",$header_dkim) . $header; 569 } 570 571 // Choose the mailer and send through it 572 switch($this->Mailer) { 573 case 'sendmail': 574 return $this->SendmailSend($header, $body); 575 case 'smtp': 576 return $this->SmtpSend($header, $body); 577 default: 578 return $this->MailSend($header, $body); 579 } 637 $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody); 638 $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader; 639 } 640 641 $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody); 642 return true; 580 643 581 644 } catch (phpmailerException $e) { … … 584 647 throw $e; 585 648 } 586 echo $e->getMessage()."\n"; 649 return false; 650 } 651 } 652 653 protected function PostSend() { 654 try { 655 // Choose the mailer and send through it 656 switch($this->Mailer) { 657 case 'sendmail': 658 return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody); 659 case 'smtp': 660 return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody); 661 case 'mail': 662 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 663 default: 664 return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 665 } 666 667 } catch (phpmailerException $e) { 668 $this->SetError($e->getMessage()); 669 if ($this->exceptions) { 670 throw $e; 671 } 672 if ($this->SMTPDebug) { 673 echo $e->getMessage()."\n"; 674 } 587 675 return false; 588 676 } … … 613 701 // implement call back function if it exists 614 702 $isSent = ($result == 0) ? 1 : 0; 615 $this->doCallback($isSent, $val,$this->cc,$this->bcc,$this->Subject,$body);703 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 616 704 if($result != 0) { 617 705 throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); … … 627 715 // implement call back function if it exists 628 716 $isSent = ($result == 0) ? 1 : 0; 629 $this->doCallback($isSent, $this->to,$this->cc,$this->bcc,$this->Subject,$body);717 $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body); 630 718 if($result != 0) { 631 719 throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); … … 649 737 $to = implode(', ', $toArr); 650 738 651 $params = sprintf("-oi -f %s", $this->Sender); 652 if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) { 739 if (empty($this->Sender)) { 740 $params = "-oi "; 741 } else { 742 $params = sprintf("-oi -f %s", $this->Sender); 743 } 744 if ($this->Sender != '' and !ini_get('safe_mode')) { 653 745 $old_from = ini_get('sendmail_from'); 654 746 ini_set('sendmail_from', $this->Sender); … … 658 750 // implement call back function if it exists 659 751 $isSent = ($rt == 1) ? 1 : 0; 660 $this->doCallback($isSent, $val,$this->cc,$this->bcc,$this->Subject,$body);752 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 661 753 } 662 754 } else { … … 664 756 // implement call back function if it exists 665 757 $isSent = ($rt == 1) ? 1 : 0; 666 $this->doCallback($isSent, $to,$this->cc,$this->bcc,$this->Subject,$body);758 $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 667 759 } 668 760 } else { … … 672 764 // implement call back function if it exists 673 765 $isSent = ($rt == 1) ? 1 : 0; 674 $this->doCallback($isSent, $val,$this->cc,$this->bcc,$this->Subject,$body);766 $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 675 767 } 676 768 } else { 677 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header );769 $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params); 678 770 // implement call back function if it exists 679 771 $isSent = ($rt == 1) ? 1 : 0; 680 $this->doCallback($isSent, $to,$this->cc,$this->bcc,$this->Subject,$body);772 $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 681 773 } 682 774 } … … 717 809 // implement call back function if it exists 718 810 $isSent = 0; 719 $this->doCallback($isSent, $to[0],'','',$this->Subject,$body);811 $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body); 720 812 } else { 721 813 // implement call back function if it exists 722 814 $isSent = 1; 723 $this->doCallback($isSent, $to[0],'','',$this->Subject,$body);815 $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body); 724 816 } 725 817 } … … 729 821 // implement call back function if it exists 730 822 $isSent = 0; 731 $this->doCallback($isSent, '',$cc[0],'',$this->Subject,$body);823 $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body); 732 824 } else { 733 825 // implement call back function if it exists 734 826 $isSent = 1; 735 $this->doCallback($isSent, '',$cc[0],'',$this->Subject,$body);827 $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body); 736 828 } 737 829 } … … 741 833 // implement call back function if it exists 742 834 $isSent = 0; 743 $this->doCallback($isSent, '','',$bcc[0],$this->Subject,$body);835 $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body); 744 836 } else { 745 837 // implement call back function if it exists 746 838 $isSent = 1; 747 $this->doCallback($isSent, '','',$bcc[0],$this->Subject,$body);839 $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body); 748 840 } 749 841 } … … 823 915 } catch (phpmailerException $e) { 824 916 $this->smtp->Reset(); 825 throw $e; 917 if ($this->exceptions) { 918 throw $e; 919 } 826 920 } 827 921 return true; … … 943 1037 $line = explode($this->LE, $message); 944 1038 $message = ''; 945 for ($i =0 ;$i < count($line); $i++) {1039 for ($i = 0 ;$i < count($line); $i++) { 946 1040 $line_part = explode(' ', $line[$i]); 947 1041 $buf = ''; … … 1057 1151 switch($this->message_type) { 1058 1152 case 'alt': 1059 case 'alt_attachments': 1153 case 'alt_inline': 1154 case 'alt_attach': 1155 case 'alt_inline_attach': 1060 1156 $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); 1061 1157 break; … … 1078 1174 $this->boundary[1] = 'b1_' . $uniq_id; 1079 1175 $this->boundary[2] = 'b2_' . $uniq_id; 1176 $this->boundary[3] = 'b3_' . $uniq_id; 1080 1177 1081 1178 $result .= $this->HeaderLine('Date', self::RFCDate()); … … 1099 1196 } 1100 1197 } 1101 }1198 } 1102 1199 1103 1200 $from = array(); … … 1117 1214 1118 1215 if(count($this->ReplyTo) > 0) { 1119 $result .= $this->AddrAppend('Reply- to', $this->ReplyTo);1216 $result .= $this->AddrAppend('Reply-To', $this->ReplyTo); 1120 1217 } 1121 1218 … … 1126 1223 1127 1224 if($this->MessageID != '') { 1128 $result .= $this->HeaderLine('Message-ID', $this->MessageID);1225 $result .= $this->HeaderLine('Message-ID', $this->MessageID); 1129 1226 } else { 1130 1227 $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); 1131 1228 } 1132 1229 $result .= $this->HeaderLine('X-Priority', $this->Priority); 1133 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)'); 1230 if($this->XMailer) { 1231 $result .= $this->HeaderLine('X-Mailer', $this->XMailer); 1232 } else { 1233 $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 1234 } 1134 1235 1135 1236 if($this->ConfirmReadingTo != '') { … … 1159 1260 case 'plain': 1160 1261 $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); 1161 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);1262 $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"'); 1162 1263 break; 1163 case 'attachments': 1164 case 'alt_attachments': 1165 if($this->InlineImageExists()){ 1166 $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); 1167 } else { 1168 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); 1169 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 1170 } 1264 case 'inline': 1265 $result .= $this->HeaderLine('Content-Type', 'multipart/related;'); 1266 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 1267 break; 1268 case 'attach': 1269 case 'inline_attach': 1270 case 'alt_attach': 1271 case 'alt_inline_attach': 1272 $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); 1273 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 1171 1274 break; 1172 1275 case 'alt': 1276 case 'alt_inline': 1173 1277 $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 1174 1278 $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); … … 1184 1288 1185 1289 /** 1290 * Returns the MIME message (headers and body). Only really valid post PreSend(). 1291 * @access public 1292 * @return string 1293 */ 1294 public function GetSentMIMEMessage() { 1295 return $this->SentMIMEMessage; 1296 } 1297 1298 1299 /** 1186 1300 * Assembles the message body. Returns an empty string on failure. 1187 1301 * @access public … … 1198 1312 1199 1313 switch($this->message_type) { 1314 case 'plain': 1315 $body .= $this->EncodeString($this->Body, $this->Encoding); 1316 break; 1317 case 'inline': 1318 $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 1319 $body .= $this->EncodeString($this->Body, $this->Encoding); 1320 $body .= $this->LE.$this->LE; 1321 $body .= $this->AttachAll("inline", $this->boundary[1]); 1322 break; 1323 case 'attach': 1324 $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 1325 $body .= $this->EncodeString($this->Body, $this->Encoding); 1326 $body .= $this->LE.$this->LE; 1327 $body .= $this->AttachAll("attachment", $this->boundary[1]); 1328 break; 1329 case 'inline_attach': 1330 $body .= $this->TextLine("--" . $this->boundary[1]); 1331 $body .= $this->HeaderLine('Content-Type', 'multipart/related;'); 1332 $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"'); 1333 $body .= $this->LE; 1334 $body .= $this->GetBoundary($this->boundary[2], '', '', ''); 1335 $body .= $this->EncodeString($this->Body, $this->Encoding); 1336 $body .= $this->LE.$this->LE; 1337 $body .= $this->AttachAll("inline", $this->boundary[2]); 1338 $body .= $this->LE; 1339 $body .= $this->AttachAll("attachment", $this->boundary[1]); 1340 break; 1200 1341 case 'alt': 1201 1342 $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); … … 1207 1348 $body .= $this->EndBoundary($this->boundary[1]); 1208 1349 break; 1209 case 'plain': 1210 $body .= $this->EncodeString($this->Body, $this->Encoding); 1211 break; 1212 case 'attachments': 1213 $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 1214 $body .= $this->EncodeString($this->Body, $this->Encoding); 1215 $body .= $this->LE; 1216 $body .= $this->AttachAll(); 1217 break; 1218 case 'alt_attachments': 1219 $body .= sprintf("--%s%s", $this->boundary[1], $this->LE); 1220 $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); 1221 $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body 1350 case 'alt_inline': 1351 $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); 1222 1352 $body .= $this->EncodeString($this->AltBody, $this->Encoding); 1223 1353 $body .= $this->LE.$this->LE; 1224 $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body 1354 $body .= $this->TextLine("--" . $this->boundary[1]); 1355 $body .= $this->HeaderLine('Content-Type', 'multipart/related;'); 1356 $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"'); 1357 $body .= $this->LE; 1358 $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', ''); 1359 $body .= $this->EncodeString($this->Body, $this->Encoding); 1360 $body .= $this->LE.$this->LE; 1361 $body .= $this->AttachAll("inline", $this->boundary[2]); 1362 $body .= $this->LE; 1363 $body .= $this->EndBoundary($this->boundary[1]); 1364 break; 1365 case 'alt_attach': 1366 $body .= $this->TextLine("--" . $this->boundary[1]); 1367 $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 1368 $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"'); 1369 $body .= $this->LE; 1370 $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', ''); 1371 $body .= $this->EncodeString($this->AltBody, $this->Encoding); 1372 $body .= $this->LE.$this->LE; 1373 $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', ''); 1225 1374 $body .= $this->EncodeString($this->Body, $this->Encoding); 1226 1375 $body .= $this->LE.$this->LE; 1227 1376 $body .= $this->EndBoundary($this->boundary[2]); 1228 $body .= $this->AttachAll(); 1377 $body .= $this->LE; 1378 $body .= $this->AttachAll("attachment", $this->boundary[1]); 1379 break; 1380 case 'alt_inline_attach': 1381 $body .= $this->TextLine("--" . $this->boundary[1]); 1382 $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 1383 $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"'); 1384 $body .= $this->LE; 1385 $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', ''); 1386 $body .= $this->EncodeString($this->AltBody, $this->Encoding); 1387 $body .= $this->LE.$this->LE; 1388 $body .= $this->TextLine("--" . $this->boundary[2]); 1389 $body .= $this->HeaderLine('Content-Type', 'multipart/related;'); 1390 $body .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"'); 1391 $body .= $this->LE; 1392 $body .= $this->GetBoundary($this->boundary[3], '', 'text/html', ''); 1393 $body .= $this->EncodeString($this->Body, $this->Encoding); 1394 $body .= $this->LE.$this->LE; 1395 $body .= $this->AttachAll("inline", $this->boundary[3]); 1396 $body .= $this->LE; 1397 $body .= $this->EndBoundary($this->boundary[2]); 1398 $body .= $this->LE; 1399 $body .= $this->AttachAll("attachment", $this->boundary[1]); 1229 1400 break; 1230 1401 } … … 1239 1410 if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) { 1240 1411 @unlink($file); 1412 $body = file_get_contents($signed); 1241 1413 @unlink($signed); 1242 $body = file_get_contents($signed);1243 1414 } else { 1244 1415 @unlink($file); … … 1259 1430 /** 1260 1431 * Returns the start of a message boundary. 1261 * @access private 1262 */ 1263 private function GetBoundary($boundary, $charSet, $contentType, $encoding) { 1432 * @access protected 1433 * @return string 1434 */ 1435 protected function GetBoundary($boundary, $charSet, $contentType, $encoding) { 1264 1436 $result = ''; 1265 1437 if($charSet == '') { … … 1273 1445 } 1274 1446 $result .= $this->TextLine('--' . $boundary); 1275 $result .= sprintf("Content-Type: %s; charset =\"%s\"", $contentType, $charSet);1447 $result .= sprintf("Content-Type: %s; charset=\"%s\"", $contentType, $charSet); 1276 1448 $result .= $this->LE; 1277 1449 $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); … … 1283 1455 /** 1284 1456 * Returns the end of a message boundary. 1285 * @access private 1286 */ 1287 private function EndBoundary($boundary) { 1457 * @access protected 1458 * @return string 1459 */ 1460 protected function EndBoundary($boundary) { 1288 1461 return $this->LE . '--' . $boundary . '--' . $this->LE; 1289 1462 } … … 1291 1464 /** 1292 1465 * Sets the message type. 1293 * @access pr ivate1466 * @access protected 1294 1467 * @return void 1295 1468 */ 1296 private function SetMessageType() { 1297 if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { 1298 $this->message_type = 'plain'; 1299 } else { 1300 if(count($this->attachment) > 0) { 1301 $this->message_type = 'attachments'; 1302 } 1303 if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { 1304 $this->message_type = 'alt'; 1305 } 1306 if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { 1307 $this->message_type = 'alt_attachments'; 1308 } 1309 } 1469 protected function SetMessageType() { 1470 $this->message_type = array(); 1471 if($this->AlternativeExists()) $this->message_type[] = "alt"; 1472 if($this->InlineImageExists()) $this->message_type[] = "inline"; 1473 if($this->AttachmentExists()) $this->message_type[] = "attach"; 1474 $this->message_type = implode("_", $this->message_type); 1475 if($this->message_type == "") $this->message_type = "plain"; 1310 1476 } 1311 1477 … … 1368 1534 throw $e; 1369 1535 } 1370 echo $e->getMessage()."\n"; 1536 if ($this->SMTPDebug) { 1537 echo $e->getMessage()."\n"; 1538 } 1371 1539 if ( $e->getCode() == self::STOP_CRITICAL ) { 1372 1540 return false; … … 1387 1555 * Attaches all fs, string, and binary attachments to the message. 1388 1556 * Returns an empty string on failure. 1389 * @access pr ivate1557 * @access protected 1390 1558 * @return string 1391 1559 */ 1392 pr ivate function AttachAll() {1560 protected function AttachAll($disposition_type, $boundary) { 1393 1561 // Return text of body 1394 1562 $mime = array(); … … 1398 1566 // Add all attachments 1399 1567 foreach ($this->attachment as $attachment) { 1400 // Check for string attachment 1401 $bString = $attachment[5]; 1402 if ($bString) { 1403 $string = $attachment[0]; 1404 } else { 1405 $path = $attachment[0]; 1406 } 1407 1408 if (in_array($attachment[0], $incl)) { continue; } 1409 $filename = $attachment[1]; 1410 $name = $attachment[2]; 1411 $encoding = $attachment[3]; 1412 $type = $attachment[4]; 1413 $disposition = $attachment[6]; 1414 $cid = $attachment[7]; 1415 $incl[] = $attachment[0]; 1416 if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } 1417 $cidUniq[$cid] = true; 1418 1419 $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); 1420 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); 1421 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); 1422 1423 if($disposition == 'inline') { 1424 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); 1425 } 1426 1427 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); 1428 1429 // Encode as string attachment 1430 if($bString) { 1431 $mime[] = $this->EncodeString($string, $encoding); 1432 if($this->IsError()) { 1433 return ''; 1568 // CHECK IF IT IS A VALID DISPOSITION_FILTER 1569 if($attachment[6] == $disposition_type) { 1570 // Check for string attachment 1571 $bString = $attachment[5]; 1572 if ($bString) { 1573 $string = $attachment[0]; 1574 } else { 1575 $path = $attachment[0]; 1434 1576 } 1435 $mime[] = $this->LE.$this->LE; 1436 } else { 1437 $mime[] = $this->EncodeFile($path, $encoding); 1438 if($this->IsError()) { 1439 return ''; 1577 1578 $inclhash = md5(serialize($attachment)); 1579 if (in_array($inclhash, $incl)) { continue; } 1580 $incl[] = $inclhash; 1581 $filename = $attachment[1]; 1582 $name = $attachment[2]; 1583 $encoding = $attachment[3]; 1584 $type = $attachment[4]; 1585 $disposition = $attachment[6]; 1586 $cid = $attachment[7]; 1587 if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } 1588 $cidUniq[$cid] = true; 1589 1590 $mime[] = sprintf("--%s%s", $boundary, $this->LE); 1591 $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); 1592 $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); 1593 1594 if($disposition == 'inline') { 1595 $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); 1440 1596 } 1441 $mime[] = $this->LE.$this->LE; 1442 } 1443 } 1444 1445 $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); 1446 1447 return join('', $mime); 1597 1598 $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); 1599 1600 // Encode as string attachment 1601 if($bString) { 1602 $mime[] = $this->EncodeString($string, $encoding); 1603 if($this->IsError()) { 1604 return ''; 1605 } 1606 $mime[] = $this->LE.$this->LE; 1607 } else { 1608 $mime[] = $this->EncodeFile($path, $encoding); 1609 if($this->IsError()) { 1610 return ''; 1611 } 1612 $mime[] = $this->LE.$this->LE; 1613 } 1614 } 1615 } 1616 1617 $mime[] = sprintf("--%s--%s", $boundary, $this->LE); 1618 1619 return implode("", $mime); 1448 1620 } 1449 1621 … … 1454 1626 * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' 1455 1627 * @see EncodeFile() 1456 * @access pr ivate1628 * @access protected 1457 1629 * @return string 1458 1630 */ 1459 pr ivatefunction EncodeFile($path, $encoding = 'base64') {1631 protected function EncodeFile($path, $encoding = 'base64') { 1460 1632 try { 1461 1633 if (!is_readable($path)) { … … 1467 1639 } 1468 1640 } 1469 if (PHP_VERSION < 6) { 1470 $magic_quotes = get_magic_quotes_runtime(); 1471 set_magic_quotes_runtime(0); 1472 } 1641 $magic_quotes = get_magic_quotes_runtime(); 1642 if ($magic_quotes) { 1643 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1644 set_magic_quotes_runtime(0); 1645 } else { 1646 ini_set('magic_quotes_runtime', 0); 1647 } 1648 } 1473 1649 $file_buffer = file_get_contents($path); 1474 1650 $file_buffer = $this->EncodeString($file_buffer, $encoding); 1475 if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); } 1651 if ($magic_quotes) { 1652 if (version_compare(PHP_VERSION, '5.3.0', '<')) { 1653 set_magic_quotes_runtime($magic_quotes); 1654 } else { 1655 ini_set('magic_quotes_runtime', $magic_quotes); 1656 } 1657 } 1476 1658 return $file_buffer; 1477 1659 } catch (Exception $e) { … … 1489 1671 * @return string 1490 1672 */ 1491 public function EncodeString ($str, $encoding = 'base64') {1673 public function EncodeString($str, $encoding = 'base64') { 1492 1674 $encoded = ''; 1493 1675 switch(strtolower($encoding)) { … … 1638 1820 */ 1639 1821 public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) { 1640 $hex = array('0', '1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');1822 $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); 1641 1823 $lines = preg_split('/(?:\r\n|\r|\n)/', $input); 1642 1824 $eol = "\r\n"; … … 1719 1901 * @return string 1720 1902 */ 1721 public function EncodeQ ($str, $position = 'text') {1903 public function EncodeQ($str, $position = 'text') { 1722 1904 // There should not be any EOL in the string 1723 1905 $encoded = preg_replace('/[\r\n]*/', '', $str); … … 1734 1916 //TODO using /e (equivalent to eval()) is probably not a good idea 1735 1917 $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', 1736 "'='.sprintf('%02X', ord('\\1'))", $encoded);1918 "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded); 1737 1919 break; 1738 1920 } … … 1808 1990 } 1809 1991 1992 public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') { 1993 // Append to $attachment array 1994 $this->attachment[] = array( 1995 0 => $string, 1996 1 => $filename, 1997 2 => basename($filename), 1998 3 => $encoding, 1999 4 => $type, 2000 5 => true, // isStringAttachment 2001 6 => 'inline', 2002 7 => $cid 2003 ); 2004 } 2005 1810 2006 /** 1811 2007 * Returns true if an inline attachment is present. … … 1820 2016 } 1821 2017 return false; 2018 } 2019 2020 public function AttachmentExists() { 2021 foreach($this->attachment as $attachment) { 2022 if ($attachment[6] == 'attachment') { 2023 return true; 2024 } 2025 } 2026 return false; 2027 } 2028 2029 public function AlternativeExists() { 2030 return strlen($this->AltBody)>0; 1822 2031 } 1823 2032 … … 1934 2143 /** 1935 2144 * Returns the server hostname or 'localhost.localdomain' if unknown. 1936 * @access pr ivate2145 * @access protected 1937 2146 * @return string 1938 2147 */ 1939 pr ivatefunction ServerHostname() {2148 protected function ServerHostname() { 1940 2149 if (!empty($this->Hostname)) { 1941 2150 $result = $this->Hostname; … … 1951 2160 /** 1952 2161 * Returns a message in the appropriate language. 1953 * @access pr ivate2162 * @access protected 1954 2163 * @return string 1955 2164 */ 1956 pr ivatefunction Lang($key) {2165 protected function Lang($key) { 1957 2166 if(count($this->language) < 1) { 1958 2167 $this->SetLanguage('en'); // set the default language … … 1977 2186 /** 1978 2187 * Changes every end of line from CR or LF to CRLF. 1979 * @access p rivate2188 * @access public 1980 2189 * @return string 1981 2190 */ 1982 p rivatefunction FixEOL($str) {2191 public function FixEOL($str) { 1983 2192 $str = str_replace("\r\n", "\n", $str); 1984 2193 $str = str_replace("\r", "\n", $str); … … 2002 2211 */ 2003 2212 public function MsgHTML($message, $basedir = '') { 2004 preg_match_all("/(src|background)= \"(.*)\"/Ui", $message, $images);2213 preg_match_all("/(src|background)=[\"'](.*)[\"']/Ui", $message, $images); 2005 2214 if(isset($images[2])) { 2006 2215 foreach($images[2] as $i => $url) { 2007 2216 // do not change urls for absolute images (thanks to corvuscorax) 2008 if (!preg_match('#^[A-z]+://#', $url)) {2217 if (!preg_match('#^[A-z]+://#', $url)) { 2009 2218 $filename = basename($url); 2010 2219 $directory = dirname($url); 2011 ($directory == '.') ?$directory='':'';2220 ($directory == '.') ? $directory='': ''; 2012 2221 $cid = 'cid:' . md5($filename); 2013 2222 $ext = pathinfo($filename, PATHINFO_EXTENSION); 2014 2223 $mimeType = self::_mime_types($ext); 2015 if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }2016 if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }2017 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {2018 $message = preg_replace("/".$images[1][$i]."= \"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);2224 if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; } 2225 if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; } 2226 if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) { 2227 $message = preg_replace("/".$images[1][$i]."=[\"']".preg_quote($url, '/')."[\"']/Ui", $images[1][$i]."=\"".$cid."\"", $message); 2019 2228 } 2020 2229 } … … 2023 2232 $this->IsHTML(true); 2024 2233 $this->Body = $message; 2025 $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); 2026 if (!empty($textMsg) && empty($this->AltBody)) { 2027 $this->AltBody = html_entity_decode($textMsg); 2028 } 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 } 2029 2240 if (empty($this->AltBody)) { 2030 2241 $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; 2031 2242 } 2243 return $message; 2032 2244 } 2033 2245 … … 2193 2405 */ 2194 2406 public function DKIM_QP($txt) { 2195 $tmp ="";2196 $line ="";2197 for ($i =0;$i<strlen($txt);$i++) {2198 $ord =ord($txt[$i]);2407 $tmp = ''; 2408 $line = ''; 2409 for ($i = 0; $i < strlen($txt); $i++) { 2410 $ord = ord($txt[$i]); 2199 2411 if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) { 2200 $line .=$txt[$i];2412 $line .= $txt[$i]; 2201 2413 } else { 2202 $line .="=".sprintf("%02X",$ord);2414 $line .= "=".sprintf("%02X", $ord); 2203 2415 } 2204 2416 } … … 2214 2426 public function DKIM_Sign($s) { 2215 2427 $privKeyStr = file_get_contents($this->DKIM_private); 2216 if ($this->DKIM_passphrase !='') {2217 $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);2428 if ($this->DKIM_passphrase != '') { 2429 $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase); 2218 2430 } else { 2219 2431 $privKey = $privKeyStr; … … 2231 2443 */ 2232 2444 public function DKIM_HeaderC($s) { 2233 $s =preg_replace("/\r\n\s+/"," ",$s);2234 $lines =explode("\r\n",$s);2235 foreach ($lines as $key =>$line) {2236 list($heading, $value)=explode(":",$line,2);2237 $heading =strtolower($heading);2238 $value =preg_replace("/\s+/"," ",$value) ; // Compress useless spaces2239 $lines[$key] =$heading.":".trim($value) ; // Don't forget to remove WSP around the value2240 } 2241 $s =implode("\r\n",$lines);2445 $s = preg_replace("/\r\n\s+/", " ", $s); 2446 $lines = explode("\r\n", $s); 2447 foreach ($lines as $key => $line) { 2448 list($heading, $value) = explode(":", $line, 2); 2449 $heading = strtolower($heading); 2450 $value = preg_replace("/\s+/", " ", $value) ; // Compress useless spaces 2451 $lines[$key] = $heading.":".trim($value) ; // Don't forget to remove WSP around the value 2452 } 2453 $s = implode("\r\n", $lines); 2242 2454 return $s; 2243 2455 } … … 2252 2464 if ($body == '') return "\r\n"; 2253 2465 // stabilize line endings 2254 $body =str_replace("\r\n","\n",$body);2255 $body =str_replace("\n","\r\n",$body);2466 $body = str_replace("\r\n", "\n", $body); 2467 $body = str_replace("\n", "\r\n", $body); 2256 2468 // END stabilize line endings 2257 while (substr($body, strlen($body)-4,4) == "\r\n\r\n") {2258 $body =substr($body,0,strlen($body)-2);2469 while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") { 2470 $body = substr($body, 0, strlen($body) - 2); 2259 2471 } 2260 2472 return $body; … … 2269 2481 * @param string $body Body 2270 2482 */ 2271 public function DKIM_Add($headers_line, $subject,$body) {2483 public function DKIM_Add($headers_line, $subject, $body) { 2272 2484 $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms 2273 2485 $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body … … 2275 2487 $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) 2276 2488 $subject_header = "Subject: $subject"; 2277 $headers = explode( "\r\n",$headers_line);2489 $headers = explode($this->LE, $headers_line); 2278 2490 foreach($headers as $header) { 2279 if (strpos($header, 'From:') === 0) {2280 $from_header =$header;2281 } elseif (strpos($header, 'To:') === 0) {2282 $to_header =$header;2283 } 2284 } 2285 $from = str_replace('|', '=7C',$this->DKIM_QP($from_header));2286 $to = str_replace('|', '=7C',$this->DKIM_QP($to_header));2287 $subject = str_replace('|', '=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable2491 if (strpos($header, 'From:') === 0) { 2492 $from_header = $header; 2493 } elseif (strpos($header, 'To:') === 0) { 2494 $to_header = $header; 2495 } 2496 } 2497 $from = str_replace('|', '=7C', $this->DKIM_QP($from_header)); 2498 $to = str_replace('|', '=7C', $this->DKIM_QP($to_header)); 2499 $subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable 2288 2500 $body = $this->DKIM_BodyC($body); 2289 2501 $DKIMlen = strlen($body) ; // Length of body … … 2304 2516 } 2305 2517 2306 protected function doCallback($isSent, $to,$cc,$bcc,$subject,$body) {2518 protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) { 2307 2519 if (!empty($this->action_function) && function_exists($this->action_function)) { 2308 $params = array($isSent, $to,$cc,$bcc,$subject,$body);2309 call_user_func_array($this->action_function, $params);2520 $params = array($isSent, $to, $cc, $bcc, $subject, $body); 2521 call_user_func_array($this->action_function, $params); 2310 2522 } 2311 2523 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)