diff --git wp-includes/class-phpmailer.php wp-includes/class-phpmailer.php
index df533c2..1530258 100644
--- wp-includes/class-phpmailer.php
+++ wp-includes/class-phpmailer.php
@@ -2,7 +2,7 @@
 /*~ class.phpmailer.php
 .---------------------------------------------------------------------------.
 |  Software: PHPMailer - PHP email class                                    |
-|   Version: 5.2.1                                                          |
+|   Version: 5.2.2-beta2                                                          |
 |      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
 | ------------------------------------------------------------------------- |
 |     Admin: Jim Jagielski (project admininistrator)                        |
@@ -31,12 +31,15 @@
  * @author Jim Jagielski
  * @copyright 2010 - 2012 Jim Jagielski
  * @copyright 2004 - 2009 Andy Prevost
- * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $
  * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  */
 
+
 if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
 
+/**
+ * Main PHPMailer class definition
+ */
 class PHPMailer {
 
   /////////////////////////////////////////////////
@@ -87,13 +90,22 @@ class PHPMailer {
   public $FromName          = 'Root User';
 
   /**
-   * Sets the Sender email (Return-Path) of the message.  If not empty,
+   * Sets the Sender email of the message.  If not empty,
    * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
+   * If not empty, and ReturnPath is empty, will also be the
+   * Return-Path header.
    * @var string
    */
   public $Sender            = '';
 
   /**
+   * Sets the Return-Path of the message.  If empty, it will
+   * be set to either From or Sender.
+   * @var string
+   */
+  public $ReturnPath        = '';
+
+  /**
    * Sets the Subject of the message.
    * @var string
    */
@@ -130,11 +142,11 @@ class PHPMailer {
   protected $MIMEHeader     = '';
 
   /**
-   * Stores the complete sent MIME message (Body and Headers)
+   * Stores the extra header list which CreateHeader() doesn't fold in
    * @var string
    * @access protected
   */
-  protected $SentMIMEMessage     = '';
+  protected $mailHeader     = '';
 
   /**
    * Sets word wrapping on the body of the message to a given number of
@@ -156,6 +168,13 @@ class PHPMailer {
   public $Sendmail          = '/usr/sbin/sendmail';
 
   /**
+   * Determine if mail() uses a fully sendmail compatible MTA that
+   * supports sendmail's "-oi -f" options
+   * @var boolean
+   */
+  public $UseSendmailOptions	= true;
+  
+  /**
    * Path to PHPMailer plugins.  Useful if the SMTP class
    * is in a different directory than the PHP include path.
    * @var string
@@ -235,7 +254,25 @@ class PHPMailer {
   public $Password      = '';
 
   /**
-   * Sets the SMTP server timeout in seconds.
+   *  Sets SMTP auth type.
+   *  @var string
+   */
+  public $AuthType      = '';
+  
+  /**
+   *  Sets SMTP realm.
+   *  @var string
+   */
+  public $Realm         = '';
+
+  /**
+   *  Sets SMTP workstation.
+   *  @var string
+   */
+  public $Workstation   = '';
+
+  /**
+   * Sets the SMTP server   in seconds.
    * This function will not work with the win32 version.
    * @var int
    */
@@ -248,6 +285,13 @@ class PHPMailer {
   public $SMTPDebug     = false;
 
   /**
+   * Sets the function/method to use for debugging output.
+   * Right now we only honor "echo" or "error_log"
+   * @var string
+   */
+  public $Debugoutput     = "echo";
+
+  /**
    * Prevents the SMTP connection from being closed after each mail
    * sending.  If this is set to true then to close the connection
    * requires an explicit call to SmtpClose().
@@ -269,12 +313,14 @@ class PHPMailer {
   public $SingleToArray = array();
 
  /**
-   * Provides the ability to change the line ending
+   * 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
    * @var string
    */
   public $LE              = "\n";
 
-  /**
+   /**
    * Used with DKIM DNS Resource Record
    * @var string
    */
@@ -308,14 +354,24 @@ class PHPMailer {
   public $DKIM_private    = '';
 
   /**
-   * Callback Action function name
-   * the function that handles the result of the send email action. Parameters:
+   * 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:
    *   bool    $result        result of the send action
    *   string  $to            email address of the recipient
    *   string  $cc            cc email addresses
    *   string  $bcc           bcc email addresses
    *   string  $subject       the subject
    *   string  $body          the email body
+   *   string  $from          email address of sender
    * @var string
    */
   public $action_function = ''; //'callbackAction';
@@ -324,11 +380,11 @@ class PHPMailer {
    * Sets the PHPMailer Version number
    * @var string
    */
-  public $Version         = '5.2.1';
+  public $Version         = '5.2.2-beta2';
 
   /**
    * What to use in the X-Mailer header
-   * @var string
+   * @var string NULL for default, whitespace for None, or actual string to use
    */
   public $XMailer         = '';
 
@@ -360,12 +416,47 @@ class PHPMailer {
   const STOP_MESSAGE  = 0; // message only, continue processing
   const STOP_CONTINUE = 1; // message?, likely ok to continue processing
   const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
-
+  const CRLF = "\r\n";     // SMTP RFC specified EOL
+  
   /////////////////////////////////////////////////
   // METHODS, VARIABLES
   /////////////////////////////////////////////////
 
   /**
+   * 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->UseSendmailOptions) ) {
+        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header);
+    } else {
+        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params);
+    }
+    return $rt;
+  }
+
+  /**
+   * Outputs debugging info via user-defined method
+   * @param string $str
+   */
+  private function edebug($str) {
+    if ($this->Debugoutput == "error_log") {
+        error_log($str);
+    } else {
+        echo $str;
+    }
+  }
+
+  /**
    * Constructor
    * @param boolean $exceptions Should we throw external exceptions?
    */
@@ -389,6 +480,7 @@ class PHPMailer {
   /**
    * Sets Mailer to send message using SMTP.
    * @return void
+   * @deprecated
    */
   public function IsSMTP() {
     $this->Mailer = 'smtp';
@@ -397,6 +489,7 @@ class PHPMailer {
   /**
    * Sets Mailer to send message using PHP mail() function.
    * @return void
+   * @deprecated
    */
   public function IsMail() {
     $this->Mailer = 'mail';
@@ -405,6 +498,7 @@ class PHPMailer {
   /**
    * Sets Mailer to send message using the $Sendmail program.
    * @return void
+   * @deprecated
    */
   public function IsSendmail() {
     if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
@@ -416,6 +510,7 @@ class PHPMailer {
   /**
    * Sets Mailer to send message using the qmail MTA.
    * @return void
+   * @deprecated
    */
   public function IsQmail() {
     if (stristr(ini_get('sendmail_path'), 'qmail')) {
@@ -485,8 +580,8 @@ class PHPMailer {
       if ($this->exceptions) {
         throw new phpmailerException('Invalid recipient array: ' . $kind);
       }
-	  if ($this->SMTPDebug) {
-        echo $this->Lang('Invalid recipient array').': '.$kind;
+      if ($this->SMTPDebug) {
+        $this->edebug($this->Lang('Invalid recipient array').': '.$kind);
       }
       return false;
     }
@@ -497,8 +592,8 @@ class PHPMailer {
       if ($this->exceptions) {
         throw new phpmailerException($this->Lang('invalid_address').': '.$address);
       }
-	  if ($this->SMTPDebug) {
-        echo $this->Lang('invalid_address').': '.$address;
+      if ($this->SMTPDebug) {
+        $this->edebug($this->Lang('invalid_address').': '.$address);
       }
       return false;
     }
@@ -521,6 +616,7 @@ class PHPMailer {
  * Set the From and FromName properties
  * @param string $address
  * @param string $name
+ * @param int $auto Also set Reply-To and Sender
  * @return boolean
  */
   public function SetFrom($address, $name = '', $auto = 1) {
@@ -531,8 +627,8 @@ class PHPMailer {
       if ($this->exceptions) {
         throw new phpmailerException($this->Lang('invalid_address').': '.$address);
       }
-	  if ($this->SMTPDebug) {
-        echo $this->Lang('invalid_address').': '.$address;
+      if ($this->SMTPDebug) {
+        $this->edebug($this->Lang('invalid_address').': '.$address);
       }
       return false;
     }
@@ -587,7 +683,7 @@ class PHPMailer {
       if(!$this->PreSend()) return false;
       return $this->PostSend();
     } catch (phpmailerException $e) {
-	  $this->SentMIMEMessage = '';
+      $this->mailHeader = '';
       $this->SetError($e->getMessage());
       if ($this->exceptions) {
         throw $e;
@@ -596,9 +692,13 @@ class PHPMailer {
     }
   }
 
-  protected function PreSend() {
+  /**
+   * Prep mail by constructing all message entities
+   * @return bool
+   */
+  public function PreSend() {
     try {
-	  $mailHeader = "";
+      $this->mailHeader = "";
       if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
         throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
       }
@@ -619,16 +719,16 @@ class PHPMailer {
       $this->MIMEBody = $this->CreateBody();
 
       // To capture the complete message when using mail(), create
-	  // an extra header list which CreateHeader() doesn't fold in
+      // an extra header list which CreateHeader() doesn't fold in
       if ($this->Mailer == 'mail') {
         if (count($this->to) > 0) {
-          $mailHeader .= $this->AddrAppend("To", $this->to);
+          $this->mailHeader .= $this->AddrAppend("To", $this->to);
         } else {
-          $mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
+          $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
         }
-        $mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
+        $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
         // if(count($this->cc) > 0) {
-            // $mailHeader .= $this->AddrAppend("Cc", $this->cc);
+            // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc);
         // }
       }
 
@@ -638,7 +738,6 @@ class PHPMailer {
         $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
       }
 
-      $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);
       return true;
 
     } catch (phpmailerException $e) {
@@ -650,18 +749,28 @@ class PHPMailer {
     }
   }
 
-  protected function PostSend() {
+  /**
+   * Actual Email transport function
+   * Send the email via the selected mechanism
+   * @return bool
+   */
+  public function PostSend() {
+    $rtn = false;
     try {
       // Choose the mailer and send through it
       switch($this->Mailer) {
         case 'sendmail':
-          return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
+          $rtn = $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
+          break;
         case 'smtp':
-          return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
+          $rtn = $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
+          break;
         case 'mail':
-          return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
+          $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody);
+          break;
         default:
-          return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
+          $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody);
+          break;
       }
 
     } catch (phpmailerException $e) {
@@ -669,11 +778,12 @@ class PHPMailer {
       if ($this->exceptions) {
         throw $e;
       }
-	  if ($this->SMTPDebug) {
-        echo $e->getMessage()."\n";
+      if ($this->SMTPDebug) {
+        $this->edebug($e->getMessage()."\n");
       }
       return false;
     }
+    return $rtn;
   }
 
   /**
@@ -744,33 +854,19 @@ class PHPMailer {
     if ($this->Sender != '' and !ini_get('safe_mode')) {
       $old_from = ini_get('sendmail_from');
       ini_set('sendmail_from', $this->Sender);
-      if ($this->SingleTo === true && count($toArr) > 1) {
-        foreach ($toArr as $key => $val) {
-          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
-          // implement call back function if it exists
-          $isSent = ($rt == 1) ? 1 : 0;
-          $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
-        }
-      } else {
-        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
+    }
+    if ($this->SingleTo === true && count($toArr) > 1) {
+      foreach ($toArr as $key => $val) {
+        $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params);
         // implement call back function if it exists
         $isSent = ($rt == 1) ? 1 : 0;
-        $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
+        $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
       }
     } else {
-      if ($this->SingleTo === true && count($toArr) > 1) {
-        foreach ($toArr as $key => $val) {
-          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
-          // implement call back function if it exists
-          $isSent = ($rt == 1) ? 1 : 0;
-          $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
-        }
-      } else {
-        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
-        // implement call back function if it exists
-        $isSent = ($rt == 1) ? 1 : 0;
-        $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
-      }
+      $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params);
+      // implement call back function if it exists
+      $isSent = ($rt == 1) ? 1 : 0;
+      $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
     }
     if (isset($old_from)) {
       ini_set('sendmail_from', $old_from);
@@ -791,7 +887,7 @@ class PHPMailer {
    * @return bool
    */
   protected function SmtpSend($header, $body) {
-    require_once $this->PluginDir . 'class-smtp.php';
+    require_once $this->PluginDir . 'class.smtp.php';
     $bad_rcpt = array();
 
     if(!$this->SmtpConnect()) {
@@ -866,10 +962,12 @@ class PHPMailer {
       $this->smtp = new SMTP();
     }
 
+    $this->smtp->Timeout = $this->Timeout;
     $this->smtp->do_debug = $this->SMTPDebug;
     $hosts = explode(';', $this->Host);
     $index = 0;
     $connection = $this->smtp->Connected();
+    $rtn = true;
 
     // Retry while there is no connection
     try {
@@ -893,6 +991,7 @@ class PHPMailer {
 
           if ($tls) {
             if (!$this->smtp->StartTLS()) {
+              $rtn = false;
               throw new phpmailerException($this->Lang('tls'));
             }
 
@@ -902,23 +1001,27 @@ class PHPMailer {
 
           $connection = true;
           if ($this->SMTPAuth) {
-            if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
+            if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType,
+                                           $this->Realm, $this->Workstation)) {
+              $rtn = false;
               throw new phpmailerException($this->Lang('authenticate'));
             }
           }
         }
         $index++;
         if (!$connection) {
+          $rtn = false;
           throw new phpmailerException($this->Lang('connect_host'));
         }
       }
     } catch (phpmailerException $e) {
       $this->smtp->Reset();
-	  if ($this->exceptions) {
+      if ($this->exceptions) {
         throw $e;
       }
+      $rtn = false;
     }
-    return true;
+    return $rtn;
   }
 
   /**
@@ -1028,13 +1131,15 @@ class PHPMailer {
     // If utf-8 encoding is used, we will need to make sure we don't
     // split multibyte characters when we wrap
     $is_utf8 = (strtolower($this->CharSet) == "utf-8");
+    $lelen = strlen($this->LE);
+    $crlflen = strlen(self::CRLF);
 
     $message = $this->FixEOL($message);
-    if (substr($message, -1) == $this->LE) {
-      $message = substr($message, 0, -1);
+    if (substr($message, -$lelen) == $this->LE) {
+      $message = substr($message, 0, -$lelen);
     }
 
-    $line = explode($this->LE, $message);
+    $line = explode($this->LE, $message);   // Magic. We know FixEOL uses $LE
     $message = '';
     for ($i = 0 ;$i < count($line); $i++) {
       $line_part = explode(' ', $line[$i]);
@@ -1042,7 +1147,7 @@ class PHPMailer {
       for ($e = 0; $e<count($line_part); $e++) {
         $word = $line_part[$e];
         if ($qp_mode and (strlen($word) > $length)) {
-          $space_left = $length - strlen($buf) - 1;
+          $space_left = $length - strlen($buf) - $crlflen;
           if ($e != 0) {
             if ($space_left > 20) {
               $len = $space_left;
@@ -1056,7 +1161,7 @@ class PHPMailer {
               $part = substr($word, 0, $len);
               $word = substr($word, $len);
               $buf .= ' ' . $part;
-              $message .= $buf . sprintf("=%s", $this->LE);
+              $message .= $buf . sprintf("=%s", self::CRLF);
             } else {
               $message .= $buf . $soft_break;
             }
@@ -1075,7 +1180,7 @@ class PHPMailer {
             $word = substr($word, $len);
 
             if (strlen($word) > 0) {
-              $message .= $part . sprintf("=%s", $this->LE);
+              $message .= $part . sprintf("=%s", self::CRLF);
             } else {
               $buf = $part;
             }
@@ -1090,7 +1195,7 @@ class PHPMailer {
           }
         }
       }
-      $message .= $buf . $this->LE;
+      $message .= $buf . self::CRLF;
     }
 
     return $message;
@@ -1176,7 +1281,9 @@ class PHPMailer {
     $this->boundary[3] = 'b3_' . $uniq_id;
 
     $result .= $this->HeaderLine('Date', self::RFCDate());
-    if($this->Sender == '') {
+    if ($this->ReturnPath) {
+      $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath));
+    } elseif ($this->Sender == '') {
       $result .= $this->HeaderLine('Return-Path', trim($this->From));
     } else {
       $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
@@ -1195,7 +1302,7 @@ class PHPMailer {
           $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
         }
       }
-	}
+    }
 
     $from = array();
     $from[0][0] = trim($this->From);
@@ -1227,10 +1334,13 @@ class PHPMailer {
       $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
     }
     $result .= $this->HeaderLine('X-Priority', $this->Priority);
-    if($this->XMailer) {
-      $result .= $this->HeaderLine('X-Mailer', $this->XMailer);
+    if ($this->XMailer == '') {
+        $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
     } else {
-      $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
+      $myXmailer = trim($this->XMailer);
+      if ($myXmailer) {
+        $result .= $this->HeaderLine('X-Mailer', $myXmailer);
+      }
     }
 
     if($this->ConfirmReadingTo != '') {
@@ -1257,10 +1367,6 @@ class PHPMailer {
   public function GetMailMIME() {
     $result = '';
     switch($this->message_type) {
-      case 'plain':
-        $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
-        $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"');
-        break;
       case 'inline':
         $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
         $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
@@ -1277,6 +1383,11 @@ class PHPMailer {
         $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
         $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
         break;
+      default:
+        // Catches case 'plain': and case '':
+        $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
+        $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet);
+        break;
     }
 
     if($this->Mailer != 'mail') {
@@ -1292,7 +1403,7 @@ class PHPMailer {
    * @return string
    */
   public function GetSentMIMEMessage() {
-    return $this->SentMIMEMessage;
+    return sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$this->mailHeader,$this->MIMEBody);
   }
 
 
@@ -1305,15 +1416,12 @@ class PHPMailer {
     $body = '';
 
     if ($this->sign_key_file) {
-      $body .= $this->GetMailMIME();
+      $body .= $this->GetMailMIME().$this->LE;
     }
 
     $this->SetWordWrap();
 
     switch($this->message_type) {
-      case 'plain':
-        $body .= $this->EncodeString($this->Body, $this->Encoding);
-        break;
       case 'inline':
         $body .= $this->GetBoundary($this->boundary[1], '', '', '');
         $body .= $this->EncodeString($this->Body, $this->Encoding);
@@ -1321,7 +1429,7 @@ class PHPMailer {
         $body .= $this->AttachAll("inline", $this->boundary[1]);
         break;
       case 'attach':
-        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
+        $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
         $body .= $this->EncodeString($this->Body, $this->Encoding);
         $body .= $this->LE.$this->LE;
         $body .= $this->AttachAll("attachment", $this->boundary[1]);
@@ -1398,6 +1506,10 @@ class PHPMailer {
         $body .= $this->LE;
         $body .= $this->AttachAll("attachment", $this->boundary[1]);
         break;
+      default:
+        // catch case 'plain' and case ''
+        $body .= $this->EncodeString($this->Body, $this->Encoding);
+        break;
     }
 
     if ($this->IsError()) {
@@ -1444,7 +1556,7 @@ class PHPMailer {
       $encoding = $this->Encoding;
     }
     $result .= $this->TextLine('--' . $boundary);
-    $result .= sprintf("Content-Type: %s; charset=\"%s\"", $contentType, $charSet);
+    $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet);
     $result .= $this->LE;
     $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
     $result .= $this->LE;
@@ -1533,8 +1645,8 @@ class PHPMailer {
       if ($this->exceptions) {
         throw $e;
       }
-	  if ($this->SMTPDebug) {
-        echo $e->getMessage()."\n";
+      if ($this->SMTPDebug) {
+        $this->edebug($e->getMessage()."\n");
       }
       if ( $e->getCode() == self::STOP_CRITICAL ) {
         return false;
@@ -1633,28 +1745,28 @@ class PHPMailer {
       if (!is_readable($path)) {
         throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
       }
-      if (function_exists('get_magic_quotes')) {
-        function get_magic_quotes() {
-          return false;
-        }
-      }
-	  $magic_quotes = get_magic_quotes_runtime();
-	  if ($magic_quotes) {
+      //  if (!function_exists('get_magic_quotes')) {
+      //    function get_magic_quotes() {
+      //      return false;
+      //    }
+      //  }
+      $magic_quotes = get_magic_quotes_runtime();
+      if ($magic_quotes) {
         if (version_compare(PHP_VERSION, '5.3.0', '<')) {
           set_magic_quotes_runtime(0);
         } else {
-		  ini_set('magic_quotes_runtime', 0);
-		}
-	  }
+          ini_set('magic_quotes_runtime', 0); 
+        }
+      }
       $file_buffer  = file_get_contents($path);
       $file_buffer  = $this->EncodeString($file_buffer, $encoding);
-	  if ($magic_quotes) {
+      if ($magic_quotes) {
         if (version_compare(PHP_VERSION, '5.3.0', '<')) {
           set_magic_quotes_runtime($magic_quotes);
         } else {
-		  ini_set('magic_quotes_runtime', $magic_quotes);
-	    }
-	  }
+          ini_set('magic_quotes_runtime', $magic_quotes); 
+        }
+      }
       return $file_buffer;
     } catch (Exception $e) {
       $this->SetError($e->getMessage());
@@ -1747,7 +1859,7 @@ class PHPMailer {
       $encoding = 'Q';
       $encoded = $this->EncodeQ($str, $position);
       $encoded = $this->WrapText($encoded, $maxlen, true);
-      $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
+      $encoded = str_replace('='.self::CRLF, "\n", trim($encoded));
     }
 
     $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
@@ -1901,29 +2013,36 @@ class PHPMailer {
    * @return string
    */
   public function EncodeQ($str, $position = 'text') {
-    // There should not be any EOL in the string
-    $encoded = preg_replace('/[\r\n]*/', '', $str);
-
+    //There should not be any EOL in the string
+    $encoded = str_replace(array("\r", "\n"), '', $str);
     switch (strtolower($position)) {
       case 'phrase':
-        $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
+        $pattern = '^A-Za-z0-9!*+\/ -';
         break;
+
       case 'comment':
-        $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
+        $pattern = '\(\)"';
+        //note that we dont break here!
+        //for this reason we build the $pattern withoud including delimiters and []
+
       case 'text':
       default:
-        // Replace every high ascii, control =, ? and _ characters
-        //TODO using /e (equivalent to eval()) is probably not a good idea
-        $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
-                                "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);
+        //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;
         break;
     }
+    
+    if (preg_match_all("/[{$pattern}]/", $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);
+}
 
-    // Replace every spaces to _ (more readable than =20)
-    $encoded = str_replace(' ', '_', $encoded);
-
-    return $encoded;
-  }
 
   /**
    * Adds a string or binary attachment (non-filesystem) to the list.
@@ -2027,7 +2146,7 @@ class PHPMailer {
   }
 
   public function AlternativeExists() {
-    return strlen($this->AltBody)>0;
+    return !empty($this->AltBody);
   }
 
   /////////////////////////////////////////////////
@@ -2184,29 +2303,43 @@ class PHPMailer {
   }
 
   /**
-   * Changes every end of line from CR or LF to CRLF.
+   * Changes every end of line from CRLF, CR or LF to $this->LE.
    * @access public
+   * @param string $str String to FixEOL
    * @return string
    */
   public function FixEOL($str) {
-    $str = str_replace("\r\n", "\n", $str);
-    $str = str_replace("\r", "\n", $str);
-    $str = str_replace("\n", $this->LE, $str);
-    return $str;
+	// condense down to \n
+	$nstr = str_replace(array("\r\n", "\r"), "\n", $str);
+	// Now convert LE as needed
+	if ($this->LE !== "\n") {
+		$nstr = str_replace("\n", $this->LE, $nstr);
+	}
+    return  $nstr;
   }
 
   /**
-   * Adds a custom header.
+   * Adds a custom header. $name value can be overloaded to contain
+   * both header name and value (name:value)
    * @access public
+   * @param string $name custom header name
+   * @param string $value header value
    * @return void
    */
-  public function AddCustomHeader($custom_header) {
-    $this->CustomHeader[] = explode(':', $custom_header, 2);
+  public function AddCustomHeader($name, $value=null) {
+	if ($value === null) {
+		// Value passed in as name:value
+		$this->CustomHeader[] = explode(':', $name, 2);
+	} else {
+		$this->CustomHeader[] = array($name, $value);
+	}
   }
 
   /**
    * Evaluates the message and returns modifications for inline images and backgrounds
    * @access public
+   * @param string $message Text to be HTML modified
+   * @param string $basedir baseline directory for path
    * @return $message
    */
   public function MsgHTML($message, $basedir = '') {
@@ -2231,40 +2364,43 @@ class PHPMailer {
     }
     $this->IsHTML(true);
     $this->Body = $message;
-	if (empty($this->AltBody)) {
-		$textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
-		if (!empty($textMsg)) {
-			$this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
-		}
-	}
+    if (empty($this->AltBody)) {
+        $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
+        if (!empty($textMsg)) {
+            $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
+        }
+    }
     if (empty($this->AltBody)) {
       $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
     }
-	return $message;
+    return $message;
   }
 
   /**
    * Gets the MIME type of the embedded or inline image
-   * @param string File extension
+   * @param string $ext File extension
    * @access public
    * @return string MIME type of ext
    * @static
    */
   public static function _mime_types($ext = '') {
     $mimes = array(
+      'xl'    =>  'application/excel',
       'hqx'   =>  'application/mac-binhex40',
       'cpt'   =>  'application/mac-compactpro',
-      'doc'   =>  'application/msword',
       'bin'   =>  'application/macbinary',
+      'doc'   =>  'application/msword',
+      'doc'   =>  'application/msword',
+      'word'  =>  'application/msword',
+      'class' =>  'application/octet-stream',
+      'dll'   =>  'application/octet-stream',
       'dms'   =>  'application/octet-stream',
+      'exe'   =>  'application/octet-stream',
       'lha'   =>  'application/octet-stream',
       'lzh'   =>  'application/octet-stream',
-      'exe'   =>  'application/octet-stream',
-      'class' =>  'application/octet-stream',
       'psd'   =>  'application/octet-stream',
-      'so'    =>  'application/octet-stream',
       'sea'   =>  'application/octet-stream',
-      'dll'   =>  'application/octet-stream',
+      'so'    =>  'application/octet-stream',
       'oda'   =>  'application/oda',
       'pdf'   =>  'application/pdf',
       'ai'    =>  'application/postscript',
@@ -2282,9 +2418,9 @@ class PHPMailer {
       'dxr'   =>  'application/x-director',
       'dvi'   =>  'application/x-dvi',
       'gtar'  =>  'application/x-gtar',
-      'php'   =>  'application/x-httpd-php',
-      'php4'  =>  'application/x-httpd-php',
       'php3'  =>  'application/x-httpd-php',
+      'php4'  =>  'application/x-httpd-php',
+      'php'   =>  'application/x-httpd-php',
       'phtml' =>  'application/x-httpd-php',
       'phps'  =>  'application/x-httpd-php-source',
       'js'    =>  'application/x-javascript',
@@ -2292,53 +2428,50 @@ class PHPMailer {
       'sit'   =>  'application/x-stuffit',
       'tar'   =>  'application/x-tar',
       'tgz'   =>  'application/x-tar',
-      'xhtml' =>  'application/xhtml+xml',
       'xht'   =>  'application/xhtml+xml',
+      'xhtml' =>  'application/xhtml+xml',
       'zip'   =>  'application/zip',
       'mid'   =>  'audio/midi',
       'midi'  =>  'audio/midi',
-      'mpga'  =>  'audio/mpeg',
       'mp2'   =>  'audio/mpeg',
       'mp3'   =>  'audio/mpeg',
+      'mpga'  =>  'audio/mpeg',
       'aif'   =>  'audio/x-aiff',
-      'aiff'  =>  'audio/x-aiff',
       'aifc'  =>  'audio/x-aiff',
+      'aiff'  =>  'audio/x-aiff',
       'ram'   =>  'audio/x-pn-realaudio',
       'rm'    =>  'audio/x-pn-realaudio',
       'rpm'   =>  'audio/x-pn-realaudio-plugin',
       'ra'    =>  'audio/x-realaudio',
-      'rv'    =>  'video/vnd.rn-realvideo',
       'wav'   =>  'audio/x-wav',
       'bmp'   =>  'image/bmp',
       'gif'   =>  'image/gif',
       'jpeg'  =>  'image/jpeg',
-      'jpg'   =>  'image/jpeg',
       'jpe'   =>  'image/jpeg',
+      'jpg'   =>  'image/jpeg',
       'png'   =>  'image/png',
       'tiff'  =>  'image/tiff',
       'tif'   =>  'image/tiff',
+      'eml'   =>  'message/rfc822',
       'css'   =>  'text/css',
       'html'  =>  'text/html',
       'htm'   =>  'text/html',
       'shtml' =>  'text/html',
-      'txt'   =>  'text/plain',
-      'text'  =>  'text/plain',
       'log'   =>  'text/plain',
+      'text'  =>  'text/plain',
+      'txt'   =>  'text/plain',
       'rtx'   =>  'text/richtext',
       'rtf'   =>  'text/rtf',
       'xml'   =>  'text/xml',
       'xsl'   =>  'text/xml',
       'mpeg'  =>  'video/mpeg',
-      'mpg'   =>  'video/mpeg',
       'mpe'   =>  'video/mpeg',
-      'qt'    =>  'video/quicktime',
+      'mpg'   =>  'video/mpeg',
       'mov'   =>  'video/quicktime',
+      'qt'    =>  'video/quicktime',
+      'rv'    =>  'video/vnd.rn-realvideo',
       'avi'   =>  'video/x-msvideo',
-      'movie' =>  'video/x-sgi-movie',
-      'doc'   =>  'application/msword',
-      'word'  =>  'application/msword',
-      'xl'    =>  'application/excel',
-      'eml'   =>  'message/rfc822'
+      'movie' =>  'video/x-sgi-movie'
     );
     return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
   }
@@ -2378,9 +2511,7 @@ class PHPMailer {
    * @return string
    */
   public function SecureHeader($str) {
-    $str = str_replace("\r", '', $str);
-    $str = str_replace("\n", '', $str);
-    return trim($str);
+    return trim(str_replace(array("\r", "\n"), '', $str));
   }
 
   /**
@@ -2515,14 +2646,20 @@ class PHPMailer {
     return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
   }
 
-  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) {
-    if (!empty($this->action_function) && function_exists($this->action_function)) {
-      $params = array($isSent, $to, $cc, $bcc, $subject, $body);
+  /**
+   * Perform callback
+   */
+  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) {
+    if (!empty($this->action_function) && is_callable($this->action_function)) {
+      $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
       call_user_func_array($this->action_function, $params);
     }
   }
 }
 
+/**
+ * Exception handling
+ */
 class phpmailerException extends Exception {
   public function errorMessage() {
     $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
diff --git wp-includes/class-smtp.php wp-includes/class-smtp.php
index 6977bff..78dbe0b 100644
--- wp-includes/class-smtp.php
+++ wp-includes/class-smtp.php
@@ -2,7 +2,7 @@
 /*~ class.smtp.php
 .---------------------------------------------------------------------------.
 |  Software: PHPMailer - PHP email class                                    |
-|   Version: 5.2.1                                                          |
+|   Version: 5.2.2-beta2                                                          |
 |      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
 | ------------------------------------------------------------------------- |
 |     Admin: Jim Jagielski (project admininistrator)                        |
@@ -32,7 +32,6 @@
  * @author Jim Jagielski
  * @copyright 2010 - 2012 Jim Jagielski
  * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
- * @version $Id: class.smtp.php 450 2010-06-23 16:46:33Z coolbru $
  */
 
 /**
@@ -63,16 +62,35 @@ class SMTP {
   public $do_debug;       // the level of debug to perform
 
   /**
+   * Sets the function/method to use for debugging output.
+   * Right now we only honor "echo" or "error_log"
+   * @var string
+   */
+  public $Debugoutput     = "echo";
+
+  /**
    *  Sets VERP use on/off (default is off)
    *  @var bool
    */
   public $do_verp = false;
 
   /**
+   * 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;
+
+  /**
    * Sets the SMTP PHPMailer Version number
    * @var string
    */
-  public $Version         = '5.2.1';
+  public $Version         = '5.2.2-beta2';
 
   /////////////////////////////////////////////////
   // PROPERTIES, PRIVATE AND PROTECTED
@@ -83,6 +101,18 @@ class SMTP {
   private $helo_rply; // the reply the server sent to us for HELO
 
   /**
+   * Outputs debugging info via user-defined method
+   * @param string $str
+   */
+  private function edebug($str) {
+    if ($this->Debugoutput == "error_log") {
+        error_log($str);
+    } else {
+        echo $str;
+    }
+  }
+
+  /**
    * Initialize the class so that the data is in a known state.
    * @access public
    * @return void
@@ -139,21 +169,26 @@ class SMTP {
                            "errno" => $errno,
                            "errstr" => $errstr);
       if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />');
       }
       return false;
     }
 
     // SMTP server can take longer to respond, give longer timeout for first read
     // Windows does not have support for this timeout function
-    if(substr(PHP_OS, 0, 3) != "WIN")
-     socket_set_timeout($this->smtp_conn, $tval, 0);
+    if(substr(PHP_OS, 0, 3) != "WIN") {
+     $max = ini_get('max_execution_time');
+     if ($max != 0 && $tval > $max) { // don't bother if unlimited
+      @set_time_limit($tval);
+     }
+     stream_set_timeout($this->smtp_conn, $tval, 0);
+    }
 
     // get any announcement
     $announce = $this->get_lines();
 
     if($this->do_debug >= 2) {
-      echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />');
     }
 
     return true;
@@ -182,7 +217,7 @@ class SMTP {
     $code = substr($rply,0,3);
 
     if($this->do_debug >= 2) {
-      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     }
 
     if($code != 220) {
@@ -191,7 +226,7 @@ class SMTP {
                "smtp_code" => $code,
                "smtp_msg"  => substr($rply,4));
       if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
       }
       return false;
     }
@@ -210,58 +245,124 @@ class SMTP {
    * @access public
    * @return bool
    */
-  public function Authenticate($username, $password) {
-    // Start authentication
-    fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
-
-    $rply = $this->get_lines();
-    $code = substr($rply,0,3);
-
-    if($code != 334) {
-      $this->error =
-        array("error" => "AUTH not accepted from server",
-              "smtp_code" => $code,
-              "smtp_msg" => substr($rply,4));
-      if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
-      }
-      return false;
-    }
-
-    // Send encoded username
-    fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
-
-    $rply = $this->get_lines();
-    $code = substr($rply,0,3);
-
-    if($code != 334) {
-      $this->error =
-        array("error" => "Username not accepted from server",
-              "smtp_code" => $code,
-              "smtp_msg" => substr($rply,4));
-      if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
-      }
-      return false;
-    }
-
-    // Send encoded password
-    fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
-
-    $rply = $this->get_lines();
-    $code = substr($rply,0,3);
-
-    if($code != 235) {
-      $this->error =
-        array("error" => "Password not accepted from server",
-              "smtp_code" => $code,
-              "smtp_msg" => substr($rply,4));
-      if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
-      }
-      return false;
+  public function Authenticate($username, $password, $authtype='LOGIN', $realm='',
+                               $workstation='') {
+    if (empty($authtype)) {
+      $authtype = 'LOGIN';
+    }
+
+    switch ($authtype) {
+      case 'LOGIN':
+        // Start authentication
+        fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
+    
+        $rply = $this->get_lines();
+        $code = substr($rply,0,3);
+    
+        if($code != 334) {
+          $this->error =
+            array("error" => "AUTH not accepted from server",
+                  "smtp_code" => $code,
+                  "smtp_msg" => substr($rply,4));
+          if($this->do_debug >= 1) {
+            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
+          }
+          return false;
+        }
+    
+        // Send encoded username
+        fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
+    
+        $rply = $this->get_lines();
+        $code = substr($rply,0,3);
+    
+        if($code != 334) {
+          $this->error =
+            array("error" => "Username not accepted from server",
+                  "smtp_code" => $code,
+                  "smtp_msg" => substr($rply,4));
+          if($this->do_debug >= 1) {
+            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
+          }
+          return false;
+        }
+    
+        // Send encoded password
+        fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
+    
+        $rply = $this->get_lines();
+        $code = substr($rply,0,3);
+    
+        if($code != 235) {
+          $this->error =
+            array("error" => "Password not accepted from server",
+                  "smtp_code" => $code,
+                  "smtp_msg" => substr($rply,4));
+          if($this->do_debug >= 1) {
+            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
+          }
+          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->Initialize($temp)){//let's test if every function its available
+            $this->error = array("error" => $temp->error);
+            if($this->do_debug >= 1) {
+                $this->edebug("You need to enable some modules in your php.ini file: " . $this->error["error"] . $this->CRLF);
+            }
+            return false;
+        }
+        $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);//msg1
+        
+        fputs($this->smtp_conn,"AUTH NTLM " . base64_encode($msg1) . $this->CRLF);
+
+        $rply = $this->get_lines();
+        $code = substr($rply,0,3);
+        
+
+        if($code != 334) {
+            $this->error =
+                array("error" => "AUTH not accepted from server",
+                      "smtp_code" => $code,
+                      "smtp_msg" => substr($rply,4));
+            if($this->do_debug >= 1) {
+                $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->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->NTLMResponse(substr($challange,24,8),$password);
+        $msg3 = $ntlm_client->TypeMsg3($ntlm_res,$username,$realm,$workstation);//msg3
+        // Send encoded username
+        fputs($this->smtp_conn, base64_encode($msg3) . $this->CRLF);
+
+        $rply = $this->get_lines();
+        $code = substr($rply,0,3);
+
+        if($code != 235) {
+            $this->error =
+                array("error" => "Could not authenticate",
+                      "smtp_code" => $code,
+                      "smtp_msg" => substr($rply,4));
+            if($this->do_debug >= 1) {
+                $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
+            }
+            return false;
+        }
+        break;
     }
-
     return true;
   }
 
@@ -276,7 +377,7 @@ class SMTP {
       if($sock_status["eof"]) {
         // the socket is valid but we are not connected
         if($this->do_debug >= 1) {
-            echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
+            $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected");
         }
         $this->Close();
         return false;
@@ -341,7 +442,7 @@ class SMTP {
     $code = substr($rply,0,3);
 
     if($this->do_debug >= 2) {
-      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     }
 
     if($code != 354) {
@@ -350,7 +451,7 @@ class SMTP {
               "smtp_code" => $code,
               "smtp_msg" => substr($rply,4));
       if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
       }
       return false;
     }
@@ -435,7 +536,7 @@ class SMTP {
     $code = substr($rply,0,3);
 
     if($this->do_debug >= 2) {
-      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     }
 
     if($code != 250) {
@@ -444,7 +545,7 @@ class SMTP {
               "smtp_code" => $code,
               "smtp_msg" => substr($rply,4));
       if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
       }
       return false;
     }
@@ -500,7 +601,7 @@ class SMTP {
     $code = substr($rply,0,3);
 
     if($this->do_debug >= 2) {
-      echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />');
     }
 
     if($code != 250) {
@@ -509,7 +610,7 @@ class SMTP {
               "smtp_code" => $code,
               "smtp_msg" => substr($rply,4));
       if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
       }
       return false;
     }
@@ -542,14 +643,14 @@ class SMTP {
       return false;
     }
 
-    $useVerp = ($this->do_verp ? "XVERP" : "");
+    $useVerp = ($this->do_verp ? " XVERP" : "");
     fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
 
     $rply = $this->get_lines();
     $code = substr($rply,0,3);
 
     if($this->do_debug >= 2) {
-      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     }
 
     if($code != 250) {
@@ -558,7 +659,7 @@ class SMTP {
               "smtp_code" => $code,
               "smtp_msg" => substr($rply,4));
       if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
       }
       return false;
     }
@@ -592,7 +693,7 @@ class SMTP {
     $byemsg = $this->get_lines();
 
     if($this->do_debug >= 2) {
-      echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />');
     }
 
     $rval = true;
@@ -606,7 +707,7 @@ class SMTP {
                  "smtp_rply" => substr($byemsg,4));
       $rval = false;
       if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />');
       }
     }
 
@@ -644,7 +745,7 @@ class SMTP {
     $code = substr($rply,0,3);
 
     if($this->do_debug >= 2) {
-      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     }
 
     if($code != 250 && $code != 251) {
@@ -653,7 +754,7 @@ class SMTP {
               "smtp_code" => $code,
               "smtp_msg" => substr($rply,4));
       if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
       }
       return false;
     }
@@ -687,7 +788,7 @@ class SMTP {
     $code = substr($rply,0,3);
 
     if($this->do_debug >= 2) {
-      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     }
 
     if($code != 250) {
@@ -696,7 +797,7 @@ class SMTP {
               "smtp_code" => $code,
               "smtp_msg" => substr($rply,4));
       if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
       }
       return false;
     }
@@ -735,7 +836,7 @@ class SMTP {
     $code = substr($rply,0,3);
 
     if($this->do_debug >= 2) {
-      echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     }
 
     if($code != 250) {
@@ -744,7 +845,7 @@ class SMTP {
               "smtp_code" => $code,
               "smtp_msg" => substr($rply,4));
       if($this->do_debug >= 1) {
-        echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
       }
       return false;
     }
@@ -768,7 +869,7 @@ class SMTP {
     $this->error = array("error" => "This method, TURN, of the SMTP ".
                                     "is not implemented");
     if($this->do_debug >= 1) {
-      echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
+      $this->edebug("SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />');
     }
     return false;
   }
@@ -797,18 +898,44 @@ class SMTP {
    */
   private function get_lines() {
     $data = "";
-    while(!feof($this->smtp_conn)) {
+    $endtime = 0;
+    /* If for some reason the fp is bad, don't inf loop */
+    if (!is_resource($this->smtp_conn)) {
+      return $data;
+    }
+    stream_set_timeout($this->smtp_conn, $this->Timeout);
+    if ($this->Timelimit > 0) {
+      $endtime = time() + $this->Timelimit;
+    }
+    while(is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
       $str = @fgets($this->smtp_conn,515);
       if($this->do_debug >= 4) {
-        echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
-        echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />');
+        $this->edebug("SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />');
       }
       $data .= $str;
       if($this->do_debug >= 4) {
-        echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
+        $this->edebug("SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />');
       }
       // if 4th character is a space, we are done reading, break the loop
       if(substr($str,3,1) == " ") { break; }
+      // Timed-out? Log and break
+      $info = stream_get_meta_data($this->smtp_conn);
+      if ($info['timed_out']) {
+        if($this->do_debug >= 4) {
+          $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " seconds) <br />");
+        }
+        break;
+      }
+      // Now check if reads took too long
+      if ($endtime) {
+        if (time() > $endtime) {
+          if($this->do_debug >= 4) {
+            $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " seconds) <br />");
+          }
+          break;
+        }
+      }
     }
     return $data;
   }
