<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[17676] trunk/wp-includes: Update phpmailer and smtp to 5.1.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17676">17676</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2011-04-21 20:29:30 +0000 (Thu, 21 Apr 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Update phpmailer and smtp to 5.1. Props MattyRob cnorris23. fixes <a href="http://trac.wordpress.org/ticket/15912">#15912</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludesclassphpmailerphp">trunk/wp-includes/class-phpmailer.php</a></li>
<li><a href="#trunkwpincludesclasssmtpphp">trunk/wp-includes/class-smtp.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludesclassphpmailerphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-phpmailer.php (17675 => 17676)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-phpmailer.php        2011-04-21 20:20:56 UTC (rev 17675)
+++ trunk/wp-includes/class-phpmailer.php        2011-04-21 20:29:30 UTC (rev 17676)
</span><span class="lines">@@ -2,14 +2,16 @@
</span><span class="cx"> /*~ class.phpmailer.php
</span><span class="cx"> .---------------------------------------------------------------------------.
</span><span class="cx"> | Software: PHPMailer - PHP email class |
</span><del>-| Version: 2.0.4 |
-| Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
</del><ins>+| Version: 5.1 |
+| Contact: via sourceforge.net support pages (also www.worxware.com) |
</ins><span class="cx"> | Info: http://phpmailer.sourceforge.net |
</span><span class="cx"> | Support: http://sourceforge.net/projects/phpmailer/ |
</span><span class="cx"> | ------------------------------------------------------------------------- |
</span><del>-| Author: Andy Prevost (project admininistrator) |
-| Author: Brent R. Matzelle (original founder) |
-| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
</del><ins>+| Admin: Andy Prevost (project admininistrator) |
+| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
+| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
+| Founder: Brent R. Matzelle (original founder) |
+| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
</ins><span class="cx"> | Copyright (c) 2001-2003, Brent R. Matzelle |
</span><span class="cx"> | ------------------------------------------------------------------------- |
</span><span class="cx"> | License: Distributed under the Lesser General Public License (LGPL) |
</span><span class="lines">@@ -18,19 +20,26 @@
</span><span class="cx"> | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
</span><span class="cx"> | FITNESS FOR A PARTICULAR PURPOSE. |
</span><span class="cx"> | ------------------------------------------------------------------------- |
</span><del>-| We offer a number of paid services (www.codeworxtech.com): |
</del><ins>+| We offer a number of paid services (www.worxware.com): |
</ins><span class="cx"> | - Web Hosting on highly optimized fast and secure servers |
</span><span class="cx"> | - Technology Consulting |
</span><span class="cx"> | - Oursourcing (highly qualified programmers and graphic designers) |
</span><span class="cx"> '---------------------------------------------------------------------------'
</span><del>- */
</del><ins>+*/
+
</ins><span class="cx"> /**
</span><span class="cx"> * PHPMailer - PHP email transport class
</span><ins>+ * NOTE: Requires PHP version 5 or later
</ins><span class="cx"> * @package PHPMailer
</span><span class="cx"> * @author Andy Prevost
</span><ins>+ * @author Marcus Bointon
</ins><span class="cx"> * @copyright 2004 - 2009 Andy Prevost
</span><ins>+ * @version $Id: class.phpmailer.php 447 2009-05-25 01:36:38Z codeworxtech $
+ * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
</ins><span class="cx"> */
</span><span class="cx">
</span><ins>+if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
+
</ins><span class="cx"> class PHPMailer {
</span><span class="cx">
</span><span class="cx"> /////////////////////////////////////////////////
</span><span class="lines">@@ -41,64 +50,64 @@
</span><span class="cx"> * Email priority (1 = High, 3 = Normal, 5 = low).
</span><span class="cx"> * @var int
</span><span class="cx"> */
</span><del>- var $Priority = 3;
</del><ins>+ public $Priority = 3;
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the CharSet of the message.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $CharSet = 'iso-8859-1';
</del><ins>+ public $CharSet = 'iso-8859-1';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the Content-type of the message.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $ContentType = 'text/plain';
</del><ins>+ public $ContentType = 'text/plain';
</ins><span class="cx">
</span><span class="cx"> /**
</span><del>- * Sets the Encoding of the message. Options for this are "8bit",
- * "7bit", "binary", "base64", and "quoted-printable".
</del><ins>+ * Sets the Encoding of the message. Options for this are
+ * "8bit", "7bit", "binary", "base64", and "quoted-printable".
</ins><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Encoding = '8bit';
</del><ins>+ public $Encoding = '8bit';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Holds the most recent mailer error message.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $ErrorInfo = '';
</del><ins>+ public $ErrorInfo = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the From email address for the message.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $From = 'root@localhost';
</del><ins>+ public $From = 'root@localhost';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the From name of the message.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $FromName = 'Root User';
</del><ins>+ public $FromName = 'Root User';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the Sender email (Return-Path) of the message. If not empty,
</span><span class="cx"> * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Sender = '';
</del><ins>+ public $Sender = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the Subject of the message.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Subject = '';
</del><ins>+ public $Subject = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the Body of the message. This can be either an HTML or text body.
</span><span class="cx"> * If HTML then run IsHTML(true).
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Body = '';
</del><ins>+ public $Body = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the text-only body of the message. This automatically sets the
</span><span class="lines">@@ -107,45 +116,39 @@
</span><span class="cx"> * that can read HTML will view the normal Body.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $AltBody = '';
</del><ins>+ public $AltBody = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets word wrapping on the body of the message to a given number of
</span><span class="cx"> * characters.
</span><span class="cx"> * @var int
</span><span class="cx"> */
</span><del>- var $WordWrap = 0;
</del><ins>+ public $WordWrap = 0;
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Method to send mail: ("mail", "sendmail", or "smtp").
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Mailer = 'mail';
</del><ins>+ public $Mailer = 'mail';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the path of the sendmail program.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Sendmail = '/usr/sbin/sendmail';
</del><ins>+ public $Sendmail = '/usr/sbin/sendmail';
</ins><span class="cx">
</span><span class="cx"> /**
</span><del>- * Path to PHPMailer plugins. This is now only useful if the SMTP class
</del><ins>+ * Path to PHPMailer plugins. Useful if the SMTP class
</ins><span class="cx"> * is in a different directory than the PHP include path.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $PluginDir = '';
</del><ins>+ public $PluginDir = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><del>- * Holds PHPMailer version.
- * @var string
- */
- var $Version = "2.0.4";
-
- /**
</del><span class="cx"> * Sets the email address that a reading confirmation will be sent.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $ConfirmReadingTo = '';
</del><ins>+ public $ConfirmReadingTo = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the hostname to use in Message-Id and Received headers
</span><span class="lines">@@ -153,14 +156,14 @@
</span><span class="cx"> * by SERVER_NAME is used or 'localhost.localdomain'.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Hostname = '';
</del><ins>+ public $Hostname = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the message ID to be used in the Message-Id header.
</span><span class="cx"> * If empty, a unique id will be generated.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $MessageID = '';
</del><ins>+ public $MessageID = '';
</ins><span class="cx">
</span><span class="cx"> /////////////////////////////////////////////////
</span><span class="cx"> // PROPERTIES FOR SMTP
</span><span class="lines">@@ -174,57 +177,57 @@
</span><span class="cx"> * Hosts will be tried in order.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Host = 'localhost';
</del><ins>+ public $Host = 'localhost';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the default SMTP server port.
</span><span class="cx"> * @var int
</span><span class="cx"> */
</span><del>- var $Port = 25;
</del><ins>+ public $Port = 25;
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets the SMTP HELO of the message (Default is $Hostname).
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Helo = '';
</del><ins>+ public $Helo = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets connection prefix.
</span><span class="cx"> * Options are "", "ssl" or "tls"
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $SMTPSecure = "";
</del><ins>+ public $SMTPSecure = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets SMTP authentication. Utilizes the Username and Password variables.
</span><span class="cx"> * @var bool
</span><span class="cx"> */
</span><del>- var $SMTPAuth = false;
</del><ins>+ public $SMTPAuth = false;
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets SMTP username.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Username = '';
</del><ins>+ public $Username = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets SMTP password.
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $Password = '';
</del><ins>+ public $Password = '';
</ins><span class="cx">
</span><span class="cx"> /**
</span><del>- * Sets the SMTP server timeout in seconds. This function will not
- * work with the win32 version.
</del><ins>+ * Sets the SMTP server timeout in seconds.
+ * This function will not work with the win32 version.
</ins><span class="cx"> * @var int
</span><span class="cx"> */
</span><del>- var $Timeout = 10;
</del><ins>+ public $Timeout = 10;
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets SMTP class debugging on or off.
</span><span class="cx"> * @var bool
</span><span class="cx"> */
</span><del>- var $SMTPDebug = false;
</del><ins>+ public $SMTPDebug = false;
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Prevents the SMTP connection from being closed after each mail
</span><span class="lines">@@ -232,46 +235,121 @@
</span><span class="cx"> * requires an explicit call to SmtpClose().
</span><span class="cx"> * @var bool
</span><span class="cx"> */
</span><del>- var $SMTPKeepAlive = false;
</del><ins>+ public $SMTPKeepAlive = false;
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Provides the ability to have the TO field process individual
</span><span class="cx"> * emails, instead of sending to entire TO addresses
</span><span class="cx"> * @var bool
</span><span class="cx"> */
</span><del>- var $SingleTo = false;
</del><ins>+ public $SingleTo = false;
</ins><span class="cx">
</span><ins>+ /**
+ * If SingleTo is true, this provides the array to hold the email addresses
+ * @var bool
+ */
+ public $SingleToArray = array();
+
+ /**
+ * Provides the ability to change the line ending
+ * @var string
+ */
+ public $LE = "\n";
+
+ /**
+ * Used with DKIM DNS Resource Record
+ * @var string
+ */
+ public $DKIM_selector = 'phpmailer';
+
+ /**
+ * Used with DKIM DNS Resource Record
+ * optional, in format of email address 'you@yourdomain.com'
+ * @var string
+ */
+ public $DKIM_identity = '';
+
+ /**
+ * Used with DKIM DNS Resource Record
+ * optional, in format of email address 'you@yourdomain.com'
+ * @var string
+ */
+ public $DKIM_domain = '';
+
+ /**
+ * Used with DKIM DNS Resource Record
+ * optional, in format of email address 'you@yourdomain.com'
+ * @var string
+ */
+ public $DKIM_private = '';
+
+ /**
+ * Callback Action function name
+ * the function that handles the result of the send email action. Parameters:
+ * bool $result result of the send action
+ * string $to email address of the recipient
+ * string $cc cc email addresses
+ * string $bcc bcc email addresses
+ * string $subject the subject
+ * string $body the email body
+ * @var string
+ */
+ public $action_function = ''; //'callbackAction';
+
+ /**
+ * Sets the PHPMailer Version number
+ * @var string
+ */
+ public $Version = '5.1';
+
</ins><span class="cx"> /////////////////////////////////////////////////
</span><del>- // PROPERTIES, PRIVATE
</del><ins>+ // PROPERTIES, PRIVATE AND PROTECTED
</ins><span class="cx"> /////////////////////////////////////////////////
</span><span class="cx">
</span><del>- var $smtp = NULL;
- var $to = array();
- var $cc = array();
- var $bcc = array();
- var $ReplyTo = array();
- var $attachment = array();
- var $CustomHeader = array();
- var $message_type = '';
- var $boundary = array();
- var $language = array();
- var $error_count = 0;
- var $LE = "\n";
- var $sign_cert_file = "";
- var $sign_key_file = "";
- var $sign_key_pass = "";
</del><ins>+ private $smtp = NULL;
+ private $to = array();
+ private $cc = array();
+ private $bcc = array();
+ private $ReplyTo = array();
+ private $all_recipients = array();
+ private $attachment = array();
+ private $CustomHeader = array();
+ private $message_type = '';
+ private $boundary = array();
+ protected $language = array();
+ private $error_count = 0;
+ private $sign_cert_file = "";
+ private $sign_key_file = "";
+ private $sign_key_pass = "";
+ private $exceptions = false;
</ins><span class="cx">
</span><span class="cx"> /////////////////////////////////////////////////
</span><ins>+ // CONSTANTS
+ /////////////////////////////////////////////////
+
+ const STOP_MESSAGE = 0; // message only, continue processing
+ const STOP_CONTINUE = 1; // message?, likely ok to continue processing
+ const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
+
+ /////////////////////////////////////////////////
</ins><span class="cx"> // METHODS, VARIABLES
</span><span class="cx"> /////////////////////////////////////////////////
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Constructor
+ * @param boolean $exceptions Should we throw external exceptions?
+ */
+ public function __construct($exceptions = false) {
+ $this->exceptions = ($exceptions == true);
+ }
+
+ /**
</ins><span class="cx"> * Sets message type to HTML.
</span><del>- * @param bool $bool
</del><ins>+ * @param bool $ishtml
</ins><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function IsHTML($bool) {
- if($bool == true) {
</del><ins>+ public function IsHTML($ishtml = true) {
+ if ($ishtml) {
</ins><span class="cx"> $this->ContentType = 'text/html';
</span><span class="cx"> } else {
</span><span class="cx"> $this->ContentType = 'text/plain';
</span><span class="lines">@@ -282,7 +360,7 @@
</span><span class="cx"> * Sets Mailer to send message using SMTP.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function IsSMTP() {
</del><ins>+ public function IsSMTP() {
</ins><span class="cx"> $this->Mailer = 'smtp';
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -290,7 +368,7 @@
</span><span class="cx"> * Sets Mailer to send message using PHP mail() function.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function IsMail() {
</del><ins>+ public function IsMail() {
</ins><span class="cx"> $this->Mailer = 'mail';
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -298,7 +376,10 @@
</span><span class="cx"> * Sets Mailer to send message using the $Sendmail program.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function IsSendmail() {
</del><ins>+ public function IsSendmail() {
+ if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
+ $this->Sendmail = '/var/qmail/bin/sendmail';
+ }
</ins><span class="cx"> $this->Mailer = 'sendmail';
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -306,8 +387,10 @@
</span><span class="cx"> * Sets Mailer to send message using the qmail MTA.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function IsQmail() {
- $this->Sendmail = '/var/qmail/bin/sendmail';
</del><ins>+ public function IsQmail() {
+ if (stristr(ini_get('sendmail_path'), 'qmail')) {
+ $this->Sendmail = '/var/qmail/bin/sendmail';
+ }
</ins><span class="cx"> $this->Mailer = 'sendmail';
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -319,54 +402,136 @@
</span><span class="cx"> * Adds a "To" address.
</span><span class="cx"> * @param string $address
</span><span class="cx"> * @param string $name
</span><del>- * @return void
</del><ins>+ * @return boolean true on success, false if address already used
</ins><span class="cx"> */
</span><del>- function AddAddress($address, $name = '') {
- $cur = count($this->to);
- $this->to[$cur][0] = trim($address);
- $this->to[$cur][1] = $name;
</del><ins>+ public function AddAddress($address, $name = '') {
+ return $this->AddAnAddress('to', $address, $name);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Adds a "Cc" address. Note: this function works
- * with the SMTP mailer on win32, not with the "mail"
- * mailer.
</del><ins>+ * Adds a "Cc" address.
+ * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
</ins><span class="cx"> * @param string $address
</span><span class="cx"> * @param string $name
</span><del>- * @return void
</del><ins>+ * @return boolean true on success, false if address already used
</ins><span class="cx"> */
</span><del>- function AddCC($address, $name = '') {
- $cur = count($this->cc);
- $this->cc[$cur][0] = trim($address);
- $this->cc[$cur][1] = $name;
</del><ins>+ public function AddCC($address, $name = '') {
+ return $this->AddAnAddress('cc', $address, $name);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Adds a "Bcc" address. Note: this function works
- * with the SMTP mailer on win32, not with the "mail"
- * mailer.
</del><ins>+ * Adds a "Bcc" address.
+ * Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.
</ins><span class="cx"> * @param string $address
</span><span class="cx"> * @param string $name
</span><del>- * @return void
</del><ins>+ * @return boolean true on success, false if address already used
</ins><span class="cx"> */
</span><del>- function AddBCC($address, $name = '') {
- $cur = count($this->bcc);
- $this->bcc[$cur][0] = trim($address);
- $this->bcc[$cur][1] = $name;
</del><ins>+ public function AddBCC($address, $name = '') {
+ return $this->AddAnAddress('bcc', $address, $name);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Adds a "Reply-To" address.
</del><ins>+ * Adds a "Reply-to" address.
</ins><span class="cx"> * @param string $address
</span><span class="cx"> * @param string $name
</span><del>- * @return void
</del><ins>+ * @return boolean
</ins><span class="cx"> */
</span><del>- function AddReplyTo($address, $name = '') {
- $cur = count($this->ReplyTo);
- $this->ReplyTo[$cur][0] = trim($address);
- $this->ReplyTo[$cur][1] = $name;
</del><ins>+ public function AddReplyTo($address, $name = '') {
+ return $this->AddAnAddress('ReplyTo', $address, $name);
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Adds an address to one of the recipient arrays
+ * Addresses that have been added already return false, but do not throw exceptions
+ * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
+ * @param string $address The email address to send to
+ * @param string $name
+ * @return boolean true on success, false if address already used or invalid in some way
+ * @access private
+ */
+ private function AddAnAddress($kind, $address, $name = '') {
+ if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
+ echo 'Invalid recipient array: ' . kind;
+ return false;
+ }
+ $address = trim($address);
+ $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
+ if (!self::ValidateAddress($address)) {
+ $this->SetError($this->Lang('invalid_address').': '. $address);
+ if ($this->exceptions) {
+ throw new phpmailerException($this->Lang('invalid_address').': '.$address);
+ }
+ echo $this->Lang('invalid_address').': '.$address;
+ return false;
+ }
+ if ($kind != 'ReplyTo') {
+ if (!isset($this->all_recipients[strtolower($address)])) {
+ array_push($this->$kind, array($address, $name));
+ $this->all_recipients[strtolower($address)] = true;
+ return true;
+ }
+ } else {
+ if (!array_key_exists(strtolower($address), $this->ReplyTo)) {
+ $this->ReplyTo[strtolower($address)] = array($address, $name);
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * Set the From and FromName properties
+ * @param string $address
+ * @param string $name
+ * @return boolean
+ */
+ public function SetFrom($address, $name = '',$auto=1) {
+ $address = trim($address);
+ $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
+ if (!self::ValidateAddress($address)) {
+ $this->SetError($this->Lang('invalid_address').': '. $address);
+ if ($this->exceptions) {
+ throw new phpmailerException($this->Lang('invalid_address').': '.$address);
+ }
+ echo $this->Lang('invalid_address').': '.$address;
+ return false;
+ }
+ $this->From = $address;
+ $this->FromName = $name;
+ if ($auto) {
+ if (empty($this->ReplyTo)) {
+ $this->AddAnAddress('ReplyTo', $address, $name);
+ }
+ if (empty($this->Sender)) {
+ $this->Sender = $address;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Check that a string looks roughly like an email address should
+ * Static so it can be used without instantiation
+ * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator
+ * Conforms approximately to RFC2822
+ * @link http://www.hexillion.com/samples/#Regex Original pattern found here
+ * @param string $address The email address to check
+ * @return boolean
+ * @static
+ * @access public
+ */
+ public static function ValidateAddress($address) {
+ if (function_exists('filter_var')) { //Introduced in PHP 5.2
+ if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
+ return false;
+ } else {
+ return true;
+ }
+ } else {
+ return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
+ }
+ }
+
</ins><span class="cx"> /////////////////////////////////////////////////
</span><span class="cx"> // METHODS, MAIL SENDING
</span><span class="cx"> /////////////////////////////////////////////////
</span><span class="lines">@@ -377,257 +542,297 @@
</span><span class="cx"> * variable to view description of the error.
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Send() {
- $header = '';
- $body = '';
- $result = true;
</del><ins>+ public function Send() {
+ try {
+ if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
+ throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
+ }
</ins><span class="cx">
</span><del>- if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
- $this->SetError($this->Lang('provide_address'));
- return false;
- }
</del><ins>+ // Set whether the message is multipart/alternative
+ if(!empty($this->AltBody)) {
+ $this->ContentType = 'multipart/alternative';
+ }
</ins><span class="cx">
</span><del>- /* Set whether the message is multipart/alternative */
- if(!empty($this->AltBody)) {
- $this->ContentType = 'multipart/alternative';
- }
</del><ins>+ $this->error_count = 0; // reset errors
+ $this->SetMessageType();
+ $header = $this->CreateHeader();
+ $body = $this->CreateBody();
</ins><span class="cx">
</span><del>- $this->error_count = 0; // reset errors
- $this->SetMessageType();
- $header .= $this->CreateHeader();
- $body = $this->CreateBody();
</del><ins>+ if (empty($this->Body)) {
+ throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
+ }
</ins><span class="cx">
</span><del>- if($body == '') {
</del><ins>+ // digitally sign with DKIM if enabled
+ if ($this->DKIM_domain && $this->DKIM_private) {
+ $header_dkim = $this->DKIM_Add($header,$this->Subject,$body);
+ $header = str_replace("\r\n","\n",$header_dkim) . $header;
+ }
+
+ // Choose the mailer and send through it
+ switch($this->Mailer) {
+ case 'sendmail':
+ return $this->SendmailSend($header, $body);
+ case 'smtp':
+ return $this->SmtpSend($header, $body);
+ default:
+ return $this->MailSend($header, $body);
+ }
+
+ } catch (phpmailerException $e) {
+ $this->SetError($e->getMessage());
+ if ($this->exceptions) {
+ throw $e;
+ }
+ echo $e->getMessage()."\n";
</ins><span class="cx"> return false;
</span><span class="cx"> }
</span><del>-
- /* Choose the mailer */
- switch($this->Mailer) {
- case 'sendmail':
- $result = $this->SendmailSend($header, $body);
- break;
- case 'smtp':
- $result = $this->SmtpSend($header, $body);
- break;
- case 'mail':
- $result = $this->MailSend($header, $body);
- break;
- default:
- $result = $this->MailSend($header, $body);
- break;
- //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
- //$result = false;
- //break;
- }
-
- return $result;
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sends mail using the $Sendmail program.
</span><del>- * @access private
</del><ins>+ * @param string $header The message headers
+ * @param string $body The message body
+ * @access protected
</ins><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function SendmailSend($header, $body) {
</del><ins>+ protected function SendmailSend($header, $body) {
</ins><span class="cx"> if ($this->Sender != '') {
</span><span class="cx"> $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
</span><span class="cx"> } else {
</span><span class="cx"> $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
</span><span class="cx"> }
</span><del>-
- if(!@$mail = popen($sendmail, 'w')) {
- $this->SetError($this->Lang('execute') . $this->Sendmail);
- return false;
</del><ins>+ if ($this->SingleTo === true) {
+ foreach ($this->SingleToArray as $key => $val) {
+ if(!@$mail = popen($sendmail, 'w')) {
+ throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
+ }
+ fputs($mail, "To: " . $val . "\n");
+ fputs($mail, $header);
+ fputs($mail, $body);
+ $result = pclose($mail);
+ // implement call back function if it exists
+ $isSent = ($result == 0) ? 1 : 0;
+ $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
+ if($result != 0) {
+ throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
+ }
+ }
+ } else {
+ if(!@$mail = popen($sendmail, 'w')) {
+ throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
+ }
+ fputs($mail, $header);
+ fputs($mail, $body);
+ $result = pclose($mail);
+ // implement call back function if it exists
+ $isSent = ($result == 0) ? 1 : 0;
+ $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
+ if($result != 0) {
+ throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
+ }
</ins><span class="cx"> }
</span><del>-
- fputs($mail, $header);
- fputs($mail, $body);
-
- $result = pclose($mail);
- if (version_compare(phpversion(), '4.2.3') == -1) {
- $result = $result >> 8 & 0xFF;
- }
- if($result != 0) {
- $this->SetError($this->Lang('execute') . $this->Sendmail);
- return false;
- }
</del><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sends mail using the PHP mail() function.
</span><del>- * @access private
</del><ins>+ * @param string $header The message headers
+ * @param string $body The message body
+ * @access protected
</ins><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function MailSend($header, $body) {
-
- $to = '';
- for($i = 0; $i < count($this->to); $i++) {
- if($i != 0) { $to .= ', '; }
- $to .= $this->AddrFormat($this->to[$i]);
</del><ins>+ protected function MailSend($header, $body) {
+ $toArr = array();
+ foreach($this->to as $t) {
+ $toArr[] = $this->AddrFormat($t);
</ins><span class="cx"> }
</span><ins>+ $to = implode(', ', $toArr);
</ins><span class="cx">
</span><del>- $toArr = split(',', $to);
-
</del><span class="cx"> $params = sprintf("-oi -f %s", $this->Sender);
</span><del>- if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
</del><ins>+ if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
</ins><span class="cx"> $old_from = ini_get('sendmail_from');
</span><span class="cx"> ini_set('sendmail_from', $this->Sender);
</span><span class="cx"> if ($this->SingleTo === true && count($toArr) > 1) {
</span><span class="cx"> foreach ($toArr as $key => $val) {
</span><span class="cx"> $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
</span><ins>+ // implement call back function if it exists
+ $isSent = ($rt == 1) ? 1 : 0;
+ $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
</ins><span class="cx"> }
</span><span class="cx"> } else {
</span><span class="cx"> $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
</span><ins>+ // implement call back function if it exists
+ $isSent = ($rt == 1) ? 1 : 0;
+ $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
</ins><span class="cx"> }
</span><span class="cx"> } else {
</span><span class="cx"> if ($this->SingleTo === true && count($toArr) > 1) {
</span><span class="cx"> foreach ($toArr as $key => $val) {
</span><span class="cx"> $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
</span><ins>+ // implement call back function if it exists
+ $isSent = ($rt == 1) ? 1 : 0;
+ $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
</ins><span class="cx"> }
</span><span class="cx"> } else {
</span><span class="cx"> $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
</span><ins>+ // implement call back function if it exists
+ $isSent = ($rt == 1) ? 1 : 0;
+ $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><del>-
</del><span class="cx"> if (isset($old_from)) {
</span><span class="cx"> ini_set('sendmail_from', $old_from);
</span><span class="cx"> }
</span><del>-
</del><span class="cx"> if(!$rt) {
</span><del>- $this->SetError($this->Lang('instantiate'));
- return false;
</del><ins>+ throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
</ins><span class="cx"> }
</span><del>-
</del><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Sends mail via SMTP using PhpSMTP (Author:
- * Chris Ryan). Returns bool. Returns false if there is a
- * bad MAIL FROM, RCPT, or DATA input.
- * @access private
</del><ins>+ * Sends mail via SMTP using PhpSMTP
+ * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
+ * @param string $header The message headers
+ * @param string $body The message body
+ * @uses SMTP
+ * @access protected
</ins><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function SmtpSend($header, $body) {
- include_once($this->PluginDir . 'class-smtp.php');
- $error = '';
</del><ins>+ protected function SmtpSend($header, $body) {
+ require_once $this->PluginDir . 'class-smtp.php';
</ins><span class="cx"> $bad_rcpt = array();
</span><span class="cx">
</span><span class="cx"> if(!$this->SmtpConnect()) {
</span><del>- return false;
</del><ins>+ throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL);
</ins><span class="cx"> }
</span><del>-
</del><span class="cx"> $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
</span><span class="cx"> if(!$this->smtp->Mail($smtp_from)) {
</span><del>- $error = $this->Lang('from_failed') . $smtp_from;
- $this->SetError($error);
- $this->smtp->Reset();
- return false;
</del><ins>+ throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- /* Attempt to send attach all recipients */
- for($i = 0; $i < count($this->to); $i++) {
- if(!$this->smtp->Recipient($this->to[$i][0])) {
- $bad_rcpt[] = $this->to[$i][0];
</del><ins>+ // Attempt to send attach all recipients
+ foreach($this->to as $to) {
+ if (!$this->smtp->Recipient($to[0])) {
+ $bad_rcpt[] = $to[0];
+ // implement call back function if it exists
+ $isSent = 0;
+ $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
+ } else {
+ // implement call back function if it exists
+ $isSent = 1;
+ $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><del>- for($i = 0; $i < count($this->cc); $i++) {
- if(!$this->smtp->Recipient($this->cc[$i][0])) {
- $bad_rcpt[] = $this->cc[$i][0];
</del><ins>+ foreach($this->cc as $cc) {
+ if (!$this->smtp->Recipient($cc[0])) {
+ $bad_rcpt[] = $cc[0];
+ // implement call back function if it exists
+ $isSent = 0;
+ $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
+ } else {
+ // implement call back function if it exists
+ $isSent = 1;
+ $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><del>- for($i = 0; $i < count($this->bcc); $i++) {
- if(!$this->smtp->Recipient($this->bcc[$i][0])) {
- $bad_rcpt[] = $this->bcc[$i][0];
</del><ins>+ foreach($this->bcc as $bcc) {
+ if (!$this->smtp->Recipient($bcc[0])) {
+ $bad_rcpt[] = $bcc[0];
+ // implement call back function if it exists
+ $isSent = 0;
+ $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
+ } else {
+ // implement call back function if it exists
+ $isSent = 1;
+ $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if(count($bad_rcpt) > 0) { // Create error message
- for($i = 0; $i < count($bad_rcpt); $i++) {
- if($i != 0) {
- $error .= ', ';
- }
- $error .= $bad_rcpt[$i];
- }
- $error = $this->Lang('recipients_failed') . $error;
- $this->SetError($error);
- $this->smtp->Reset();
- return false;
</del><ins>+
+ if (count($bad_rcpt) > 0 ) { //Create error message for any bad addresses
+ $badaddresses = implode(', ', $bad_rcpt);
+ throw new phpmailerException($this->Lang('recipients_failed') . $badaddresses);
</ins><span class="cx"> }
</span><del>-
</del><span class="cx"> if(!$this->smtp->Data($header . $body)) {
</span><del>- $this->SetError($this->Lang('data_not_accepted'));
- $this->smtp->Reset();
- return false;
</del><ins>+ throw new phpmailerException($this->Lang('data_not_accepted'), self::STOP_CRITICAL);
</ins><span class="cx"> }
</span><span class="cx"> if($this->SMTPKeepAlive == true) {
</span><span class="cx"> $this->smtp->Reset();
</span><del>- } else {
- $this->SmtpClose();
</del><span class="cx"> }
</span><del>-
</del><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Initiates a connection to an SMTP server. Returns false if the
- * operation failed.
- * @access private
</del><ins>+ * Initiates a connection to an SMTP server.
+ * Returns false if the operation failed.
+ * @uses SMTP
+ * @access public
</ins><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function SmtpConnect() {
- if($this->smtp == NULL) {
</del><ins>+ public function SmtpConnect() {
+ if(is_null($this->smtp)) {
</ins><span class="cx"> $this->smtp = new SMTP();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $this->smtp->do_debug = $this->SMTPDebug;
</span><span class="cx"> $hosts = explode(';', $this->Host);
</span><span class="cx"> $index = 0;
</span><del>- $connection = ($this->smtp->Connected());
</del><ins>+ $connection = $this->smtp->Connected();
</ins><span class="cx">
</span><del>- /* Retry while there is no connection */
- while($index < count($hosts) && $connection == false) {
- $hostinfo = array();
- if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
- $host = $hostinfo[1];
- $port = $hostinfo[2];
- } else {
- $host = $hosts[$index];
- $port = $this->Port;
- }
-
- if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
- if ($this->Helo != '') {
- $this->smtp->Hello($this->Helo);
</del><ins>+ // Retry while there is no connection
+ try {
+ while($index < count($hosts) && !$connection) {
+ $hostinfo = array();
+ if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
+ $host = $hostinfo[1];
+ $port = $hostinfo[2];
</ins><span class="cx"> } else {
</span><del>- $this->smtp->Hello($this->ServerHostname());
</del><ins>+ $host = $hosts[$index];
+ $port = $this->Port;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- $connection = true;
- if($this->SMTPAuth) {
- if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
- $this->SetError($this->Lang('authenticate'));
- $this->smtp->Reset();
- $connection = false;
</del><ins>+ $tls = ($this->SMTPSecure == 'tls');
+ $ssl = ($this->SMTPSecure == 'ssl');
+
+ if ($this->smtp->Connect(($ssl ? 'ssl://':'').$host, $port, $this->Timeout)) {
+
+ $hello = ($this->Helo != '' ? $this->Helo : $this->ServerHostname());
+ $this->smtp->Hello($hello);
+
+ if ($tls) {
+ if (!$this->smtp->StartTLS()) {
+ throw new phpmailerException($this->Lang('tls'));
+ }
+
+ //We must resend HELO after tls negotiation
+ $this->smtp->Hello($hello);
</ins><span class="cx"> }
</span><ins>+
+ $connection = true;
+ if ($this->SMTPAuth) {
+ if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
+ throw new phpmailerException($this->Lang('authenticate'));
+ }
+ }
</ins><span class="cx"> }
</span><ins>+ $index++;
+ if (!$connection) {
+ throw new phpmailerException($this->Lang('connect_host'));
+ }
</ins><span class="cx"> }
</span><del>- $index++;
</del><ins>+ } catch (phpmailerException $e) {
+ $this->smtp->Reset();
+ throw $e;
</ins><span class="cx"> }
</span><del>- if(!$connection) {
- $this->SetError($this->Lang('connect_host'));
- }
-
- return $connection;
</del><ins>+ return true;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Closes the active SMTP session if one exists.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function SmtpClose() {
- if($this->smtp != NULL) {
</del><ins>+ public function SmtpClose() {
+ if(!is_null($this->smtp)) {
</ins><span class="cx"> if($this->smtp->Connected()) {
</span><span class="cx"> $this->smtp->Quit();
</span><span class="cx"> $this->smtp->Close();
</span><span class="lines">@@ -636,38 +841,48 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Sets the language for all class error messages. Returns false
- * if it cannot load the language file. The default language type
- * is English.
- * @param string $lang_type Type of language (e.g. Portuguese: "br")
- * @param string $lang_path Path to the language file directory
- * @access public
- * @return bool
- */
- function SetLanguage($lang_type, $lang_path = 'language/') {
- if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
- include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
- } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
- include($lang_path.'phpmailer.lang-en.php');
- } else {
- $PHPMAILER_LANG = array();
- $PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' .
- $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
- $PHPMAILER_LANG["execute"] = 'Could not execute: ';
- $PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
- $PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
- $PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
- $PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' .
- $PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
- $PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
- $PHPMAILER_LANG["file_access"] = 'Could not access file: ';
- $PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: ';
- $PHPMAILER_LANG["encoding"] = 'Unknown encoding: ';
- $PHPMAILER_LANG["signing"] = 'Signing Error: ';
</del><ins>+ * Sets the language for all class error messages.
+ * Returns false if it cannot load the language file. The default language is English.
+ * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
+ * @param string $lang_path Path to the language file directory
+ * @access public
+ */
+ function SetLanguage($langcode = 'en', $lang_path = 'language/') {
+ //Define full set of translatable strings
+ $PHPMAILER_LANG = array(
+ 'provide_address' => 'You must provide at least one recipient email address.',
+ 'mailer_not_supported' => ' mailer is not supported.',
+ 'execute' => 'Could not execute: ',
+ 'instantiate' => 'Could not instantiate mail function.',
+ 'authenticate' => 'SMTP Error: Could not authenticate.',
+ 'from_failed' => 'The following From address failed: ',
+ 'recipients_failed' => 'SMTP Error: The following recipients failed: ',
+ 'data_not_accepted' => 'SMTP Error: Data not accepted.',
+ 'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
+ 'file_access' => 'Could not access file: ',
+ 'file_open' => 'File Error: Could not open file: ',
+ 'encoding' => 'Unknown encoding: ',
+ 'signing' => 'Signing Error: ',
+ 'smtp_error' => 'SMTP server error: ',
+ 'empty_message' => 'Message body empty',
+ 'invalid_address' => 'Invalid address',
+ 'variable_set' => 'Cannot set or reset variable: '
+ );
+ //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
+ $l = true;
+ if ($langcode != 'en') { //There is no English translation file
+ $l = @include $lang_path.'phpmailer.lang-'.$langcode.'.php';
</ins><span class="cx"> }
</span><span class="cx"> $this->language = $PHPMAILER_LANG;
</span><ins>+ return ($l == true); //Returns false if language not found
+ }
</ins><span class="cx">
</span><del>- return true;
</del><ins>+ /**
+ * Return the current array of language strings
+ * @return array
+ */
+ public function GetTranslations() {
+ return $this->language;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /////////////////////////////////////////////////
</span><span class="lines">@@ -676,17 +891,16 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Creates recipient headers.
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function AddrAppend($type, $addr) {
</del><ins>+ public function AddrAppend($type, $addr) {
</ins><span class="cx"> $addr_str = $type . ': ';
</span><del>- $addr_str .= $this->AddrFormat($addr[0]);
- if(count($addr) > 1) {
- for($i = 1; $i < count($addr); $i++) {
- $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
- }
</del><ins>+ $addresses = array();
+ foreach ($addr as $a) {
+ $addresses[] = $this->AddrFormat($a);
</ins><span class="cx"> }
</span><ins>+ $addr_str .= implode(', ', $addresses);
</ins><span class="cx"> $addr_str .= $this->LE;
</span><span class="cx">
</span><span class="cx"> return $addr_str;
</span><span class="lines">@@ -694,27 +908,28 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Formats an address correctly.
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function AddrFormat($addr) {
- if(empty($addr[1])) {
- $formatted = $this->SecureHeader($addr[0]);
</del><ins>+ public function AddrFormat($addr) {
+ if (empty($addr[1])) {
+ return $this->SecureHeader($addr[0]);
</ins><span class="cx"> } else {
</span><del>- $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
</del><ins>+ return $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
</ins><span class="cx"> }
</span><del>-
- return $formatted;
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Wraps message for use with mailers that do not
</span><span class="cx"> * automatically perform wrapping and for quoted-printable.
</span><span class="cx"> * Original written by philippe.
</span><del>- * @access private
</del><ins>+ * @param string $message The message to wrap
+ * @param integer $length The line length to wrap to
+ * @param boolean $qp_mode Whether to run in Quoted-Printable mode
+ * @access public
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function WrapText($message, $length, $qp_mode = false) {
</del><ins>+ public function WrapText($message, $length, $qp_mode = false) {
</ins><span class="cx"> $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
</span><span class="cx"> // If utf-8 encoding is used, we will need to make sure we don't
</span><span class="cx"> // split multibyte characters when we wrap
</span><span class="lines">@@ -791,12 +1006,12 @@
</span><span class="cx"> * Finds last character boundary prior to maxLength in a utf-8
</span><span class="cx"> * quoted (printable) encoded string.
</span><span class="cx"> * Original written by Colin Brown.
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @param string $encodedText utf-8 QP text
</span><span class="cx"> * @param int $maxLength find last character boundary prior to this length
</span><span class="cx"> * @return int
</span><span class="cx"> */
</span><del>- function UTF8CharBoundary($encodedText, $maxLength) {
</del><ins>+ public function UTF8CharBoundary($encodedText, $maxLength) {
</ins><span class="cx"> $foundSplitPos = false;
</span><span class="cx"> $lookBack = 3;
</span><span class="cx"> while (!$foundSplitPos) {
</span><span class="lines">@@ -828,19 +1043,19 @@
</span><span class="cx"> return $maxLength;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+
</ins><span class="cx"> /**
</span><span class="cx"> * Set the body wrapping.
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function SetWordWrap() {
</del><ins>+ public function SetWordWrap() {
</ins><span class="cx"> if($this->WordWrap < 1) {
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> switch($this->message_type) {
</span><span class="cx"> case 'alt':
</span><del>- /* fall through */
</del><span class="cx"> case 'alt_attachments':
</span><span class="cx"> $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
</span><span class="cx"> break;
</span><span class="lines">@@ -852,30 +1067,36 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Assembles message header.
</span><del>- * @access private
- * @return string
</del><ins>+ * @access public
+ * @return string The assembled header
</ins><span class="cx"> */
</span><del>- function CreateHeader() {
</del><ins>+ public function CreateHeader() {
</ins><span class="cx"> $result = '';
</span><span class="cx">
</span><del>- /* Set the boundaries */
</del><ins>+ // Set the boundaries
</ins><span class="cx"> $uniq_id = md5(uniqid(time()));
</span><span class="cx"> $this->boundary[1] = 'b1_' . $uniq_id;
</span><span class="cx"> $this->boundary[2] = 'b2_' . $uniq_id;
</span><span class="cx">
</span><del>- $result .= $this->HeaderLine('Date', $this->RFCDate());
</del><ins>+ $result .= $this->HeaderLine('Date', self::RFCDate());
</ins><span class="cx"> if($this->Sender == '') {
</span><span class="cx"> $result .= $this->HeaderLine('Return-Path', trim($this->From));
</span><span class="cx"> } else {
</span><span class="cx"> $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
</span><span class="cx"> }
</span><span class="cx">
</span><del>- /* To be created automatically by mail() */
</del><ins>+ // To be created automatically by mail()
</ins><span class="cx"> if($this->Mailer != 'mail') {
</span><del>- if(count($this->to) > 0) {
- $result .= $this->AddrAppend('To', $this->to);
- } elseif (count($this->cc) == 0) {
- $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
</del><ins>+ if ($this->SingleTo === true) {
+ foreach($this->to as $t) {
+ $this->SingleToArray[] = $this->AddrFormat($t);
+ }
+ } else {
+ if(count($this->to) > 0) {
+ $result .= $this->AddrAppend('To', $this->to);
+ } elseif (count($this->cc) == 0) {
+ $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
+ }
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -884,21 +1105,21 @@
</span><span class="cx"> $from[0][1] = $this->FromName;
</span><span class="cx"> $result .= $this->AddrAppend('From', $from);
</span><span class="cx">
</span><del>- /* sendmail and mail() extract Cc from the header before sending */
- if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
</del><ins>+ // sendmail and mail() extract Cc from the header before sending
+ if(count($this->cc) > 0) {
</ins><span class="cx"> $result .= $this->AddrAppend('Cc', $this->cc);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- /* sendmail and mail() extract Bcc from the header before sending */
</del><ins>+ // sendmail and mail() extract Bcc from the header before sending
</ins><span class="cx"> if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
</span><span class="cx"> $result .= $this->AddrAppend('Bcc', $this->bcc);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if(count($this->ReplyTo) > 0) {
</span><del>- $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
</del><ins>+ $result .= $this->AddrAppend('Reply-to', $this->ReplyTo);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- /* mail() sets the subject itself */
</del><ins>+ // mail() sets the subject itself
</ins><span class="cx"> if($this->Mailer != 'mail') {
</span><span class="cx"> $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
</span><span class="cx"> }
</span><span class="lines">@@ -909,7 +1130,7 @@
</span><span class="cx"> $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
</span><span class="cx"> }
</span><span class="cx"> $result .= $this->HeaderLine('X-Priority', $this->Priority);
</span><del>- $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
</del><ins>+ $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)');
</ins><span class="cx">
</span><span class="cx"> if($this->ConfirmReadingTo != '') {
</span><span class="cx"> $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
</span><span class="lines">@@ -929,10 +1150,10 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Returns the message MIME.
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function GetMailMIME() {
</del><ins>+ public function GetMailMIME() {
</ins><span class="cx"> $result = '';
</span><span class="cx"> switch($this->message_type) {
</span><span class="cx"> case 'plain':
</span><span class="lines">@@ -940,7 +1161,6 @@
</span><span class="cx"> $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
</span><span class="cx"> break;
</span><span class="cx"> case 'attachments':
</span><del>- /* fall through */
</del><span class="cx"> case 'alt_attachments':
</span><span class="cx"> if($this->InlineImageExists()){
</span><span class="cx"> $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
</span><span class="lines">@@ -964,84 +1184,83 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Assembles the message body. Returns an empty string on failure.
</span><del>- * @access private
- * @return string
</del><ins>+ * @access public
+ * @return string The assembled message body
</ins><span class="cx"> */
</span><del>- function CreateBody() {
- $result = '';
</del><ins>+ public function CreateBody() {
+ $body = '';
+
</ins><span class="cx"> if ($this->sign_key_file) {
</span><del>- $result .= $this->GetMailMIME();
</del><ins>+ $body .= $this->GetMailMIME();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $this->SetWordWrap();
</span><span class="cx">
</span><span class="cx"> switch($this->message_type) {
</span><span class="cx"> case 'alt':
</span><del>- $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
- $result .= $this->EncodeString($this->AltBody, $this->Encoding);
- $result .= $this->LE.$this->LE;
- $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
- $result .= $this->EncodeString($this->Body, $this->Encoding);
- $result .= $this->LE.$this->LE;
- $result .= $this->EndBoundary($this->boundary[1]);
</del><ins>+ $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
+ $body .= $this->EncodeString($this->AltBody, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
+ $body .= $this->EncodeString($this->Body, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->EndBoundary($this->boundary[1]);
</ins><span class="cx"> break;
</span><span class="cx"> case 'plain':
</span><del>- $result .= $this->EncodeString($this->Body, $this->Encoding);
</del><ins>+ $body .= $this->EncodeString($this->Body, $this->Encoding);
</ins><span class="cx"> break;
</span><span class="cx"> case 'attachments':
</span><del>- $result .= $this->GetBoundary($this->boundary[1], '', '', '');
- $result .= $this->EncodeString($this->Body, $this->Encoding);
- $result .= $this->LE;
- $result .= $this->AttachAll();
</del><ins>+ $body .= $this->GetBoundary($this->boundary[1], '', '', '');
+ $body .= $this->EncodeString($this->Body, $this->Encoding);
+ $body .= $this->LE;
+ $body .= $this->AttachAll();
</ins><span class="cx"> break;
</span><span class="cx"> case 'alt_attachments':
</span><del>- $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
- $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
- $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
- $result .= $this->EncodeString($this->AltBody, $this->Encoding);
- $result .= $this->LE.$this->LE;
- $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
- $result .= $this->EncodeString($this->Body, $this->Encoding);
- $result .= $this->LE.$this->LE;
- $result .= $this->EndBoundary($this->boundary[2]);
- $result .= $this->AttachAll();
</del><ins>+ $body .= sprintf("--%s%s", $this->boundary[1], $this->LE);
+ $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
+ $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
+ $body .= $this->EncodeString($this->AltBody, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
+ $body .= $this->EncodeString($this->Body, $this->Encoding);
+ $body .= $this->LE.$this->LE;
+ $body .= $this->EndBoundary($this->boundary[2]);
+ $body .= $this->AttachAll();
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if($this->IsError()) {
- $result = '';
- } else if ($this->sign_key_file) {
- $file = tempnam("", "mail");
- $fp = fopen($file, "w");
- fwrite($fp, $result);
- fclose($fp);
- $signed = tempnam("", "signed");
-
- if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
- $fp = fopen($signed, "r");
- $result = fread($fp, filesize($this->sign_key_file));
- $result = '';
- while(!feof($fp)){
- $result = $result . fread($fp, 1024);
</del><ins>+ if ($this->IsError()) {
+ $body = '';
+ } elseif ($this->sign_key_file) {
+ try {
+ $file = tempnam('', 'mail');
+ file_put_contents($file, $body); //TODO check this worked
+ $signed = tempnam("", "signed");
+ if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
+ @unlink($file);
+ @unlink($signed);
+ $body = file_get_contents($signed);
+ } else {
+ @unlink($file);
+ @unlink($signed);
+ throw new phpmailerException($this->Lang("signing").openssl_error_string());
</ins><span class="cx"> }
</span><del>- fclose($fp);
- } else {
- $this->SetError($this->Lang("signing").openssl_error_string());
- $result = '';
</del><ins>+ } catch (phpmailerException $e) {
+ $body = '';
+ if ($this->exceptions) {
+ throw $e;
+ }
</ins><span class="cx"> }
</span><del>-
- unlink($file);
- unlink($signed);
</del><span class="cx"> }
</span><span class="cx">
</span><del>- return $result;
</del><ins>+ return $body;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Returns the start of a message boundary.
</span><span class="cx"> * @access private
</span><span class="cx"> */
</span><del>- function GetBoundary($boundary, $charSet, $contentType, $encoding) {
</del><ins>+ private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
</ins><span class="cx"> $result = '';
</span><span class="cx"> if($charSet == '') {
</span><span class="cx"> $charSet = $this->CharSet;
</span><span class="lines">@@ -1065,7 +1284,7 @@
</span><span class="cx"> * Returns the end of a message boundary.
</span><span class="cx"> * @access private
</span><span class="cx"> */
</span><del>- function EndBoundary($boundary) {
</del><ins>+ private function EndBoundary($boundary) {
</ins><span class="cx"> return $this->LE . '--' . $boundary . '--' . $this->LE;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1074,7 +1293,7 @@
</span><span class="cx"> * @access private
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function SetMessageType() {
</del><ins>+ private function SetMessageType() {
</ins><span class="cx"> if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
</span><span class="cx"> $this->message_type = 'plain';
</span><span class="cx"> } else {
</span><span class="lines">@@ -1090,20 +1309,21 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- /* Returns a formatted header line.
- * @access private
</del><ins>+ /**
+ * Returns a formatted header line.
+ * @access public
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function HeaderLine($name, $value) {
</del><ins>+ public function HeaderLine($name, $value) {
</ins><span class="cx"> return $name . ': ' . $value . $this->LE;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Returns a formatted mail line.
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function TextLine($value) {
</del><ins>+ public function TextLine($value) {
</ins><span class="cx"> return $value . $this->LE;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1121,56 +1341,80 @@
</span><span class="cx"> * @param string $type File extension (MIME) type.
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
- if(!@is_file($path)) {
- $this->SetError($this->Lang('file_access') . $path);
- return false;
- }
</del><ins>+ public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
+ try {
+ if ( !@is_file($path) ) {
+ throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
+ }
+ $filename = basename($path);
+ if ( $name == '' ) {
+ $name = $filename;
+ }
</ins><span class="cx">
</span><del>- $filename = basename($path);
- if($name == '') {
- $name = $filename;
</del><ins>+ $this->attachment[] = array(
+ 0 => $path,
+ 1 => $filename,
+ 2 => $name,
+ 3 => $encoding,
+ 4 => $type,
+ 5 => false, // isStringAttachment
+ 6 => 'attachment',
+ 7 => 0
+ );
+
+ } catch (phpmailerException $e) {
+ $this->SetError($e->getMessage());
+ if ($this->exceptions) {
+ throw $e;
+ }
+ echo $e->getMessage()."\n";
+ if ( $e->getCode() == self::STOP_CRITICAL ) {
+ return false;
+ }
</ins><span class="cx"> }
</span><del>-
- $cur = count($this->attachment);
- $this->attachment[$cur][0] = $path;
- $this->attachment[$cur][1] = $filename;
- $this->attachment[$cur][2] = $name;
- $this->attachment[$cur][3] = $encoding;
- $this->attachment[$cur][4] = $type;
- $this->attachment[$cur][5] = false; // isStringAttachment
- $this->attachment[$cur][6] = 'attachment';
- $this->attachment[$cur][7] = 0;
-
</del><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Return the current array of attachments
+ * @return array
+ */
+ public function GetAttachments() {
+ return $this->attachment;
+ }
+
+ /**
</ins><span class="cx"> * Attaches all fs, string, and binary attachments to the message.
</span><span class="cx"> * Returns an empty string on failure.
</span><span class="cx"> * @access private
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function AttachAll() {
- /* Return text of body */
</del><ins>+ private function AttachAll() {
+ // Return text of body
</ins><span class="cx"> $mime = array();
</span><ins>+ $cidUniq = array();
+ $incl = array();
</ins><span class="cx">
</span><del>- /* Add all attachments */
- for($i = 0; $i < count($this->attachment); $i++) {
- /* Check for string attachment */
- $bString = $this->attachment[$i][5];
</del><ins>+ // Add all attachments
+ foreach ($this->attachment as $attachment) {
+ // Check for string attachment
+ $bString = $attachment[5];
</ins><span class="cx"> if ($bString) {
</span><del>- $string = $this->attachment[$i][0];
</del><ins>+ $string = $attachment[0];
</ins><span class="cx"> } else {
</span><del>- $path = $this->attachment[$i][0];
</del><ins>+ $path = $attachment[0];
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- $filename = $this->attachment[$i][1];
- $name = $this->attachment[$i][2];
- $encoding = $this->attachment[$i][3];
- $type = $this->attachment[$i][4];
- $disposition = $this->attachment[$i][6];
- $cid = $this->attachment[$i][7];
</del><ins>+ if (in_array($attachment[0], $incl)) { continue; }
+ $filename = $attachment[1];
+ $name = $attachment[2];
+ $encoding = $attachment[3];
+ $type = $attachment[4];
+ $disposition = $attachment[6];
+ $cid = $attachment[7];
+ $incl[] = $attachment[0];
+ if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
+ $cidUniq[$cid] = true;
</ins><span class="cx">
</span><span class="cx"> $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
</span><span class="cx"> $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
</span><span class="lines">@@ -1182,7 +1426,7 @@
</span><span class="cx">
</span><span class="cx"> $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
</span><span class="cx">
</span><del>- /* Encode as string attachment */
</del><ins>+ // Encode as string attachment
</ins><span class="cx"> if($bString) {
</span><span class="cx"> $mime[] = $this->EncodeString($string, $encoding);
</span><span class="cx"> if($this->IsError()) {
</span><span class="lines">@@ -1204,42 +1448,56 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Encodes attachment in requested format. Returns an
- * empty string on failure.
</del><ins>+ * Encodes attachment in requested format.
+ * Returns an empty string on failure.
+ * @param string $path The full path to the file
+ * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
+ * @see EncodeFile()
</ins><span class="cx"> * @access private
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function EncodeFile ($path, $encoding = 'base64') {
- if(!@$fd = fopen($path, 'rb')) {
- $this->SetError($this->Lang('file_open') . $path);
</del><ins>+ private function EncodeFile($path, $encoding = 'base64') {
+ try {
+ if (!is_readable($path)) {
+ throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
+ }
+ if (function_exists('get_magic_quotes')) {
+ function get_magic_quotes() {
+ return false;
+ }
+ }
+ if (PHP_VERSION < 6) {
+ $magic_quotes = get_magic_quotes_runtime();
+ set_magic_quotes_runtime(0);
+ }
+ $file_buffer = file_get_contents($path);
+ $file_buffer = $this->EncodeString($file_buffer, $encoding);
+ if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
+ return $file_buffer;
+ } catch (Exception $e) {
+ $this->SetError($e->getMessage());
</ins><span class="cx"> return '';
</span><span class="cx"> }
</span><del>- $magic_quotes = get_magic_quotes_runtime();
- set_magic_quotes_runtime(0);
- $file_buffer = fread($fd, filesize($path));
- $file_buffer = $this->EncodeString($file_buffer, $encoding);
- fclose($fd);
- set_magic_quotes_runtime($magic_quotes);
-
- return $file_buffer;
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Encodes string to requested format. Returns an
- * empty string on failure.
- * @access private
</del><ins>+ * Encodes string to requested format.
+ * Returns an empty string on failure.
+ * @param string $str The text to encode
+ * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
+ * @access public
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function EncodeString ($str, $encoding = 'base64') {
</del><ins>+ public function EncodeString ($str, $encoding = 'base64') {
</ins><span class="cx"> $encoded = '';
</span><span class="cx"> switch(strtolower($encoding)) {
</span><span class="cx"> case 'base64':
</span><del>- /* chunk_split is found in PHP >= 3.0.6 */
</del><span class="cx"> $encoded = chunk_split(base64_encode($str), 76, $this->LE);
</span><span class="cx"> break;
</span><span class="cx"> case '7bit':
</span><span class="cx"> case '8bit':
</span><span class="cx"> $encoded = $this->FixEOL($str);
</span><ins>+ //Make sure it ends with a line break
</ins><span class="cx"> if (substr($encoded, -(strlen($this->LE))) != $this->LE)
</span><span class="cx"> $encoded .= $this->LE;
</span><span class="cx"> break;
</span><span class="lines">@@ -1257,17 +1515,17 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Encode a header string to best of Q, B, quoted or none.
- * @access private
</del><ins>+ * Encode a header string to best (shortest) of Q, B, quoted or none.
+ * @access public
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function EncodeHeader ($str, $position = 'text') {
</del><ins>+ public function EncodeHeader($str, $position = 'text') {
</ins><span class="cx"> $x = 0;
</span><span class="cx">
</span><span class="cx"> switch (strtolower($position)) {
</span><span class="cx"> case 'phrase':
</span><span class="cx"> if (!preg_match('/[\200-\377]/', $str)) {
</span><del>- /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
</del><ins>+ // Can't use addslashes as we don't know what value has magic_quotes_sybase
</ins><span class="cx"> $encoded = addcslashes($str, "\0..\37\177\\\"");
</span><span class="cx"> if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
</span><span class="cx"> return ($encoded);
</span><span class="lines">@@ -1279,7 +1537,7 @@
</span><span class="cx"> break;
</span><span class="cx"> case 'comment':
</span><span class="cx"> $x = preg_match_all('/[()"]/', $str, $matches);
</span><del>- /* Fall-through */
</del><ins>+ // Fall-through
</ins><span class="cx"> case 'text':
</span><span class="cx"> default:
</span><span class="cx"> $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
</span><span class="lines">@@ -1291,12 +1549,12 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $maxlen = 75 - 7 - strlen($this->CharSet);
</span><del>- /* Try to select the encoding which should produce the shortest output */
</del><ins>+ // Try to select the encoding which should produce the shortest output
</ins><span class="cx"> if (strlen($str)/3 < $x) {
</span><span class="cx"> $encoding = 'B';
</span><span class="cx"> if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
</span><del>- // Use a custom function which correctly encodes and wraps long
- // multibyte strings without breaking lines within a character
</del><ins>+ // Use a custom function which correctly encodes and wraps long
+ // multibyte strings without breaking lines within a character
</ins><span class="cx"> $encoded = $this->Base64EncodeWrapMB($str);
</span><span class="cx"> } else {
</span><span class="cx"> $encoded = base64_encode($str);
</span><span class="lines">@@ -1318,15 +1576,15 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Checks if a string contains multibyte characters.
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @param string $str multi-byte text to wrap encode
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function HasMultiBytes($str) {
</del><ins>+ public function HasMultiBytes($str) {
</ins><span class="cx"> if (function_exists('mb_strlen')) {
</span><span class="cx"> return (strlen($str) > mb_strlen($str, $this->CharSet));
</span><span class="cx"> } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
</span><del>- return False;
</del><ins>+ return false;
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1334,11 +1592,11 @@
</span><span class="cx"> * Correctly encodes and wraps long multibyte strings for mail headers
</span><span class="cx"> * without breaking lines within a character.
</span><span class="cx"> * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @param string $str multi-byte text to wrap encode
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function Base64EncodeWrapMB($str) {
</del><ins>+ public function Base64EncodeWrapMB($str) {
</ins><span class="cx"> $start = "=?".$this->CharSet."?B?";
</span><span class="cx"> $end = "?=";
</span><span class="cx"> $encoded = "";
</span><span class="lines">@@ -1371,11 +1629,14 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Encode string to quoted-printable.
- * @access private
- * @return string
- */
- function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
</del><ins>+ * Encode string to quoted-printable.
+ * Only uses standard PHP, slow, but will always work
+ * @access public
+ * @param string $string the text to encode
+ * @param integer $line_max Number of chars allowed on a line before wrapping
+ * @return string
+ */
+ public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
</ins><span class="cx"> $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
</span><span class="cx"> $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
</span><span class="cx"> $eol = "\r\n";
</span><span class="lines">@@ -1417,41 +1678,66 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Callback for converting to "=XX".
- * @access private
- * @return string
- */
- function EncodeQ_callback ($matches) {
- return sprintf('=%02X', ord($matches[1]));
</del><ins>+ * Encode string to RFC2045 (6.7) quoted-printable format
+ * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version
+ * Also results in same content as you started with after decoding
+ * @see EncodeQPphp()
+ * @access public
+ * @param string $string the text to encode
+ * @param integer $line_max Number of chars allowed on a line before wrapping
+ * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function
+ * @return string
+ * @author Marcus Bointon
+ */
+ public function EncodeQP($string, $line_max = 76, $space_conv = false) {
+ if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
+ return quoted_printable_encode($string);
+ }
+ $filters = stream_get_filters();
+ if (!in_array('convert.*', $filters)) { //Got convert stream filter?
+ return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation
+ }
+ $fp = fopen('php://temp/', 'r+');
+ $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks
+ $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE);
+ $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
+ fputs($fp, $string);
+ rewind($fp);
+ $out = stream_get_contents($fp);
+ stream_filter_remove($s);
+ $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange
+ fclose($fp);
+ return $out;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Encode string to q encoding.
</span><del>- * @access private
</del><ins>+ * @link http://tools.ietf.org/html/rfc2047
+ * @param string $str the text to encode
+ * @param string $position Where the text is going to be used, see the RFC for what that means
+ * @access public
</ins><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function EncodeQ ($str, $position = 'text') {
- /* There should not be any EOL in the string */
- $encoded = preg_replace("/[\r\n]/", '', $str);
</del><ins>+ public function EncodeQ ($str, $position = 'text') {
+ // There should not be any EOL in the string
+ $encoded = preg_replace('/[\r\n]*/', '', $str);
</ins><span class="cx">
</span><span class="cx"> switch (strtolower($position)) {
</span><span class="cx"> case 'phrase':
</span><del>- $encoded = preg_replace_callback("/([^A-Za-z0-9!*+\/ -])/",
- array('PHPMailer', 'EncodeQ_callback'), $encoded);
</del><ins>+ $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
</ins><span class="cx"> break;
</span><span class="cx"> case 'comment':
</span><del>- $encoded = preg_replace_callback("/([\(\)\"])/",
- array('PHPMailer', 'EncodeQ_callback'), $encoded);
- break;
</del><ins>+ $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
</ins><span class="cx"> case 'text':
</span><span class="cx"> default:
</span><del>- /* Replace every high ascii, control =, ? and _ characters */
- $encoded = preg_replace_callback('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/',
- array('PHPMailer', 'EncodeQ_callback'), $encoded);
</del><ins>+ // Replace every high ascii, control =, ? and _ characters
+ //TODO using /e (equivalent to eval()) is probably not a good idea
+ $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
+ "'='.sprintf('%02X', ord('\\1'))", $encoded);
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- /* Replace every spaces to _ (more readable than =20) */
</del><ins>+ // Replace every spaces to _ (more readable than =20)
</ins><span class="cx"> $encoded = str_replace(' ', '_', $encoded);
</span><span class="cx">
</span><span class="cx"> return $encoded;
</span><span class="lines">@@ -1467,17 +1753,18 @@
</span><span class="cx"> * @param string $type File extension (MIME) type.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
- /* Append to $attachment array */
- $cur = count($this->attachment);
- $this->attachment[$cur][0] = $string;
- $this->attachment[$cur][1] = $filename;
- $this->attachment[$cur][2] = $filename;
- $this->attachment[$cur][3] = $encoding;
- $this->attachment[$cur][4] = $type;
- $this->attachment[$cur][5] = true; // isString
- $this->attachment[$cur][6] = 'attachment';
- $this->attachment[$cur][7] = 0;
</del><ins>+ public function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
+ // Append to $attachment array
+ $this->attachment[] = array(
+ 0 => $string,
+ 1 => $filename,
+ 2 => basename($filename),
+ 3 => $encoding,
+ 4 => $type,
+ 5 => true, // isStringAttachment
+ 6 => 'attachment',
+ 7 => 0
+ );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -1493,47 +1780,45 @@
</span><span class="cx"> * @param string $type File extension (MIME) type.
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
</del><ins>+ public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
</ins><span class="cx">
</span><del>- if(!@is_file($path)) {
</del><ins>+ if ( !@is_file($path) ) {
</ins><span class="cx"> $this->SetError($this->Lang('file_access') . $path);
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $filename = basename($path);
</span><del>- if($name == '') {
</del><ins>+ if ( $name == '' ) {
</ins><span class="cx"> $name = $filename;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- /* Append to $attachment array */
- $cur = count($this->attachment);
- $this->attachment[$cur][0] = $path;
- $this->attachment[$cur][1] = $filename;
- $this->attachment[$cur][2] = $name;
- $this->attachment[$cur][3] = $encoding;
- $this->attachment[$cur][4] = $type;
- $this->attachment[$cur][5] = false;
- $this->attachment[$cur][6] = 'inline';
- $this->attachment[$cur][7] = $cid;
</del><ins>+ // Append to $attachment array
+ $this->attachment[] = array(
+ 0 => $path,
+ 1 => $filename,
+ 2 => $name,
+ 3 => $encoding,
+ 4 => $type,
+ 5 => false, // isStringAttachment
+ 6 => 'inline',
+ 7 => $cid
+ );
</ins><span class="cx">
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Returns true if an inline attachment is present.
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function InlineImageExists() {
- $result = false;
- for($i = 0; $i < count($this->attachment); $i++) {
- if($this->attachment[$i][6] == 'inline') {
- $result = true;
- break;
</del><ins>+ public function InlineImageExists() {
+ foreach($this->attachment as $attachment) {
+ if ($attachment[6] == 'inline') {
+ return true;
</ins><span class="cx"> }
</span><span class="cx"> }
</span><del>-
- return $result;
</del><ins>+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /////////////////////////////////////////////////
</span><span class="lines">@@ -1544,7 +1829,10 @@
</span><span class="cx"> * Clears all recipients assigned in the TO array. Returns void.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function ClearAddresses() {
</del><ins>+ public function ClearAddresses() {
+ foreach($this->to as $to) {
+ unset($this->all_recipients[strtolower($to[0])]);
+ }
</ins><span class="cx"> $this->to = array();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1552,7 +1840,10 @@
</span><span class="cx"> * Clears all recipients assigned in the CC array. Returns void.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function ClearCCs() {
</del><ins>+ public function ClearCCs() {
+ foreach($this->cc as $cc) {
+ unset($this->all_recipients[strtolower($cc[0])]);
+ }
</ins><span class="cx"> $this->cc = array();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1560,7 +1851,10 @@
</span><span class="cx"> * Clears all recipients assigned in the BCC array. Returns void.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function ClearBCCs() {
</del><ins>+ public function ClearBCCs() {
+ foreach($this->bcc as $bcc) {
+ unset($this->all_recipients[strtolower($bcc[0])]);
+ }
</ins><span class="cx"> $this->bcc = array();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1568,7 +1862,7 @@
</span><span class="cx"> * Clears all recipients assigned in the ReplyTo array. Returns void.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function ClearReplyTos() {
</del><ins>+ public function ClearReplyTos() {
</ins><span class="cx"> $this->ReplyTo = array();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1577,10 +1871,11 @@
</span><span class="cx"> * array. Returns void.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function ClearAllRecipients() {
</del><ins>+ public function ClearAllRecipients() {
</ins><span class="cx"> $this->to = array();
</span><span class="cx"> $this->cc = array();
</span><span class="cx"> $this->bcc = array();
</span><ins>+ $this->all_recipients = array();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -1588,7 +1883,7 @@
</span><span class="cx"> * attachments. Returns void.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function ClearAttachments() {
</del><ins>+ public function ClearAttachments() {
</ins><span class="cx"> $this->attachment = array();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1596,7 +1891,7 @@
</span><span class="cx"> * Clears all custom headers. Returns void.
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function ClearCustomHeaders() {
</del><ins>+ public function ClearCustomHeaders() {
</ins><span class="cx"> $this->CustomHeader = array();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1606,21 +1901,27 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Adds the error message to the error container.
</span><del>- * Returns void.
- * @access private
</del><ins>+ * @access protected
</ins><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function SetError($msg) {
</del><ins>+ protected function SetError($msg) {
</ins><span class="cx"> $this->error_count++;
</span><ins>+ if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
+ $lasterror = $this->smtp->getError();
+ if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
+ $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
+ }
+ }
</ins><span class="cx"> $this->ErrorInfo = $msg;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Returns the proper RFC 822 formatted date.
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @return string
</span><ins>+ * @static
</ins><span class="cx"> */
</span><del>- function RFCDate() {
</del><ins>+ public static function RFCDate() {
</ins><span class="cx"> $tz = date('Z');
</span><span class="cx"> $tzs = ($tz < 0) ? '-' : '+';
</span><span class="cx"> $tz = abs($tz);
</span><span class="lines">@@ -1631,40 +1932,15 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Returns the appropriate server variable. Should work with both
- * PHP 4.1.0+ as well as older versions. Returns an empty string
- * if nothing is found.
- * @access private
- * @return mixed
- */
- function ServerVar($varName) {
- global $HTTP_SERVER_VARS;
- global $HTTP_ENV_VARS;
-
- if(!isset($_SERVER)) {
- $_SERVER = $HTTP_SERVER_VARS;
- if(!isset($_SERVER['REMOTE_ADDR'])) {
- $_SERVER = $HTTP_ENV_VARS; // must be Apache
- }
- }
-
- if(isset($_SERVER[$varName])) {
- return $_SERVER[$varName];
- } else {
- return '';
- }
- }
-
- /**
</del><span class="cx"> * Returns the server hostname or 'localhost.localdomain' if unknown.
</span><span class="cx"> * @access private
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function ServerHostname() {
- if ($this->Hostname != '') {
</del><ins>+ private function ServerHostname() {
+ if (!empty($this->Hostname)) {
</ins><span class="cx"> $result = $this->Hostname;
</span><del>- } elseif ($this->ServerVar('SERVER_NAME') != '') {
- $result = $this->ServerVar('SERVER_NAME');
</del><ins>+ } elseif (isset($_SERVER['SERVER_NAME'])) {
+ $result = $_SERVER['SERVER_NAME'];
</ins><span class="cx"> } else {
</span><span class="cx"> $result = 'localhost.localdomain';
</span><span class="cx"> }
</span><span class="lines">@@ -1677,7 +1953,7 @@
</span><span class="cx"> * @access private
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function Lang($key) {
</del><ins>+ private function Lang($key) {
</ins><span class="cx"> if(count($this->language) < 1) {
</span><span class="cx"> $this->SetLanguage('en'); // set the default language
</span><span class="cx"> }
</span><span class="lines">@@ -1691,9 +1967,10 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Returns true if an error occurred.
</span><ins>+ * @access public
</ins><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function IsError() {
</del><ins>+ public function IsError() {
</ins><span class="cx"> return ($this->error_count > 0);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1702,7 +1979,7 @@
</span><span class="cx"> * @access private
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function FixEOL($str) {
</del><ins>+ private function FixEOL($str) {
</ins><span class="cx"> $str = str_replace("\r\n", "\n", $str);
</span><span class="cx"> $str = str_replace("\r", "\n", $str);
</span><span class="cx"> $str = str_replace("\n", $this->LE, $str);
</span><span class="lines">@@ -1711,9 +1988,10 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Adds a custom header.
</span><ins>+ * @access public
</ins><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function AddCustomHeader($custom_header) {
</del><ins>+ public function AddCustomHeader($custom_header) {
</ins><span class="cx"> $this->CustomHeader[] = explode(':', $custom_header, 2);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1722,19 +2000,18 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return $message
</span><span class="cx"> */
</span><del>- function MsgHTML($message,$basedir='') {
</del><ins>+ public function MsgHTML($message, $basedir = '') {
</ins><span class="cx"> preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
</span><span class="cx"> if(isset($images[2])) {
</span><span class="cx"> foreach($images[2] as $i => $url) {
</span><span class="cx"> // do not change urls for absolute images (thanks to corvuscorax)
</span><del>- if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
</del><ins>+ if (!preg_match('#^[A-z]+://#',$url)) {
</ins><span class="cx"> $filename = basename($url);
</span><span class="cx"> $directory = dirname($url);
</span><span class="cx"> ($directory == '.')?$directory='':'';
</span><span class="cx"> $cid = 'cid:' . md5($filename);
</span><del>- $fileParts = split("\.", $filename);
- $ext = $fileParts[1];
- $mimeType = $this->_mime_types($ext);
</del><ins>+ $ext = pathinfo($filename, PATHINFO_EXTENSION);
+ $mimeType = self::_mime_types($ext);
</ins><span class="cx"> if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
</span><span class="cx"> if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
</span><span class="cx"> if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
</span><span class="lines">@@ -1746,176 +2023,298 @@
</span><span class="cx"> $this->IsHTML(true);
</span><span class="cx"> $this->Body = $message;
</span><span class="cx"> $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
</span><del>- if ( !empty($textMsg) && empty($this->AltBody) ) {
</del><ins>+ if (!empty($textMsg) && empty($this->AltBody)) {
</ins><span class="cx"> $this->AltBody = html_entity_decode($textMsg);
</span><span class="cx"> }
</span><del>- if ( empty($this->AltBody) ) {
- $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
</del><ins>+ if (empty($this->AltBody)) {
+ $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Gets the mime type of the embedded or inline image
- * @access private
- * @return mime type of ext
</del><ins>+ * Gets the MIME type of the embedded or inline image
+ * @param string File extension
+ * @access public
+ * @return string MIME type of ext
+ * @static
</ins><span class="cx"> */
</span><del>- function _mime_types($ext = '') {
</del><ins>+ public static function _mime_types($ext = '') {
</ins><span class="cx"> $mimes = array(
</span><del>- 'ai' => 'application/postscript',
- 'aif' => 'audio/x-aiff',
- 'aifc' => 'audio/x-aiff',
- 'aiff' => 'audio/x-aiff',
- 'avi' => 'video/x-msvideo',
</del><ins>+ 'hqx' => 'application/mac-binhex40',
+ 'cpt' => 'application/mac-compactpro',
+ 'doc' => 'application/msword',
</ins><span class="cx"> 'bin' => 'application/macbinary',
</span><del>- 'bmp' => 'image/bmp',
</del><ins>+ 'dms' => 'application/octet-stream',
+ 'lha' => 'application/octet-stream',
+ 'lzh' => 'application/octet-stream',
+ 'exe' => 'application/octet-stream',
</ins><span class="cx"> 'class' => 'application/octet-stream',
</span><del>- 'cpt' => 'application/mac-compactpro',
- 'css' => 'text/css',
</del><ins>+ 'psd' => 'application/octet-stream',
+ 'so' => 'application/octet-stream',
+ 'sea' => 'application/octet-stream',
+ 'dll' => 'application/octet-stream',
+ 'oda' => 'application/oda',
+ 'pdf' => 'application/pdf',
+ 'ai' => 'application/postscript',
+ 'eps' => 'application/postscript',
+ 'ps' => 'application/postscript',
+ 'smi' => 'application/smil',
+ 'smil' => 'application/smil',
+ 'mif' => 'application/vnd.mif',
+ 'xls' => 'application/vnd.ms-excel',
+ 'ppt' => 'application/vnd.ms-powerpoint',
+ 'wbxml' => 'application/vnd.wap.wbxml',
+ 'wmlc' => 'application/vnd.wap.wmlc',
</ins><span class="cx"> 'dcr' => 'application/x-director',
</span><span class="cx"> 'dir' => 'application/x-director',
</span><del>- 'dll' => 'application/octet-stream',
- 'dms' => 'application/octet-stream',
- 'doc' => 'application/msword',
</del><ins>+ 'dxr' => 'application/x-director',
</ins><span class="cx"> 'dvi' => 'application/x-dvi',
</span><del>- 'dxr' => 'application/x-director',
- 'eml' => 'message/rfc822',
- 'eps' => 'application/postscript',
- 'exe' => 'application/octet-stream',
- 'gif' => 'image/gif',
</del><span class="cx"> 'gtar' => 'application/x-gtar',
</span><del>- 'htm' => 'text/html',
- 'html' => 'text/html',
- 'jpe' => 'image/jpeg',
- 'jpeg' => 'image/jpeg',
- 'jpg' => 'image/jpeg',
- 'hqx' => 'application/mac-binhex40',
</del><ins>+ 'php' => 'application/x-httpd-php',
+ 'php4' => 'application/x-httpd-php',
+ 'php3' => 'application/x-httpd-php',
+ 'phtml' => 'application/x-httpd-php',
+ 'phps' => 'application/x-httpd-php-source',
</ins><span class="cx"> 'js' => 'application/x-javascript',
</span><del>- 'lha' => 'application/octet-stream',
- 'log' => 'text/plain',
- 'lzh' => 'application/octet-stream',
</del><ins>+ 'swf' => 'application/x-shockwave-flash',
+ 'sit' => 'application/x-stuffit',
+ 'tar' => 'application/x-tar',
+ 'tgz' => 'application/x-tar',
+ 'xhtml' => 'application/xhtml+xml',
+ 'xht' => 'application/xhtml+xml',
+ 'zip' => 'application/zip',
</ins><span class="cx"> 'mid' => 'audio/midi',
</span><span class="cx"> 'midi' => 'audio/midi',
</span><del>- 'mif' => 'application/vnd.mif',
- 'mov' => 'video/quicktime',
- 'movie' => 'video/x-sgi-movie',
</del><ins>+ 'mpga' => 'audio/mpeg',
</ins><span class="cx"> 'mp2' => 'audio/mpeg',
</span><span class="cx"> 'mp3' => 'audio/mpeg',
</span><del>- 'mpe' => 'video/mpeg',
- 'mpeg' => 'video/mpeg',
- 'mpg' => 'video/mpeg',
- 'mpga' => 'audio/mpeg',
- 'oda' => 'application/oda',
- 'pdf' => 'application/pdf',
- 'php' => 'application/x-httpd-php',
- 'php3' => 'application/x-httpd-php',
- 'php4' => 'application/x-httpd-php',
- 'phps' => 'application/x-httpd-php-source',
- 'phtml' => 'application/x-httpd-php',
- 'png' => 'image/png',
- 'ppt' => 'application/vnd.ms-powerpoint',
- 'ps' => 'application/postscript',
- 'psd' => 'application/octet-stream',
- 'qt' => 'video/quicktime',
- 'ra' => 'audio/x-realaudio',
</del><ins>+ 'aif' => 'audio/x-aiff',
+ 'aiff' => 'audio/x-aiff',
+ 'aifc' => 'audio/x-aiff',
</ins><span class="cx"> 'ram' => 'audio/x-pn-realaudio',
</span><span class="cx"> 'rm' => 'audio/x-pn-realaudio',
</span><span class="cx"> 'rpm' => 'audio/x-pn-realaudio-plugin',
</span><del>- 'rtf' => 'text/rtf',
- 'rtx' => 'text/richtext',
</del><ins>+ 'ra' => 'audio/x-realaudio',
</ins><span class="cx"> 'rv' => 'video/vnd.rn-realvideo',
</span><del>- 'sea' => 'application/octet-stream',
</del><ins>+ 'wav' => 'audio/x-wav',
+ 'bmp' => 'image/bmp',
+ 'gif' => 'image/gif',
+ 'jpeg' => 'image/jpeg',
+ 'jpg' => 'image/jpeg',
+ 'jpe' => 'image/jpeg',
+ 'png' => 'image/png',
+ 'tiff' => 'image/tiff',
+ 'tif' => 'image/tiff',
+ 'css' => 'text/css',
+ 'html' => 'text/html',
+ 'htm' => 'text/html',
</ins><span class="cx"> 'shtml' => 'text/html',
</span><del>- 'sit' => 'application/x-stuffit',
- 'so' => 'application/octet-stream',
- 'smi' => 'application/smil',
- 'smil' => 'application/smil',
- 'swf' => 'application/x-shockwave-flash',
- 'tar' => 'application/x-tar',
</del><ins>+ 'txt' => 'text/plain',
</ins><span class="cx"> 'text' => 'text/plain',
</span><del>- 'txt' => 'text/plain',
- 'tgz' => 'application/x-tar',
- 'tif' => 'image/tiff',
- 'tiff' => 'image/tiff',
- 'wav' => 'audio/x-wav',
- 'wbxml' => 'application/vnd.wap.wbxml',
- 'wmlc' => 'application/vnd.wap.wmlc',
</del><ins>+ 'log' => 'text/plain',
+ 'rtx' => 'text/richtext',
+ 'rtf' => 'text/rtf',
+ 'xml' => 'text/xml',
+ 'xsl' => 'text/xml',
+ 'mpeg' => 'video/mpeg',
+ 'mpg' => 'video/mpeg',
+ 'mpe' => 'video/mpeg',
+ 'qt' => 'video/quicktime',
+ 'mov' => 'video/quicktime',
+ 'avi' => 'video/x-msvideo',
+ 'movie' => 'video/x-sgi-movie',
+ 'doc' => 'application/msword',
</ins><span class="cx"> 'word' => 'application/msword',
</span><del>- 'xht' => 'application/xhtml+xml',
- 'xhtml' => 'application/xhtml+xml',
</del><span class="cx"> 'xl' => 'application/excel',
</span><del>- 'xls' => 'application/vnd.ms-excel',
- 'xml' => 'text/xml',
- 'xsl' => 'text/xml',
- 'zip' => 'application/zip'
</del><ins>+ 'eml' => 'message/rfc822'
</ins><span class="cx"> );
</span><del>- return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
</del><ins>+ return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Set (or reset) Class Objects (variables)
</del><ins>+ * Set (or reset) Class Objects (variables)
+ *
+ * Usage Example:
+ * $page->set('X-Priority', '3');
+ *
+ * @access public
+ * @param string $name Parameter Name
+ * @param mixed $value Parameter Value
+ * NOTE: will not work with arrays, there are no arrays to set/reset
+ * @todo Should this not be using __set() magic function?
+ */
+ public function set($name, $value = '') {
+ try {
+ if (isset($this->$name) ) {
+ $this->$name = $value;
+ } else {
+ throw new phpmailerException($this->Lang('variable_set') . $name, self::STOP_CRITICAL);
+ }
+ } catch (Exception $e) {
+ $this->SetError($e->getMessage());
+ if ($e->getCode() == self::STOP_CRITICAL) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Strips newlines to prevent header injection.
+ * @access public
+ * @param string $str String
+ * @return string
+ */
+ public function SecureHeader($str) {
+ $str = str_replace("\r", '', $str);
+ $str = str_replace("\n", '', $str);
+ return trim($str);
+ }
+
+ /**
+ * Set the private key file and password to sign the message.
</ins><span class="cx"> *
</span><del>- * Usage Example:
- * $page->set('X-Priority', '3');
</del><ins>+ * @access public
+ * @param string $key_filename Parameter File Name
+ * @param string $key_pass Password for private key
+ */
+ public function Sign($cert_filename, $key_filename, $key_pass) {
+ $this->sign_cert_file = $cert_filename;
+ $this->sign_key_file = $key_filename;
+ $this->sign_key_pass = $key_pass;
+ }
+
+ /**
+ * Set the private key file and password to sign the message.
</ins><span class="cx"> *
</span><span class="cx"> * @access public
</span><del>- * @param string $name Parameter Name
- * @param mixed $value Parameter Value
- * NOTE: will not work with arrays, there are no arrays to set/reset
</del><ins>+ * @param string $key_filename Parameter File Name
+ * @param string $key_pass Password for private key
</ins><span class="cx"> */
</span><del>- function set ( $name, $value = '' ) {
- if ( isset($this->$name) ) {
- $this->$name = $value;
- } else {
- $this->SetError('Cannot set or reset variable ' . $name);
- return false;
</del><ins>+ public function DKIM_QP($txt) {
+ $tmp="";
+ $line="";
+ for ($i=0;$i<strlen($txt);$i++) {
+ $ord=ord($txt[$i]);
+ if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
+ $line.=$txt[$i];
+ } else {
+ $line.="=".sprintf("%02X",$ord);
+ }
</ins><span class="cx"> }
</span><ins>+ return $line;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Read a file from a supplied filename and return it.
</del><ins>+ * Generate DKIM signature
</ins><span class="cx"> *
</span><span class="cx"> * @access public
</span><del>- * @param string $filename Parameter File Name
</del><ins>+ * @param string $s Header
</ins><span class="cx"> */
</span><del>- function getFile($filename) {
- $return = '';
- if ($fp = fopen($filename, 'rb')) {
- while (!feof($fp)) {
- $return .= fread($fp, 1024);
- }
- fclose($fp);
- return $return;
</del><ins>+ public function DKIM_Sign($s) {
+ $privKeyStr = file_get_contents($this->DKIM_private);
+ if ($this->DKIM_passphrase!='') {
+ $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase);
</ins><span class="cx"> } else {
</span><del>- return false;
</del><ins>+ $privKey = $privKeyStr;
</ins><span class="cx"> }
</span><ins>+ if (openssl_sign($s, $signature, $privKey)) {
+ return base64_encode($signature);
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Strips newlines to prevent header injection.
- * @access private
- * @param string $str String
- * @return string
</del><ins>+ * Generate DKIM Canonicalization Header
+ *
+ * @access public
+ * @param string $s Header
</ins><span class="cx"> */
</span><del>- function SecureHeader($str) {
- $str = trim($str);
- $str = str_replace("\r", "", $str);
- $str = str_replace("\n", "", $str);
- return $str;
</del><ins>+ public function DKIM_HeaderC($s) {
+ $s=preg_replace("/\r\n\s+/"," ",$s);
+ $lines=explode("\r\n",$s);
+ foreach ($lines as $key=>$line) {
+ list($heading,$value)=explode(":",$line,2);
+ $heading=strtolower($heading);
+ $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces
+ $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value
+ }
+ $s=implode("\r\n",$lines);
+ return $s;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Set the private key file and password to sign the message.
</del><ins>+ * Generate DKIM Canonicalization Body
</ins><span class="cx"> *
</span><span class="cx"> * @access public
</span><del>- * @param string $key_filename Parameter File Name
- * @param string $key_pass Password for private key
</del><ins>+ * @param string $body Message Body
</ins><span class="cx"> */
</span><del>- function Sign($cert_filename, $key_filename, $key_pass) {
- $this->sign_cert_file = $cert_filename;
- $this->sign_key_file = $key_filename;
- $this->sign_key_pass = $key_pass;
</del><ins>+ public function DKIM_BodyC($body) {
+ if ($body == '') return "\r\n";
+ // stabilize line endings
+ $body=str_replace("\r\n","\n",$body);
+ $body=str_replace("\n","\r\n",$body);
+ // END stabilize line endings
+ while (substr($body,strlen($body)-4,4) == "\r\n\r\n") {
+ $body=substr($body,0,strlen($body)-2);
+ }
+ return $body;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+ /**
+ * Create the DKIM header, body, as new header
+ *
+ * @access public
+ * @param string $headers_line Header lines
+ * @param string $subject Subject
+ * @param string $body Body
+ */
+ public function DKIM_Add($headers_line,$subject,$body) {
+ $DKIMsignatureType = 'rsa-sha1'; // Signature & hash algorithms
+ $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
+ $DKIMquery = 'dns/txt'; // Query method
+ $DKIMtime = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
+ $subject_header = "Subject: $subject";
+ $headers = explode("\r\n",$headers_line);
+ foreach($headers as $header) {
+ if (strpos($header,'From:') === 0) {
+ $from_header=$header;
+ } elseif (strpos($header,'To:') === 0) {
+ $to_header=$header;
+ }
+ }
+ $from = str_replace('|','=7C',$this->DKIM_QP($from_header));
+ $to = str_replace('|','=7C',$this->DKIM_QP($to_header));
+ $subject = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
+ $body = $this->DKIM_BodyC($body);
+ $DKIMlen = strlen($body) ; // Length of body
+ $DKIMb64 = base64_encode(pack("H*", sha1($body))) ; // Base64 of packed binary SHA-1 hash of body
+ $ident = ($this->DKIM_identity == '')? '' : " i=" . $this->DKIM_identity . ";";
+ $dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n".
+ "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n".
+ "\th=From:To:Subject;\r\n".
+ "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n".
+ "\tz=$from\r\n".
+ "\t|$to\r\n".
+ "\t|$subject;\r\n".
+ "\tbh=" . $DKIMb64 . ";\r\n".
+ "\tb=";
+ $toSign = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
+ $signed = $this->DKIM_Sign($toSign);
+ return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
+ }
+
+ protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) {
+ if (!empty($this->action_function) && function_exists($this->action_function)) {
+ $params = array($isSent,$to,$cc,$bcc,$subject,$body);
+ call_user_func_array($this->action_function,$params);
+ }
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-?>
</del><ins>+class phpmailerException extends Exception {
+ public function errorMessage() {
+ $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
+ return $errorMsg;
+ }
+}
+?>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesclasssmtpphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-smtp.php (17675 => 17676)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-smtp.php        2011-04-21 20:20:56 UTC (rev 17675)
+++ trunk/wp-includes/class-smtp.php        2011-04-21 20:29:30 UTC (rev 17676)
</span><span class="lines">@@ -2,14 +2,16 @@
</span><span class="cx"> /*~ class.smtp.php
</span><span class="cx"> .---------------------------------------------------------------------------.
</span><span class="cx"> | Software: PHPMailer - PHP email class |
</span><del>-| Version: 2.0.4 |
</del><ins>+| Version: 5.1 |
</ins><span class="cx"> | Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
</span><span class="cx"> | Info: http://phpmailer.sourceforge.net |
</span><span class="cx"> | Support: http://sourceforge.net/projects/phpmailer/ |
</span><span class="cx"> | ------------------------------------------------------------------------- |
</span><del>-| Author: Andy Prevost (project admininistrator) |
-| Author: Brent R. Matzelle (original founder) |
-| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
</del><ins>+| Admin: Andy Prevost (project admininistrator) |
+| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
+| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
+| Founder: Brent R. Matzelle (original founder) |
+| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
</ins><span class="cx"> | Copyright (c) 2001-2003, Brent R. Matzelle |
</span><span class="cx"> | ------------------------------------------------------------------------- |
</span><span class="cx"> | License: Distributed under the Lesser General Public License (LGPL) |
</span><span class="lines">@@ -23,56 +25,66 @@
</span><span class="cx"> | - Technology Consulting |
</span><span class="cx"> | - Oursourcing (highly qualified programmers and graphic designers) |
</span><span class="cx"> '---------------------------------------------------------------------------'
</span><ins>+*/
+
+/**
+ * PHPMailer - PHP SMTP email transport class
+ * NOTE: Designed for use with PHP version 5 and up
+ * @package PHPMailer
+ * @author Andy Prevost
+ * @author Marcus Bointon
+ * @copyright 2004 - 2008 Andy Prevost
+ * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
+ * @version $Id: class.smtp.php 444 2009-05-05 11:22:26Z coolbru $
</ins><span class="cx"> */
</span><ins>+
</ins><span class="cx"> /**
</span><span class="cx"> * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
</span><span class="cx"> * commands except TURN which will always return a not implemented
</span><span class="cx"> * error. SMTP also provides some utility methods for sending mail
</span><span class="cx"> * to an SMTP server.
</span><del>- * @package PHPMailer
- * @author Chris Ryan
</del><ins>+ * original author: Chris Ryan
</ins><span class="cx"> */
</span><span class="cx">
</span><del>-class SMTP
-{
</del><ins>+class SMTP {
</ins><span class="cx"> /**
</span><span class="cx"> * SMTP server port
</span><span class="cx"> * @var int
</span><span class="cx"> */
</span><del>- var $SMTP_PORT = 25;
</del><ins>+ public $SMTP_PORT = 25;
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * SMTP reply line ending
</span><span class="cx"> * @var string
</span><span class="cx"> */
</span><del>- var $CRLF = "\r\n";
</del><ins>+ public $CRLF = "\r\n";
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets whether debugging is turned on
</span><span class="cx"> * @var bool
</span><span class="cx"> */
</span><del>- var $do_debug; # the level of debug to perform
</del><ins>+ public $do_debug; // the level of debug to perform
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Sets VERP use on/off (default is off)
</span><span class="cx"> * @var bool
</span><span class="cx"> */
</span><del>- var $do_verp = false;
</del><ins>+ public $do_verp = false;
</ins><span class="cx">
</span><del>- /**#@+
- * @access private
- */
- var $smtp_conn; # the socket to the server
- var $error; # error if any on the last call
- var $helo_rply; # the reply the server sent to us for HELO
- /**#@-*/
</del><ins>+ /////////////////////////////////////////////////
+ // PROPERTIES, PRIVATE AND PROTECTED
+ /////////////////////////////////////////////////
</ins><span class="cx">
</span><ins>+ private $smtp_conn; // the socket to the server
+ private $error; // error if any on the last call
+ private $helo_rply; // the reply the server sent to us for HELO
+
</ins><span class="cx"> /**
</span><span class="cx"> * Initialize the class so that the data is in a known state.
</span><span class="cx"> * @access public
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function SMTP() {
</del><ins>+ public function __construct() {
</ins><span class="cx"> $this->smtp_conn = 0;
</span><span class="cx"> $this->error = null;
</span><span class="cx"> $this->helo_rply = null;
</span><span class="lines">@@ -80,9 +92,9 @@
</span><span class="cx"> $this->do_debug = 0;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- /*************************************************************
- * CONNECTION FUNCTIONS *
- ***********************************************************/
</del><ins>+ /////////////////////////////////////////////////
+ // CONNECTION FUNCTIONS
+ /////////////////////////////////////////////////
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Connect to the server specified on the port specified.
</span><span class="lines">@@ -97,15 +109,13 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Connect($host,$port=0,$tval=30) {
- # set the error val to null so there is no confusion
</del><ins>+ public function Connect($host, $port = 0, $tval = 30) {
+ // set the error val to null so there is no confusion
</ins><span class="cx"> $this->error = null;
</span><span class="cx">
</span><del>- # make sure we are __not__ connected
</del><ins>+ // make sure we are __not__ connected
</ins><span class="cx"> if($this->connected()) {
</span><del>- # ok we are connected! what should we do?
- # for now we will just give an error saying we
- # are already connected
</del><ins>+ // already connected, generate error
</ins><span class="cx"> $this->error = array("error" => "Already connected to a server");
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -114,41 +124,80 @@
</span><span class="cx"> $port = $this->SMTP_PORT;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- #connect to the smtp server
- $this->smtp_conn = fsockopen($host, # the host of the server
- $port, # the port to use
- $errno, # error number if any
- $errstr, # error message if any
- $tval); # give up after ? secs
- # verify we connected properly
</del><ins>+ // connect to the smtp server
+ $this->smtp_conn = @fsockopen($host, // the host of the server
+ $port, // the port to use
+ $errno, // error number if any
+ $errstr, // error message if any
+ $tval); // give up after ? secs
+ // verify we connected properly
</ins><span class="cx"> if(empty($this->smtp_conn)) {
</span><span class="cx"> $this->error = array("error" => "Failed to connect to server",
</span><span class="cx"> "errno" => $errno,
</span><span class="cx"> "errstr" => $errstr);
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": $errstr ($errno)" . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- # sometimes the SMTP server takes a little longer to respond
- # so we will give it a longer timeout for the first read
- // Windows still does not have support for this timeout function
</del><ins>+ // SMTP server can take longer to respond, give longer timeout for first read
+ // Windows does not have support for this timeout function
</ins><span class="cx"> if(substr(PHP_OS, 0, 3) != "WIN")
</span><span class="cx"> socket_set_timeout($this->smtp_conn, $tval, 0);
</span><span class="cx">
</span><del>- # get any announcement stuff
</del><ins>+ // get any announcement
</ins><span class="cx"> $announce = $this->get_lines();
</span><span class="cx">
</span><del>- # set the timeout of any socket functions at 1/10 of a second
- //if(function_exists("socket_set_timeout"))
- // socket_set_timeout($this->smtp_conn, 0, 100000);
</del><ins>+ if($this->do_debug >= 2) {
+ echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
+ }
</ins><span class="cx">
</span><ins>+ return true;
+ }
+
+ /**
+ * Initiate a TLS communication with the server.
+ *
+ * SMTP CODE 220 Ready to start TLS
+ * SMTP CODE 501 Syntax error (no parameters allowed)
+ * SMTP CODE 454 TLS not available due to temporary reason
+ * @access public
+ * @return bool success
+ */
+ public function StartTLS() {
+ $this->error = null; # to avoid confusion
+
+ if(!$this->connected()) {
+ $this->error = array("error" => "Called StartTLS() without being connected");
+ return false;
+ }
+
+ fputs($this->smtp_conn,"STARTTLS" . $this->CRLF);
+
+ $rply = $this->get_lines();
+ $code = substr($rply,0,3);
+
</ins><span class="cx"> if($this->do_debug >= 2) {
</span><del>- echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
</del><ins>+ echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+ if($code != 220) {
+ $this->error =
+ array("error" => "STARTTLS not accepted from server",
+ "smtp_code" => $code,
+ "smtp_msg" => substr($rply,4));
+ if($this->do_debug >= 1) {
+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
+ }
+ return false;
+ }
+
+ // Begin encrypted connection
+ if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
+ return false;
+ }
+
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -158,7 +207,7 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Authenticate($username, $password) {
</del><ins>+ public function Authenticate($username, $password) {
</ins><span class="cx"> // Start authentication
</span><span class="cx"> fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
</span><span class="cx">
</span><span class="lines">@@ -171,8 +220,7 @@
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_msg" => substr($rply,4));
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -189,8 +237,7 @@
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_msg" => substr($rply,4));
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -207,8 +254,7 @@
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_msg" => substr($rply,4));
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -218,23 +264,21 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Returns true if connected to a server otherwise false
</span><del>- * @access private
</del><ins>+ * @access public
</ins><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Connected() {
</del><ins>+ public function Connected() {
</ins><span class="cx"> if(!empty($this->smtp_conn)) {
</span><span class="cx"> $sock_status = socket_get_status($this->smtp_conn);
</span><span class="cx"> if($sock_status["eof"]) {
</span><del>- # hmm this is an odd situation... the socket is
- # valid but we are not connected anymore
</del><ins>+ // the socket is valid but we are not connected
</ins><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> NOTICE:" . $this->CRLF .
- "EOF caught while checking if connected";
</del><ins>+ echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
</ins><span class="cx"> }
</span><span class="cx"> $this->Close();
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><del>- return true; # everything looks good
</del><ins>+ return true; // everything looks good
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -246,26 +290,26 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return void
</span><span class="cx"> */
</span><del>- function Close() {
- $this->error = null; # so there is no confusion
</del><ins>+ public function Close() {
+ $this->error = null; // so there is no confusion
</ins><span class="cx"> $this->helo_rply = null;
</span><span class="cx"> if(!empty($this->smtp_conn)) {
</span><del>- # close the connection and cleanup
</del><ins>+ // close the connection and cleanup
</ins><span class="cx"> fclose($this->smtp_conn);
</span><span class="cx"> $this->smtp_conn = 0;
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- /***************************************************************
- * SMTP COMMANDS *
- *************************************************************/
</del><ins>+ /////////////////////////////////////////////////
+ // SMTP COMMANDS
+ /////////////////////////////////////////////////
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Issues a data command and sends the msg_data to the server
</span><span class="cx"> * finializing the mail transaction. $msg_data is the message
</span><span class="cx"> * that is to be send with the headers. Each header needs to be
</span><span class="cx"> * on a single line followed by a <CRLF> with the message headers
</span><del>- * and the message body being separated by and additional <CRLF>.
</del><ins>+ * and the message body being seperated by and additional <CRLF>.
</ins><span class="cx"> *
</span><span class="cx"> * Implements rfc 821: DATA <CRLF>
</span><span class="cx"> *
</span><span class="lines">@@ -279,8 +323,8 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Data($msg_data) {
- $this->error = null; # so no confusion is caused
</del><ins>+ public function Data($msg_data) {
+ $this->error = null; // so no confusion is caused
</ins><span class="cx">
</span><span class="cx"> if(!$this->connected()) {
</span><span class="cx"> $this->error = array(
</span><span class="lines">@@ -294,7 +338,7 @@
</span><span class="cx"> $code = substr($rply,0,3);
</span><span class="cx">
</span><span class="cx"> if($this->do_debug >= 2) {
</span><del>- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
</del><ins>+ echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if($code != 354) {
</span><span class="lines">@@ -303,69 +347,73 @@
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_msg" => substr($rply,4));
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- # the server is ready to accept data!
- # according to rfc 821 we should not send more than 1000
- # including the CRLF
- # characters on a single line so we will break the data up
- # into lines by \r and/or \n then if needed we will break
- # each of those into smaller lines to fit within the limit.
- # in addition we will be looking for lines that start with
- # a period '.' and append and additional period '.' to that
- # line. NOTE: this does not count towards are limit.
</del><ins>+ /* the server is ready to accept data!
+ * according to rfc 821 we should not send more than 1000
+ * including the CRLF
+ * characters on a single line so we will break the data up
+ * into lines by \r and/or \n then if needed we will break
+ * each of those into smaller lines to fit within the limit.
+ * in addition we will be looking for lines that start with
+ * a period '.' and append and additional period '.' to that
+ * line. NOTE: this does not count towards limit.
+ */
</ins><span class="cx">
</span><del>- # normalize the line breaks so we know the explode works
</del><ins>+ // normalize the line breaks so we know the explode works
</ins><span class="cx"> $msg_data = str_replace("\r\n","\n",$msg_data);
</span><span class="cx"> $msg_data = str_replace("\r","\n",$msg_data);
</span><span class="cx"> $lines = explode("\n",$msg_data);
</span><span class="cx">
</span><del>- # we need to find a good way to determine is headers are
- # in the msg_data or if it is a straight msg body
- # currently I am assuming rfc 822 definitions of msg headers
- # and if the first field of the first line (':' sperated)
- # does not contain a space then it _should_ be a header
- # and we can process all lines before a blank "" line as
- # headers.
</del><ins>+ /* we need to find a good way to determine is headers are
+ * in the msg_data or if it is a straight msg body
+ * currently I am assuming rfc 822 definitions of msg headers
+ * and if the first field of the first line (':' sperated)
+ * does not contain a space then it _should_ be a header
+ * and we can process all lines before a blank "" line as
+ * headers.
+ */
+
</ins><span class="cx"> $field = substr($lines[0],0,strpos($lines[0],":"));
</span><span class="cx"> $in_headers = false;
</span><span class="cx"> if(!empty($field) && !strstr($field," ")) {
</span><span class="cx"> $in_headers = true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- $max_line_length = 998; # used below; set here for ease in change
</del><ins>+ $max_line_length = 998; // used below; set here for ease in change
</ins><span class="cx">
</span><span class="cx"> while(list(,$line) = @each($lines)) {
</span><span class="cx"> $lines_out = null;
</span><span class="cx"> if($line == "" && $in_headers) {
</span><span class="cx"> $in_headers = false;
</span><span class="cx"> }
</span><del>- # ok we need to break this line up into several
- # smaller lines
</del><ins>+ // ok we need to break this line up into several smaller lines
</ins><span class="cx"> while(strlen($line) > $max_line_length) {
</span><span class="cx"> $pos = strrpos(substr($line,0,$max_line_length)," ");
</span><span class="cx">
</span><del>- # Patch to fix DOS attack
</del><ins>+ // Patch to fix DOS attack
</ins><span class="cx"> if(!$pos) {
</span><span class="cx"> $pos = $max_line_length - 1;
</span><ins>+ $lines_out[] = substr($line,0,$pos);
+ $line = substr($line,$pos);
+ } else {
+ $lines_out[] = substr($line,0,$pos);
+ $line = substr($line,$pos + 1);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- $lines_out[] = substr($line,0,$pos);
- $line = substr($line,$pos + 1);
- # if we are processing headers we need to
- # add a LWSP-char to the front of the new line
- # rfc 822 on long msg headers
</del><ins>+ /* if processing headers add a LWSP-char to the front of new line
+ * rfc 822 on long msg headers
+ */
</ins><span class="cx"> if($in_headers) {
</span><span class="cx"> $line = "\t" . $line;
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> $lines_out[] = $line;
</span><span class="cx">
</span><del>- # now send the lines to the server
</del><ins>+ // send the lines to the server
</ins><span class="cx"> while(list(,$line_out) = @each($lines_out)) {
</span><span class="cx"> if(strlen($line_out) > 0)
</span><span class="cx"> {
</span><span class="lines">@@ -377,15 +425,14 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- # ok all the message data has been sent so lets get this
- # over with aleady
</del><ins>+ // message data has been sent
</ins><span class="cx"> fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
</span><span class="cx">
</span><span class="cx"> $rply = $this->get_lines();
</span><span class="cx"> $code = substr($rply,0,3);
</span><span class="cx">
</span><span class="cx"> if($this->do_debug >= 2) {
</span><del>- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
</del><ins>+ echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if($code != 250) {
</span><span class="lines">@@ -394,8 +441,7 @@
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_msg" => substr($rply,4));
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -403,61 +449,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Expand takes the name and asks the server to list all the
- * people who are members of the _list_. Expand will return
- * back and array of the result or false if an error occurs.
- * Each value in the array returned has the format of:
- * [ <full-name> <sp> ] <path>
- * The definition of <path> is defined in rfc 821
- *
- * Implements rfc 821: EXPN <SP> <string> <CRLF>
- *
- * SMTP CODE SUCCESS: 250
- * SMTP CODE FAILURE: 550
- * SMTP CODE ERROR : 500,501,502,504,421
- * @access public
- * @return string array
- */
- function Expand($name) {
- $this->error = null; # so no confusion is caused
-
- if(!$this->connected()) {
- $this->error = array(
- "error" => "Called Expand() without being connected");
- return false;
- }
-
- fputs($this->smtp_conn,"EXPN " . $name . $this->CRLF);
-
- $rply = $this->get_lines();
- $code = substr($rply,0,3);
-
- if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
- }
-
- if($code != 250) {
- $this->error =
- array("error" => "EXPN not accepted from server",
- "smtp_code" => $code,
- "smtp_msg" => substr($rply,4));
- if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
- }
- return false;
- }
-
- # parse the reply and place in our array to return to user
- $entries = explode($this->CRLF,$rply);
- while(list(,$l) = @each($entries)) {
- $list[] = substr($l,4);
- }
-
- return $list;
- }
-
- /**
</del><span class="cx"> * Sends the HELO command to the smtp server.
</span><span class="cx"> * This makes sure that we and the server are in
</span><span class="cx"> * the same known state.
</span><span class="lines">@@ -469,8 +460,8 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Hello($host="") {
- $this->error = null; # so no confusion is caused
</del><ins>+ public function Hello($host = '') {
+ $this->error = null; // so no confusion is caused
</ins><span class="cx">
</span><span class="cx"> if(!$this->connected()) {
</span><span class="cx"> $this->error = array(
</span><span class="lines">@@ -478,19 +469,17 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- # if a hostname for the HELO was not specified determine
- # a suitable one to send
</del><ins>+ // if hostname for HELO was not specified send default
</ins><span class="cx"> if(empty($host)) {
</span><del>- # we need to determine some sort of appopiate default
- # to send to the server
</del><ins>+ // determine appropriate default to send to server
</ins><span class="cx"> $host = "localhost";
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Send extended hello first (RFC 2821)
</span><del>- if(!$this->SendHello("EHLO", $host))
- {
- if(!$this->SendHello("HELO", $host))
- return false;
</del><ins>+ if(!$this->SendHello("EHLO", $host)) {
+ if(!$this->SendHello("HELO", $host)) {
+ return false;
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> return true;
</span><span class="lines">@@ -501,14 +490,14 @@
</span><span class="cx"> * @access private
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function SendHello($hello, $host) {
</del><ins>+ private function SendHello($hello, $host) {
</ins><span class="cx"> fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
</span><span class="cx">
</span><span class="cx"> $rply = $this->get_lines();
</span><span class="cx"> $code = substr($rply,0,3);
</span><span class="cx">
</span><span class="cx"> if($this->do_debug >= 2) {
</span><del>- echo "SMTP -> FROM SERVER: " . $this->CRLF . $rply;
</del><ins>+ echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if($code != 250) {
</span><span class="lines">@@ -517,8 +506,7 @@
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_msg" => substr($rply,4));
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -529,59 +517,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Gets help information on the keyword specified. If the keyword
- * is not specified then returns generic help, ussually contianing
- * A list of keywords that help is available on. This function
- * returns the results back to the user. It is up to the user to
- * handle the returned data. If an error occurs then false is
- * returned with $this->error set appropiately.
- *
- * Implements rfc 821: HELP [ <SP> <string> ] <CRLF>
- *
- * SMTP CODE SUCCESS: 211,214
- * SMTP CODE ERROR : 500,501,502,504,421
- * @access public
- * @return string
- */
- function Help($keyword="") {
- $this->error = null; # to avoid confusion
-
- if(!$this->connected()) {
- $this->error = array(
- "error" => "Called Help() without being connected");
- return false;
- }
-
- $extra = "";
- if(!empty($keyword)) {
- $extra = " " . $keyword;
- }
-
- fputs($this->smtp_conn,"HELP" . $extra . $this->CRLF);
-
- $rply = $this->get_lines();
- $code = substr($rply,0,3);
-
- if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
- }
-
- if($code != 211 && $code != 214) {
- $this->error =
- array("error" => "HELP not accepted from server",
- "smtp_code" => $code,
- "smtp_msg" => substr($rply,4));
- if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
- }
- return false;
- }
-
- return $rply;
- }
-
- /**
</del><span class="cx"> * Starts a mail transaction from the email address specified in
</span><span class="cx"> * $from. Returns true if successful or false otherwise. If True
</span><span class="cx"> * the mail transaction is started and then one or more Recipient
</span><span class="lines">@@ -595,8 +530,8 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Mail($from) {
- $this->error = null; # so no confusion is caused
</del><ins>+ public function Mail($from) {
+ $this->error = null; // so no confusion is caused
</ins><span class="cx">
</span><span class="cx"> if(!$this->connected()) {
</span><span class="cx"> $this->error = array(
</span><span class="lines">@@ -611,7 +546,7 @@
</span><span class="cx"> $code = substr($rply,0,3);
</span><span class="cx">
</span><span class="cx"> if($this->do_debug >= 2) {
</span><del>- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
</del><ins>+ echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if($code != 250) {
</span><span class="lines">@@ -620,8 +555,7 @@
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_msg" => substr($rply,4));
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -629,48 +563,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Sends the command NOOP to the SMTP server.
- *
- * Implements from rfc 821: NOOP <CRLF>
- *
- * SMTP CODE SUCCESS: 250
- * SMTP CODE ERROR : 500, 421
- * @access public
- * @return bool
- */
- function Noop() {
- $this->error = null; # so no confusion is caused
-
- if(!$this->connected()) {
- $this->error = array(
- "error" => "Called Noop() without being connected");
- return false;
- }
-
- fputs($this->smtp_conn,"NOOP" . $this->CRLF);
-
- $rply = $this->get_lines();
- $code = substr($rply,0,3);
-
- if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
- }
-
- if($code != 250) {
- $this->error =
- array("error" => "NOOP not accepted from server",
- "smtp_code" => $code,
- "smtp_msg" => substr($rply,4));
- if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
- }
- return false;
- }
- return true;
- }
-
- /**
</del><span class="cx"> * Sends the quit command to the server and then closes the socket
</span><span class="cx"> * if there is no error or the $close_on_error argument is true.
</span><span class="cx"> *
</span><span class="lines">@@ -681,8 +573,8 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Quit($close_on_error=true) {
- $this->error = null; # so there is no confusion
</del><ins>+ public function Quit($close_on_error = true) {
+ $this->error = null; // so there is no confusion
</ins><span class="cx">
</span><span class="cx"> if(!$this->connected()) {
</span><span class="cx"> $this->error = array(
</span><span class="lines">@@ -690,14 +582,14 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- # send the quit command to the server
</del><ins>+ // send the quit command to the server
</ins><span class="cx"> fputs($this->smtp_conn,"quit" . $this->CRLF);
</span><span class="cx">
</span><del>- # get any good-bye messages
</del><ins>+ // get any good-bye messages
</ins><span class="cx"> $byemsg = $this->get_lines();
</span><span class="cx">
</span><span class="cx"> if($this->do_debug >= 2) {
</span><del>- echo "SMTP -> FROM SERVER:" . $this->CRLF . $byemsg;
</del><ins>+ echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> $rval = true;
</span><span class="lines">@@ -705,14 +597,13 @@
</span><span class="cx">
</span><span class="cx"> $code = substr($byemsg,0,3);
</span><span class="cx"> if($code != 221) {
</span><del>- # use e as a tmp var cause Close will overwrite $this->error
</del><ins>+ // use e as a tmp var cause Close will overwrite $this->error
</ins><span class="cx"> $e = array("error" => "SMTP server rejected quit command",
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_rply" => substr($byemsg,4));
</span><span class="cx"> $rval = false;
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $e["error"] . ": " .
- $byemsg . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -735,8 +626,8 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Recipient($to) {
- $this->error = null; # so no confusion is caused
</del><ins>+ public function Recipient($to) {
+ $this->error = null; // so no confusion is caused
</ins><span class="cx">
</span><span class="cx"> if(!$this->connected()) {
</span><span class="cx"> $this->error = array(
</span><span class="lines">@@ -750,7 +641,7 @@
</span><span class="cx"> $code = substr($rply,0,3);
</span><span class="cx">
</span><span class="cx"> if($this->do_debug >= 2) {
</span><del>- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
</del><ins>+ echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if($code != 250 && $code != 251) {
</span><span class="lines">@@ -759,8 +650,7 @@
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_msg" => substr($rply,4));
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -779,8 +669,8 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Reset() {
- $this->error = null; # so no confusion is caused
</del><ins>+ public function Reset() {
+ $this->error = null; // so no confusion is caused
</ins><span class="cx">
</span><span class="cx"> if(!$this->connected()) {
</span><span class="cx"> $this->error = array(
</span><span class="lines">@@ -794,7 +684,7 @@
</span><span class="cx"> $code = substr($rply,0,3);
</span><span class="cx">
</span><span class="cx"> if($this->do_debug >= 2) {
</span><del>- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
</del><ins>+ echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if($code != 250) {
</span><span class="lines">@@ -803,8 +693,7 @@
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_msg" => substr($rply,4));
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -818,54 +707,6 @@
</span><span class="cx"> * the mail transaction is started and then one or more Recipient
</span><span class="cx"> * commands may be called followed by a Data command. This command
</span><span class="cx"> * will send the message to the users terminal if they are logged
</span><del>- * in.
- *
- * Implements rfc 821: SEND <SP> FROM:<reverse-path> <CRLF>
- *
- * SMTP CODE SUCCESS: 250
- * SMTP CODE SUCCESS: 552,451,452
- * SMTP CODE SUCCESS: 500,501,502,421
- * @access public
- * @return bool
- */
- function Send($from) {
- $this->error = null; # so no confusion is caused
-
- if(!$this->connected()) {
- $this->error = array(
- "error" => "Called Send() without being connected");
- return false;
- }
-
- fputs($this->smtp_conn,"SEND FROM:" . $from . $this->CRLF);
-
- $rply = $this->get_lines();
- $code = substr($rply,0,3);
-
- if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
- }
-
- if($code != 250) {
- $this->error =
- array("error" => "SEND not accepted from server",
- "smtp_code" => $code,
- "smtp_msg" => substr($rply,4));
- if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
- }
- return false;
- }
- return true;
- }
-
- /**
- * Starts a mail transaction from the email address specified in
- * $from. Returns true if successful or false otherwise. If True
- * the mail transaction is started and then one or more Recipient
- * commands may be called followed by a Data command. This command
- * will send the message to the users terminal if they are logged
</del><span class="cx"> * in and send them an email.
</span><span class="cx"> *
</span><span class="cx"> * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
</span><span class="lines">@@ -876,8 +717,8 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function SendAndMail($from) {
- $this->error = null; # so no confusion is caused
</del><ins>+ public function SendAndMail($from) {
+ $this->error = null; // so no confusion is caused
</ins><span class="cx">
</span><span class="cx"> if(!$this->connected()) {
</span><span class="cx"> $this->error = array(
</span><span class="lines">@@ -891,7 +732,7 @@
</span><span class="cx"> $code = substr($rply,0,3);
</span><span class="cx">
</span><span class="cx"> if($this->do_debug >= 2) {
</span><del>- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
</del><ins>+ echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if($code != 250) {
</span><span class="lines">@@ -900,8 +741,7 @@
</span><span class="cx"> "smtp_code" => $code,
</span><span class="cx"> "smtp_msg" => substr($rply,4));
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
</del><ins>+ echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="lines">@@ -909,54 +749,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Starts a mail transaction from the email address specified in
- * $from. Returns true if successful or false otherwise. If True
- * the mail transaction is started and then one or more Recipient
- * commands may be called followed by a Data command. This command
- * will send the message to the users terminal if they are logged
- * in or mail it to them if they are not.
- *
- * Implements rfc 821: SOML <SP> FROM:<reverse-path> <CRLF>
- *
- * SMTP CODE SUCCESS: 250
- * SMTP CODE SUCCESS: 552,451,452
- * SMTP CODE SUCCESS: 500,501,502,421
- * @access public
- * @return bool
- */
- function SendOrMail($from) {
- $this->error = null; # so no confusion is caused
-
- if(!$this->connected()) {
- $this->error = array(
- "error" => "Called SendOrMail() without being connected");
- return false;
- }
-
- fputs($this->smtp_conn,"SOML FROM:" . $from . $this->CRLF);
-
- $rply = $this->get_lines();
- $code = substr($rply,0,3);
-
- if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
- }
-
- if($code != 250) {
- $this->error =
- array("error" => "SOML not accepted from server",
- "smtp_code" => $code,
- "smtp_msg" => substr($rply,4));
- if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
- }
- return false;
- }
- return true;
- }
-
- /**
</del><span class="cx"> * This is an optional command for SMTP that this class does not
</span><span class="cx"> * support. This method is here to make the RFC821 Definition
</span><span class="cx"> * complete for this class and __may__ be implimented in the future
</span><span class="lines">@@ -969,63 +761,27 @@
</span><span class="cx"> * @access public
</span><span class="cx"> * @return bool
</span><span class="cx"> */
</span><del>- function Turn() {
</del><ins>+ public function Turn() {
</ins><span class="cx"> $this->error = array("error" => "This method, TURN, of the SMTP ".
</span><span class="cx"> "is not implemented");
</span><span class="cx"> if($this->do_debug >= 1) {
</span><del>- echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF;
</del><ins>+ echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Verifies that the name is recognized by the server.
- * Returns false if the name could not be verified otherwise
- * the response from the server is returned.
- *
- * Implements rfc 821: VRFY <SP> <string> <CRLF>
- *
- * SMTP CODE SUCCESS: 250,251
- * SMTP CODE FAILURE: 550,551,553
- * SMTP CODE ERROR : 500,501,502,421
- * @access public
- * @return int
- */
- function Verify($name) {
- $this->error = null; # so no confusion is caused
-
- if(!$this->connected()) {
- $this->error = array(
- "error" => "Called Verify() without being connected");
- return false;
- }
-
- fputs($this->smtp_conn,"VRFY " . $name . $this->CRLF);
-
- $rply = $this->get_lines();
- $code = substr($rply,0,3);
-
- if($this->do_debug >= 2) {
- echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
- }
-
- if($code != 250 && $code != 251) {
- $this->error =
- array("error" => "VRFY failed on name '$name'",
- "smtp_code" => $code,
- "smtp_msg" => substr($rply,4));
- if($this->do_debug >= 1) {
- echo "SMTP -> ERROR: " . $this->error["error"] .
- ": " . $rply . $this->CRLF;
- }
- return false;
- }
- return $rply;
</del><ins>+ * Get the current error
+ * @access public
+ * @return array
+ */
+ public function getError() {
+ return $this->error;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- /*******************************************************************
- * INTERNAL FUNCTIONS *
- ******************************************************************/
</del><ins>+ /////////////////////////////////////////////////
+ // INTERNAL FUNCTIONS
+ /////////////////////////////////////////////////
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Read in as many lines as possible
</span><span class="lines">@@ -1036,21 +792,18 @@
</span><span class="cx"> * @access private
</span><span class="cx"> * @return string
</span><span class="cx"> */
</span><del>- function get_lines() {
</del><ins>+ private function get_lines() {
</ins><span class="cx"> $data = "";
</span><span class="cx"> while($str = @fgets($this->smtp_conn,515)) {
</span><span class="cx"> if($this->do_debug >= 4) {
</span><del>- echo "SMTP -> get_lines(): \$data was \"$data\"" .
- $this->CRLF;
- echo "SMTP -> get_lines(): \$str is \"$str\"" .
- $this->CRLF;
</del><ins>+ echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
+ echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><span class="cx"> $data .= $str;
</span><span class="cx"> if($this->do_debug >= 4) {
</span><del>- echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF;
</del><ins>+ echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
</ins><span class="cx"> }
</span><del>- # if the 4th character is a space then we are done reading
- # so just break the loop
</del><ins>+ // if 4th character is a space, we are done reading, break the loop
</ins><span class="cx"> if(substr($str,3,1) == " ") { break; }
</span><span class="cx"> }
</span><span class="cx"> return $data;
</span><span class="lines">@@ -1058,5 +811,4 @@
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><del>-
- ?>
</del><ins>+?>
</ins><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>
</body>
</html>