Index: /trunk/wp-includes/class-phpmailer.php
===================================================================
--- /trunk/wp-includes/class-phpmailer.php	(revision 19631)
+++ /trunk/wp-includes/class-phpmailer.php	(revision 19632)
@@ -3,13 +3,13 @@
 .---------------------------------------------------------------------------.
 |  Software: PHPMailer - PHP email class                                    |
-|   Version: 5.1                                                            |
-|   Contact: via sourceforge.net support pages (also www.worxware.com)      |
-|      Info: http://phpmailer.sourceforge.net                               |
-|   Support: http://sourceforge.net/projects/phpmailer/                     |
+|   Version: 5.2                                                            |
+|      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
 | ------------------------------------------------------------------------- |
-|     Admin: Andy Prevost (project admininistrator)                         |
+|     Admin: Jim Jagielski (project admininistrator)                        |
 |   Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
 |          : Marcus Bointon (coolbru) coolbru@users.sourceforge.net         |
+|          : Jim Jagielski (jimjag) jimjag@gmail.com                        |
 |   Founder: Brent R. Matzelle (original founder)                           |
+| Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved.               |
 | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved.               |
 | Copyright (c) 2001-2003, Brent R. Matzelle                                |
@@ -20,9 +20,4 @@
 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     |
 | FITNESS FOR A PARTICULAR PURPOSE.                                         |
-| ------------------------------------------------------------------------- |
-| We offer a number of paid services (www.worxware.com):                    |
-| - Web Hosting on highly optimized fast and secure servers                 |
-| - Technology Consulting                                                   |
-| - Oursourcing (highly qualified programmers and graphic designers)        |
 '---------------------------------------------------------------------------'
 */
@@ -34,6 +29,8 @@
  * @author Andy Prevost
  * @author Marcus Bointon
+ * @author Jim Jagielski
+ * @copyright 2010 - 2011 Jim Jagielski
  * @copyright 2004 - 2009 Andy Prevost
- * @version $Id: class.phpmailer.php 447 2009-05-25 01:36:38Z codeworxtech $
+ * @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
  */
@@ -118,4 +115,18 @@
    */
   public $AltBody           = '';
+
+  /**
+   * Stores the complete compiled MIME message body.
+   * @var string
+   * @access protected
+   */
+  protected $MIMEBody       = '';
+
+  /**
+   * Stores the complete compiled MIME message headers.
+   * @var string
+   * @access protected
+   */
+  protected $MIMEHeader     = '';
 
   /**
@@ -269,4 +280,10 @@
    */
   public $DKIM_identity   = '';
+
+  /**
+   * Used with DKIM DNS Resource Record
+   * @var string
+   */
+  public $DKIM_passphrase   = '';
 
   /**
@@ -301,5 +318,11 @@
    * @var string
    */
-  public $Version         = '5.1';
+  public $Version         = '5.2';
+
+  /**
+   * What to use in the X-Mailer header
+   * @var string
+   */
+  public $XMailer         = '';
 
   /////////////////////////////////////////////////
@@ -307,20 +330,20 @@
   /////////////////////////////////////////////////
 
-  private   $smtp           = NULL;
-  private   $to             = array();
-  private   $cc             = array();
-  private   $bcc            = array();
-  private   $ReplyTo        = array();
-  private   $all_recipients = array();
-  private   $attachment     = array();
-  private   $CustomHeader   = array();
-  private   $message_type   = '';
-  private   $boundary       = array();
-  protected $language       = array();
-  private   $error_count    = 0;
-  private   $sign_cert_file = "";
-  private   $sign_key_file  = "";
-  private   $sign_key_pass  = "";
-  private   $exceptions     = false;
+  protected   $smtp           = NULL;
+  protected   $to             = array();
+  protected   $cc             = array();
+  protected   $bcc            = array();
+  protected   $ReplyTo        = array();
+  protected   $all_recipients = array();
+  protected   $attachment     = array();
+  protected   $CustomHeader   = array();
+  protected   $message_type   = '';
+  protected   $boundary       = array();
+  protected   $language       = array();
+  protected   $error_count    = 0;
+  protected   $sign_cert_file = '';
+  protected   $sign_key_file  = '';
+  protected   $sign_key_pass  = '';
+  protected   $exceptions     = false;
 
   /////////////////////////////////////////////////
@@ -448,9 +471,13 @@
    * @param string $name
    * @return boolean true on success, false if address already used or invalid in some way
-   * @access private
-   */
-  private function AddAnAddress($kind, $address, $name = '') {
+   * @access protected
+   */
+  protected function AddAnAddress($kind, $address, $name = '') {
     if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) {
-      echo 'Invalid recipient array: ' . $kind;
+      $this->SetError($this->Lang('Invalid recipient array').': '.$kind);
+      if ($this->exceptions) {
+        throw new phpmailerException('Invalid recipient array: ' . $kind);
+      }
+      echo $this->Lang('Invalid recipient array').': '.$kind;
       return false;
     }
@@ -486,5 +513,5 @@
  * @return boolean
  */
-  public function SetFrom($address, $name = '',$auto=1) {
+  public function SetFrom($address, $name = '', $auto = 1) {
     $address = trim($address);
     $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
@@ -545,4 +572,17 @@
   public function Send() {
     try {
+      if(!$this->PreSend()) return false;
+      return $this->PostSend();
+    } catch (phpmailerException $e) {
+      $this->SetError($e->getMessage());
+      if ($this->exceptions) {
+        throw $e;
+      }
+      return false;
+    }
+  }
+
+  protected function PreSend() {
+    try {
       if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
         throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
@@ -556,25 +596,39 @@
       $this->error_count = 0; // reset errors
       $this->SetMessageType();
-      $header = $this->CreateHeader();
-      $body = $this->CreateBody();
-
+      //Refuse to send an empty message
       if (empty($this->Body)) {
         throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
       }
 
+      $this->MIMEHeader = $this->CreateHeader();
+      $this->MIMEBody = $this->CreateBody();
+
+
       // digitally sign with DKIM if enabled
       if ($this->DKIM_domain && $this->DKIM_private) {
-        $header_dkim = $this->DKIM_Add($header,$this->Subject,$body);
-        $header = str_replace("\r\n","\n",$header_dkim) . $header;
-      }
-
+        $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
+        $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
+      }
+
+      return true;
+    } catch (phpmailerException $e) {
+      $this->SetError($e->getMessage());
+      if ($this->exceptions) {
+        throw $e;
+      }
+      return false;
+    }
+  }
+
+  protected function PostSend() {
+    try {
       // Choose the mailer and send through it
       switch($this->Mailer) {
         case 'sendmail':
-          return $this->SendmailSend($header, $body);
+          return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
         case 'smtp':
-          return $this->SmtpSend($header, $body);
+          return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
         default:
-          return $this->MailSend($header, $body);
+          return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
       }
 
@@ -613,5 +667,5 @@
         // implement call back function if it exists
         $isSent = ($result == 0) ? 1 : 0;
-        $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
+        $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
         if($result != 0) {
           throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
@@ -627,5 +681,5 @@
       // implement call back function if it exists
       $isSent = ($result == 0) ? 1 : 0;
-      $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body);
+      $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body);
       if($result != 0) {
         throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
@@ -649,6 +703,10 @@
     $to = implode(', ', $toArr);
 
-    $params = sprintf("-oi -f %s", $this->Sender);
-    if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) {
+    if (empty($this->Sender)) {
+      $params = "-oi -f %s";
+    } else {
+      $params = sprintf("-oi -f %s", $this->Sender);
+    }
+    if ($this->Sender != '' and !ini_get('safe_mode')) {
       $old_from = ini_get('sendmail_from');
       ini_set('sendmail_from', $this->Sender);
@@ -658,5 +716,5 @@
           // implement call back function if it exists
           $isSent = ($rt == 1) ? 1 : 0;
-          $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
+          $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
         }
       } else {
@@ -664,5 +722,5 @@
         // 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, $to, $this->cc, $this->bcc, $this->Subject, $body);
       }
     } else {
@@ -672,5 +730,5 @@
           // implement call back function if it exists
           $isSent = ($rt == 1) ? 1 : 0;
-          $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body);
+          $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
         }
       } else {
@@ -678,5 +736,5 @@
         // 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, $to, $this->cc, $this->bcc, $this->Subject, $body);
       }
     }
@@ -700,5 +758,5 @@
    */
   protected function SmtpSend($header, $body) {
-    require_once $this->PluginDir . 'class-smtp.php';
+    require_once $this->PluginDir . 'class.smtp.php';
     $bad_rcpt = array();
 
@@ -717,9 +775,9 @@
         // implement call back function if it exists
         $isSent = 0;
-        $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
+        $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
       } else {
         // implement call back function if it exists
         $isSent = 1;
-        $this->doCallback($isSent,$to[0],'','',$this->Subject,$body);
+        $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body);
       }
     }
@@ -729,9 +787,9 @@
         // implement call back function if it exists
         $isSent = 0;
-        $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
+        $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
       } else {
         // implement call back function if it exists
         $isSent = 1;
-        $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body);
+        $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body);
       }
     }
@@ -741,9 +799,9 @@
         // implement call back function if it exists
         $isSent = 0;
-        $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
+        $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
       } else {
         // implement call back function if it exists
         $isSent = 1;
-        $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body);
+        $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body);
       }
     }
@@ -943,5 +1001,5 @@
     $line = explode($this->LE, $message);
     $message = '';
-    for ($i=0 ;$i < count($line); $i++) {
+    for ($i = 0 ;$i < count($line); $i++) {
       $line_part = explode(' ', $line[$i]);
       $buf = '';
@@ -1057,5 +1115,7 @@
     switch($this->message_type) {
       case 'alt':
-      case 'alt_attachments':
+      case 'alt_inline':
+      case 'alt_attach':
+      case 'alt_inline_attach':
         $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
         break;
@@ -1078,4 +1138,5 @@
     $this->boundary[1] = 'b1_' . $uniq_id;
     $this->boundary[2] = 'b2_' . $uniq_id;
+    $this->boundary[3] = 'b3_' . $uniq_id;
 
     $result .= $this->HeaderLine('Date', self::RFCDate());
@@ -1126,10 +1187,14 @@
 
     if($this->MessageID != '') {
-      $result .= $this->HeaderLine('Message-ID',$this->MessageID);
+      $result .= $this->HeaderLine('Message-ID', $this->MessageID);
     } else {
       $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
     }
     $result .= $this->HeaderLine('X-Priority', $this->Priority);
-    $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)');
+    if($this->XMailer) {
+      $result .= $this->HeaderLine('X-Mailer', $this->XMailer);
+    } else {
+      $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
+    }
 
     if($this->ConfirmReadingTo != '') {
@@ -1159,16 +1224,19 @@
       case 'plain':
         $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
-        $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
+        $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"');
         break;
-      case 'attachments':
-      case 'alt_attachments':
-        if($this->InlineImageExists()){
-          $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
-        } else {
-          $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
-          $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
-        }
+      case 'inline':
+        $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
+        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
+        break;
+      case 'attach':
+      case 'inline_attach':
+      case 'alt_attach':
+      case 'alt_inline_attach':
+        $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
+        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
         break;
       case 'alt':
+      case 'alt_inline':
         $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
         $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
@@ -1198,4 +1266,31 @@
 
     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);
+        $body .= $this->LE.$this->LE;
+        $body .= $this->AttachAll("inline", $this->boundary[1]);
+        break;
+      case 'attach':
+        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
+        $body .= $this->EncodeString($this->Body, $this->Encoding);
+        $body .= $this->LE.$this->LE;
+        $body .= $this->AttachAll("attachment", $this->boundary[1]);
+        break;
+      case 'inline_attach':
+        $body .= $this->TextLine("--" . $this->boundary[1]);
+        $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
+        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
+        $body .= $this->LE;
+        $body .= $this->GetBoundary($this->boundary[2], '', '', '');
+        $body .= $this->EncodeString($this->Body, $this->Encoding);
+        $body .= $this->LE.$this->LE;
+        $body .= $this->AttachAll("inline", $this->boundary[2]);
+        $body .= $this->LE;
+        $body .= $this->AttachAll("attachment", $this->boundary[1]);
+        break;
       case 'alt':
         $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
@@ -1207,24 +1302,54 @@
         $body .= $this->EndBoundary($this->boundary[1]);
         break;
-      case 'plain':
-        $body .= $this->EncodeString($this->Body, $this->Encoding);
-        break;
-      case 'attachments':
-        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
-        $body .= $this->EncodeString($this->Body, $this->Encoding);
-        $body .= $this->LE;
-        $body .= $this->AttachAll();
-        break;
-      case 'alt_attachments':
-        $body .= sprintf("--%s%s", $this->boundary[1], $this->LE);
-        $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
-        $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
+      case 'alt_inline':
+        $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
         $body .= $this->EncodeString($this->AltBody, $this->Encoding);
         $body .= $this->LE.$this->LE;
-        $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
+        $body .= $this->TextLine("--" . $this->boundary[1]);
+        $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
+        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
+        $body .= $this->LE;
+        $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
+        $body .= $this->EncodeString($this->Body, $this->Encoding);
+        $body .= $this->LE.$this->LE;
+        $body .= $this->AttachAll("inline", $this->boundary[2]);
+        $body .= $this->LE;
+        $body .= $this->EndBoundary($this->boundary[1]);
+        break;
+      case 'alt_attach':
+        $body .= $this->TextLine("--" . $this->boundary[1]);
+        $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
+        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
+        $body .= $this->LE;
+        $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
+        $body .= $this->EncodeString($this->AltBody, $this->Encoding);
+        $body .= $this->LE.$this->LE;
+        $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
         $body .= $this->EncodeString($this->Body, $this->Encoding);
         $body .= $this->LE.$this->LE;
         $body .= $this->EndBoundary($this->boundary[2]);
-        $body .= $this->AttachAll();
+        $body .= $this->LE;
+        $body .= $this->AttachAll("attachment", $this->boundary[1]);
+        break;
+      case 'alt_inline_attach':
+        $body .= $this->TextLine("--" . $this->boundary[1]);
+        $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
+        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
+        $body .= $this->LE;
+        $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
+        $body .= $this->EncodeString($this->AltBody, $this->Encoding);
+        $body .= $this->LE.$this->LE;
+        $body .= $this->TextLine("--" . $this->boundary[2]);
+        $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
+        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"');
+        $body .= $this->LE;
+        $body .= $this->GetBoundary($this->boundary[3], '', 'text/html', '');
+        $body .= $this->EncodeString($this->Body, $this->Encoding);
+        $body .= $this->LE.$this->LE;
+        $body .= $this->AttachAll("inline", $this->boundary[3]);
+        $body .= $this->LE;
+        $body .= $this->EndBoundary($this->boundary[2]);
+        $body .= $this->LE;
+        $body .= $this->AttachAll("attachment", $this->boundary[1]);
         break;
     }
@@ -1259,7 +1384,8 @@
   /**
    * Returns the start of a message boundary.
-   * @access private
-   */
-  private function GetBoundary($boundary, $charSet, $contentType, $encoding) {
+   * @access protected
+   * @return string
+   */
+  protected function GetBoundary($boundary, $charSet, $contentType, $encoding) {
     $result = '';
     if($charSet == '') {
@@ -1273,5 +1399,5 @@
     }
     $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);
@@ -1283,7 +1409,8 @@
   /**
    * Returns the end of a message boundary.
-   * @access private
-   */
-  private function EndBoundary($boundary) {
+   * @access protected
+   * @return string
+   */
+  protected function EndBoundary($boundary) {
     return $this->LE . '--' . $boundary . '--' . $this->LE;
   }
@@ -1291,21 +1418,14 @@
   /**
    * Sets the message type.
-   * @access private
+   * @access protected
    * @return void
    */
-  private function SetMessageType() {
-    if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
-      $this->message_type = 'plain';
-    } else {
-      if(count($this->attachment) > 0) {
-        $this->message_type = 'attachments';
-      }
-      if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
-        $this->message_type = 'alt';
-      }
-      if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
-        $this->message_type = 'alt_attachments';
-      }
-    }
+  protected function SetMessageType() {
+    $this->message_type = array();
+    if($this->AlternativeExists()) $this->message_type[] = "alt";
+    if($this->InlineImageExists()) $this->message_type[] = "inline";
+    if($this->AttachmentExists()) $this->message_type[] = "attach";
+    $this->message_type = implode("_", $this->message_type);
+    if($this->message_type == "") $this->message_type = "plain";
   }
 
@@ -1387,8 +1507,8 @@
    * Attaches all fs, string, and binary attachments to the message.
    * Returns an empty string on failure.
-   * @access private
+   * @access protected
    * @return string
    */
-  private function AttachAll() {
+  protected function AttachAll($disposition_type, $boundary) {
     // Return text of body
     $mime = array();
@@ -1398,52 +1518,56 @@
     // Add all attachments
     foreach ($this->attachment as $attachment) {
-      // Check for string attachment
-      $bString = $attachment[5];
-      if ($bString) {
-        $string = $attachment[0];
-      } else {
-        $path = $attachment[0];
-      }
-
-      if (in_array($attachment[0], $incl)) { continue; }
-      $filename    = $attachment[1];
-      $name        = $attachment[2];
-      $encoding    = $attachment[3];
-      $type        = $attachment[4];
-      $disposition = $attachment[6];
-      $cid         = $attachment[7];
-      $incl[]      = $attachment[0];
-      if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
-      $cidUniq[$cid] = true;
-
-      $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
-      $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
-      $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
-
-      if($disposition == 'inline') {
-        $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
-      }
-
-      $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
-
-      // Encode as string attachment
-      if($bString) {
-        $mime[] = $this->EncodeString($string, $encoding);
-        if($this->IsError()) {
-          return '';
+      // CHECK IF IT IS A VALID DISPOSITION_FILTER
+      if($attachment[6] == $disposition_type) {
+        // Check for string attachment
+        $bString = $attachment[5];
+        if ($bString) {
+          $string = $attachment[0];
+        } else {
+          $path = $attachment[0];
         }
-        $mime[] = $this->LE.$this->LE;
-      } else {
-        $mime[] = $this->EncodeFile($path, $encoding);
-        if($this->IsError()) {
-          return '';
+
+        $inclhash = md5(serialize($attachment));
+        if (in_array($inclhash, $incl)) { continue; }
+        $incl[]      = $inclhash;
+        $filename    = $attachment[1];
+        $name        = $attachment[2];
+        $encoding    = $attachment[3];
+        $type        = $attachment[4];
+        $disposition = $attachment[6];
+        $cid         = $attachment[7];
+        if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; }
+        $cidUniq[$cid] = true;
+
+        $mime[] = sprintf("--%s%s", $boundary, $this->LE);
+        $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
+        $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
+
+        if($disposition == 'inline') {
+          $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
         }
-        $mime[] = $this->LE.$this->LE;
-      }
-    }
-
-    $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
-
-    return join('', $mime);
+
+        $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
+
+        // Encode as string attachment
+        if($bString) {
+          $mime[] = $this->EncodeString($string, $encoding);
+          if($this->IsError()) {
+            return '';
+          }
+          $mime[] = $this->LE.$this->LE;
+        } else {
+          $mime[] = $this->EncodeFile($path, $encoding);
+          if($this->IsError()) {
+            return '';
+          }
+          $mime[] = $this->LE.$this->LE;
+        }
+      }
+    }
+
+    $mime[] = sprintf("--%s--%s", $boundary, $this->LE);
+
+    return implode("", $mime);
   }
 
@@ -1454,8 +1578,8 @@
    * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
    * @see EncodeFile()
-   * @access private
+   * @access protected
    * @return string
    */
-  private function EncodeFile($path, $encoding = 'base64') {
+  protected function EncodeFile($path, $encoding = 'base64') {
     try {
       if (!is_readable($path)) {
@@ -1467,5 +1591,5 @@
         }
       }
-      if (PHP_VERSION < 6) {
+      if (version_compare(PHP_VERSION, '5.3.0', '<')) {
         $magic_quotes = get_magic_quotes_runtime();
         set_magic_quotes_runtime(0);
@@ -1473,5 +1597,7 @@
       $file_buffer  = file_get_contents($path);
       $file_buffer  = $this->EncodeString($file_buffer, $encoding);
-      if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
+      if (version_compare(PHP_VERSION, '5.3.0', '<')) {
+        set_magic_quotes_runtime($magic_quotes);
+      }
       return $file_buffer;
     } catch (Exception $e) {
@@ -1489,5 +1615,5 @@
    * @return string
    */
-  public function EncodeString ($str, $encoding = 'base64') {
+  public function EncodeString($str, $encoding = 'base64') {
     $encoded = '';
     switch(strtolower($encoding)) {
@@ -1638,5 +1764,5 @@
   */
   public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
-    $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
+    $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
     $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
     $eol = "\r\n";
@@ -1719,5 +1845,5 @@
    * @return string
    */
-  public function EncodeQ ($str, $position = 'text') {
+  public function EncodeQ($str, $position = 'text') {
     // There should not be any EOL in the string
     $encoded = preg_replace('/[\r\n]*/', '', $str);
@@ -1734,5 +1860,5 @@
         //TODO using /e (equivalent to eval()) is probably not a good idea
         $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
-              "'='.sprintf('%02X', ord('\\1'))", $encoded);
+                                "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);
         break;
     }
@@ -1808,4 +1934,18 @@
   }
 
+  public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') {
+    // Append to $attachment array
+    $this->attachment[] = array(
+      0 => $string,
+      1 => $filename,
+      2 => basename($filename),
+      3 => $encoding,
+      4 => $type,
+      5 => true,  // isStringAttachment
+      6 => 'inline',
+      7 => $cid
+    );
+  }
+
   /**
    * Returns true if an inline attachment is present.
@@ -1820,4 +1960,17 @@
     }
     return false;
+  }
+
+  public function AttachmentExists() {
+    foreach($this->attachment as $attachment) {
+      if ($attachment[6] == 'attachment') {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  public function AlternativeExists() {
+    return strlen($this->AltBody)>0;
   }
 
@@ -1934,8 +2087,8 @@
   /**
    * Returns the server hostname or 'localhost.localdomain' if unknown.
-   * @access private
+   * @access protected
    * @return string
    */
-  private function ServerHostname() {
+  protected function ServerHostname() {
     if (!empty($this->Hostname)) {
       $result = $this->Hostname;
@@ -1951,8 +2104,8 @@
   /**
    * Returns a message in the appropriate language.
-   * @access private
+   * @access protected
    * @return string
    */
-  private function Lang($key) {
+  protected function Lang($key) {
     if(count($this->language) < 1) {
       $this->SetLanguage('en'); // set the default language
@@ -1977,8 +2130,8 @@
   /**
    * Changes every end of line from CR or LF to CRLF.
-   * @access private
+   * @access public
    * @return string
    */
-  private function FixEOL($str) {
+  public function FixEOL($str) {
     $str = str_replace("\r\n", "\n", $str);
     $str = str_replace("\r", "\n", $str);
@@ -2006,14 +2159,14 @@
       foreach($images[2] as $i => $url) {
         // do not change urls for absolute images (thanks to corvuscorax)
-        if (!preg_match('#^[A-z]+://#',$url)) {
+        if (!preg_match('#^[A-z]+://#', $url)) {
           $filename = basename($url);
           $directory = dirname($url);
-          ($directory == '.')?$directory='':'';
+          ($directory == '.') ? $directory='': '';
           $cid = 'cid:' . md5($filename);
           $ext = pathinfo($filename, PATHINFO_EXTENSION);
           $mimeType  = self::_mime_types($ext);
-          if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
-          if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
-          if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
+          if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }
+          if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
+          if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {
             $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
           }
@@ -2023,5 +2176,5 @@
     $this->IsHTML(true);
     $this->Body = $message;
-    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
+    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
     if (!empty($textMsg) && empty($this->AltBody)) {
       $this->AltBody = html_entity_decode($textMsg);
@@ -2193,12 +2346,12 @@
    */
   public function DKIM_QP($txt) {
-    $tmp="";
-    $line="";
-    for ($i=0;$i<strlen($txt);$i++) {
-      $ord=ord($txt[$i]);
+    $tmp = '';
+    $line = '';
+    for ($i = 0; $i < strlen($txt); $i++) {
+      $ord = ord($txt[$i]);
       if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) {
-        $line.=$txt[$i];
+        $line .= $txt[$i];
       } else {
-        $line.="=".sprintf("%02X",$ord);
+        $line .= "=".sprintf("%02X", $ord);
       }
     }
@@ -2214,6 +2367,6 @@
   public function DKIM_Sign($s) {
     $privKeyStr = file_get_contents($this->DKIM_private);
-    if ($this->DKIM_passphrase!='') {
-      $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase);
+    if ($this->DKIM_passphrase != '') {
+      $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
     } else {
       $privKey = $privKeyStr;
@@ -2231,13 +2384,13 @@
    */
   public function DKIM_HeaderC($s) {
-    $s=preg_replace("/\r\n\s+/"," ",$s);
-    $lines=explode("\r\n",$s);
-    foreach ($lines as $key=>$line) {
-      list($heading,$value)=explode(":",$line,2);
-      $heading=strtolower($heading);
-      $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces
-      $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value
-    }
-    $s=implode("\r\n",$lines);
+    $s = preg_replace("/\r\n\s+/", " ", $s);
+    $lines = explode("\r\n", $s);
+    foreach ($lines as $key => $line) {
+      list($heading, $value) = explode(":", $line, 2);
+      $heading = strtolower($heading);
+      $value = preg_replace("/\s+/", " ", $value) ; // Compress useless spaces
+      $lines[$key] = $heading.":".trim($value) ; // Don't forget to remove WSP around the value
+    }
+    $s = implode("\r\n", $lines);
     return $s;
   }
@@ -2252,9 +2405,9 @@
     if ($body == '') return "\r\n";
     // stabilize line endings
-    $body=str_replace("\r\n","\n",$body);
-    $body=str_replace("\n","\r\n",$body);
+    $body = str_replace("\r\n", "\n", $body);
+    $body = str_replace("\n", "\r\n", $body);
     // END stabilize line endings
-    while (substr($body,strlen($body)-4,4) == "\r\n\r\n") {
-      $body=substr($body,0,strlen($body)-2);
+    while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") {
+      $body = substr($body, 0, strlen($body) - 2);
     }
     return $body;
@@ -2269,5 +2422,5 @@
    * @param string $body Body
    */
-  public function DKIM_Add($headers_line,$subject,$body) {
+  public function DKIM_Add($headers_line, $subject, $body) {
     $DKIMsignatureType    = 'rsa-sha1'; // Signature & hash algorithms
     $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body
@@ -2275,15 +2428,15 @@
     $DKIMtime             = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
     $subject_header       = "Subject: $subject";
-    $headers              = explode("\r\n",$headers_line);
+    $headers              = explode($this->LE, $headers_line);
     foreach($headers as $header) {
-      if (strpos($header,'From:') === 0) {
-        $from_header=$header;
-      } elseif (strpos($header,'To:') === 0) {
-        $to_header=$header;
-      }
-    }
-    $from     = str_replace('|','=7C',$this->DKIM_QP($from_header));
-    $to       = str_replace('|','=7C',$this->DKIM_QP($to_header));
-    $subject  = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
+      if (strpos($header, 'From:') === 0) {
+        $from_header = $header;
+      } elseif (strpos($header, 'To:') === 0) {
+        $to_header = $header;
+      }
+    }
+    $from     = str_replace('|', '=7C', $this->DKIM_QP($from_header));
+    $to       = str_replace('|', '=7C', $this->DKIM_QP($to_header));
+    $subject  = str_replace('|', '=7C', $this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable
     $body     = $this->DKIM_BodyC($body);
     $DKIMlen  = strlen($body) ; // Length of body
@@ -2304,8 +2457,8 @@
   }
 
-  protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) {
+  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) {
     if (!empty($this->action_function) && function_exists($this->action_function)) {
-      $params = array($isSent,$to,$cc,$bcc,$subject,$body);
-      call_user_func_array($this->action_function,$params);
+      $params = array($isSent, $to, $cc, $bcc, $subject, $body);
+      call_user_func_array($this->action_function, $params);
     }
   }
Index: /trunk/wp-includes/class-smtp.php
===================================================================
--- /trunk/wp-includes/class-smtp.php	(revision 19631)
+++ /trunk/wp-includes/class-smtp.php	(revision 19632)
@@ -3,13 +3,13 @@
 .---------------------------------------------------------------------------.
 |  Software: PHPMailer - PHP email class                                    |
-|   Version: 5.1                                                            |
-|   Contact: via sourceforge.net support pages (also www.codeworxtech.com)  |
-|      Info: http://phpmailer.sourceforge.net                               |
-|   Support: http://sourceforge.net/projects/phpmailer/                     |
+|   Version: 5.2                                                            |
+|      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
 | ------------------------------------------------------------------------- |
-|     Admin: Andy Prevost (project admininistrator)                         |
+|     Admin: Jim Jagielski (project admininistrator)                        |
 |   Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
 |          : Marcus Bointon (coolbru) coolbru@users.sourceforge.net         |
+|          : Jim Jagielski (jimjag) jimjag@gmail.com                        |
 |   Founder: Brent R. Matzelle (original founder)                           |
+| Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved.               |
 | Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved.               |
 | Copyright (c) 2001-2003, Brent R. Matzelle                                |
@@ -20,9 +20,4 @@
 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     |
 | FITNESS FOR A PARTICULAR PURPOSE.                                         |
-| ------------------------------------------------------------------------- |
-| We offer a number of paid services (www.codeworxtech.com):                |
-| - Web Hosting on highly optimized fast and secure servers                 |
-| - Technology Consulting                                                   |
-| - Oursourcing (highly qualified programmers and graphic designers)        |
 '---------------------------------------------------------------------------'
 */
@@ -35,6 +30,8 @@
  * @author Marcus Bointon
  * @copyright 2004 - 2008 Andy Prevost
+ * @author Jim Jagielski
+ * @copyright 2010 - 2011 Jim Jagielski
  * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
- * @version $Id: class.smtp.php 444 2009-05-05 11:22:26Z coolbru $
+ * @version $Id: class.smtp.php 450 2010-06-23 16:46:33Z coolbru $
  */
 
@@ -71,4 +68,10 @@
    */
   public $do_verp = false;
+
+  /**
+   * Sets the SMTP PHPMailer Version number
+   * @var string
+   */
+  public $Version         = '5.2';
 
   /////////////////////////////////////////////////
