WordPress.org

Make WordPress Core

Changeset 19632


Ignore:
Timestamp:
12/28/11 12:59:13 (3 years ago)
Author:
westi
Message:

Update PHPMailer to version 5.2. See #19677

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-phpmailer.php

    r18107 r19632  
    33.---------------------------------------------------------------------------. 
    44|  Software: PHPMailer - PHP email class                                    | 
    5 |   Version: 5.1                                                            | 
    6 |   Contact: via sourceforge.net support pages (also www.worxware.com)      | 
    7 |      Info: http://phpmailer.sourceforge.net                               | 
    8 |   Support: http://sourceforge.net/projects/phpmailer/                     | 
     5|   Version: 5.2                                                            | 
     6|      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       | 
    97| ------------------------------------------------------------------------- | 
    10 |     Admin: Andy Prevost (project admininistrator)                         | 
     8|     Admin: Jim Jagielski (project admininistrator)                        | 
    119|   Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net | 
    1210|          : Marcus Bointon (coolbru) coolbru@users.sourceforge.net         | 
     11|          : Jim Jagielski (jimjag) jimjag@gmail.com                        | 
    1312|   Founder: Brent R. Matzelle (original founder)                           | 
     13| Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved.               | 
    1414| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved.               | 
    1515| Copyright (c) 2001-2003, Brent R. Matzelle                                | 
     
    2020| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     | 
    2121| FITNESS FOR A PARTICULAR PURPOSE.                                         | 
    22 | ------------------------------------------------------------------------- | 
    23 | We offer a number of paid services (www.worxware.com):                    | 
    24 | - Web Hosting on highly optimized fast and secure servers                 | 
    25 | - Technology Consulting                                                   | 
    26 | - Oursourcing (highly qualified programmers and graphic designers)        | 
    2722'---------------------------------------------------------------------------' 
    2823*/ 
     
    3429 * @author Andy Prevost 
    3530 * @author Marcus Bointon 
     31 * @author Jim Jagielski 
     32 * @copyright 2010 - 2011 Jim Jagielski 
    3633 * @copyright 2004 - 2009 Andy Prevost 
    37  * @version $Id: class.phpmailer.php 447 2009-05-25 01:36:38Z codeworxtech $ 
     34 * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $ 
    3835 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License 
    3936 */ 
     
    118115   */ 
    119116  public $AltBody           = ''; 
     117 
     118  /** 
     119   * Stores the complete compiled MIME message body. 
     120   * @var string 
     121   * @access protected 
     122   */ 
     123  protected $MIMEBody       = ''; 
     124 
     125  /** 
     126   * Stores the complete compiled MIME message headers. 
     127   * @var string 
     128   * @access protected 
     129   */ 
     130  protected $MIMEHeader     = ''; 
    120131 
    121132  /** 
     
    269280   */ 
    270281  public $DKIM_identity   = ''; 
     282 
     283  /** 
     284   * Used with DKIM DNS Resource Record 
     285   * @var string 
     286   */ 
     287  public $DKIM_passphrase   = ''; 
    271288 
    272289  /** 
     
    301318   * @var string 
    302319   */ 
    303   public $Version         = '5.1'; 
     320  public $Version         = '5.2'; 
     321 
     322  /** 
     323   * What to use in the X-Mailer header 
     324   * @var string 
     325   */ 
     326  public $XMailer         = ''; 
    304327 
    305328  ///////////////////////////////////////////////// 
     
    307330  ///////////////////////////////////////////////// 
    308331 
    309   private   $smtp           = NULL; 
    310   private   $to             = array(); 
    311   private   $cc             = array(); 
    312   private   $bcc            = array(); 
    313   private   $ReplyTo        = array(); 
    314   private   $all_recipients = array(); 
    315   private   $attachment     = array(); 
    316   private   $CustomHeader   = array(); 
    317   private   $message_type   = ''; 
    318   private   $boundary       = array(); 
    319   protected $language       = array(); 
    320   private   $error_count    = 0; 
    321   private   $sign_cert_file = ""; 
    322   private   $sign_key_file  = ""; 
    323   private   $sign_key_pass  = ""; 
    324   private   $exceptions     = false; 
     332  protected   $smtp           = NULL; 
     333  protected   $to             = array(); 
     334  protected   $cc             = array(); 
     335  protected   $bcc            = array(); 
     336  protected   $ReplyTo        = array(); 
     337  protected   $all_recipients = array(); 
     338  protected   $attachment     = array(); 
     339  protected   $CustomHeader   = array(); 
     340  protected   $message_type   = ''; 
     341  protected   $boundary       = array(); 
     342  protected   $language       = array(); 
     343  protected   $error_count    = 0; 
     344  protected   $sign_cert_file = ''; 
     345  protected   $sign_key_file  = ''; 
     346  protected   $sign_key_pass  = ''; 
     347  protected   $exceptions     = false; 
    325348 
    326349  ///////////////////////////////////////////////// 
     
    448471   * @param string $name 
    449472   * @return boolean true on success, false if address already used or invalid in some way 
    450    * @access private 
    451    */ 
    452   private function AddAnAddress($kind, $address, $name = '') { 
     473   * @access protected 
     474   */ 
     475  protected function AddAnAddress($kind, $address, $name = '') { 
    453476    if (!preg_match('/^(to|cc|bcc|ReplyTo)$/', $kind)) { 
    454       echo 'Invalid recipient array: ' . $kind; 
     477      $this->SetError($this->Lang('Invalid recipient array').': '.$kind); 
     478      if ($this->exceptions) { 
     479        throw new phpmailerException('Invalid recipient array: ' . $kind); 
     480      } 
     481      echo $this->Lang('Invalid recipient array').': '.$kind; 
    455482      return false; 
    456483    } 
     
    486513 * @return boolean 
    487514 */ 
    488   public function SetFrom($address, $name = '',$auto=1) { 
     515  public function SetFrom($address, $name = '', $auto = 1) { 
    489516    $address = trim($address); 
    490517    $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim 
     
    545572  public function Send() { 
    546573    try { 
     574      if(!$this->PreSend()) return false; 
     575      return $this->PostSend(); 
     576    } catch (phpmailerException $e) { 
     577      $this->SetError($e->getMessage()); 
     578      if ($this->exceptions) { 
     579        throw $e; 
     580      } 
     581      return false; 
     582    } 
     583  } 
     584 
     585  protected function PreSend() { 
     586    try { 
    547587      if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) { 
    548588        throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL); 
     
    556596      $this->error_count = 0; // reset errors 
    557597      $this->SetMessageType(); 
    558       $header = $this->CreateHeader(); 
    559       $body = $this->CreateBody(); 
    560  
     598      //Refuse to send an empty message 
    561599      if (empty($this->Body)) { 
    562600        throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL); 
    563601      } 
    564602 
     603      $this->MIMEHeader = $this->CreateHeader(); 
     604      $this->MIMEBody = $this->CreateBody(); 
     605 
     606 
    565607      // digitally sign with DKIM if enabled 
    566608      if ($this->DKIM_domain && $this->DKIM_private) { 
    567         $header_dkim = $this->DKIM_Add($header,$this->Subject,$body); 
    568         $header = str_replace("\r\n","\n",$header_dkim) . $header; 
    569       } 
    570  
     609        $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody); 
     610        $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader; 
     611      } 
     612 
     613      return true; 
     614    } catch (phpmailerException $e) { 
     615      $this->SetError($e->getMessage()); 
     616      if ($this->exceptions) { 
     617        throw $e; 
     618      } 
     619      return false; 
     620    } 
     621  } 
     622 
     623  protected function PostSend() { 
     624    try { 
    571625      // Choose the mailer and send through it 
    572626      switch($this->Mailer) { 
    573627        case 'sendmail': 
    574           return $this->SendmailSend($header, $body); 
     628          return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody); 
    575629        case 'smtp': 
    576           return $this->SmtpSend($header, $body); 
     630          return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody); 
    577631        default: 
    578           return $this->MailSend($header, $body); 
     632          return $this->MailSend($this->MIMEHeader, $this->MIMEBody); 
    579633      } 
    580634 
     
    613667        // implement call back function if it exists 
    614668        $isSent = ($result == 0) ? 1 : 0; 
    615         $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); 
     669        $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 
    616670        if($result != 0) { 
    617671          throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 
     
    627681      // implement call back function if it exists 
    628682      $isSent = ($result == 0) ? 1 : 0; 
    629       $this->doCallback($isSent,$this->to,$this->cc,$this->bcc,$this->Subject,$body); 
     683      $this->doCallback($isSent, $this->to, $this->cc, $this->bcc, $this->Subject, $body); 
    630684      if($result != 0) { 
    631685        throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL); 
     
    649703    $to = implode(', ', $toArr); 
    650704 
    651     $params = sprintf("-oi -f %s", $this->Sender); 
    652     if ($this->Sender != '' && strlen(ini_get('safe_mode'))< 1) { 
     705    if (empty($this->Sender)) { 
     706      $params = "-oi -f %s"; 
     707    } else { 
     708      $params = sprintf("-oi -f %s", $this->Sender); 
     709    } 
     710    if ($this->Sender != '' and !ini_get('safe_mode')) { 
    653711      $old_from = ini_get('sendmail_from'); 
    654712      ini_set('sendmail_from', $this->Sender); 
     
    658716          // implement call back function if it exists 
    659717          $isSent = ($rt == 1) ? 1 : 0; 
    660           $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); 
     718          $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 
    661719        } 
    662720      } else { 
     
    664722        // implement call back function if it exists 
    665723        $isSent = ($rt == 1) ? 1 : 0; 
    666         $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); 
     724        $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 
    667725      } 
    668726    } else { 
     
    672730          // implement call back function if it exists 
    673731          $isSent = ($rt == 1) ? 1 : 0; 
    674           $this->doCallback($isSent,$val,$this->cc,$this->bcc,$this->Subject,$body); 
     732          $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body); 
    675733        } 
    676734      } else { 
     
    678736        // implement call back function if it exists 
    679737        $isSent = ($rt == 1) ? 1 : 0; 
    680         $this->doCallback($isSent,$to,$this->cc,$this->bcc,$this->Subject,$body); 
     738        $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body); 
    681739      } 
    682740    } 
     
    700758   */ 
    701759  protected function SmtpSend($header, $body) { 
    702     require_once $this->PluginDir . 'class-smtp.php'; 
     760    require_once $this->PluginDir . 'class.smtp.php'; 
    703761    $bad_rcpt = array(); 
    704762 
     
    717775        // implement call back function if it exists 
    718776        $isSent = 0; 
    719         $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); 
     777        $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body); 
    720778      } else { 
    721779        // implement call back function if it exists 
    722780        $isSent = 1; 
    723         $this->doCallback($isSent,$to[0],'','',$this->Subject,$body); 
     781        $this->doCallback($isSent, $to[0], '', '', $this->Subject, $body); 
    724782      } 
    725783    } 
     
    729787        // implement call back function if it exists 
    730788        $isSent = 0; 
    731         $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); 
     789        $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body); 
    732790      } else { 
    733791        // implement call back function if it exists 
    734792        $isSent = 1; 
    735         $this->doCallback($isSent,'',$cc[0],'',$this->Subject,$body); 
     793        $this->doCallback($isSent, '', $cc[0], '', $this->Subject, $body); 
    736794      } 
    737795    } 
     
    741799        // implement call back function if it exists 
    742800        $isSent = 0; 
    743         $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); 
     801        $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body); 
    744802      } else { 
    745803        // implement call back function if it exists 
    746804        $isSent = 1; 
    747         $this->doCallback($isSent,'','',$bcc[0],$this->Subject,$body); 
     805        $this->doCallback($isSent, '', '', $bcc[0], $this->Subject, $body); 
    748806      } 
    749807    } 
     
    9431001    $line = explode($this->LE, $message); 
    9441002    $message = ''; 
    945     for ($i=0 ;$i < count($line); $i++) { 
     1003    for ($i = 0 ;$i < count($line); $i++) { 
    9461004      $line_part = explode(' ', $line[$i]); 
    9471005      $buf = ''; 
     
    10571115    switch($this->message_type) { 
    10581116      case 'alt': 
    1059       case 'alt_attachments': 
     1117      case 'alt_inline': 
     1118      case 'alt_attach': 
     1119      case 'alt_inline_attach': 
    10601120        $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap); 
    10611121        break; 
     
    10781138    $this->boundary[1] = 'b1_' . $uniq_id; 
    10791139    $this->boundary[2] = 'b2_' . $uniq_id; 
     1140    $this->boundary[3] = 'b3_' . $uniq_id; 
    10801141 
    10811142    $result .= $this->HeaderLine('Date', self::RFCDate()); 
     
    11261187 
    11271188    if($this->MessageID != '') { 
    1128       $result .= $this->HeaderLine('Message-ID',$this->MessageID); 
     1189      $result .= $this->HeaderLine('Message-ID', $this->MessageID); 
    11291190    } else { 
    11301191      $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE); 
    11311192    } 
    11321193    $result .= $this->HeaderLine('X-Priority', $this->Priority); 
    1133     $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (phpmailer.sourceforge.net)'); 
     1194    if($this->XMailer) { 
     1195      $result .= $this->HeaderLine('X-Mailer', $this->XMailer); 
     1196    } else { 
     1197      $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)'); 
     1198    } 
    11341199 
    11351200    if($this->ConfirmReadingTo != '') { 
     
    11591224      case 'plain': 
    11601225        $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding); 
    1161         $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet); 
     1226        $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"'); 
    11621227        break; 
    1163       case 'attachments': 
    1164       case 'alt_attachments': 
    1165         if($this->InlineImageExists()){ 
    1166           $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE); 
    1167         } else { 
    1168           $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); 
    1169           $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 
    1170         } 
     1228      case 'inline': 
     1229        $result .= $this->HeaderLine('Content-Type', 'multipart/related;'); 
     1230        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 
     1231        break; 
     1232      case 'attach': 
     1233      case 'inline_attach': 
     1234      case 'alt_attach': 
     1235      case 'alt_inline_attach': 
     1236        $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;'); 
     1237        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 
    11711238        break; 
    11721239      case 'alt': 
     1240      case 'alt_inline': 
    11731241        $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 
    11741242        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"'); 
     
    11981266 
    11991267    switch($this->message_type) { 
     1268      case 'plain': 
     1269        $body .= $this->EncodeString($this->Body, $this->Encoding); 
     1270        break; 
     1271      case 'inline': 
     1272        $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 
     1273        $body .= $this->EncodeString($this->Body, $this->Encoding); 
     1274        $body .= $this->LE.$this->LE; 
     1275        $body .= $this->AttachAll("inline", $this->boundary[1]); 
     1276        break; 
     1277      case 'attach': 
     1278        $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 
     1279        $body .= $this->EncodeString($this->Body, $this->Encoding); 
     1280        $body .= $this->LE.$this->LE; 
     1281        $body .= $this->AttachAll("attachment", $this->boundary[1]); 
     1282        break; 
     1283      case 'inline_attach': 
     1284        $body .= $this->TextLine("--" . $this->boundary[1]); 
     1285        $body .= $this->HeaderLine('Content-Type', 'multipart/related;'); 
     1286        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"'); 
     1287        $body .= $this->LE; 
     1288        $body .= $this->GetBoundary($this->boundary[2], '', '', ''); 
     1289        $body .= $this->EncodeString($this->Body, $this->Encoding); 
     1290        $body .= $this->LE.$this->LE; 
     1291        $body .= $this->AttachAll("inline", $this->boundary[2]); 
     1292        $body .= $this->LE; 
     1293        $body .= $this->AttachAll("attachment", $this->boundary[1]); 
     1294        break; 
    12001295      case 'alt': 
    12011296        $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); 
     
    12071302        $body .= $this->EndBoundary($this->boundary[1]); 
    12081303        break; 
    1209       case 'plain': 
    1210         $body .= $this->EncodeString($this->Body, $this->Encoding); 
    1211         break; 
    1212       case 'attachments': 
    1213         $body .= $this->GetBoundary($this->boundary[1], '', '', ''); 
    1214         $body .= $this->EncodeString($this->Body, $this->Encoding); 
    1215         $body .= $this->LE; 
    1216         $body .= $this->AttachAll(); 
    1217         break; 
    1218       case 'alt_attachments': 
    1219         $body .= sprintf("--%s%s", $this->boundary[1], $this->LE); 
    1220         $body .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE); 
    1221         $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body 
     1304      case 'alt_inline': 
     1305        $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', ''); 
    12221306        $body .= $this->EncodeString($this->AltBody, $this->Encoding); 
    12231307        $body .= $this->LE.$this->LE; 
    1224         $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body 
     1308        $body .= $this->TextLine("--" . $this->boundary[1]); 
     1309        $body .= $this->HeaderLine('Content-Type', 'multipart/related;'); 
     1310        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"'); 
     1311        $body .= $this->LE; 
     1312        $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', ''); 
     1313        $body .= $this->EncodeString($this->Body, $this->Encoding); 
     1314        $body .= $this->LE.$this->LE; 
     1315        $body .= $this->AttachAll("inline", $this->boundary[2]); 
     1316        $body .= $this->LE; 
     1317        $body .= $this->EndBoundary($this->boundary[1]); 
     1318        break; 
     1319      case 'alt_attach': 
     1320        $body .= $this->TextLine("--" . $this->boundary[1]); 
     1321        $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 
     1322        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"'); 
     1323        $body .= $this->LE; 
     1324        $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', ''); 
     1325        $body .= $this->EncodeString($this->AltBody, $this->Encoding); 
     1326        $body .= $this->LE.$this->LE; 
     1327        $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', ''); 
    12251328        $body .= $this->EncodeString($this->Body, $this->Encoding); 
    12261329        $body .= $this->LE.$this->LE; 
    12271330        $body .= $this->EndBoundary($this->boundary[2]); 
    1228         $body .= $this->AttachAll(); 
     1331        $body .= $this->LE; 
     1332        $body .= $this->AttachAll("attachment", $this->boundary[1]); 
     1333        break; 
     1334      case 'alt_inline_attach': 
     1335        $body .= $this->TextLine("--" . $this->boundary[1]); 
     1336        $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;'); 
     1337        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"'); 
     1338        $body .= $this->LE; 
     1339        $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', ''); 
     1340        $body .= $this->EncodeString($this->AltBody, $this->Encoding); 
     1341        $body .= $this->LE.$this->LE; 
     1342        $body .= $this->TextLine("--" . $this->boundary[2]); 
     1343        $body .= $this->HeaderLine('Content-Type', 'multipart/related;'); 
     1344        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"'); 
     1345        $body .= $this->LE; 
     1346        $body .= $this->GetBoundary($this->boundary[3], '', 'text/html', ''); 
     1347        $body .= $this->EncodeString($this->Body, $this->Encoding); 
     1348        $body .= $this->LE.$this->LE; 
     1349        $body .= $this->AttachAll("inline", $this->boundary[3]); 
     1350        $body .= $this->LE; 
     1351        $body .= $this->EndBoundary($this->boundary[2]); 
     1352        $body .= $this->LE; 
     1353        $body .= $this->AttachAll("attachment", $this->boundary[1]); 
    12291354        break; 
    12301355    } 
     
    12591384  /** 
    12601385   * Returns the start of a message boundary. 
    1261    * @access private 
    1262    */ 
    1263   private function GetBoundary($boundary, $charSet, $contentType, $encoding) { 
     1386   * @access protected 
     1387   * @return string 
     1388   */ 
     1389  protected function GetBoundary($boundary, $charSet, $contentType, $encoding) { 
    12641390    $result = ''; 
    12651391    if($charSet == '') { 
     
    12731399    } 
    12741400    $result .= $this->TextLine('--' . $boundary); 
    1275     $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet); 
     1401    $result .= sprintf("Content-Type: %s; charset=\"%s\"", $contentType, $charSet); 
    12761402    $result .= $this->LE; 
    12771403    $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding); 
     
    12831409  /** 
    12841410   * Returns the end of a message boundary. 
    1285    * @access private 
    1286    */ 
    1287   private function EndBoundary($boundary) { 
     1411   * @access protected 
     1412   * @return string 
     1413   */ 
     1414  protected function EndBoundary($boundary) { 
    12881415    return $this->LE . '--' . $boundary . '--' . $this->LE; 
    12891416  } 
     
    12911418  /** 
    12921419   * Sets the message type. 
    1293    * @access private 
     1420   * @access protected 
    12941421   * @return void 
    12951422   */ 
    1296   private function SetMessageType() { 
    1297     if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) { 
    1298       $this->message_type = 'plain'; 
    1299     } else { 
    1300       if(count($this->attachment) > 0) { 
    1301         $this->message_type = 'attachments'; 
    1302       } 
    1303       if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) { 
    1304         $this->message_type = 'alt'; 
    1305       } 
    1306       if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) { 
    1307         $this->message_type = 'alt_attachments'; 
    1308       } 
    1309     } 
     1423  protected function SetMessageType() { 
     1424    $this->message_type = array(); 
     1425    if($this->AlternativeExists()) $this->message_type[] = "alt"; 
     1426    if($this->InlineImageExists()) $this->message_type[] = "inline"; 
     1427    if($this->AttachmentExists()) $this->message_type[] = "attach"; 
     1428    $this->message_type = implode("_", $this->message_type); 
     1429    if($this->message_type == "") $this->message_type = "plain"; 
    13101430  } 
    13111431 
     
    13871507   * Attaches all fs, string, and binary attachments to the message. 
    13881508   * Returns an empty string on failure. 
    1389    * @access private 
     1509   * @access protected 
    13901510   * @return string 
    13911511   */ 
    1392   private function AttachAll() { 
     1512  protected function AttachAll($disposition_type, $boundary) { 
    13931513    // Return text of body 
    13941514    $mime = array(); 
     
    13981518    // Add all attachments 
    13991519    foreach ($this->attachment as $attachment) { 
    1400       // Check for string attachment 
    1401       $bString = $attachment[5]; 
    1402       if ($bString) { 
    1403         $string = $attachment[0]; 
    1404       } else { 
    1405         $path = $attachment[0]; 
    1406       } 
    1407  
    1408       if (in_array($attachment[0], $incl)) { continue; } 
    1409       $filename    = $attachment[1]; 
    1410       $name        = $attachment[2]; 
    1411       $encoding    = $attachment[3]; 
    1412       $type        = $attachment[4]; 
    1413       $disposition = $attachment[6]; 
    1414       $cid         = $attachment[7]; 
    1415       $incl[]      = $attachment[0]; 
    1416       if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } 
    1417       $cidUniq[$cid] = true; 
    1418  
    1419       $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE); 
    1420       $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); 
    1421       $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); 
    1422  
    1423       if($disposition == 'inline') { 
    1424         $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); 
    1425       } 
    1426  
    1427       $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); 
    1428  
    1429       // Encode as string attachment 
    1430       if($bString) { 
    1431         $mime[] = $this->EncodeString($string, $encoding); 
    1432         if($this->IsError()) { 
    1433           return ''; 
     1520      // CHECK IF IT IS A VALID DISPOSITION_FILTER 
     1521      if($attachment[6] == $disposition_type) { 
     1522        // Check for string attachment 
     1523        $bString = $attachment[5]; 
     1524        if ($bString) { 
     1525          $string = $attachment[0]; 
     1526        } else { 
     1527          $path = $attachment[0]; 
    14341528        } 
    1435         $mime[] = $this->LE.$this->LE; 
    1436       } else { 
    1437         $mime[] = $this->EncodeFile($path, $encoding); 
    1438         if($this->IsError()) { 
    1439           return ''; 
     1529 
     1530        $inclhash = md5(serialize($attachment)); 
     1531        if (in_array($inclhash, $incl)) { continue; } 
     1532        $incl[]      = $inclhash; 
     1533        $filename    = $attachment[1]; 
     1534        $name        = $attachment[2]; 
     1535        $encoding    = $attachment[3]; 
     1536        $type        = $attachment[4]; 
     1537        $disposition = $attachment[6]; 
     1538        $cid         = $attachment[7]; 
     1539        if ( $disposition == 'inline' && isset($cidUniq[$cid]) ) { continue; } 
     1540        $cidUniq[$cid] = true; 
     1541 
     1542        $mime[] = sprintf("--%s%s", $boundary, $this->LE); 
     1543        $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE); 
     1544        $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE); 
     1545 
     1546        if($disposition == 'inline') { 
     1547          $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE); 
    14401548        } 
    1441         $mime[] = $this->LE.$this->LE; 
    1442       } 
    1443     } 
    1444  
    1445     $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE); 
    1446  
    1447     return join('', $mime); 
     1549 
     1550        $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE); 
     1551 
     1552        // Encode as string attachment 
     1553        if($bString) { 
     1554          $mime[] = $this->EncodeString($string, $encoding); 
     1555          if($this->IsError()) { 
     1556            return ''; 
     1557          } 
     1558          $mime[] = $this->LE.$this->LE; 
     1559        } else { 
     1560          $mime[] = $this->EncodeFile($path, $encoding); 
     1561          if($this->IsError()) { 
     1562            return ''; 
     1563          } 
     1564          $mime[] = $this->LE.$this->LE; 
     1565        } 
     1566      } 
     1567    } 
     1568 
     1569    $mime[] = sprintf("--%s--%s", $boundary, $this->LE); 
     1570 
     1571    return implode("", $mime); 
    14481572  } 
    14491573 
     
    14541578   * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' 
    14551579   * @see EncodeFile() 
    1456    * @access private 
     1580   * @access protected 
    14571581   * @return string 
    14581582   */ 
    1459   private function EncodeFile($path, $encoding = 'base64') { 
     1583  protected function EncodeFile($path, $encoding = 'base64') { 
    14601584    try { 
    14611585      if (!is_readable($path)) { 
     
    14671591        } 
    14681592      } 
    1469       if (PHP_VERSION < 6) { 
     1593      if (version_compare(PHP_VERSION, '5.3.0', '<')) { 
    14701594        $magic_quotes = get_magic_quotes_runtime(); 
    14711595        set_magic_quotes_runtime(0); 
     
    14731597      $file_buffer  = file_get_contents($path); 
    14741598      $file_buffer  = $this->EncodeString($file_buffer, $encoding); 
    1475       if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); } 
     1599      if (version_compare(PHP_VERSION, '5.3.0', '<')) { 
     1600        set_magic_quotes_runtime($magic_quotes); 
     1601      } 
    14761602      return $file_buffer; 
    14771603    } catch (Exception $e) { 
     
    14891615   * @return string 
    14901616   */ 
    1491   public function EncodeString ($str, $encoding = 'base64') { 
     1617  public function EncodeString($str, $encoding = 'base64') { 
    14921618    $encoded = ''; 
    14931619    switch(strtolower($encoding)) { 
     
    16381764  */ 
    16391765  public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) { 
    1640     $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); 
     1766    $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); 
    16411767    $lines = preg_split('/(?:\r\n|\r|\n)/', $input); 
    16421768    $eol = "\r\n"; 
     
    17191845   * @return string 
    17201846   */ 
    1721   public function EncodeQ ($str, $position = 'text') { 
     1847  public function EncodeQ($str, $position = 'text') { 
    17221848    // There should not be any EOL in the string 
    17231849    $encoded = preg_replace('/[\r\n]*/', '', $str); 
     
    17341860        //TODO using /e (equivalent to eval()) is probably not a good idea 
    17351861        $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e', 
    1736               "'='.sprintf('%02X', ord('\\1'))", $encoded); 
     1862                                "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded); 
    17371863        break; 
    17381864    } 
     
    18081934  } 
    18091935 
     1936  public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') { 
     1937    // Append to $attachment array 
     1938    $this->attachment[] = array( 
     1939      0 => $string, 
     1940      1 => $filename, 
     1941      2 => basename($filename), 
     1942      3 => $encoding, 
     1943      4 => $type, 
     1944      5 => true,  // isStringAttachment 
     1945      6 => 'inline', 
     1946      7 => $cid 
     1947    ); 
     1948  } 
     1949 
    18101950  /** 
    18111951   * Returns true if an inline attachment is present. 
     
    18201960    } 
    18211961    return false; 
     1962  } 
     1963 
     1964  public function AttachmentExists() { 
     1965    foreach($this->attachment as $attachment) { 
     1966      if ($attachment[6] == 'attachment') { 
     1967        return true; 
     1968      } 
     1969    } 
     1970    return false; 
     1971  } 
     1972 
     1973  public function AlternativeExists() { 
     1974    return strlen($this->AltBody)>0; 
    18221975  } 
    18231976 
     
    19342087  /** 
    19352088   * Returns the server hostname or 'localhost.localdomain' if unknown. 
    1936    * @access private 
     2089   * @access protected 
    19372090   * @return string 
    19382091   */ 
    1939   private function ServerHostname() { 
     2092  protected function ServerHostname() { 
    19402093    if (!empty($this->Hostname)) { 
    19412094      $result = $this->Hostname; 
     
    19512104  /** 
    19522105   * Returns a message in the appropriate language. 
    1953    * @access private 
     2106   * @access protected 
    19542107   * @return string 
    19552108   */ 
    1956   private function Lang($key) { 
     2109  protected function Lang($key) { 
    19572110    if(count($this->language) < 1) { 
    19582111      $this->SetLanguage('en'); // set the default language 
     
    19772130  /** 
    19782131   * Changes every end of line from CR or LF to CRLF. 
    1979    * @access private 
     2132   * @access public 
    19802133   * @return string 
    19812134   */ 
    1982   private function FixEOL($str) { 
     2135  public function FixEOL($str) { 
    19832136    $str = str_replace("\r\n", "\n", $str); 
    19842137    $str = str_replace("\r", "\n", $str); 
     
    20062159      foreach($images[2] as $i => $url) { 
    20072160        // do not change urls for absolute images (thanks to corvuscorax) 
    2008         if (!preg_match('#^[A-z]+://#',$url)) { 
     2161        if (!preg_match('#^[A-z]+://#', $url)) { 
    20092162          $filename = basename($url); 
    20102163          $directory = dirname($url); 
    2011           ($directory == '.')?$directory='':''; 
     2164          ($directory == '.') ? $directory='': ''; 
    20122165          $cid = 'cid:' . md5($filename); 
    20132166          $ext = pathinfo($filename, PATHINFO_EXTENSION); 
    20142167          $mimeType  = self::_mime_types($ext); 
    2015           if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; } 
    2016           if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; } 
    2017           if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) { 
     2168          if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; } 
     2169          if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; } 
     2170          if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) { 
    20182171            $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message); 
    20192172          } 
     
    20232176    $this->IsHTML(true); 
    20242177    $this->Body = $message; 
    2025     $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message))); 
     2178    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message))); 
    20262179    if (!empty($textMsg) && empty($this->AltBody)) { 
    20272180      $this->AltBody = html_entity_decode($textMsg); 
     
    21932346   */ 
    21942347  public function DKIM_QP($txt) { 
    2195     $tmp=""; 
    2196     $line=""; 
    2197     for ($i=0;$i<strlen($txt);$i++) { 
    2198       $ord=ord($txt[$i]); 
     2348    $tmp = ''; 
     2349    $line = ''; 
     2350    for ($i = 0; $i < strlen($txt); $i++) { 
     2351      $ord = ord($txt[$i]); 
    21992352      if ( ((0x21 <= $ord) && ($ord <= 0x3A)) || $ord == 0x3C || ((0x3E <= $ord) && ($ord <= 0x7E)) ) { 
    2200         $line.=$txt[$i]; 
     2353        $line .= $txt[$i]; 
    22012354      } else { 
    2202         $line.="=".sprintf("%02X",$ord); 
     2355        $line .= "=".sprintf("%02X", $ord); 
    22032356      } 
    22042357    } 
     
    22142367  public function DKIM_Sign($s) { 
    22152368    $privKeyStr = file_get_contents($this->DKIM_private); 
    2216     if ($this->DKIM_passphrase!='') { 
    2217       $privKey = openssl_pkey_get_private($privKeyStr,$this->DKIM_passphrase); 
     2369    if ($this->DKIM_passphrase != '') { 
     2370      $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase); 
    22182371    } else { 
    22192372      $privKey = $privKeyStr; 
     
    22312384   */ 
    22322385  public function DKIM_HeaderC($s) { 
    2233     $s=preg_replace("/\r\n\s+/"," ",$s); 
    2234     $lines=explode("\r\n",$s); 
    2235     foreach ($lines as $key=>$line) { 
    2236       list($heading,$value)=explode(":",$line,2); 
    2237       $heading=strtolower($heading); 
    2238       $value=preg_replace("/\s+/"," ",$value) ; // Compress useless spaces 
    2239       $lines[$key]=$heading.":".trim($value) ; // Don't forget to remove WSP around the value 
    2240     } 
    2241     $s=implode("\r\n",$lines); 
     2386    $s = preg_replace("/\r\n\s+/", " ", $s); 
     2387    $lines = explode("\r\n", $s); 
     2388    foreach ($lines as $key => $line) { 
     2389      list($heading, $value) = explode(":", $line, 2); 
     2390      $heading = strtolower($heading); 
     2391      $value = preg_replace("/\s+/", " ", $value) ; // Compress useless spaces 
     2392      $lines[$key] = $heading.":".trim($value) ; // Don't forget to remove WSP around the value 
     2393    } 
     2394    $s = implode("\r\n", $lines); 
    22422395    return $s; 
    22432396  } 
     
    22522405    if ($body == '') return "\r\n"; 
    22532406    // stabilize line endings 
    2254     $body=str_replace("\r\n","\n",$body); 
    2255     $body=str_replace("\n","\r\n",$body); 
     2407    $body = str_replace("\r\n", "\n", $body); 
     2408    $body = str_replace("\n", "\r\n", $body); 
    22562409    // END stabilize line endings 
    2257     while (substr($body,strlen($body)-4,4) == "\r\n\r\n") { 
    2258       $body=substr($body,0,strlen($body)-2); 
     2410    while (substr($body, strlen($body) - 4, 4) == "\r\n\r\n") { 
     2411      $body = substr($body, 0, strlen($body) - 2); 
    22592412    } 
    22602413    return $body; 
     
    22692422   * @param string $body Body 
    22702423   */ 
    2271   public function DKIM_Add($headers_line,$subject,$body) { 
     2424  public function DKIM_Add($headers_line, $subject, $body) { 
    22722425    $DKIMsignatureType    = 'rsa-sha1'; // Signature & hash algorithms 
    22732426    $DKIMcanonicalization = 'relaxed/simple'; // Canonicalization of header/body 
     
    22752428    $DKIMtime             = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone) 
    22762429    $subject_header       = "Subject: $subject"; 
    2277     $headers              = explode("\r\n",$headers_line); 
     2430    $headers              = explode($this->LE, $headers_line); 
    22782431    foreach($headers as $header) { 
    2279       if (strpos($header,'From:') === 0) { 
    2280         $from_header=$header; 
    2281       } elseif (strpos($header,'To:') === 0) { 
    2282         $to_header=$header; 
    2283       } 
    2284     } 
    2285     $from     = str_replace('|','=7C',$this->DKIM_QP($from_header)); 
    2286     $to       = str_replace('|','=7C',$this->DKIM_QP($to_header)); 
    2287     $subject  = str_replace('|','=7C',$this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable 
     2432      if (strpos($header, 'From:') === 0) { 
     2433        $from_header = $header; 
     2434      } elseif (strpos($header, 'To:') === 0) { 
     2435        $to_header = $header; 
     2436      } 
     2437    } 
     2438    $from     = str_replace('|', '=7C', $this->DKIM_QP($from_header)); 
     2439    $to       = str_replace('|', '=7C', $this->DKIM_QP($to_header)); 
     2440    $subject  = str_replace('|', '=7C', $this->DKIM_QP($subject_header)) ; // Copied header fields (dkim-quoted-printable 
    22882441    $body     = $this->DKIM_BodyC($body); 
    22892442    $DKIMlen  = strlen($body) ; // Length of body 
     
    23042457  } 
    23052458 
    2306   protected function doCallback($isSent,$to,$cc,$bcc,$subject,$body) { 
     2459  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) { 
    23072460    if (!empty($this->action_function) && function_exists($this->action_function)) { 
    2308       $params = array($isSent,$to,$cc,$bcc,$subject,$body); 
    2309       call_user_func_array($this->action_function,$params); 
     2461      $params = array($isSent, $to, $cc, $bcc, $subject, $body); 
     2462      call_user_func_array($this->action_function, $params); 
    23102463    } 
    23112464  } 
  • trunk/wp-includes/class-smtp.php

    r17676 r19632  
    33.---------------------------------------------------------------------------. 
    44|  Software: PHPMailer - PHP email class                                    | 
    5 |   Version: 5.1                                                            | 
    6 |   Contact: via sourceforge.net support pages (also www.codeworxtech.com)  | 
    7 |      Info: http://phpmailer.sourceforge.net                               | 
    8 |   Support: http://sourceforge.net/projects/phpmailer/                     | 
     5|   Version: 5.2                                                            | 
     6|      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       | 
    97| ------------------------------------------------------------------------- | 
    10 |     Admin: Andy Prevost (project admininistrator)                         | 
     8|     Admin: Jim Jagielski (project admininistrator)                        | 
    119|   Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net | 
    1210|          : Marcus Bointon (coolbru) coolbru@users.sourceforge.net         | 
     11|          : Jim Jagielski (jimjag) jimjag@gmail.com                        | 
    1312|   Founder: Brent R. Matzelle (original founder)                           | 
     13| Copyright (c) 2010-2011, Jim Jagielski. All Rights Reserved.               | 
    1414| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved.               | 
    1515| Copyright (c) 2001-2003, Brent R. Matzelle                                | 
     
    2020| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or     | 
    2121| FITNESS FOR A PARTICULAR PURPOSE.                                         | 
    22 | ------------------------------------------------------------------------- | 
    23 | We offer a number of paid services (www.codeworxtech.com):                | 
    24 | - Web Hosting on highly optimized fast and secure servers                 | 
    25 | - Technology Consulting                                                   | 
    26 | - Oursourcing (highly qualified programmers and graphic designers)        | 
    2722'---------------------------------------------------------------------------' 
    2823*/ 
     
    3530 * @author Marcus Bointon 
    3631 * @copyright 2004 - 2008 Andy Prevost 
     32 * @author Jim Jagielski 
     33 * @copyright 2010 - 2011 Jim Jagielski 
    3734 * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL) 
    38  * @version $Id: class.smtp.php 444 2009-05-05 11:22:26Z coolbru $ 
     35 * @version $Id: class.smtp.php 450 2010-06-23 16:46:33Z coolbru $ 
    3936 */ 
    4037 
     
    7168   */ 
    7269  public $do_verp = false; 
     70 
     71  /** 
     72   * Sets the SMTP PHPMailer Version number 
     73   * @var string 
     74   */ 
     75  public $Version         = '5.2'; 
    7376 
    7477  ///////////////////////////////////////////////// 
Note: See TracChangeset for help on using the changeset viewer.