<!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" />
<title>[23522] trunk/wp-includes: Update to PHPMailer 5.2.4.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/23522">23522</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2013-02-28 18:33:13 +0000 (Thu, 28 Feb 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Update to PHPMailer 5.2.4. props bpetty. fixes <a href="http://core.trac.wordpress.org/ticket/21074">#21074</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 (23521 => 23522)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-phpmailer.php        2013-02-28 18:27:13 UTC (rev 23521)
+++ trunk/wp-includes/class-phpmailer.php        2013-02-28 18:33:13 UTC (rev 23522)
</span><span class="lines">@@ -2,7 +2,7 @@
</span><span class="cx"> /*~ class.phpmailer.php
</span><span class="cx"> .---------------------------------------------------------------------------.
</span><span class="cx"> |  Software: PHPMailer - PHP email class                                    |
</span><del>-|   Version: 5.2.1                                                          |
</del><ins>+|   Version: 5.2.4                                                          |
</ins><span class="cx"> |      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
</span><span class="cx"> | ------------------------------------------------------------------------- |
</span><span class="cx"> |     Admin: Jim Jagielski (project admininistrator)                        |
</span><span class="lines">@@ -23,7 +23,7 @@
</span><span class="cx"> */
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * PHPMailer - PHP email transport class
</del><ins>+ * PHPMailer - PHP email creation and transport class
</ins><span class="cx">  * NOTE: Requires PHP version 5 or later
</span><span class="cx">  * @package PHPMailer
</span><span class="cx">  * @author Andy Prevost
</span><span class="lines">@@ -31,12 +31,15 @@
</span><span class="cx">  * @author Jim Jagielski
</span><span class="cx">  * @copyright 2010 - 2012 Jim Jagielski
</span><span class="cx">  * @copyright 2004 - 2009 Andy Prevost
</span><del>- * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $
</del><span class="cx">  * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
</span><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> if (version_compare(PHP_VERSION, '5.0.0', '&lt;') ) exit(&quot;Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n&quot;);
</span><span class="cx"> 
</span><ins>+/**
+ * PHP email creation and transport class
+ * @package PHPMailer
+ */
</ins><span class="cx"> class PHPMailer {
</span><span class="cx"> 
</span><span class="cx">   /////////////////////////////////////////////////
</span><span class="lines">@@ -94,6 +97,13 @@
</span><span class="cx">   public $Sender            = '';
</span><span class="cx"> 
</span><span class="cx">   /**
</span><ins>+   * Sets the Return-Path of the message.  If empty, it will
+   * be set to either From or Sender.
+   * @var string
+   */
+  public $ReturnPath        = '';
+
+  /**
</ins><span class="cx">    * Sets the Subject of the message.
</span><span class="cx">    * @var string
</span><span class="cx">    */
</span><span class="lines">@@ -130,11 +140,11 @@
</span><span class="cx">   protected $MIMEHeader     = '';
</span><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   * Stores the complete sent MIME message (Body and Headers)
</del><ins>+   * Stores the extra header list which CreateHeader() doesn't fold in
</ins><span class="cx">    * @var string
</span><span class="cx">    * @access protected
</span><span class="cx">   */
</span><del>-  protected $SentMIMEMessage     = '';
</del><ins>+  protected $mailHeader     = '';
</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="lines">@@ -156,6 +166,13 @@
</span><span class="cx">   public $Sendmail          = '/usr/sbin/sendmail';
</span><span class="cx"> 
</span><span class="cx">   /**
</span><ins>+   * Determine if mail() uses a fully sendmail compatible MTA that
+   * supports sendmail's &quot;-oi -f&quot; options
+   * @var boolean
+   */
+  public $UseSendmailOptions        = true;
+  
+  /**
</ins><span class="cx">    * Path to PHPMailer plugins.  Useful if the SMTP class
</span><span class="cx">    * is in a different directory than the PHP include path.
</span><span class="cx">    * @var string
</span><span class="lines">@@ -183,12 +200,21 @@
</span><span class="cx">    */
</span><span class="cx">   public $MessageID         = '';
</span><span class="cx"> 
</span><ins>+  /**
+   * Sets the message Date to be used in the Date header.
+   * If empty, the current date will be added.
+   * @var string
+   */
+  public $MessageDate       = '';
+
</ins><span class="cx">   /////////////////////////////////////////////////
</span><span class="cx">   // PROPERTIES FOR SMTP
</span><span class="cx">   /////////////////////////////////////////////////
</span><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   * Sets the SMTP hosts.  All hosts must be separated by a
</del><ins>+   * Sets the SMTP hosts.
+   *
+   * All hosts must be separated by a
</ins><span class="cx">    * semicolon.  You can also specify a different port
</span><span class="cx">    * for each host by using this format: [hostname:port]
</span><span class="cx">    * (e.g. &quot;smtp1.example.com:25;smtp2.example.com&quot;).
</span><span class="lines">@@ -210,8 +236,7 @@
</span><span class="cx">   public $Helo          = '';
</span><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   * Sets connection prefix.
-   * Options are &quot;&quot;, &quot;ssl&quot; or &quot;tls&quot;
</del><ins>+   * Sets connection prefix. Options are &quot;&quot;, &quot;ssl&quot; or &quot;tls&quot;
</ins><span class="cx">    * @var string
</span><span class="cx">    */
</span><span class="cx">   public $SMTPSecure    = '';
</span><span class="lines">@@ -235,6 +260,24 @@
</span><span class="cx">   public $Password      = '';
</span><span class="cx"> 
</span><span class="cx">   /**
</span><ins>+   *  Sets SMTP auth type. Options are LOGIN | PLAIN | NTLM  (default LOGIN)
+   *  @var string
+   */
+  public $AuthType      = '';
+  
+  /**
+   *  Sets SMTP realm.
+   *  @var string
+   */
+  public $Realm         = '';
+
+  /**
+   *  Sets SMTP workstation.
+   *  @var string
+   */
+  public $Workstation   = '';
+
+  /**
</ins><span class="cx">    * Sets the SMTP server timeout in seconds.
</span><span class="cx">    * This function will not work with the win32 version.
</span><span class="cx">    * @var int
</span><span class="lines">@@ -248,6 +291,13 @@
</span><span class="cx">   public $SMTPDebug     = false;
</span><span class="cx"> 
</span><span class="cx">   /**
</span><ins>+   * Sets the function/method to use for debugging output.
+   * Right now we only honor &quot;echo&quot; or &quot;error_log&quot;
+   * @var string
+   */
+  public $Debugoutput     = &quot;echo&quot;;
+
+  /**
</ins><span class="cx">    * Prevents the SMTP connection from being closed after each mail
</span><span class="cx">    * sending.  If this is set to true then to close the connection
</span><span class="cx">    * requires an explicit call to SmtpClose().
</span><span class="lines">@@ -269,53 +319,69 @@
</span><span class="cx">   public $SingleToArray = array();
</span><span class="cx"> 
</span><span class="cx">  /**
</span><del>-   * Provides the ability to change the line ending
</del><ins>+   * Provides the ability to change the generic line ending
+   * NOTE: The default remains '\n'. We force CRLF where we KNOW
+   *        it must be used via self::CRLF
</ins><span class="cx">    * @var string
</span><span class="cx">    */
</span><span class="cx">   public $LE              = &quot;\n&quot;;
</span><span class="cx"> 
</span><del>-  /**
-   * Used with DKIM DNS Resource Record
</del><ins>+   /**
+   * Used with DKIM Signing
+   * required parameter if DKIM is enabled
+   *
+   * domain selector example domainkey
</ins><span class="cx">    * @var string
</span><span class="cx">    */
</span><del>-  public $DKIM_selector   = 'phpmailer';
</del><ins>+  public $DKIM_selector   = '';
</ins><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   * Used with DKIM DNS Resource Record
-   * optional, in format of email address 'you@yourdomain.com'
</del><ins>+   * Used with DKIM Signing
+   * required if DKIM is enabled, in format of email address 'you@yourdomain.com' typically used as the source of the email
</ins><span class="cx">    * @var string
</span><span class="cx">    */
</span><span class="cx">   public $DKIM_identity   = '';
</span><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   * Used with DKIM DNS Resource Record
</del><ins>+   * Used with DKIM Signing
+   * optional parameter if your private key requires a passphras
</ins><span class="cx">    * @var string
</span><span class="cx">    */
</span><span class="cx">   public $DKIM_passphrase   = '';
</span><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   * Used with DKIM DNS Resource Record
-   * optional, in format of email address 'you@yourdomain.com'
</del><ins>+   * Used with DKIM Singing
+   * required if DKIM is enabled, in format of email address 'domain.com'
</ins><span class="cx">    * @var string
</span><span class="cx">    */
</span><span class="cx">   public $DKIM_domain     = '';
</span><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   * Used with DKIM DNS Resource Record
-   * optional, in format of email address 'you@yourdomain.com'
</del><ins>+   * Used with DKIM Signing
+   * required if DKIM is enabled, path to private key file
</ins><span class="cx">    * @var string
</span><span class="cx">    */
</span><span class="cx">   public $DKIM_private    = '';
</span><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   * Callback Action function name
-   * the function that handles the result of the send email action. Parameters:
</del><ins>+   * Callback Action function name.
+   * The function that handles the result of the send email action.
+   * It is called out by Send() for each email sent.
+   *
+   * Value can be:
+   * - 'function_name' for function names
+   * - 'Class::Method' for static method calls
+   * - array($object, 'Method') for calling methods on $object
+   * See http://php.net/is_callable manual page for more details.
+   *
+   * Parameters:
</ins><span class="cx">    *   bool    $result        result of the send action
</span><span class="cx">    *   string  $to            email address of the recipient
</span><span class="cx">    *   string  $cc            cc email addresses
</span><span class="cx">    *   string  $bcc           bcc email addresses
</span><span class="cx">    *   string  $subject       the subject
</span><span class="cx">    *   string  $body          the email body
</span><ins>+   *   string  $from          email address of sender
</ins><span class="cx">    * @var string
</span><span class="cx">    */
</span><span class="cx">   public $action_function = ''; //'callbackAction';
</span><span class="lines">@@ -324,11 +390,11 @@
</span><span class="cx">    * Sets the PHPMailer Version number
</span><span class="cx">    * @var string
</span><span class="cx">    */
</span><del>-  public $Version         = '5.2.1';
</del><ins>+  public $Version         = '5.2.4';
</ins><span class="cx"> 
</span><span class="cx">   /**
</span><span class="cx">    * What to use in the X-Mailer header
</span><del>-   * @var string
</del><ins>+   * @var string NULL for default, whitespace for None, or actual string to use
</ins><span class="cx">    */
</span><span class="cx">   public $XMailer         = '';
</span><span class="cx"> 
</span><span class="lines">@@ -336,21 +402,85 @@
</span><span class="cx">   // PROPERTIES, PRIVATE AND PROTECTED
</span><span class="cx">   /////////////////////////////////////////////////
</span><span class="cx"> 
</span><del>-  protected   $smtp           = NULL;
</del><ins>+  /**
+   * @var SMTP An instance of the SMTP sender class
+   * @access protected
+   */
+  protected   $smtp           = null;
+  /**
+   * @var array An array of 'to' addresses
+   * @access protected
+   */
</ins><span class="cx">   protected   $to             = array();
</span><ins>+  /**
+   * @var array An array of 'cc' addresses
+   * @access protected
+   */
</ins><span class="cx">   protected   $cc             = array();
</span><ins>+  /**
+   * @var array An array of 'bcc' addresses
+   * @access protected
+   */
</ins><span class="cx">   protected   $bcc            = array();
</span><ins>+  /**
+   * @var array An array of reply-to name and address
+   * @access protected
+   */
</ins><span class="cx">   protected   $ReplyTo        = array();
</span><ins>+  /**
+   * @var array An array of all kinds of addresses: to, cc, bcc, replyto
+   * @access protected
+   */
</ins><span class="cx">   protected   $all_recipients = array();
</span><ins>+  /**
+   * @var array An array of attachments
+   * @access protected
+   */
</ins><span class="cx">   protected   $attachment     = array();
</span><ins>+  /**
+   * @var array An array of custom headers
+   * @access protected
+   */
</ins><span class="cx">   protected   $CustomHeader   = array();
</span><ins>+  /**
+   * @var string The message's MIME type
+   * @access protected
+   */
</ins><span class="cx">   protected   $message_type   = '';
</span><ins>+  /**
+   * @var array An array of MIME boundary strings
+   * @access protected
+   */
</ins><span class="cx">   protected   $boundary       = array();
</span><ins>+  /**
+   * @var array An array of available languages
+   * @access protected
+   */
</ins><span class="cx">   protected   $language       = array();
</span><ins>+  /**
+   * @var integer The number of errors encountered
+   * @access protected
+   */
</ins><span class="cx">   protected   $error_count    = 0;
</span><ins>+  /**
+   * @var string The filename of a DKIM certificate file
+   * @access protected
+   */
</ins><span class="cx">   protected   $sign_cert_file = '';
</span><ins>+  /**
+   * @var string The filename of a DKIM key file
+   * @access protected
+   */
</ins><span class="cx">   protected   $sign_key_file  = '';
</span><ins>+  /**
+   * @var string The password of a DKIM key
+   * @access protected
+   */
</ins><span class="cx">   protected   $sign_key_pass  = '';
</span><ins>+  /**
+   * @var boolean Whether to throw exceptions for errors
+   * @access protected
+   */
</ins><span class="cx">   protected   $exceptions     = false;
</span><span class="cx"> 
</span><span class="cx">   /////////////////////////////////////////////////
</span><span class="lines">@@ -360,12 +490,47 @@
</span><span class="cx">   const STOP_MESSAGE  = 0; // message only, continue processing
</span><span class="cx">   const STOP_CONTINUE = 1; // message?, likely ok to continue processing
</span><span class="cx">   const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
</span><del>-
</del><ins>+  const CRLF = &quot;\r\n&quot;;     // SMTP RFC specified EOL
+  
</ins><span class="cx">   /////////////////////////////////////////////////
</span><span class="cx">   // METHODS, VARIABLES
</span><span class="cx">   /////////////////////////////////////////////////
</span><span class="cx"> 
</span><span class="cx">   /**
</span><ins>+   * Calls actual mail() function, but in a safe_mode aware fashion
+   * Also, unless sendmail_path points to sendmail (or something that
+   * claims to be sendmail), don't pass params (not a perfect fix,
+   * but it will do)
+   * @param string $to To
+   * @param string $subject Subject
+   * @param string $body Message Body
+   * @param string $header Additional Header(s)
+   * @param string $params Params
+   * @access private
+   * @return bool
+   */
+  private function mail_passthru($to, $subject, $body, $header, $params) {
+    if ( ini_get('safe_mode') || !($this-&gt;UseSendmailOptions) ) {
+        $rt = @mail($to, $this-&gt;EncodeHeader($this-&gt;SecureHeader($subject)), $body, $header);
+    } else {
+        $rt = @mail($to, $this-&gt;EncodeHeader($this-&gt;SecureHeader($subject)), $body, $header, $params);
+    }
+    return $rt;
+  }
+
+  /**
+   * Outputs debugging info via user-defined method
+   * @param string $str
+   */
+  private function edebug($str) {
+    if ($this-&gt;Debugoutput == &quot;error_log&quot;) {
+        error_log($str);
+    } else {
+        echo $str;
+    }
+  }
+
+  /**
</ins><span class="cx">    * Constructor
</span><span class="cx">    * @param boolean $exceptions Should we throw external exceptions?
</span><span class="cx">    */
</span><span class="lines">@@ -476,6 +641,7 @@
</span><span class="cx">    * @param string $kind One of 'to', 'cc', 'bcc', 'ReplyTo'
</span><span class="cx">    * @param string $address The email address to send to
</span><span class="cx">    * @param string $name
</span><ins>+   * @throws phpmailerException
</ins><span class="cx">    * @return boolean true on success, false if address already used or invalid in some way
</span><span class="cx">    * @access protected
</span><span class="cx">    */
</span><span class="lines">@@ -485,20 +651,20 @@
</span><span class="cx">       if ($this-&gt;exceptions) {
</span><span class="cx">         throw new phpmailerException('Invalid recipient array: ' . $kind);
</span><span class="cx">       }
</span><del>-          if ($this-&gt;SMTPDebug) {
-        echo $this-&gt;Lang('Invalid recipient array').': '.$kind;
</del><ins>+      if ($this-&gt;SMTPDebug) {
+        $this-&gt;edebug($this-&gt;Lang('Invalid recipient array').': '.$kind);
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="cx">     $address = trim($address);
</span><span class="cx">     $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
</span><del>-    if (!self::ValidateAddress($address)) {
</del><ins>+    if (!$this-&gt;ValidateAddress($address)) {
</ins><span class="cx">       $this-&gt;SetError($this-&gt;Lang('invalid_address').': '. $address);
</span><span class="cx">       if ($this-&gt;exceptions) {
</span><span class="cx">         throw new phpmailerException($this-&gt;Lang('invalid_address').': '.$address);
</span><span class="cx">       }
</span><del>-          if ($this-&gt;SMTPDebug) {
-        echo $this-&gt;Lang('invalid_address').': '.$address;
</del><ins>+      if ($this-&gt;SMTPDebug) {
+        $this-&gt;edebug($this-&gt;Lang('invalid_address').': '.$address);
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="lines">@@ -521,18 +687,20 @@
</span><span class="cx">  * Set the From and FromName properties
</span><span class="cx">  * @param string $address
</span><span class="cx">  * @param string $name
</span><ins>+ * @param int $auto Also set Reply-To and Sender
+   * @throws phpmailerException
</ins><span class="cx">  * @return boolean
</span><span class="cx">  */
</span><span class="cx">   public function SetFrom($address, $name = '', $auto = 1) {
</span><span class="cx">     $address = trim($address);
</span><span class="cx">     $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
</span><del>-    if (!self::ValidateAddress($address)) {
</del><ins>+    if (!$this-&gt;ValidateAddress($address)) {
</ins><span class="cx">       $this-&gt;SetError($this-&gt;Lang('invalid_address').': '. $address);
</span><span class="cx">       if ($this-&gt;exceptions) {
</span><span class="cx">         throw new phpmailerException($this-&gt;Lang('invalid_address').': '.$address);
</span><span class="cx">       }
</span><del>-          if ($this-&gt;SMTPDebug) {
-        echo $this-&gt;Lang('invalid_address').': '.$address;
</del><ins>+      if ($this-&gt;SMTPDebug) {
+        $this-&gt;edebug($this-&gt;Lang('invalid_address').': '.$address);
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="lines">@@ -551,25 +719,31 @@
</span><span class="cx"> 
</span><span class="cx">   /**
</span><span class="cx">    * Check that a string looks roughly like an email address should
</span><del>-   * 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
</del><ins>+   * Static so it can be used without instantiation, public so people can overload
+   * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is
+   * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to
+   * not allow a@b type valid addresses :(
+   * Some Versions of PHP break on the regex though, likely due to PCRE, so use
+   * the older validation method for those users. (http://php.net/manual/en/pcre.installation.php)
+   * @link http://squiloople.com/2009/12/20/email-address-validation/
+   * @copyright regex Copyright Michael Rushton 2009-10 | http://squiloople.com/ | Feel free to use and redistribute this code. But please keep this copyright notice.
</ins><span class="cx">    * @param string $address The email address to check
</span><span class="cx">    * @return boolean
</span><span class="cx">    * @static
</span><span class="cx">    * @access public
</span><span class="cx">    */
</span><span class="cx">   public static function ValidateAddress($address) {
</span><del>-    if (function_exists('filter_var')) { //Introduced in PHP 5.2
-      if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
-        return false;
-      } else {
-        return true;
-      }
</del><ins>+        if ((defined('PCRE_VERSION')) &amp;&amp; (version_compare(PCRE_VERSION, '8.0') &gt;= 0)) {
+          return preg_match('/^(?!(?&gt;(?1)&quot;?(?&gt;\\\[ -~]|[^&quot;])&quot;?(?1)){255,})(?!(?&gt;(?1)&quot;?(?&gt;\\\[ -~]|[^&quot;])&quot;?(?1)){65,}@)((?&gt;(?&gt;(?&gt;((?&gt;(?&gt;(?&gt;\x0D\x0A)?[         ])+|(?&gt;[         ]*\x0D\x0A)?[         ]+)?)(\((?&gt;(?2)(?&gt;[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|&quot;(?&gt;(?2)(?&gt;[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)&quot;)(?&gt;(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?&gt;([a-z0-9](?&gt;[a-z0-9-]*[a-z0-9])?)(?&gt;(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?&gt;IPv6:(?&gt;([a-f0-9]{1,4})(?&gt;:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?&gt;:(?6)){0,5})?::(?7)?))|(?&gt;(?&gt;IPv6:(?&gt;(?6)(?&gt;:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?&gt;((?6)(?&gt;:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?&gt;\.(?9)){3}))\])(?1)$/isD', $address);
+        } elseif (function_exists('filter_var')) { //Introduced in PHP 5.2
+        if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
+          return false;
+        } else {
+          return true;
+        }
</ins><span class="cx">     } else {
</span><del>-      return preg_match('/^(?:[\w\!\#\$\%\&amp;\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&amp;\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[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);
-    }
</del><ins>+        return preg_match('/^(?:[\w\!\#\$\%\&amp;\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&amp;\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[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"> 
</span><span class="cx">   /////////////////////////////////////////////////
</span><span class="lines">@@ -580,6 +754,7 @@
</span><span class="cx">    * Creates message and assigns Mailer. If the message is
</span><span class="cx">    * not sent successfully then it returns false.  Use the ErrorInfo
</span><span class="cx">    * variable to view description of the error.
</span><ins>+   * @throws phpmailerException
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   public function Send() {
</span><span class="lines">@@ -587,7 +762,7 @@
</span><span class="cx">       if(!$this-&gt;PreSend()) return false;
</span><span class="cx">       return $this-&gt;PostSend();
</span><span class="cx">     } catch (phpmailerException $e) {
</span><del>-          $this-&gt;SentMIMEMessage = '';
</del><ins>+      $this-&gt;mailHeader = '';
</ins><span class="cx">       $this-&gt;SetError($e-&gt;getMessage());
</span><span class="cx">       if ($this-&gt;exceptions) {
</span><span class="cx">         throw $e;
</span><span class="lines">@@ -596,9 +771,14 @@
</span><span class="cx">     }
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-  protected function PreSend() {
</del><ins>+  /**
+   * Prep mail by constructing all message entities
+   * @throws phpmailerException
+   * @return bool
+   */
+  public function PreSend() {
</ins><span class="cx">     try {
</span><del>-          $mailHeader = &quot;&quot;;
</del><ins>+      $this-&gt;mailHeader = &quot;&quot;;
</ins><span class="cx">       if ((count($this-&gt;to) + count($this-&gt;cc) + count($this-&gt;bcc)) &lt; 1) {
</span><span class="cx">         throw new phpmailerException($this-&gt;Lang('provide_address'), self::STOP_CRITICAL);
</span><span class="cx">       }
</span><span class="lines">@@ -619,26 +799,25 @@
</span><span class="cx">       $this-&gt;MIMEBody = $this-&gt;CreateBody();
</span><span class="cx"> 
</span><span class="cx">       // To capture the complete message when using mail(), create
</span><del>-          // an extra header list which CreateHeader() doesn't fold in
</del><ins>+      // an extra header list which CreateHeader() doesn't fold in
</ins><span class="cx">       if ($this-&gt;Mailer == 'mail') {
</span><span class="cx">         if (count($this-&gt;to) &gt; 0) {
</span><del>-          $mailHeader .= $this-&gt;AddrAppend(&quot;To&quot;, $this-&gt;to);
</del><ins>+          $this-&gt;mailHeader .= $this-&gt;AddrAppend(&quot;To&quot;, $this-&gt;to);
</ins><span class="cx">         } else {
</span><del>-          $mailHeader .= $this-&gt;HeaderLine(&quot;To&quot;, &quot;undisclosed-recipients:;&quot;);
</del><ins>+          $this-&gt;mailHeader .= $this-&gt;HeaderLine(&quot;To&quot;, &quot;undisclosed-recipients:;&quot;);
</ins><span class="cx">         }
</span><del>-        $mailHeader .= $this-&gt;HeaderLine('Subject', $this-&gt;EncodeHeader($this-&gt;SecureHeader(trim($this-&gt;Subject))));
</del><ins>+        $this-&gt;mailHeader .= $this-&gt;HeaderLine('Subject', $this-&gt;EncodeHeader($this-&gt;SecureHeader(trim($this-&gt;Subject))));
</ins><span class="cx">         // if(count($this-&gt;cc) &gt; 0) {
</span><del>-            // $mailHeader .= $this-&gt;AddrAppend(&quot;Cc&quot;, $this-&gt;cc);
</del><ins>+            // $this-&gt;mailHeader .= $this-&gt;AddrAppend(&quot;Cc&quot;, $this-&gt;cc);
</ins><span class="cx">         // }
</span><span class="cx">       }
</span><span class="cx"> 
</span><span class="cx">       // digitally sign with DKIM if enabled
</span><del>-      if ($this-&gt;DKIM_domain &amp;&amp; $this-&gt;DKIM_private) {
</del><ins>+      if (!empty($this-&gt;DKIM_domain) &amp;&amp; !empty($this-&gt;DKIM_private) &amp;&amp; !empty($this-&gt;DKIM_selector) &amp;&amp; !empty($this-&gt;DKIM_domain) &amp;&amp; file_exists($this-&gt;DKIM_private)) {
</ins><span class="cx">         $header_dkim = $this-&gt;DKIM_Add($this-&gt;MIMEHeader, $this-&gt;EncodeHeader($this-&gt;SecureHeader($this-&gt;Subject)), $this-&gt;MIMEBody);
</span><span class="cx">         $this-&gt;MIMEHeader = str_replace(&quot;\r\n&quot;, &quot;\n&quot;, $header_dkim) . $this-&gt;MIMEHeader;
</span><span class="cx">       }
</span><span class="cx"> 
</span><del>-      $this-&gt;SentMIMEMessage = sprintf(&quot;%s%s\r\n\r\n%s&quot;,$this-&gt;MIMEHeader,$mailHeader,$this-&gt;MIMEBody);
</del><span class="cx">       return true;
</span><span class="cx"> 
</span><span class="cx">     } catch (phpmailerException $e) {
</span><span class="lines">@@ -650,7 +829,13 @@
</span><span class="cx">     }
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-  protected function PostSend() {
</del><ins>+  /**
+   * Actual Email transport function
+   * Send the email via the selected mechanism
+   * @throws phpmailerException
+   * @return bool
+   */
+  public function PostSend() {
</ins><span class="cx">     try {
</span><span class="cx">       // Choose the mailer and send through it
</span><span class="cx">       switch($this-&gt;Mailer) {
</span><span class="lines">@@ -663,34 +848,34 @@
</span><span class="cx">         default:
</span><span class="cx">           return $this-&gt;MailSend($this-&gt;MIMEHeader, $this-&gt;MIMEBody);
</span><span class="cx">       }
</span><del>-
</del><span class="cx">     } catch (phpmailerException $e) {
</span><span class="cx">       $this-&gt;SetError($e-&gt;getMessage());
</span><span class="cx">       if ($this-&gt;exceptions) {
</span><span class="cx">         throw $e;
</span><span class="cx">       }
</span><del>-          if ($this-&gt;SMTPDebug) {
-        echo $e-&gt;getMessage().&quot;\n&quot;;
</del><ins>+      if ($this-&gt;SMTPDebug) {
+        $this-&gt;edebug($e-&gt;getMessage().&quot;\n&quot;);
</ins><span class="cx">       }
</span><del>-      return false;
</del><span class="cx">     }
</span><ins>+    return false;
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   /**
</span><span class="cx">    * Sends mail using the $Sendmail program.
</span><span class="cx">    * @param string $header The message headers
</span><span class="cx">    * @param string $body The message body
</span><ins>+   * @throws phpmailerException
</ins><span class="cx">    * @access protected
</span><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   protected function SendmailSend($header, $body) {
</span><span class="cx">     if ($this-&gt;Sender != '') {
</span><del>-      $sendmail = sprintf(&quot;%s -oi -f %s -t&quot;, escapeshellcmd($this-&gt;Sendmail), escapeshellarg($this-&gt;Sender));
</del><ins>+      $sendmail = sprintf(&quot;%s -oi -f%s -t&quot;, escapeshellcmd($this-&gt;Sendmail), escapeshellarg($this-&gt;Sender));
</ins><span class="cx">     } else {
</span><span class="cx">       $sendmail = sprintf(&quot;%s -oi -t&quot;, escapeshellcmd($this-&gt;Sendmail));
</span><span class="cx">     }
</span><span class="cx">     if ($this-&gt;SingleTo === true) {
</span><del>-      foreach ($this-&gt;SingleToArray as $key =&gt; $val) {
</del><ins>+      foreach ($this-&gt;SingleToArray as $val) {
</ins><span class="cx">         if(!@$mail = popen($sendmail, 'w')) {
</span><span class="cx">           throw new phpmailerException($this-&gt;Lang('execute') . $this-&gt;Sendmail, self::STOP_CRITICAL);
</span><span class="cx">         }
</span><span class="lines">@@ -726,6 +911,7 @@
</span><span class="cx">    * Sends mail using the PHP mail() function.
</span><span class="cx">    * @param string $header The message headers
</span><span class="cx">    * @param string $body The message body
</span><ins>+     * @throws phpmailerException
</ins><span class="cx">    * @access protected
</span><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="lines">@@ -739,38 +925,25 @@
</span><span class="cx">     if (empty($this-&gt;Sender)) {
</span><span class="cx">       $params = &quot;-oi &quot;;
</span><span class="cx">     } else {
</span><del>-      $params = sprintf(&quot;-oi -f %s&quot;, $this-&gt;Sender);
</del><ins>+      $params = sprintf(&quot;-oi -f%s&quot;, $this-&gt;Sender);
</ins><span class="cx">     }
</span><span class="cx">     if ($this-&gt;Sender != '' and !ini_get('safe_mode')) {
</span><span class="cx">       $old_from = ini_get('sendmail_from');
</span><span class="cx">       ini_set('sendmail_from', $this-&gt;Sender);
</span><del>-      if ($this-&gt;SingleTo === true &amp;&amp; count($toArr) &gt; 1) {
-        foreach ($toArr as $key =&gt; $val) {
-          $rt = @mail($val, $this-&gt;EncodeHeader($this-&gt;SecureHeader($this-&gt;Subject)), $body, $header, $params);
-          // implement call back function if it exists
-          $isSent = ($rt == 1) ? 1 : 0;
-          $this-&gt;doCallback($isSent, $val, $this-&gt;cc, $this-&gt;bcc, $this-&gt;Subject, $body);
-        }
-      } else {
-        $rt = @mail($to, $this-&gt;EncodeHeader($this-&gt;SecureHeader($this-&gt;Subject)), $body, $header, $params);
</del><ins>+    }
+      $rt = false;
+    if ($this-&gt;SingleTo === true &amp;&amp; count($toArr) &gt; 1) {
+      foreach ($toArr as $val) {
+        $rt = $this-&gt;mail_passthru($val, $this-&gt;Subject, $body, $header, $params);
</ins><span class="cx">         // implement call back function if it exists
</span><span class="cx">         $isSent = ($rt == 1) ? 1 : 0;
</span><del>-        $this-&gt;doCallback($isSent, $to, $this-&gt;cc, $this-&gt;bcc, $this-&gt;Subject, $body);
</del><ins>+        $this-&gt;doCallback($isSent, $val, $this-&gt;cc, $this-&gt;bcc, $this-&gt;Subject, $body);
</ins><span class="cx">       }
</span><span class="cx">     } else {
</span><del>-      if ($this-&gt;SingleTo === true &amp;&amp; count($toArr) &gt; 1) {
-        foreach ($toArr as $key =&gt; $val) {
-          $rt = @mail($val, $this-&gt;EncodeHeader($this-&gt;SecureHeader($this-&gt;Subject)), $body, $header);
-          // implement call back function if it exists
-          $isSent = ($rt == 1) ? 1 : 0;
-          $this-&gt;doCallback($isSent, $val, $this-&gt;cc, $this-&gt;bcc, $this-&gt;Subject, $body);
-        }
-      } else {
-        $rt = @mail($to, $this-&gt;EncodeHeader($this-&gt;SecureHeader($this-&gt;Subject)), $body, $header);
-        // implement call back function if it exists
-        $isSent = ($rt == 1) ? 1 : 0;
-        $this-&gt;doCallback($isSent, $to, $this-&gt;cc, $this-&gt;bcc, $this-&gt;Subject, $body);
-      }
</del><ins>+      $rt = $this-&gt;mail_passthru($to, $this-&gt;Subject, $body, $header, $params);
+      // implement call back function if it exists
+      $isSent = ($rt == 1) ? 1 : 0;
+      $this-&gt;doCallback($isSent, $to, $this-&gt;cc, $this-&gt;bcc, $this-&gt;Subject, $body);
</ins><span class="cx">     }
</span><span class="cx">     if (isset($old_from)) {
</span><span class="cx">       ini_set('sendmail_from', $old_from);
</span><span class="lines">@@ -786,6 +959,7 @@
</span><span class="cx">    * Returns false if there is a bad MAIL FROM, RCPT, or DATA input.
</span><span class="cx">    * @param string $header The message headers
</span><span class="cx">    * @param string $body The message body
</span><ins>+   * @throws phpmailerException
</ins><span class="cx">    * @uses SMTP
</span><span class="cx">    * @access protected
</span><span class="cx">    * @return bool
</span><span class="lines">@@ -799,7 +973,8 @@
</span><span class="cx">     }
</span><span class="cx">     $smtp_from = ($this-&gt;Sender == '') ? $this-&gt;From : $this-&gt;Sender;
</span><span class="cx">     if(!$this-&gt;smtp-&gt;Mail($smtp_from)) {
</span><del>-      throw new phpmailerException($this-&gt;Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
</del><ins>+      $this-&gt;SetError($this-&gt;Lang('from_failed') . $smtp_from . &quot; : &quot; . implode(&quot;,&quot;,$this-&gt;smtp-&gt;getError())) ;
+      throw new phpmailerException($this-&gt;ErrorInfo, self::STOP_CRITICAL);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Attempt to send attach all recipients
</span><span class="lines">@@ -850,6 +1025,9 @@
</span><span class="cx">     }
</span><span class="cx">     if($this-&gt;SMTPKeepAlive == true) {
</span><span class="cx">       $this-&gt;smtp-&gt;Reset();
</span><ins>+    } else {
+        $this-&gt;smtp-&gt;Quit();
+        $this-&gt;smtp-&gt;Close();
</ins><span class="cx">     }
</span><span class="cx">     return true;
</span><span class="cx">   }
</span><span class="lines">@@ -859,13 +1037,15 @@
</span><span class="cx">    * Returns false if the operation failed.
</span><span class="cx">    * @uses SMTP
</span><span class="cx">    * @access public
</span><ins>+   * @throws phpmailerException
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   public function SmtpConnect() {
</span><span class="cx">     if(is_null($this-&gt;smtp)) {
</span><del>-      $this-&gt;smtp = new SMTP();
</del><ins>+      $this-&gt;smtp = new SMTP;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    $this-&gt;smtp-&gt;Timeout = $this-&gt;Timeout;
</ins><span class="cx">     $this-&gt;smtp-&gt;do_debug = $this-&gt;SMTPDebug;
</span><span class="cx">     $hosts = explode(';', $this-&gt;Host);
</span><span class="cx">     $index = 0;
</span><span class="lines">@@ -893,7 +1073,7 @@
</span><span class="cx"> 
</span><span class="cx">           if ($tls) {
</span><span class="cx">             if (!$this-&gt;smtp-&gt;StartTLS()) {
</span><del>-              throw new phpmailerException($this-&gt;Lang('tls'));
</del><ins>+              throw new phpmailerException($this-&gt;Lang('connect_host'));
</ins><span class="cx">             }
</span><span class="cx"> 
</span><span class="cx">             //We must resend HELO after tls negotiation
</span><span class="lines">@@ -902,19 +1082,20 @@
</span><span class="cx"> 
</span><span class="cx">           $connection = true;
</span><span class="cx">           if ($this-&gt;SMTPAuth) {
</span><del>-            if (!$this-&gt;smtp-&gt;Authenticate($this-&gt;Username, $this-&gt;Password)) {
</del><ins>+            if (!$this-&gt;smtp-&gt;Authenticate($this-&gt;Username, $this-&gt;Password, $this-&gt;AuthType,
+                                           $this-&gt;Realm, $this-&gt;Workstation)) {
</ins><span class="cx">               throw new phpmailerException($this-&gt;Lang('authenticate'));
</span><span class="cx">             }
</span><span class="cx">           }
</span><span class="cx">         }
</span><span class="cx">         $index++;
</span><del>-        if (!$connection) {
-          throw new phpmailerException($this-&gt;Lang('connect_host'));
-        }
</del><ins>+      if (!$connection) {
+        throw new phpmailerException($this-&gt;Lang('connect_host'));
</ins><span class="cx">       }
</span><ins>+      }
</ins><span class="cx">     } catch (phpmailerException $e) {
</span><span class="cx">       $this-&gt;smtp-&gt;Reset();
</span><del>-          if ($this-&gt;exceptions) {
</del><ins>+      if ($this-&gt;exceptions) {
</ins><span class="cx">         throw $e;
</span><span class="cx">       }
</span><span class="cx">     }
</span><span class="lines">@@ -926,7 +1107,7 @@
</span><span class="cx">    * @return void
</span><span class="cx">    */
</span><span class="cx">   public function SmtpClose() {
</span><del>-    if(!is_null($this-&gt;smtp)) {
</del><ins>+    if ($this-&gt;smtp !== null) {
</ins><span class="cx">       if($this-&gt;smtp-&gt;Connected()) {
</span><span class="cx">         $this-&gt;smtp-&gt;Quit();
</span><span class="cx">         $this-&gt;smtp-&gt;Close();
</span><span class="lines">@@ -939,28 +1120,30 @@
</span><span class="cx">   * Returns false if it cannot load the language file.  The default language is English.
</span><span class="cx">   * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: &quot;br&quot;)
</span><span class="cx">   * @param string $lang_path Path to the language file directory
</span><ins>+   * @return bool
</ins><span class="cx">   * @access public
</span><span class="cx">   */
</span><span class="cx">   function SetLanguage($langcode = 'en', $lang_path = 'language/') {
</span><span class="cx">     //Define full set of translatable strings
</span><span class="cx">     $PHPMAILER_LANG = array(
</span><del>-      'provide_address' =&gt; 'You must provide at least one recipient email address.',
</del><ins>+      'authenticate'         =&gt; 'SMTP Error: Could not authenticate.',
+      'connect_host'         =&gt; 'SMTP Error: Could not connect to SMTP host.',
+      'data_not_accepted'    =&gt; 'SMTP Error: Data not accepted.',
+      'empty_message'        =&gt; 'Message body empty',
+      'encoding'             =&gt; 'Unknown encoding: ',
+      'execute'              =&gt; 'Could not execute: ',
+      'file_access'          =&gt; 'Could not access file: ',
+      'file_open'            =&gt; 'File Error: Could not open file: ',
+      'from_failed'          =&gt; 'The following From address failed: ',
+      'instantiate'          =&gt; 'Could not instantiate mail function.',
+      'invalid_address'      =&gt; 'Invalid address',
</ins><span class="cx">       'mailer_not_supported' =&gt; ' mailer is not supported.',
</span><del>-      'execute' =&gt; 'Could not execute: ',
-      'instantiate' =&gt; 'Could not instantiate mail function.',
-      'authenticate' =&gt; 'SMTP Error: Could not authenticate.',
-      'from_failed' =&gt; 'The following From address failed: ',
-      'recipients_failed' =&gt; 'SMTP Error: The following recipients failed: ',
-      'data_not_accepted' =&gt; 'SMTP Error: Data not accepted.',
-      'connect_host' =&gt; 'SMTP Error: Could not connect to SMTP host.',
-      'file_access' =&gt; 'Could not access file: ',
-      'file_open' =&gt; 'File Error: Could not open file: ',
-      'encoding' =&gt; 'Unknown encoding: ',
-      'signing' =&gt; 'Signing Error: ',
-      'smtp_error' =&gt; 'SMTP server error: ',
-      'empty_message' =&gt; 'Message body empty',
-      'invalid_address' =&gt; 'Invalid address',
-      'variable_set' =&gt; 'Cannot set or reset variable: '
</del><ins>+      'provide_address'      =&gt; 'You must provide at least one recipient email address.',
+      'recipients_failed'    =&gt; 'SMTP Error: The following recipients failed: ',
+      'signing'              =&gt; 'Signing Error: ',
+      'smtp_connect_failed'  =&gt; 'SMTP Connect() failed.',
+      'smtp_error'           =&gt; 'SMTP server error: ',
+      'variable_set'         =&gt; 'Cannot set or reset variable: '
</ins><span class="cx">     );
</span><span class="cx">     //Overwrite language-specific strings. This way we'll never have missing translations - no more &quot;language string failed to load&quot;!
</span><span class="cx">     $l = true;
</span><span class="lines">@@ -986,6 +1169,8 @@
</span><span class="cx">   /**
</span><span class="cx">    * Creates recipient headers.
</span><span class="cx">    * @access public
</span><ins>+   * @param string $type
+   * @param array $addr
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   public function AddrAppend($type, $addr) {
</span><span class="lines">@@ -1003,6 +1188,7 @@
</span><span class="cx">   /**
</span><span class="cx">    * Formats an address correctly.
</span><span class="cx">    * @access public
</span><ins>+   * @param string $addr
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   public function AddrFormat($addr) {
</span><span class="lines">@@ -1028,13 +1214,15 @@
</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="cx">     $is_utf8 = (strtolower($this-&gt;CharSet) == &quot;utf-8&quot;);
</span><ins>+    $lelen = strlen($this-&gt;LE);
+    $crlflen = strlen(self::CRLF);
</ins><span class="cx"> 
</span><span class="cx">     $message = $this-&gt;FixEOL($message);
</span><del>-    if (substr($message, -1) == $this-&gt;LE) {
-      $message = substr($message, 0, -1);
</del><ins>+    if (substr($message, -$lelen) == $this-&gt;LE) {
+      $message = substr($message, 0, -$lelen);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    $line = explode($this-&gt;LE, $message);
</del><ins>+    $line = explode($this-&gt;LE, $message);   // Magic. We know FixEOL uses $LE
</ins><span class="cx">     $message = '';
</span><span class="cx">     for ($i = 0 ;$i &lt; count($line); $i++) {
</span><span class="cx">       $line_part = explode(' ', $line[$i]);
</span><span class="lines">@@ -1042,7 +1230,7 @@
</span><span class="cx">       for ($e = 0; $e&lt;count($line_part); $e++) {
</span><span class="cx">         $word = $line_part[$e];
</span><span class="cx">         if ($qp_mode and (strlen($word) &gt; $length)) {
</span><del>-          $space_left = $length - strlen($buf) - 1;
</del><ins>+          $space_left = $length - strlen($buf) - $crlflen;
</ins><span class="cx">           if ($e != 0) {
</span><span class="cx">             if ($space_left &gt; 20) {
</span><span class="cx">               $len = $space_left;
</span><span class="lines">@@ -1056,7 +1244,7 @@
</span><span class="cx">               $part = substr($word, 0, $len);
</span><span class="cx">               $word = substr($word, $len);
</span><span class="cx">               $buf .= ' ' . $part;
</span><del>-              $message .= $buf . sprintf(&quot;=%s&quot;, $this-&gt;LE);
</del><ins>+              $message .= $buf . sprintf(&quot;=%s&quot;, self::CRLF);
</ins><span class="cx">             } else {
</span><span class="cx">               $message .= $buf . $soft_break;
</span><span class="cx">             }
</span><span class="lines">@@ -1075,7 +1263,7 @@
</span><span class="cx">             $word = substr($word, $len);
</span><span class="cx"> 
</span><span class="cx">             if (strlen($word) &gt; 0) {
</span><del>-              $message .= $part . sprintf(&quot;=%s&quot;, $this-&gt;LE);
</del><ins>+              $message .= $part . sprintf(&quot;=%s&quot;, self::CRLF);
</ins><span class="cx">             } else {
</span><span class="cx">               $buf = $part;
</span><span class="cx">             }
</span><span class="lines">@@ -1090,7 +1278,7 @@
</span><span class="cx">           }
</span><span class="cx">         }
</span><span class="cx">       }
</span><del>-      $message .= $buf . $this-&gt;LE;
</del><ins>+      $message .= $buf . self::CRLF;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return $message;
</span><span class="lines">@@ -1175,8 +1363,15 @@
</span><span class="cx">     $this-&gt;boundary[2] = 'b2_' . $uniq_id;
</span><span class="cx">     $this-&gt;boundary[3] = 'b3_' . $uniq_id;
</span><span class="cx"> 
</span><del>-    $result .= $this-&gt;HeaderLine('Date', self::RFCDate());
-    if($this-&gt;Sender == '') {
</del><ins>+    if ($this-&gt;MessageDate == '') {
+      $result .= $this-&gt;HeaderLine('Date', self::RFCDate());
+    } else {
+      $result .= $this-&gt;HeaderLine('Date', $this-&gt;MessageDate);
+    }
+
+    if ($this-&gt;ReturnPath) {
+      $result .= $this-&gt;HeaderLine('Return-Path', trim($this-&gt;ReturnPath));
+    } elseif ($this-&gt;Sender == '') {
</ins><span class="cx">       $result .= $this-&gt;HeaderLine('Return-Path', trim($this-&gt;From));
</span><span class="cx">     } else {
</span><span class="cx">       $result .= $this-&gt;HeaderLine('Return-Path', trim($this-&gt;Sender));
</span><span class="lines">@@ -1195,7 +1390,7 @@
</span><span class="cx">           $result .= $this-&gt;HeaderLine('To', 'undisclosed-recipients:;');
</span><span class="cx">         }
</span><span class="cx">       }
</span><del>-        }
</del><ins>+    }
</ins><span class="cx"> 
</span><span class="cx">     $from = array();
</span><span class="cx">     $from[0][0] = trim($this-&gt;From);
</span><span class="lines">@@ -1227,10 +1422,13 @@
</span><span class="cx">       $result .= sprintf(&quot;Message-ID: &lt;%s@%s&gt;%s&quot;, $uniq_id, $this-&gt;ServerHostname(), $this-&gt;LE);
</span><span class="cx">     }
</span><span class="cx">     $result .= $this-&gt;HeaderLine('X-Priority', $this-&gt;Priority);
</span><del>-    if($this-&gt;XMailer) {
-      $result .= $this-&gt;HeaderLine('X-Mailer', $this-&gt;XMailer);
</del><ins>+    if ($this-&gt;XMailer == '') {
+        $result .= $this-&gt;HeaderLine('X-Mailer', 'PHPMailer '.$this-&gt;Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
</ins><span class="cx">     } else {
</span><del>-      $result .= $this-&gt;HeaderLine('X-Mailer', 'PHPMailer '.$this-&gt;Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
</del><ins>+      $myXmailer = trim($this-&gt;XMailer);
+      if ($myXmailer) {
+        $result .= $this-&gt;HeaderLine('X-Mailer', $myXmailer);
+      }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;ConfirmReadingTo != '') {
</span><span class="lines">@@ -1257,10 +1455,6 @@
</span><span class="cx">   public function GetMailMIME() {
</span><span class="cx">     $result = '';
</span><span class="cx">     switch($this-&gt;message_type) {
</span><del>-      case 'plain':
-        $result .= $this-&gt;HeaderLine('Content-Transfer-Encoding', $this-&gt;Encoding);
-        $result .= $this-&gt;TextLine('Content-Type: '.$this-&gt;ContentType.'; charset=&quot;'.$this-&gt;CharSet.'&quot;');
-        break;
</del><span class="cx">       case 'inline':
</span><span class="cx">         $result .= $this-&gt;HeaderLine('Content-Type', 'multipart/related;');
</span><span class="cx">         $result .= $this-&gt;TextLine(&quot;\tboundary=\&quot;&quot; . $this-&gt;boundary[1] . '&quot;');
</span><span class="lines">@@ -1277,10 +1471,15 @@
</span><span class="cx">         $result .= $this-&gt;HeaderLine('Content-Type', 'multipart/alternative;');
</span><span class="cx">         $result .= $this-&gt;TextLine(&quot;\tboundary=\&quot;&quot; . $this-&gt;boundary[1] . '&quot;');
</span><span class="cx">         break;
</span><ins>+      default:
+        // Catches case 'plain': and case '':
+        $result .= $this-&gt;HeaderLine('Content-Transfer-Encoding', $this-&gt;Encoding);
+        $result .= $this-&gt;TextLine('Content-Type: '.$this-&gt;ContentType.'; charset='.$this-&gt;CharSet);
+        break;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;Mailer != 'mail') {
</span><del>-      $result .= $this-&gt;LE.$this-&gt;LE;
</del><ins>+      $result .= $this-&gt;LE;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return $result;
</span><span class="lines">@@ -1292,28 +1491,26 @@
</span><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   public function GetSentMIMEMessage() {
</span><del>-    return $this-&gt;SentMIMEMessage;
</del><ins>+    return $this-&gt;MIMEHeader . $this-&gt;mailHeader . self::CRLF . $this-&gt;MIMEBody;
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">   /**
</span><span class="cx">    * Assembles the message body.  Returns an empty string on failure.
</span><span class="cx">    * @access public
</span><ins>+   * @throws phpmailerException
</ins><span class="cx">    * @return string The assembled message body
</span><span class="cx">    */
</span><span class="cx">   public function CreateBody() {
</span><span class="cx">     $body = '';
</span><span class="cx"> 
</span><span class="cx">     if ($this-&gt;sign_key_file) {
</span><del>-      $body .= $this-&gt;GetMailMIME();
</del><ins>+      $body .= $this-&gt;GetMailMIME().$this-&gt;LE;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     $this-&gt;SetWordWrap();
</span><span class="cx"> 
</span><span class="cx">     switch($this-&gt;message_type) {
</span><del>-      case 'plain':
-        $body .= $this-&gt;EncodeString($this-&gt;Body, $this-&gt;Encoding);
-        break;
</del><span class="cx">       case 'inline':
</span><span class="cx">         $body .= $this-&gt;GetBoundary($this-&gt;boundary[1], '', '', '');
</span><span class="cx">         $body .= $this-&gt;EncodeString($this-&gt;Body, $this-&gt;Encoding);
</span><span class="lines">@@ -1398,6 +1595,10 @@
</span><span class="cx">         $body .= $this-&gt;LE;
</span><span class="cx">         $body .= $this-&gt;AttachAll(&quot;attachment&quot;, $this-&gt;boundary[1]);
</span><span class="cx">         break;
</span><ins>+      default:
+        // catch case 'plain' and case ''
+        $body .= $this-&gt;EncodeString($this-&gt;Body, $this-&gt;Encoding);
+        break;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if ($this-&gt;IsError()) {
</span><span class="lines">@@ -1430,6 +1631,10 @@
</span><span class="cx">   /**
</span><span class="cx">    * Returns the start of a message boundary.
</span><span class="cx">    * @access protected
</span><ins>+   * @param string $boundary
+   * @param string $charSet
+   * @param string $contentType
+   * @param string $encoding
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   protected function GetBoundary($boundary, $charSet, $contentType, $encoding) {
</span><span class="lines">@@ -1444,7 +1649,7 @@
</span><span class="cx">       $encoding = $this-&gt;Encoding;
</span><span class="cx">     }
</span><span class="cx">     $result .= $this-&gt;TextLine('--' . $boundary);
</span><del>-    $result .= sprintf(&quot;Content-Type: %s; charset=\&quot;%s\&quot;&quot;, $contentType, $charSet);
</del><ins>+    $result .= sprintf(&quot;Content-Type: %s; charset=%s&quot;, $contentType, $charSet);
</ins><span class="cx">     $result .= $this-&gt;LE;
</span><span class="cx">     $result .= $this-&gt;HeaderLine('Content-Transfer-Encoding', $encoding);
</span><span class="cx">     $result .= $this-&gt;LE;
</span><span class="lines">@@ -1455,6 +1660,7 @@
</span><span class="cx">   /**
</span><span class="cx">    * Returns the end of a message boundary.
</span><span class="cx">    * @access protected
</span><ins>+   * @param string $boundary
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   protected function EndBoundary($boundary) {
</span><span class="lines">@@ -1478,6 +1684,8 @@
</span><span class="cx">   /**
</span><span class="cx">    *  Returns a formatted header line.
</span><span class="cx">    * @access public
</span><ins>+   * @param string $name
+   * @param string $value
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   public function HeaderLine($name, $value) {
</span><span class="lines">@@ -1487,6 +1695,7 @@
</span><span class="cx">   /**
</span><span class="cx">    * Returns a formatted mail line.
</span><span class="cx">    * @access public
</span><ins>+   * @param string $value
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   public function TextLine($value) {
</span><span class="lines">@@ -1505,6 +1714,7 @@
</span><span class="cx">    * @param string $name Overrides the attachment name.
</span><span class="cx">    * @param string $encoding File encoding (see $Encoding).
</span><span class="cx">    * @param string $type File extension (MIME) type.
</span><ins>+   * @throws phpmailerException
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
</span><span class="lines">@@ -1533,8 +1743,8 @@
</span><span class="cx">       if ($this-&gt;exceptions) {
</span><span class="cx">         throw $e;
</span><span class="cx">       }
</span><del>-          if ($this-&gt;SMTPDebug) {
-        echo $e-&gt;getMessage().&quot;\n&quot;;
</del><ins>+      if ($this-&gt;SMTPDebug) {
+        $this-&gt;edebug($e-&gt;getMessage().&quot;\n&quot;);
</ins><span class="cx">       }
</span><span class="cx">       if ( $e-&gt;getCode() == self::STOP_CRITICAL ) {
</span><span class="cx">         return false;
</span><span class="lines">@@ -1555,6 +1765,8 @@
</span><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 protected
</span><ins>+   * @param string $disposition_type
+   * @param string $boundary
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   protected function AttachAll($disposition_type, $boundary) {
</span><span class="lines">@@ -1568,6 +1780,8 @@
</span><span class="cx">       // CHECK IF IT IS A VALID DISPOSITION_FILTER
</span><span class="cx">       if($attachment[6] == $disposition_type) {
</span><span class="cx">         // Check for string attachment
</span><ins>+        $string = '';
+        $path = '';
</ins><span class="cx">         $bString = $attachment[5];
</span><span class="cx">         if ($bString) {
</span><span class="cx">           $string = $attachment[0];
</span><span class="lines">@@ -1624,6 +1838,7 @@
</span><span class="cx">    * Returns an empty string on failure.
</span><span class="cx">    * @param string $path The full path to the file
</span><span class="cx">    * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
</span><ins>+   * @throws phpmailerException
</ins><span class="cx">    * @see EncodeFile()
</span><span class="cx">    * @access protected
</span><span class="cx">    * @return string
</span><span class="lines">@@ -1633,28 +1848,28 @@
</span><span class="cx">       if (!is_readable($path)) {
</span><span class="cx">         throw new phpmailerException($this-&gt;Lang('file_open') . $path, self::STOP_CONTINUE);
</span><span class="cx">       }
</span><del>-      if (function_exists('get_magic_quotes')) {
-        function get_magic_quotes() {
-          return false;
-        }
-      }
-          $magic_quotes = get_magic_quotes_runtime();
-          if ($magic_quotes) {
</del><ins>+      //  if (!function_exists('get_magic_quotes')) {
+      //    function get_magic_quotes() {
+      //      return false;
+      //    }
+      //  }
+      $magic_quotes = get_magic_quotes_runtime();
+      if ($magic_quotes) {
</ins><span class="cx">         if (version_compare(PHP_VERSION, '5.3.0', '&lt;')) {
</span><span class="cx">           set_magic_quotes_runtime(0);
</span><span class="cx">         } else {
</span><del>-                  ini_set('magic_quotes_runtime', 0);
-                }
-          }
</del><ins>+          ini_set('magic_quotes_runtime', 0); 
+        }
+      }
</ins><span class="cx">       $file_buffer  = file_get_contents($path);
</span><span class="cx">       $file_buffer  = $this-&gt;EncodeString($file_buffer, $encoding);
</span><del>-          if ($magic_quotes) {
</del><ins>+      if ($magic_quotes) {
</ins><span class="cx">         if (version_compare(PHP_VERSION, '5.3.0', '&lt;')) {
</span><span class="cx">           set_magic_quotes_runtime($magic_quotes);
</span><span class="cx">         } else {
</span><del>-                  ini_set('magic_quotes_runtime', $magic_quotes);
-            }
-          }
</del><ins>+          ini_set('magic_quotes_runtime', $magic_quotes); 
+        }
+      }
</ins><span class="cx">       return $file_buffer;
</span><span class="cx">     } catch (Exception $e) {
</span><span class="cx">       $this-&gt;SetError($e-&gt;getMessage());
</span><span class="lines">@@ -1699,6 +1914,8 @@
</span><span class="cx">   /**
</span><span class="cx">    * Encode a header string to best (shortest) of Q, B, quoted or none.
</span><span class="cx">    * @access public
</span><ins>+   * @param string $str
+   * @param string $position
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   public function EncodeHeader($str, $position = 'text') {
</span><span class="lines">@@ -1737,7 +1954,7 @@
</span><span class="cx">       if (function_exists('mb_strlen') &amp;&amp; $this-&gt;HasMultiBytes($str)) {
</span><span class="cx">         // Use a custom function which correctly encodes and wraps long
</span><span class="cx">         // multibyte strings without breaking lines within a character
</span><del>-        $encoded = $this-&gt;Base64EncodeWrapMB($str);
</del><ins>+        $encoded = $this-&gt;Base64EncodeWrapMB($str, &quot;\n&quot;);
</ins><span class="cx">       } else {
</span><span class="cx">         $encoded = base64_encode($str);
</span><span class="cx">         $maxlen -= $maxlen % 4;
</span><span class="lines">@@ -1747,7 +1964,7 @@
</span><span class="cx">       $encoding = 'Q';
</span><span class="cx">       $encoded = $this-&gt;EncodeQ($str, $position);
</span><span class="cx">       $encoded = $this-&gt;WrapText($encoded, $maxlen, true);
</span><del>-      $encoded = str_replace('='.$this-&gt;LE, &quot;\n&quot;, trim($encoded));
</del><ins>+      $encoded = str_replace('='.self::CRLF, &quot;\n&quot;, trim($encoded));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     $encoded = preg_replace('/^(.*)$/m', &quot; =?&quot;.$this-&gt;CharSet.&quot;?$encoding?\\1?=&quot;, $encoded);
</span><span class="lines">@@ -1776,12 +1993,16 @@
</span><span class="cx">    * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
</span><span class="cx">    * @access public
</span><span class="cx">    * @param string $str multi-byte text to wrap encode
</span><ins>+   * @param string $lf string to use as linefeed/end-of-line
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><del>-  public function Base64EncodeWrapMB($str) {
</del><ins>+  public function Base64EncodeWrapMB($str, $lf=null) {
</ins><span class="cx">     $start = &quot;=?&quot;.$this-&gt;CharSet.&quot;?B?&quot;;
</span><span class="cx">     $end = &quot;?=&quot;;
</span><span class="cx">     $encoded = &quot;&quot;;
</span><ins>+    if ($lf === null) {
+      $lf = $this-&gt;LE;
+    }
</ins><span class="cx"> 
</span><span class="cx">     $mb_length = mb_strlen($str, $this-&gt;CharSet);
</span><span class="cx">     // Each line must have length &lt;= 75, including $start and $end
</span><span class="lines">@@ -1802,11 +2023,11 @@
</span><span class="cx">       }
</span><span class="cx">       while (strlen($chunk) &gt; $length);
</span><span class="cx"> 
</span><del>-      $encoded .= $chunk . $this-&gt;LE;
</del><ins>+      $encoded .= $chunk . $lf;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Chomp the last linefeed
</span><del>-    $encoded = substr($encoded, 0, -strlen($this-&gt;LE));
</del><ins>+    $encoded = substr($encoded, 0, -strlen($lf));
</ins><span class="cx">     return $encoded;
</span><span class="cx">   }
</span><span class="cx"> 
</span><span class="lines">@@ -1814,8 +2035,10 @@
</span><span class="cx">   * Encode string to quoted-printable.
</span><span class="cx">   * Only uses standard PHP, slow, but will always work
</span><span class="cx">   * @access public
</span><del>-  * @param string $string the text to encode
</del><ins>+   * @param string $input
</ins><span class="cx">   * @param integer $line_max Number of chars allowed on a line before wrapping
</span><ins>+   * @param bool $space_conv
+   * @internal param string $string the text to encode
</ins><span class="cx">   * @return string
</span><span class="cx">   */
</span><span class="cx">   public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
</span><span class="lines">@@ -1840,8 +2063,8 @@
</span><span class="cx">             $c = '=20';
</span><span class="cx">           }
</span><span class="cx">         } elseif ( ($dec == 61) || ($dec &lt; 32 ) || ($dec &gt; 126) ) { // always encode &quot;\t&quot;, which is *not* required
</span><del>-          $h2 = floor($dec/16);
-          $h1 = floor($dec%16);
</del><ins>+          $h2 = (integer)floor($dec/16);
+          $h1 = (integer)floor($dec%16);
</ins><span class="cx">           $c = $escape.$hex[$h2].$hex[$h1];
</span><span class="cx">         }
</span><span class="cx">         if ( (strlen($newline) + strlen($c)) &gt;= $line_max ) { // CRLF is not counted
</span><span class="lines">@@ -1901,30 +2124,38 @@
</span><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   public function EncodeQ($str, $position = 'text') {
</span><del>-    // There should not be any EOL in the string
-    $encoded = preg_replace('/[\r\n]*/', '', $str);
-
</del><ins>+    //There should not be any EOL in the string
+        $pattern=&quot;&quot;;
+    $encoded = str_replace(array(&quot;\r&quot;, &quot;\n&quot;), '', $str);
</ins><span class="cx">     switch (strtolower($position)) {
</span><span class="cx">       case 'phrase':
</span><del>-        $encoded = preg_replace(&quot;/([^A-Za-z0-9!*+\/ -])/e&quot;, &quot;'='.sprintf('%02X', ord('\\1'))&quot;, $encoded);
</del><ins>+        $pattern = '^A-Za-z0-9!*+\/ -';
</ins><span class="cx">         break;
</span><ins>+
</ins><span class="cx">       case 'comment':
</span><del>-        $encoded = preg_replace(&quot;/([\(\)\&quot;])/e&quot;, &quot;'='.sprintf('%02X', ord('\\1'))&quot;, $encoded);
</del><ins>+        $pattern = '\(\)&quot;';
+        //note that we dont break here!
+        //for this reason we build the $pattern withoud including delimiters and []
+
</ins><span class="cx">       case 'text':
</span><span class="cx">       default:
</span><del>-        // 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',
-                                &quot;'='.sprintf('%02X', ord(stripslashes('\\1')))&quot;, $encoded);
</del><ins>+        //Replace every high ascii, control =, ? and _ characters
+        //We put \075 (=) as first value to make sure it's the first one in being converted, preventing double encode
+        $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern;
</ins><span class="cx">         break;
</span><span class="cx">     }
</span><ins>+    
+    if (preg_match_all(&quot;/[{$pattern}]/&quot;, $encoded, $matches)) {
+      foreach (array_unique($matches[0]) as $char) {
+        $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
+      }
+    }
+    
+    //Replace every spaces to _ (more readable than =20)
+    return str_replace(' ', '_', $encoded);
+}
</ins><span class="cx"> 
</span><del>-    // Replace every spaces to _ (more readable than =20)
-    $encoded = str_replace(' ', '_', $encoded);
</del><span class="cx"> 
</span><del>-    return $encoded;
-  }
-
</del><span class="cx">   /**
</span><span class="cx">    * Adds a string or binary attachment (non-filesystem) to the list.
</span><span class="cx">    * This method can be used to attach ascii or binary data,
</span><span class="lines">@@ -1989,12 +2220,25 @@
</span><span class="cx">     return true;
</span><span class="cx">   }
</span><span class="cx"> 
</span><del>-  public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') {
</del><ins>+  /**
+   * Adds an embedded stringified attachment.  This can include images, sounds, and
+   * just about any other document.  Make sure to set the $type to an
+   * image type.  For JPEG images use &quot;image/jpeg&quot; and for GIF images
+   * use &quot;image/gif&quot;.
+   * @param string $string The attachment.
+   * @param string $cid Content ID of the attachment.  Use this to identify
+   *        the Id for accessing the image in an HTML form.
+   * @param string $name Overrides the attachment name.
+   * @param string $encoding File encoding (see $Encoding).
+   * @param string $type File extension (MIME) type.
+   * @return bool
+   */
+  public function AddStringEmbeddedImage($string, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
</ins><span class="cx">     // Append to $attachment array
</span><span class="cx">     $this-&gt;attachment[] = array(
</span><span class="cx">       0 =&gt; $string,
</span><del>-      1 =&gt; $filename,
-      2 =&gt; basename($filename),
</del><ins>+      1 =&gt; $name,
+      2 =&gt; $name,
</ins><span class="cx">       3 =&gt; $encoding,
</span><span class="cx">       4 =&gt; $type,
</span><span class="cx">       5 =&gt; true,  // isStringAttachment
</span><span class="lines">@@ -2017,6 +2261,10 @@
</span><span class="cx">     return false;
</span><span class="cx">   }
</span><span class="cx"> 
</span><ins>+  /**
+   * Returns true if an attachment (non-inline) is present.
+   * @return bool
+   */
</ins><span class="cx">   public function AttachmentExists() {
</span><span class="cx">     foreach($this-&gt;attachment as $attachment) {
</span><span class="cx">       if ($attachment[6] == 'attachment') {
</span><span class="lines">@@ -2026,8 +2274,12 @@
</span><span class="cx">     return false;
</span><span class="cx">   }
</span><span class="cx"> 
</span><ins>+  /**
+   * Does this message have an alternative body set?
+   * @return bool
+   */
</ins><span class="cx">   public function AlternativeExists() {
</span><del>-    return strlen($this-&gt;AltBody)&gt;0;
</del><ins>+    return !empty($this-&gt;AltBody);
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   /////////////////////////////////////////////////
</span><span class="lines">@@ -2111,6 +2363,7 @@
</span><span class="cx">   /**
</span><span class="cx">    * Adds the error message to the error container.
</span><span class="cx">    * @access protected
</span><ins>+   * @param string $msg
</ins><span class="cx">    * @return void
</span><span class="cx">    */
</span><span class="cx">   protected function SetError($msg) {
</span><span class="lines">@@ -2160,6 +2413,7 @@
</span><span class="cx">   /**
</span><span class="cx">    * Returns a message in the appropriate language.
</span><span class="cx">    * @access protected
</span><ins>+   * @param string $key
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   protected function Lang($key) {
</span><span class="lines">@@ -2184,30 +2438,44 @@
</span><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   * Changes every end of line from CR or LF to CRLF.
</del><ins>+   * Changes every end of line from CRLF, CR or LF to $this-&gt;LE.
</ins><span class="cx">    * @access public
</span><ins>+   * @param string $str String to FixEOL
</ins><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   public function FixEOL($str) {
</span><del>-    $str = str_replace(&quot;\r\n&quot;, &quot;\n&quot;, $str);
-    $str = str_replace(&quot;\r&quot;, &quot;\n&quot;, $str);
-    $str = str_replace(&quot;\n&quot;, $this-&gt;LE, $str);
-    return $str;
</del><ins>+        // condense down to \n
+        $nstr = str_replace(array(&quot;\r\n&quot;, &quot;\r&quot;), &quot;\n&quot;, $str);
+        // Now convert LE as needed
+        if ($this-&gt;LE !== &quot;\n&quot;) {
+                $nstr = str_replace(&quot;\n&quot;, $this-&gt;LE, $nstr);
+        }
+    return  $nstr;
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   * Adds a custom header.
</del><ins>+   * Adds a custom header. $name value can be overloaded to contain
+   * both header name and value (name:value)
</ins><span class="cx">    * @access public
</span><ins>+   * @param string $name custom header name
+   * @param string $value header value
</ins><span class="cx">    * @return void
</span><span class="cx">    */
</span><del>-  public function AddCustomHeader($custom_header) {
-    $this-&gt;CustomHeader[] = explode(':', $custom_header, 2);
</del><ins>+  public function AddCustomHeader($name, $value=null) {
+        if ($value === null) {
+                // Value passed in as name:value
+                $this-&gt;CustomHeader[] = explode(':', $name, 2);
+        } else {
+                $this-&gt;CustomHeader[] = array($name, $value);
+        }
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   /**
</span><span class="cx">    * Evaluates the message and returns modifications for inline images and backgrounds
</span><span class="cx">    * @access public
</span><del>-   * @return $message
</del><ins>+   * @param string $message Text to be HTML modified
+   * @param string $basedir baseline directory for path
+   * @return string $message
</ins><span class="cx">    */
</span><span class="cx">   public function MsgHTML($message, $basedir = '') {
</span><span class="cx">     preg_match_all(&quot;/(src|background)=[\&quot;'](.*)[\&quot;']/Ui&quot;, $message, $images);
</span><span class="lines">@@ -2217,13 +2485,15 @@
</span><span class="cx">         if (!preg_match('#^[A-z]+://#', $url)) {
</span><span class="cx">           $filename = basename($url);
</span><span class="cx">           $directory = dirname($url);
</span><del>-          ($directory == '.') ? $directory='': '';
-          $cid = 'cid:' . md5($filename);
</del><ins>+          if ($directory == '.') {
+            $directory = '';
+          }
+          $cid = 'cid:' . md5($url);
</ins><span class="cx">           $ext = pathinfo($filename, PATHINFO_EXTENSION);
</span><span class="cx">           $mimeType  = self::_mime_types($ext);
</span><span class="cx">           if ( strlen($basedir) &gt; 1 &amp;&amp; substr($basedir, -1) != '/') { $basedir .= '/'; }
</span><span class="cx">           if ( strlen($directory) &gt; 1 &amp;&amp; substr($directory, -1) != '/') { $directory .= '/'; }
</span><del>-          if ( $this-&gt;AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {
</del><ins>+          if ( $this-&gt;AddEmbeddedImage($basedir.$directory.$filename, md5($url), $filename, 'base64', $mimeType) ) {
</ins><span class="cx">             $message = preg_replace(&quot;/&quot;.$images[1][$i].&quot;=[\&quot;']&quot;.preg_quote($url, '/').&quot;[\&quot;']/Ui&quot;, $images[1][$i].&quot;=\&quot;&quot;.$cid.&quot;\&quot;&quot;, $message);
</span><span class="cx">           }
</span><span class="cx">         }
</span><span class="lines">@@ -2231,40 +2501,42 @@
</span><span class="cx">     }
</span><span class="cx">     $this-&gt;IsHTML(true);
</span><span class="cx">     $this-&gt;Body = $message;
</span><del>-        if (empty($this-&gt;AltBody)) {
-                $textMsg = trim(strip_tags(preg_replace('/&lt;(head|title|style|script)[^&gt;]*&gt;.*?&lt;\/\\1&gt;/s', '', $message)));
-                if (!empty($textMsg)) {
-                        $this-&gt;AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this-&gt;CharSet);
-                }
-        }
</del><span class="cx">     if (empty($this-&gt;AltBody)) {
</span><ins>+        $textMsg = trim(strip_tags(preg_replace('/&lt;(head|title|style|script)[^&gt;]*&gt;.*?&lt;\/\\1&gt;/s', '', $message)));
+        if (!empty($textMsg)) {
+            $this-&gt;AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this-&gt;CharSet);
+        }
+    }
+    if (empty($this-&gt;AltBody)) {
</ins><span class="cx">       $this-&gt;AltBody = 'To view this email message, open it in a program that understands HTML!' . &quot;\n\n&quot;;
</span><span class="cx">     }
</span><del>-        return $message;
</del><ins>+    return $message;
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   /**
</span><span class="cx">    * Gets the MIME type of the embedded or inline image
</span><del>-   * @param string File extension
</del><ins>+   * @param string $ext File extension
</ins><span class="cx">    * @access public
</span><span class="cx">    * @return string MIME type of ext
</span><span class="cx">    * @static
</span><span class="cx">    */
</span><span class="cx">   public static function _mime_types($ext = '') {
</span><span class="cx">     $mimes = array(
</span><ins>+      'xl'    =&gt;  'application/excel',
</ins><span class="cx">       'hqx'   =&gt;  'application/mac-binhex40',
</span><span class="cx">       'cpt'   =&gt;  'application/mac-compactpro',
</span><ins>+      'bin'   =&gt;  'application/macbinary',
</ins><span class="cx">       'doc'   =&gt;  'application/msword',
</span><del>-      'bin'   =&gt;  'application/macbinary',
</del><ins>+      'word'  =&gt;  'application/msword',
+      'class' =&gt;  'application/octet-stream',
+      'dll'   =&gt;  'application/octet-stream',
</ins><span class="cx">       'dms'   =&gt;  'application/octet-stream',
</span><ins>+      'exe'   =&gt;  'application/octet-stream',
</ins><span class="cx">       'lha'   =&gt;  'application/octet-stream',
</span><span class="cx">       'lzh'   =&gt;  'application/octet-stream',
</span><del>-      'exe'   =&gt;  'application/octet-stream',
-      'class' =&gt;  'application/octet-stream',
</del><span class="cx">       'psd'   =&gt;  'application/octet-stream',
</span><ins>+      'sea'   =&gt;  'application/octet-stream',
</ins><span class="cx">       'so'    =&gt;  'application/octet-stream',
</span><del>-      'sea'   =&gt;  'application/octet-stream',
-      'dll'   =&gt;  'application/octet-stream',
</del><span class="cx">       'oda'   =&gt;  'application/oda',
</span><span class="cx">       'pdf'   =&gt;  'application/pdf',
</span><span class="cx">       'ai'    =&gt;  'application/postscript',
</span><span class="lines">@@ -2282,9 +2554,9 @@
</span><span class="cx">       'dxr'   =&gt;  'application/x-director',
</span><span class="cx">       'dvi'   =&gt;  'application/x-dvi',
</span><span class="cx">       'gtar'  =&gt;  'application/x-gtar',
</span><ins>+      'php3'  =&gt;  'application/x-httpd-php',
+      'php4'  =&gt;  'application/x-httpd-php',
</ins><span class="cx">       'php'   =&gt;  'application/x-httpd-php',
</span><del>-      'php4'  =&gt;  'application/x-httpd-php',
-      'php3'  =&gt;  'application/x-httpd-php',
</del><span class="cx">       'phtml' =&gt;  'application/x-httpd-php',
</span><span class="cx">       'phps'  =&gt;  'application/x-httpd-php-source',
</span><span class="cx">       'js'    =&gt;  'application/x-javascript',
</span><span class="lines">@@ -2292,53 +2564,50 @@
</span><span class="cx">       'sit'   =&gt;  'application/x-stuffit',
</span><span class="cx">       'tar'   =&gt;  'application/x-tar',
</span><span class="cx">       'tgz'   =&gt;  'application/x-tar',
</span><ins>+      'xht'   =&gt;  'application/xhtml+xml',
</ins><span class="cx">       'xhtml' =&gt;  'application/xhtml+xml',
</span><del>-      'xht'   =&gt;  'application/xhtml+xml',
</del><span class="cx">       'zip'   =&gt;  'application/zip',
</span><span class="cx">       'mid'   =&gt;  'audio/midi',
</span><span class="cx">       'midi'  =&gt;  'audio/midi',
</span><del>-      'mpga'  =&gt;  'audio/mpeg',
</del><span class="cx">       'mp2'   =&gt;  'audio/mpeg',
</span><span class="cx">       'mp3'   =&gt;  'audio/mpeg',
</span><ins>+      'mpga'  =&gt;  'audio/mpeg',
</ins><span class="cx">       'aif'   =&gt;  'audio/x-aiff',
</span><ins>+      'aifc'  =&gt;  'audio/x-aiff',
</ins><span class="cx">       'aiff'  =&gt;  'audio/x-aiff',
</span><del>-      'aifc'  =&gt;  'audio/x-aiff',
</del><span class="cx">       'ram'   =&gt;  'audio/x-pn-realaudio',
</span><span class="cx">       'rm'    =&gt;  'audio/x-pn-realaudio',
</span><span class="cx">       'rpm'   =&gt;  'audio/x-pn-realaudio-plugin',
</span><span class="cx">       'ra'    =&gt;  'audio/x-realaudio',
</span><del>-      'rv'    =&gt;  'video/vnd.rn-realvideo',
</del><span class="cx">       'wav'   =&gt;  'audio/x-wav',
</span><span class="cx">       'bmp'   =&gt;  'image/bmp',
</span><span class="cx">       'gif'   =&gt;  'image/gif',
</span><span class="cx">       'jpeg'  =&gt;  'image/jpeg',
</span><ins>+      'jpe'   =&gt;  'image/jpeg',
</ins><span class="cx">       'jpg'   =&gt;  'image/jpeg',
</span><del>-      'jpe'   =&gt;  'image/jpeg',
</del><span class="cx">       'png'   =&gt;  'image/png',
</span><span class="cx">       'tiff'  =&gt;  'image/tiff',
</span><span class="cx">       'tif'   =&gt;  'image/tiff',
</span><ins>+      'eml'   =&gt;  'message/rfc822',
</ins><span class="cx">       'css'   =&gt;  'text/css',
</span><span class="cx">       'html'  =&gt;  'text/html',
</span><span class="cx">       'htm'   =&gt;  'text/html',
</span><span class="cx">       'shtml' =&gt;  'text/html',
</span><ins>+      'log'   =&gt;  'text/plain',
+      'text'  =&gt;  'text/plain',
</ins><span class="cx">       'txt'   =&gt;  'text/plain',
</span><del>-      'text'  =&gt;  'text/plain',
-      'log'   =&gt;  'text/plain',
</del><span class="cx">       'rtx'   =&gt;  'text/richtext',
</span><span class="cx">       'rtf'   =&gt;  'text/rtf',
</span><span class="cx">       'xml'   =&gt;  'text/xml',
</span><span class="cx">       'xsl'   =&gt;  'text/xml',
</span><span class="cx">       'mpeg'  =&gt;  'video/mpeg',
</span><ins>+      'mpe'   =&gt;  'video/mpeg',
</ins><span class="cx">       'mpg'   =&gt;  'video/mpeg',
</span><del>-      'mpe'   =&gt;  'video/mpeg',
</del><ins>+      'mov'   =&gt;  'video/quicktime',
</ins><span class="cx">       'qt'    =&gt;  'video/quicktime',
</span><del>-      'mov'   =&gt;  'video/quicktime',
</del><ins>+      'rv'    =&gt;  'video/vnd.rn-realvideo',
</ins><span class="cx">       'avi'   =&gt;  'video/x-msvideo',
</span><del>-      'movie' =&gt;  'video/x-sgi-movie',
-      'doc'   =&gt;  'application/msword',
-      'word'  =&gt;  'application/msword',
-      'xl'    =&gt;  'application/excel',
-      'eml'   =&gt;  'message/rfc822'
</del><ins>+      'movie' =&gt;  'video/x-sgi-movie'
</ins><span class="cx">     );
</span><span class="cx">     return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
</span><span class="cx">   }
</span><span class="lines">@@ -2353,6 +2622,8 @@
</span><span class="cx">   * @param string $name Parameter Name
</span><span class="cx">   * @param mixed $value Parameter Value
</span><span class="cx">   * NOTE: will not work with arrays, there are no arrays to set/reset
</span><ins>+   * @throws phpmailerException
+   * @return bool
</ins><span class="cx">   * @todo Should this not be using __set() magic function?
</span><span class="cx">   */
</span><span class="cx">   public function set($name, $value = '') {
</span><span class="lines">@@ -2378,15 +2649,14 @@
</span><span class="cx">    * @return string
</span><span class="cx">    */
</span><span class="cx">   public function SecureHeader($str) {
</span><del>-    $str = str_replace(&quot;\r&quot;, '', $str);
-    $str = str_replace(&quot;\n&quot;, '', $str);
-    return trim($str);
</del><ins>+    return trim(str_replace(array(&quot;\r&quot;, &quot;\n&quot;), '', $str));
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   /**
</span><span class="cx">    * Set the private key file and password to sign the message.
</span><span class="cx">    *
</span><span class="cx">    * @access public
</span><ins>+   * @param $cert_filename
</ins><span class="cx">    * @param string $key_filename Parameter File Name
</span><span class="cx">    * @param string $key_pass Password for private key
</span><span class="cx">    */
</span><span class="lines">@@ -2400,11 +2670,10 @@
</span><span class="cx">    * Set the private key file and password to sign the message.
</span><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 $txt
+   * @return string
</ins><span class="cx">    */
</span><span class="cx">   public function DKIM_QP($txt) {
</span><del>-    $tmp = '';
</del><span class="cx">     $line = '';
</span><span class="cx">     for ($i = 0; $i &lt; strlen($txt); $i++) {
</span><span class="cx">       $ord = ord($txt[$i]);
</span><span class="lines">@@ -2422,6 +2691,7 @@
</span><span class="cx">    *
</span><span class="cx">    * @access public
</span><span class="cx">    * @param string $s Header
</span><ins>+   * @return string
</ins><span class="cx">    */
</span><span class="cx">   public function DKIM_Sign($s) {
</span><span class="cx">     $privKeyStr = file_get_contents($this-&gt;DKIM_private);
</span><span class="lines">@@ -2433,6 +2703,7 @@
</span><span class="cx">     if (openssl_sign($s, $signature, $privKey)) {
</span><span class="cx">       return base64_encode($signature);
</span><span class="cx">     }
</span><ins>+    return '';
</ins><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx">   /**
</span><span class="lines">@@ -2440,6 +2711,7 @@
</span><span class="cx">    *
</span><span class="cx">    * @access public
</span><span class="cx">    * @param string $s Header
</span><ins>+   * @return string
</ins><span class="cx">    */
</span><span class="cx">   public function DKIM_HeaderC($s) {
</span><span class="cx">     $s = preg_replace(&quot;/\r\n\s+/&quot;, &quot; &quot;, $s);
</span><span class="lines">@@ -2459,6 +2731,7 @@
</span><span class="cx">    *
</span><span class="cx">    * @access public
</span><span class="cx">    * @param string $body Message Body
</span><ins>+   * @return string
</ins><span class="cx">    */
</span><span class="cx">   public function DKIM_BodyC($body) {
</span><span class="cx">     if ($body == '') return &quot;\r\n&quot;;
</span><span class="lines">@@ -2479,6 +2752,7 @@
</span><span class="cx">    * @param string $headers_line Header lines
</span><span class="cx">    * @param string $subject Subject
</span><span class="cx">    * @param string $body Body
</span><ins>+   * @return string
</ins><span class="cx">    */
</span><span class="cx">   public function DKIM_Add($headers_line, $subject, $body) {
</span><span class="cx">     $DKIMsignatureType    = 'rsa-sha1'; // Signature &amp; hash algorithms
</span><span class="lines">@@ -2487,6 +2761,8 @@
</span><span class="cx">     $DKIMtime             = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
</span><span class="cx">     $subject_header       = &quot;Subject: $subject&quot;;
</span><span class="cx">     $headers              = explode($this-&gt;LE, $headers_line);
</span><ins>+        $from_header          = &quot;&quot;;
+        $to_header            = &quot;&quot;;
</ins><span class="cx">     foreach($headers as $header) {
</span><span class="cx">       if (strpos($header, 'From:') === 0) {
</span><span class="cx">         $from_header = $header;
</span><span class="lines">@@ -2512,18 +2788,36 @@
</span><span class="cx">                 &quot;\tb=&quot;;
</span><span class="cx">     $toSign   = $this-&gt;DKIM_HeaderC($from_header . &quot;\r\n&quot; . $to_header . &quot;\r\n&quot; . $subject_header . &quot;\r\n&quot; . $dkimhdrs);
</span><span class="cx">     $signed   = $this-&gt;DKIM_Sign($toSign);
</span><del>-    return &quot;X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n&quot;.$dkimhdrs.$signed.&quot;\r\n&quot;;
</del><ins>+    return &quot;X-PHPMAILER-DKIM: code.google.com/a/apache-extras.org/p/phpmailer/\r\n&quot;.$dkimhdrs.$signed.&quot;\r\n&quot;;
</ins><span class="cx">   }
</span><span class="cx"> 
</span><del>-  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) {
-    if (!empty($this-&gt;action_function) &amp;&amp; function_exists($this-&gt;action_function)) {
-      $params = array($isSent, $to, $cc, $bcc, $subject, $body);
</del><ins>+  /**
+   * Perform callback
+   * @param boolean $isSent
+   * @param string $to
+   * @param string $cc
+   * @param string $bcc
+   * @param string $subject
+   * @param string $body
+   * @param string $from
+   */
+  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) {
+    if (!empty($this-&gt;action_function) &amp;&amp; is_callable($this-&gt;action_function)) {
+      $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
</ins><span class="cx">       call_user_func_array($this-&gt;action_function, $params);
</span><span class="cx">     }
</span><span class="cx">   }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/**
+ * Exception handler for PHPMailer
+ * @package PHPMailer
+ */
</ins><span class="cx"> class phpmailerException extends Exception {
</span><ins>+  /**
+   * Prettify error message output
+   * @return string
+   */
</ins><span class="cx">   public function errorMessage() {
</span><span class="cx">     $errorMsg = '&lt;strong&gt;' . $this-&gt;getMessage() . &quot;&lt;/strong&gt;&lt;br /&gt;\n&quot;;
</span><span class="cx">     return $errorMsg;
</span></span></pre></div>
<a id="trunkwpincludesclasssmtpphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/class-smtp.php (23521 => 23522)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/class-smtp.php        2013-02-28 18:27:13 UTC (rev 23521)
+++ trunk/wp-includes/class-smtp.php        2013-02-28 18:33:13 UTC (rev 23522)
</span><span class="lines">@@ -2,7 +2,7 @@
</span><span class="cx"> /*~ class.smtp.php
</span><span class="cx"> .---------------------------------------------------------------------------.
</span><span class="cx"> |  Software: PHPMailer - PHP email class                                    |
</span><del>-|   Version: 5.2.1                                                          |
</del><ins>+|   Version: 5.2.4                                                          |
</ins><span class="cx"> |      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
</span><span class="cx"> | ------------------------------------------------------------------------- |
</span><span class="cx"> |     Admin: Jim Jagielski (project admininistrator)                        |
</span><span class="lines">@@ -32,15 +32,15 @@
</span><span class="cx">  * @author Jim Jagielski
</span><span class="cx">  * @copyright 2010 - 2012 Jim Jagielski
</span><span class="cx">  * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
</span><del>- * @version $Id: class.smtp.php 450 2010-06-23 16:46:33Z coolbru $
</del><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> /**
</span><del>- * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
- * commands except TURN which will always return a not implemented
- * error. SMTP also provides some utility methods for sending mail
- * to an SMTP server.
- * original author: Chris Ryan
</del><ins>+ * PHP RFC821 SMTP client
+ *
+ * Implements all the RFC 821 SMTP commands except TURN which will always return a not implemented error.
+ * SMTP also provides some utility methods for sending mail to an SMTP server.
+ * @author Chris Ryan
+ * @package PHPMailer
</ins><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> class SMTP {
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx">   public $SMTP_PORT = 25;
</span><span class="cx"> 
</span><span class="cx">   /**
</span><del>-   *  SMTP reply line ending
</del><ins>+   *  SMTP reply line ending (don't change)
</ins><span class="cx">    *  @var string
</span><span class="cx">    */
</span><span class="cx">   public $CRLF = &quot;\r\n&quot;;
</span><span class="lines">@@ -63,29 +63,69 @@
</span><span class="cx">   public $do_debug;       // the level of debug to perform
</span><span class="cx"> 
</span><span class="cx">   /**
</span><ins>+   * Sets the function/method to use for debugging output.
+   * Right now we only honor &quot;echo&quot; or &quot;error_log&quot;
+   * @var string
+   */
+  public $Debugoutput     = &quot;echo&quot;;
+
+  /**
</ins><span class="cx">    *  Sets VERP use on/off (default is off)
</span><span class="cx">    *  @var bool
</span><span class="cx">    */
</span><span class="cx">   public $do_verp = false;
</span><span class="cx"> 
</span><span class="cx">   /**
</span><ins>+   * Sets the SMTP timeout value for reads, in seconds
+   * @var int
+   */
+  public $Timeout         = 15;
+
+  /**
+   * Sets the SMTP timelimit value for reads, in seconds
+   * @var int
+   */
+  public $Timelimit       = 30;
+
+  /**
</ins><span class="cx">    * Sets the SMTP PHPMailer Version number
</span><span class="cx">    * @var string
</span><span class="cx">    */
</span><del>-  public $Version         = '5.2.1';
</del><ins>+  public $Version         = '5.2.4';
</ins><span class="cx"> 
</span><span class="cx">   /////////////////////////////////////////////////
</span><span class="cx">   // PROPERTIES, PRIVATE AND PROTECTED
</span><span class="cx">   /////////////////////////////////////////////////
</span><span class="cx"> 
</span><del>-  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
</del><ins>+  /**
+   * @var resource The socket to the server
+   */
+  private $smtp_conn;
+  /**
+   * @var string Error message, if any, for the last call
+   */
+  private $error;
+  /**
+   * @var string The reply the server sent to us for HELO
+   */
+  private $helo_rply;
</ins><span class="cx"> 
</span><span class="cx">   /**
</span><ins>+   * Outputs debugging info via user-defined method
+   * @param string $str
+   */
+  private function edebug($str) {
+    if ($this-&gt;Debugoutput == &quot;error_log&quot;) {
+        error_log($str);
+    } else {
+        echo $str;
+    }
+  }
+
+  /**
</ins><span class="cx">    * Initialize the class so that the data is in a known state.
</span><span class="cx">    * @access public
</span><del>-   * @return void
</del><ins>+   * @return SMTP
</ins><span class="cx">    */
</span><span class="cx">   public function __construct() {
</span><span class="cx">     $this-&gt;smtp_conn = 0;
</span><span class="lines">@@ -110,6 +150,9 @@
</span><span class="cx">    * SMTP CODE SUCCESS: 220
</span><span class="cx">    * SMTP CODE FAILURE: 421
</span><span class="cx">    * @access public
</span><ins>+   * @param string $host
+   * @param int $port
+   * @param int $tval
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   public function Connect($host, $port = 0, $tval = 30) {
</span><span class="lines">@@ -139,21 +182,26 @@
</span><span class="cx">                            &quot;errno&quot; =&gt; $errno,
</span><span class="cx">                            &quot;errstr&quot; =&gt; $errstr);
</span><span class="cx">       if($this-&gt;do_debug &gt;= 1) {
</span><del>-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: $errstr ($errno)&quot; . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: $errstr ($errno)&quot; . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // SMTP server can take longer to respond, give longer timeout for first read
</span><span class="cx">     // Windows does not have support for this timeout function
</span><del>-    if(substr(PHP_OS, 0, 3) != &quot;WIN&quot;)
-     socket_set_timeout($this-&gt;smtp_conn, $tval, 0);
</del><ins>+    if(substr(PHP_OS, 0, 3) != &quot;WIN&quot;) {
+     $max = ini_get('max_execution_time');
+     if ($max != 0 &amp;&amp; $tval &gt; $max) { // don't bother if unlimited
+      @set_time_limit($tval);
+     }
+     stream_set_timeout($this-&gt;smtp_conn, $tval, 0);
+    }
</ins><span class="cx"> 
</span><span class="cx">     // get any announcement
</span><span class="cx">     $announce = $this-&gt;get_lines();
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;do_debug &gt;= 2) {
</span><del>-      echo &quot;SMTP -&gt; FROM SERVER:&quot; . $announce . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; FROM SERVER:&quot; . $announce . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="lines">@@ -182,7 +230,7 @@
</span><span class="cx">     $code = substr($rply,0,3);
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;do_debug &gt;= 2) {
</span><del>-      echo &quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if($code != 220) {
</span><span class="lines">@@ -191,7 +239,7 @@
</span><span class="cx">                &quot;smtp_code&quot; =&gt; $code,
</span><span class="cx">                &quot;smtp_msg&quot;  =&gt; substr($rply,4));
</span><span class="cx">       if($this-&gt;do_debug &gt;= 1) {
</span><del>-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="lines">@@ -208,60 +256,164 @@
</span><span class="cx">    * Performs SMTP authentication.  Must be run after running the
</span><span class="cx">    * Hello() method.  Returns true if successfully authenticated.
</span><span class="cx">    * @access public
</span><ins>+   * @param string $username
+   * @param string $password
+   * @param string $authtype
+   * @param string $realm
+   * @param string $workstation
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><del>-  public function Authenticate($username, $password) {
-    // Start authentication
-    fputs($this-&gt;smtp_conn,&quot;AUTH LOGIN&quot; . $this-&gt;CRLF);
-
-    $rply = $this-&gt;get_lines();
-    $code = substr($rply,0,3);
-
-    if($code != 334) {
-      $this-&gt;error =
-        array(&quot;error&quot; =&gt; &quot;AUTH not accepted from server&quot;,
-              &quot;smtp_code&quot; =&gt; $code,
-              &quot;smtp_msg&quot; =&gt; substr($rply,4));
-      if($this-&gt;do_debug &gt;= 1) {
-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
-      }
-      return false;
</del><ins>+  public function Authenticate($username, $password, $authtype='LOGIN', $realm='', $workstation='') {
+    if (empty($authtype)) {
+      $authtype = 'LOGIN';
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // Send encoded username
-    fputs($this-&gt;smtp_conn, base64_encode($username) . $this-&gt;CRLF);
</del><ins>+    switch ($authtype) {
+      case 'PLAIN':
+        // Start authentication
+        fputs($this-&gt;smtp_conn,&quot;AUTH PLAIN&quot; . $this-&gt;CRLF);
+    
+        $rply = $this-&gt;get_lines();
+        $code = substr($rply,0,3);
+    
+        if($code != 334) {
+          $this-&gt;error =
+            array(&quot;error&quot; =&gt; &quot;AUTH not accepted from server&quot;,
+                  &quot;smtp_code&quot; =&gt; $code,
+                  &quot;smtp_msg&quot; =&gt; substr($rply,4));
+          if($this-&gt;do_debug &gt;= 1) {
+            $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
+          }
+          return false;
+        }
+        // Send encoded username and password
+        fputs($this-&gt;smtp_conn, base64_encode(&quot;\0&quot;.$username.&quot;\0&quot;.$password) . $this-&gt;CRLF);
</ins><span class="cx"> 
</span><del>-    $rply = $this-&gt;get_lines();
-    $code = substr($rply,0,3);
</del><ins>+        $rply = $this-&gt;get_lines();
+        $code = substr($rply,0,3);
+    
+        if($code != 235) {
+          $this-&gt;error =
+            array(&quot;error&quot; =&gt; &quot;Authentication not accepted from server&quot;,
+                  &quot;smtp_code&quot; =&gt; $code,
+                  &quot;smtp_msg&quot; =&gt; substr($rply,4));
+          if($this-&gt;do_debug &gt;= 1) {
+            $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
+          }
+          return false;
+        }
+        break;
+      case 'LOGIN':
+        // Start authentication
+        fputs($this-&gt;smtp_conn,&quot;AUTH LOGIN&quot; . $this-&gt;CRLF);
+    
+        $rply = $this-&gt;get_lines();
+        $code = substr($rply,0,3);
+    
+        if($code != 334) {
+          $this-&gt;error =
+            array(&quot;error&quot; =&gt; &quot;AUTH not accepted from server&quot;,
+                  &quot;smtp_code&quot; =&gt; $code,
+                  &quot;smtp_msg&quot; =&gt; substr($rply,4));
+          if($this-&gt;do_debug &gt;= 1) {
+            $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
+          }
+          return false;
+        }
+    
+        // Send encoded username
+        fputs($this-&gt;smtp_conn, base64_encode($username) . $this-&gt;CRLF);
+    
+        $rply = $this-&gt;get_lines();
+        $code = substr($rply,0,3);
+    
+        if($code != 334) {
+          $this-&gt;error =
+            array(&quot;error&quot; =&gt; &quot;Username not accepted from server&quot;,
+                  &quot;smtp_code&quot; =&gt; $code,
+                  &quot;smtp_msg&quot; =&gt; substr($rply,4));
+          if($this-&gt;do_debug &gt;= 1) {
+            $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
+          }
+          return false;
+        }
+    
+        // Send encoded password
+        fputs($this-&gt;smtp_conn, base64_encode($password) . $this-&gt;CRLF);
+    
+        $rply = $this-&gt;get_lines();
+        $code = substr($rply,0,3);
+    
+        if($code != 235) {
+          $this-&gt;error =
+            array(&quot;error&quot; =&gt; &quot;Password not accepted from server&quot;,
+                  &quot;smtp_code&quot; =&gt; $code,
+                  &quot;smtp_msg&quot; =&gt; substr($rply,4));
+          if($this-&gt;do_debug &gt;= 1) {
+            $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
+          }
+          return false;
+        }
+        break;
+      case 'NTLM':
+        /*
+         * ntlm_sasl_client.php
+         ** Bundled with Permission
+         **
+         ** How to telnet in windows: http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
+         ** PROTOCOL Documentation http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
+         */
+        require_once('ntlm_sasl_client.php');
+        $temp = new stdClass();
+        $ntlm_client = new ntlm_sasl_client_class;
+        if(! $ntlm_client-&gt;Initialize($temp)){//let's test if every function its available
+            $this-&gt;error = array(&quot;error&quot; =&gt; $temp-&gt;error);
+            if($this-&gt;do_debug &gt;= 1) {
+                $this-&gt;edebug(&quot;You need to enable some modules in your php.ini file: &quot; . $this-&gt;error[&quot;error&quot;] . $this-&gt;CRLF);
+            }
+            return false;
+        }
+        $msg1 = $ntlm_client-&gt;TypeMsg1($realm, $workstation);//msg1
+        
+        fputs($this-&gt;smtp_conn,&quot;AUTH NTLM &quot; . base64_encode($msg1) . $this-&gt;CRLF);
</ins><span class="cx"> 
</span><del>-    if($code != 334) {
-      $this-&gt;error =
-        array(&quot;error&quot; =&gt; &quot;Username not accepted from server&quot;,
-              &quot;smtp_code&quot; =&gt; $code,
-              &quot;smtp_msg&quot; =&gt; substr($rply,4));
-      if($this-&gt;do_debug &gt;= 1) {
-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
-      }
-      return false;
-    }
</del><ins>+        $rply = $this-&gt;get_lines();
+        $code = substr($rply,0,3);
+        
</ins><span class="cx"> 
</span><del>-    // Send encoded password
-    fputs($this-&gt;smtp_conn, base64_encode($password) . $this-&gt;CRLF);
</del><ins>+        if($code != 334) {
+            $this-&gt;error =
+                array(&quot;error&quot; =&gt; &quot;AUTH not accepted from server&quot;,
+                      &quot;smtp_code&quot; =&gt; $code,
+                      &quot;smtp_msg&quot; =&gt; substr($rply,4));
+            if($this-&gt;do_debug &gt;= 1) {
+                $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF);
+            }
+            return false;
+        }
+        
+        $challange = substr($rply,3);//though 0 based, there is a white space after the 3 digit number....//msg2
+        $challange = base64_decode($challange);
+        $ntlm_res = $ntlm_client-&gt;NTLMResponse(substr($challange,24,8),$password);
+        $msg3 = $ntlm_client-&gt;TypeMsg3($ntlm_res,$username,$realm,$workstation);//msg3
+        // Send encoded username
+        fputs($this-&gt;smtp_conn, base64_encode($msg3) . $this-&gt;CRLF);
</ins><span class="cx"> 
</span><del>-    $rply = $this-&gt;get_lines();
-    $code = substr($rply,0,3);
</del><ins>+        $rply = $this-&gt;get_lines();
+        $code = substr($rply,0,3);
</ins><span class="cx"> 
</span><del>-    if($code != 235) {
-      $this-&gt;error =
-        array(&quot;error&quot; =&gt; &quot;Password not accepted from server&quot;,
-              &quot;smtp_code&quot; =&gt; $code,
-              &quot;smtp_msg&quot; =&gt; substr($rply,4));
-      if($this-&gt;do_debug &gt;= 1) {
-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
-      }
-      return false;
</del><ins>+        if($code != 235) {
+            $this-&gt;error =
+                array(&quot;error&quot; =&gt; &quot;Could not authenticate&quot;,
+                      &quot;smtp_code&quot; =&gt; $code,
+                      &quot;smtp_msg&quot; =&gt; substr($rply,4));
+            if($this-&gt;do_debug &gt;= 1) {
+                $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF);
+            }
+            return false;
+        }
+        break;
</ins><span class="cx">     }
</span><del>-
</del><span class="cx">     return true;
</span><span class="cx">   }
</span><span class="cx"> 
</span><span class="lines">@@ -276,7 +428,7 @@
</span><span class="cx">       if($sock_status[&quot;eof&quot;]) {
</span><span class="cx">         // the socket is valid but we are not connected
</span><span class="cx">         if($this-&gt;do_debug &gt;= 1) {
</span><del>-            echo &quot;SMTP -&gt; NOTICE:&quot; . $this-&gt;CRLF . &quot;EOF caught while checking if connected&quot;;
</del><ins>+            $this-&gt;edebug(&quot;SMTP -&gt; NOTICE:&quot; . $this-&gt;CRLF . &quot;EOF caught while checking if connected&quot;);
</ins><span class="cx">         }
</span><span class="cx">         $this-&gt;Close();
</span><span class="cx">         return false;
</span><span class="lines">@@ -324,6 +476,7 @@
</span><span class="cx">    * SMTP CODE FAILURE: 451,554
</span><span class="cx">    * SMTP CODE ERROR  : 500,501,503,421
</span><span class="cx">    * @access public
</span><ins>+   * @param string $msg_data
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   public function Data($msg_data) {
</span><span class="lines">@@ -341,7 +494,7 @@
</span><span class="cx">     $code = substr($rply,0,3);
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;do_debug &gt;= 2) {
</span><del>-      echo &quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if($code != 354) {
</span><span class="lines">@@ -350,7 +503,7 @@
</span><span class="cx">               &quot;smtp_code&quot; =&gt; $code,
</span><span class="cx">               &quot;smtp_msg&quot; =&gt; substr($rply,4));
</span><span class="cx">       if($this-&gt;do_debug &gt;= 1) {
</span><del>-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="lines">@@ -435,7 +588,7 @@
</span><span class="cx">     $code = substr($rply,0,3);
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;do_debug &gt;= 2) {
</span><del>-      echo &quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if($code != 250) {
</span><span class="lines">@@ -444,7 +597,7 @@
</span><span class="cx">               &quot;smtp_code&quot; =&gt; $code,
</span><span class="cx">               &quot;smtp_msg&quot; =&gt; substr($rply,4));
</span><span class="cx">       if($this-&gt;do_debug &gt;= 1) {
</span><del>-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="lines">@@ -461,6 +614,7 @@
</span><span class="cx">    * SMTP CODE SUCCESS: 250
</span><span class="cx">    * SMTP CODE ERROR  : 500, 501, 504, 421
</span><span class="cx">    * @access public
</span><ins>+   * @param string $host
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   public function Hello($host = '') {
</span><span class="lines">@@ -491,6 +645,8 @@
</span><span class="cx">   /**
</span><span class="cx">    * Sends a HELO/EHLO command.
</span><span class="cx">    * @access private
</span><ins>+   * @param string $hello
+   * @param string $host
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   private function SendHello($hello, $host) {
</span><span class="lines">@@ -500,7 +656,7 @@
</span><span class="cx">     $code = substr($rply,0,3);
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;do_debug &gt;= 2) {
</span><del>-      echo &quot;SMTP -&gt; FROM SERVER: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; FROM SERVER: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if($code != 250) {
</span><span class="lines">@@ -509,7 +665,7 @@
</span><span class="cx">               &quot;smtp_code&quot; =&gt; $code,
</span><span class="cx">               &quot;smtp_msg&quot; =&gt; substr($rply,4));
</span><span class="cx">       if($this-&gt;do_debug &gt;= 1) {
</span><del>-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="lines">@@ -531,6 +687,7 @@
</span><span class="cx">    * SMTP CODE SUCCESS: 552,451,452
</span><span class="cx">    * SMTP CODE SUCCESS: 500,501,421
</span><span class="cx">    * @access public
</span><ins>+   * @param string $from
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   public function Mail($from) {
</span><span class="lines">@@ -542,14 +699,14 @@
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    $useVerp = ($this-&gt;do_verp ? &quot;XVERP&quot; : &quot;&quot;);
</del><ins>+    $useVerp = ($this-&gt;do_verp ? &quot; XVERP&quot; : &quot;&quot;);
</ins><span class="cx">     fputs($this-&gt;smtp_conn,&quot;MAIL FROM:&lt;&quot; . $from . &quot;&gt;&quot; . $useVerp . $this-&gt;CRLF);
</span><span class="cx"> 
</span><span class="cx">     $rply = $this-&gt;get_lines();
</span><span class="cx">     $code = substr($rply,0,3);
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;do_debug &gt;= 2) {
</span><del>-      echo &quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if($code != 250) {
</span><span class="lines">@@ -558,7 +715,7 @@
</span><span class="cx">               &quot;smtp_code&quot; =&gt; $code,
</span><span class="cx">               &quot;smtp_msg&quot; =&gt; substr($rply,4));
</span><span class="cx">       if($this-&gt;do_debug &gt;= 1) {
</span><del>-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="lines">@@ -574,6 +731,7 @@
</span><span class="cx">    * SMTP CODE SUCCESS: 221
</span><span class="cx">    * SMTP CODE ERROR  : 500
</span><span class="cx">    * @access public
</span><ins>+   * @param bool $close_on_error
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   public function Quit($close_on_error = true) {
</span><span class="lines">@@ -592,7 +750,7 @@
</span><span class="cx">     $byemsg = $this-&gt;get_lines();
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;do_debug &gt;= 2) {
</span><del>-      echo &quot;SMTP -&gt; FROM SERVER:&quot; . $byemsg . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; FROM SERVER:&quot; . $byemsg . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     $rval = true;
</span><span class="lines">@@ -606,7 +764,7 @@
</span><span class="cx">                  &quot;smtp_rply&quot; =&gt; substr($byemsg,4));
</span><span class="cx">       $rval = false;
</span><span class="cx">       if($this-&gt;do_debug &gt;= 1) {
</span><del>-        echo &quot;SMTP -&gt; ERROR: &quot; . $e[&quot;error&quot;] . &quot;: &quot; . $byemsg . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $e[&quot;error&quot;] . &quot;: &quot; . $byemsg . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -627,6 +785,7 @@
</span><span class="cx">    * SMTP CODE FAILURE: 550,551,552,553,450,451,452
</span><span class="cx">    * SMTP CODE ERROR  : 500,501,503,421
</span><span class="cx">    * @access public
</span><ins>+   * @param string $to
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   public function Recipient($to) {
</span><span class="lines">@@ -644,7 +803,7 @@
</span><span class="cx">     $code = substr($rply,0,3);
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;do_debug &gt;= 2) {
</span><del>-      echo &quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if($code != 250 &amp;&amp; $code != 251) {
</span><span class="lines">@@ -653,7 +812,7 @@
</span><span class="cx">               &quot;smtp_code&quot; =&gt; $code,
</span><span class="cx">               &quot;smtp_msg&quot; =&gt; substr($rply,4));
</span><span class="cx">       if($this-&gt;do_debug &gt;= 1) {
</span><del>-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="lines">@@ -687,7 +846,7 @@
</span><span class="cx">     $code = substr($rply,0,3);
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;do_debug &gt;= 2) {
</span><del>-      echo &quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if($code != 250) {
</span><span class="lines">@@ -696,7 +855,7 @@
</span><span class="cx">               &quot;smtp_code&quot; =&gt; $code,
</span><span class="cx">               &quot;smtp_msg&quot; =&gt; substr($rply,4));
</span><span class="cx">       if($this-&gt;do_debug &gt;= 1) {
</span><del>-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="lines">@@ -718,6 +877,7 @@
</span><span class="cx">    * SMTP CODE SUCCESS: 552,451,452
</span><span class="cx">    * SMTP CODE SUCCESS: 500,501,502,421
</span><span class="cx">    * @access public
</span><ins>+   * @param string $from
</ins><span class="cx">    * @return bool
</span><span class="cx">    */
</span><span class="cx">   public function SendAndMail($from) {
</span><span class="lines">@@ -735,7 +895,7 @@
</span><span class="cx">     $code = substr($rply,0,3);
</span><span class="cx"> 
</span><span class="cx">     if($this-&gt;do_debug &gt;= 2) {
</span><del>-      echo &quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; FROM SERVER:&quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if($code != 250) {
</span><span class="lines">@@ -744,7 +904,7 @@
</span><span class="cx">               &quot;smtp_code&quot; =&gt; $code,
</span><span class="cx">               &quot;smtp_msg&quot; =&gt; substr($rply,4));
</span><span class="cx">       if($this-&gt;do_debug &gt;= 1) {
</span><del>-        echo &quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; ERROR: &quot; . $this-&gt;error[&quot;error&quot;] . &quot;: &quot; . $rply . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       return false;
</span><span class="cx">     }
</span><span class="lines">@@ -768,7 +928,7 @@
</span><span class="cx">     $this-&gt;error = array(&quot;error&quot; =&gt; &quot;This method, TURN, of the SMTP &quot;.
</span><span class="cx">                                     &quot;is not implemented&quot;);
</span><span class="cx">     if($this-&gt;do_debug &gt;= 1) {
</span><del>-      echo &quot;SMTP -&gt; NOTICE: &quot; . $this-&gt;error[&quot;error&quot;] . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+      $this-&gt;edebug(&quot;SMTP -&gt; NOTICE: &quot; . $this-&gt;error[&quot;error&quot;] . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">     }
</span><span class="cx">     return false;
</span><span class="cx">   }
</span><span class="lines">@@ -797,22 +957,47 @@
</span><span class="cx">    */
</span><span class="cx">   private function get_lines() {
</span><span class="cx">     $data = &quot;&quot;;
</span><del>-    while(!feof($this-&gt;smtp_conn)) {
</del><ins>+    $endtime = 0;
+    /* If for some reason the fp is bad, don't inf loop */
+    if (!is_resource($this-&gt;smtp_conn)) {
+      return $data;
+    }
+    stream_set_timeout($this-&gt;smtp_conn, $this-&gt;Timeout);
+    if ($this-&gt;Timelimit &gt; 0) {
+      $endtime = time() + $this-&gt;Timelimit;
+    }
+    while(is_resource($this-&gt;smtp_conn) &amp;&amp; !feof($this-&gt;smtp_conn)) {
</ins><span class="cx">       $str = @fgets($this-&gt;smtp_conn,515);
</span><span class="cx">       if($this-&gt;do_debug &gt;= 4) {
</span><del>-        echo &quot;SMTP -&gt; get_lines(): \$data was \&quot;$data\&quot;&quot; . $this-&gt;CRLF . '&lt;br /&gt;';
-        echo &quot;SMTP -&gt; get_lines(): \$str is \&quot;$str\&quot;&quot; . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; get_lines(): \$data was \&quot;$data\&quot;&quot; . $this-&gt;CRLF . '&lt;br /&gt;');
+        $this-&gt;edebug(&quot;SMTP -&gt; get_lines(): \$str is \&quot;$str\&quot;&quot; . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       $data .= $str;
</span><span class="cx">       if($this-&gt;do_debug &gt;= 4) {
</span><del>-        echo &quot;SMTP -&gt; get_lines(): \$data is \&quot;$data\&quot;&quot; . $this-&gt;CRLF . '&lt;br /&gt;';
</del><ins>+        $this-&gt;edebug(&quot;SMTP -&gt; get_lines(): \$data is \&quot;$data\&quot;&quot; . $this-&gt;CRLF . '&lt;br /&gt;');
</ins><span class="cx">       }
</span><span class="cx">       // if 4th character is a space, we are done reading, break the loop
</span><span class="cx">       if(substr($str,3,1) == &quot; &quot;) { break; }
</span><ins>+      // Timed-out? Log and break
+      $info = stream_get_meta_data($this-&gt;smtp_conn);
+      if ($info['timed_out']) {
+        if($this-&gt;do_debug &gt;= 4) {
+          $this-&gt;edebug(&quot;SMTP -&gt; get_lines(): timed-out (&quot; . $this-&gt;Timeout . &quot; seconds) &lt;br /&gt;&quot;);
+        }
+        break;
+      }
+      // Now check if reads took too long
+      if ($endtime) {
+        if (time() &gt; $endtime) {
+          if($this-&gt;do_debug &gt;= 4) {
+            $this-&gt;edebug(&quot;SMTP -&gt; get_lines(): timelimit reached (&quot; . $this-&gt;Timelimit . &quot; seconds) &lt;br /&gt;&quot;);
+          }
+          break;
+        }
+      }
</ins><span class="cx">     }
</span><span class="cx">     return $data;
</span><span class="cx">   }
</span><span class="cx"> 
</span><span class="cx"> }
</span><del>-
</del><span class="cx"> ?&gt;
</span></span></pre>
</div>
</div>

</body>
</html>