Make WordPress Core

Changeset 23522


Ignore:
Timestamp:
02/28/2013 06:33:13 PM (11 years ago)
Author:
nacin
Message:

Update to PHPMailer 5.2.4. props bpetty. fixes #21074.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r21128 r23522  
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 5.2.1                                                          |
     5|   Version: 5.2.4                                                          |
    66|      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
    77| ------------------------------------------------------------------------- |
     
    2424
    2525/**
    26  * PHPMailer - PHP email transport class
     26 * PHPMailer - PHP email creation and transport class
    2727 * NOTE: Requires PHP version 5 or later
    2828 * @package PHPMailer
     
    3232 * @copyright 2010 - 2012 Jim Jagielski
    3333 * @copyright 2004 - 2009 Andy Prevost
    34  * @version $Id: class.phpmailer.php 450 2010-06-23 16:46:33Z coolbru $
    3534 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
    3635 */
     
    3837if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
    3938
     39/**
     40 * PHP email creation and transport class
     41 * @package PHPMailer
     42 */
    4043class PHPMailer {
    4144
     
    9396   */
    9497  public $Sender            = '';
     98
     99  /**
     100   * Sets the Return-Path of the message.  If empty, it will
     101   * be set to either From or Sender.
     102   * @var string
     103   */
     104  public $ReturnPath        = '';
    95105
    96106  /**
     
    131141
    132142  /**
    133    * Stores the complete sent MIME message (Body and Headers)
     143   * Stores the extra header list which CreateHeader() doesn't fold in
    134144   * @var string
    135145   * @access protected
    136146  */
    137   protected $SentMIMEMessage     = '';
     147  protected $mailHeader     = '';
    138148
    139149  /**
     
    157167
    158168  /**
     169   * Determine if mail() uses a fully sendmail compatible MTA that
     170   * supports sendmail's "-oi -f" options
     171   * @var boolean
     172   */
     173  public $UseSendmailOptions    = true;
     174 
     175  /**
    159176   * Path to PHPMailer plugins.  Useful if the SMTP class
    160177   * is in a different directory than the PHP include path.
     
    184201  public $MessageID         = '';
    185202
     203  /**
     204   * Sets the message Date to be used in the Date header.
     205   * If empty, the current date will be added.
     206   * @var string
     207   */
     208  public $MessageDate       = '';
     209
    186210  /////////////////////////////////////////////////
    187211  // PROPERTIES FOR SMTP
     
    189213
    190214  /**
    191    * Sets the SMTP hosts.  All hosts must be separated by a
     215   * Sets the SMTP hosts.
     216   *
     217   * All hosts must be separated by a
    192218   * semicolon.  You can also specify a different port
    193219   * for each host by using this format: [hostname:port]
     
    211237
    212238  /**
    213    * Sets connection prefix.
    214    * Options are "", "ssl" or "tls"
     239   * Sets connection prefix. Options are "", "ssl" or "tls"
    215240   * @var string
    216241   */
     
    234259   */
    235260  public $Password      = '';
     261
     262  /**
     263   *  Sets SMTP auth type. Options are LOGIN | PLAIN | NTLM  (default LOGIN)
     264   *  @var string
     265   */
     266  public $AuthType      = '';
     267 
     268  /**
     269   *  Sets SMTP realm.
     270   *  @var string
     271   */
     272  public $Realm         = '';
     273
     274  /**
     275   *  Sets SMTP workstation.
     276   *  @var string
     277   */
     278  public $Workstation   = '';
    236279
    237280  /**
     
    247290   */
    248291  public $SMTPDebug     = false;
     292
     293  /**
     294   * Sets the function/method to use for debugging output.
     295   * Right now we only honor "echo" or "error_log"
     296   * @var string
     297   */
     298  public $Debugoutput     = "echo";
    249299
    250300  /**
     
    270320
    271321 /**
    272    * Provides the ability to change the line ending
     322   * Provides the ability to change the generic line ending
     323   * NOTE: The default remains '\n'. We force CRLF where we KNOW
     324   *        it must be used via self::CRLF
    273325   * @var string
    274326   */
    275327  public $LE              = "\n";
    276328
    277   /**
    278    * Used with DKIM DNS Resource Record
    279    * @var string
    280    */
    281   public $DKIM_selector   = 'phpmailer';
    282 
    283   /**
    284    * Used with DKIM DNS Resource Record
    285    * optional, in format of email address 'you@yourdomain.com'
     329   /**
     330   * Used with DKIM Signing
     331   * required parameter if DKIM is enabled
     332   *
     333   * domain selector example domainkey
     334   * @var string
     335   */
     336  public $DKIM_selector   = '';
     337
     338  /**
     339   * Used with DKIM Signing
     340   * required if DKIM is enabled, in format of email address 'you@yourdomain.com' typically used as the source of the email
    286341   * @var string
    287342   */
     
    289344
    290345  /**
    291    * Used with DKIM DNS Resource Record
     346   * Used with DKIM Signing
     347   * optional parameter if your private key requires a passphras
    292348   * @var string
    293349   */
     
    295351
    296352  /**
    297    * Used with DKIM DNS Resource Record
    298    * optional, in format of email address 'you@yourdomain.com'
     353   * Used with DKIM Singing
     354   * required if DKIM is enabled, in format of email address 'domain.com'
    299355   * @var string
    300356   */
     
    302358
    303359  /**
    304    * Used with DKIM DNS Resource Record
    305    * optional, in format of email address 'you@yourdomain.com'
     360   * Used with DKIM Signing
     361   * required if DKIM is enabled, path to private key file
    306362   * @var string
    307363   */
     
    309365
    310366  /**
    311    * Callback Action function name
    312    * the function that handles the result of the send email action. Parameters:
     367   * Callback Action function name.
     368   * The function that handles the result of the send email action.
     369   * It is called out by Send() for each email sent.
     370   *
     371   * Value can be:
     372   * - 'function_name' for function names
     373   * - 'Class::Method' for static method calls
     374   * - array($object, 'Method') for calling methods on $object
     375   * See http://php.net/is_callable manual page for more details.
     376   *
     377   * Parameters:
    313378   *   bool    $result        result of the send action
    314379   *   string  $to            email address of the recipient
     
    317382   *   string  $subject       the subject
    318383   *   string  $body          the email body
     384   *   string  $from          email address of sender
    319385   * @var string
    320386   */
     
    325391   * @var string
    326392   */
    327   public $Version         = '5.2.1';
     393  public $Version         = '5.2.4';
    328394
    329395  /**
    330396   * What to use in the X-Mailer header
    331    * @var string
     397   * @var string NULL for default, whitespace for None, or actual string to use
    332398   */
    333399  public $XMailer         = '';
     
    337403  /////////////////////////////////////////////////
    338404
    339   protected   $smtp           = NULL;
     405  /**
     406   * @var SMTP An instance of the SMTP sender class
     407   * @access protected
     408   */
     409  protected   $smtp           = null;
     410  /**
     411   * @var array An array of 'to' addresses
     412   * @access protected
     413   */
    340414  protected   $to             = array();
     415  /**
     416   * @var array An array of 'cc' addresses
     417   * @access protected
     418   */
    341419  protected   $cc             = array();
     420  /**
     421   * @var array An array of 'bcc' addresses
     422   * @access protected
     423   */
    342424  protected   $bcc            = array();
     425  /**
     426   * @var array An array of reply-to name and address
     427   * @access protected
     428   */
    343429  protected   $ReplyTo        = array();
     430  /**
     431   * @var array An array of all kinds of addresses: to, cc, bcc, replyto
     432   * @access protected
     433   */
    344434  protected   $all_recipients = array();
     435  /**
     436   * @var array An array of attachments
     437   * @access protected
     438   */
    345439  protected   $attachment     = array();
     440  /**
     441   * @var array An array of custom headers
     442   * @access protected
     443   */
    346444  protected   $CustomHeader   = array();
     445  /**
     446   * @var string The message's MIME type
     447   * @access protected
     448   */
    347449  protected   $message_type   = '';
     450  /**
     451   * @var array An array of MIME boundary strings
     452   * @access protected
     453   */
    348454  protected   $boundary       = array();
     455  /**
     456   * @var array An array of available languages
     457   * @access protected
     458   */
    349459  protected   $language       = array();
     460  /**
     461   * @var integer The number of errors encountered
     462   * @access protected
     463   */
    350464  protected   $error_count    = 0;
     465  /**
     466   * @var string The filename of a DKIM certificate file
     467   * @access protected
     468   */
    351469  protected   $sign_cert_file = '';
     470  /**
     471   * @var string The filename of a DKIM key file
     472   * @access protected
     473   */
    352474  protected   $sign_key_file  = '';
     475  /**
     476   * @var string The password of a DKIM key
     477   * @access protected
     478   */
    353479  protected   $sign_key_pass  = '';
     480  /**
     481   * @var boolean Whether to throw exceptions for errors
     482   * @access protected
     483   */
    354484  protected   $exceptions     = false;
    355485
     
    361491  const STOP_CONTINUE = 1; // message?, likely ok to continue processing
    362492  const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
    363 
     493  const CRLF = "\r\n";     // SMTP RFC specified EOL
     494 
    364495  /////////////////////////////////////////////////
    365496  // METHODS, VARIABLES
    366497  /////////////////////////////////////////////////
     498
     499  /**
     500   * Calls actual mail() function, but in a safe_mode aware fashion
     501   * Also, unless sendmail_path points to sendmail (or something that
     502   * claims to be sendmail), don't pass params (not a perfect fix,
     503   * but it will do)
     504   * @param string $to To
     505   * @param string $subject Subject
     506   * @param string $body Message Body
     507   * @param string $header Additional Header(s)
     508   * @param string $params Params
     509   * @access private
     510   * @return bool
     511   */
     512  private function mail_passthru($to, $subject, $body, $header, $params) {
     513    if ( ini_get('safe_mode') || !($this->UseSendmailOptions) ) {
     514        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header);
     515    } else {
     516        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params);
     517    }
     518    return $rt;
     519  }
     520
     521  /**
     522   * Outputs debugging info via user-defined method
     523   * @param string $str
     524   */
     525  private function edebug($str) {
     526    if ($this->Debugoutput == "error_log") {
     527        error_log($str);
     528    } else {
     529        echo $str;
     530    }
     531  }
    367532
    368533  /**
     
    477642   * @param string $address The email address to send to
    478643   * @param string $name
     644   * @throws phpmailerException
    479645   * @return boolean true on success, false if address already used or invalid in some way
    480646   * @access protected
     
    486652        throw new phpmailerException('Invalid recipient array: ' . $kind);
    487653      }
    488       if ($this->SMTPDebug) {
    489         echo $this->Lang('Invalid recipient array').': '.$kind;
     654      if ($this->SMTPDebug) {
     655        $this->edebug($this->Lang('Invalid recipient array').': '.$kind);
    490656      }
    491657      return false;
     
    493659    $address = trim($address);
    494660    $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
    495     if (!self::ValidateAddress($address)) {
     661    if (!$this->ValidateAddress($address)) {
    496662      $this->SetError($this->Lang('invalid_address').': '. $address);
    497663      if ($this->exceptions) {
    498664        throw new phpmailerException($this->Lang('invalid_address').': '.$address);
    499665      }
    500       if ($this->SMTPDebug) {
    501         echo $this->Lang('invalid_address').': '.$address;
     666      if ($this->SMTPDebug) {
     667        $this->edebug($this->Lang('invalid_address').': '.$address);
    502668      }
    503669      return false;
     
    522688 * @param string $address
    523689 * @param string $name
     690 * @param int $auto Also set Reply-To and Sender
     691   * @throws phpmailerException
    524692 * @return boolean
    525693 */
     
    527695    $address = trim($address);
    528696    $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
    529     if (!self::ValidateAddress($address)) {
     697    if (!$this->ValidateAddress($address)) {
    530698      $this->SetError($this->Lang('invalid_address').': '. $address);
    531699      if ($this->exceptions) {
    532700        throw new phpmailerException($this->Lang('invalid_address').': '.$address);
    533701      }
    534       if ($this->SMTPDebug) {
    535         echo $this->Lang('invalid_address').': '.$address;
     702      if ($this->SMTPDebug) {
     703        $this->edebug($this->Lang('invalid_address').': '.$address);
    536704      }
    537705      return false;
     
    552720  /**
    553721   * Check that a string looks roughly like an email address should
    554    * Static so it can be used without instantiation
    555    * Tries to use PHP built-in validator in the filter extension (from PHP 5.2), falls back to a reasonably competent regex validator
    556    * Conforms approximately to RFC2822
    557    * @link http://www.hexillion.com/samples/#Regex Original pattern found here
     722   * Static so it can be used without instantiation, public so people can overload
     723   * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is
     724   * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to
     725   * not allow a@b type valid addresses :(
     726   * Some Versions of PHP break on the regex though, likely due to PCRE, so use
     727   * the older validation method for those users. (http://php.net/manual/en/pcre.installation.php)
     728   * @link http://squiloople.com/2009/12/20/email-address-validation/
     729   * @copyright regex Copyright Michael Rushton 2009-10 | http://squiloople.com/ | Feel free to use and redistribute this code. But please keep this copyright notice.
    558730   * @param string $address The email address to check
    559731   * @return boolean
     
    562734   */
    563735  public static function ValidateAddress($address) {
    564     if (function_exists('filter_var')) { //Introduced in PHP 5.2
    565       if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
    566         return false;
    567       } else {
    568         return true;
    569       }
     736    if ((defined('PCRE_VERSION')) && (version_compare(PCRE_VERSION, '8.0') >= 0)) {
     737      return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[     ])+|(?>[    ]*\x0D\x0A)?[   ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
     738    } elseif (function_exists('filter_var')) { //Introduced in PHP 5.2
     739        if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
     740          return false;
     741        } else {
     742          return true;
     743        }
    570744    } else {
    571       return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
    572     }
     745        return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
     746    }
    573747  }
    574748
     
    581755   * not sent successfully then it returns false.  Use the ErrorInfo
    582756   * variable to view description of the error.
     757   * @throws phpmailerException
    583758   * @return bool
    584759   */
     
    588763      return $this->PostSend();
    589764    } catch (phpmailerException $e) {
    590       $this->SentMIMEMessage = '';
     765      $this->mailHeader = '';
    591766      $this->SetError($e->getMessage());
    592767      if ($this->exceptions) {
     
    597772  }
    598773
    599   protected function PreSend() {
     774  /**
     775   * Prep mail by constructing all message entities
     776   * @throws phpmailerException
     777   * @return bool
     778   */
     779  public function PreSend() {
    600780    try {
    601       $mailHeader = "";
     781      $this->mailHeader = "";
    602782      if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
    603783        throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
     
    620800
    621801      // To capture the complete message when using mail(), create
    622       // an extra header list which CreateHeader() doesn't fold in
     802      // an extra header list which CreateHeader() doesn't fold in
    623803      if ($this->Mailer == 'mail') {
    624804        if (count($this->to) > 0) {
    625           $mailHeader .= $this->AddrAppend("To", $this->to);
     805          $this->mailHeader .= $this->AddrAppend("To", $this->to);
    626806        } else {
    627           $mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
     807          $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
    628808        }
    629         $mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
     809        $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
    630810        // if(count($this->cc) > 0) {
    631             // $mailHeader .= $this->AddrAppend("Cc", $this->cc);
     811            // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc);
    632812        // }
    633813      }
    634814
    635815      // digitally sign with DKIM if enabled
    636       if ($this->DKIM_domain && $this->DKIM_private) {
     816      if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) {
    637817        $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
    638818        $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
    639819      }
    640820
    641       $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);
    642821      return true;
    643822
     
    651830  }
    652831
    653   protected function PostSend() {
     832  /**
     833   * Actual Email transport function
     834   * Send the email via the selected mechanism
     835   * @throws phpmailerException
     836   * @return bool
     837   */
     838  public function PostSend() {
    654839    try {
    655840      // Choose the mailer and send through it
     
    664849          return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
    665850      }
    666 
    667851    } catch (phpmailerException $e) {
    668852      $this->SetError($e->getMessage());
     
    670854        throw $e;
    671855      }
    672       if ($this->SMTPDebug) {
    673         echo $e->getMessage()."\n";
    674       }
    675       return false;
    676     }
     856      if ($this->SMTPDebug) {
     857        $this->edebug($e->getMessage()."\n");
     858      }
     859    }
     860    return false;
    677861  }
    678862
     
    681865   * @param string $header The message headers
    682866   * @param string $body The message body
     867   * @throws phpmailerException
    683868   * @access protected
    684869   * @return bool
     
    686871  protected function SendmailSend($header, $body) {
    687872    if ($this->Sender != '') {
    688       $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
     873      $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
    689874    } else {
    690875      $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
    691876    }
    692877    if ($this->SingleTo === true) {
    693       foreach ($this->SingleToArray as $key => $val) {
     878      foreach ($this->SingleToArray as $val) {
    694879        if(!@$mail = popen($sendmail, 'w')) {
    695880          throw new phpmailerException($this->Lang('execute') . $this->Sendmail, self::STOP_CRITICAL);
     
    727912   * @param string $header The message headers
    728913   * @param string $body The message body
     914     * @throws phpmailerException
    729915   * @access protected
    730916   * @return bool
     
    740926      $params = "-oi ";
    741927    } else {
    742       $params = sprintf("-oi -f %s", $this->Sender);
     928      $params = sprintf("-oi -f%s", $this->Sender);
    743929    }
    744930    if ($this->Sender != '' and !ini_get('safe_mode')) {
    745931      $old_from = ini_get('sendmail_from');
    746932      ini_set('sendmail_from', $this->Sender);
    747       if ($this->SingleTo === true && count($toArr) > 1) {
    748         foreach ($toArr as $key => $val) {
    749           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
    750           // implement call back function if it exists
    751           $isSent = ($rt == 1) ? 1 : 0;
    752           $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
    753         }
    754       } else {
    755         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
     933    }
     934      $rt = false;
     935    if ($this->SingleTo === true && count($toArr) > 1) {
     936      foreach ($toArr as $val) {
     937        $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params);
    756938        // implement call back function if it exists
    757939        $isSent = ($rt == 1) ? 1 : 0;
    758         $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
     940        $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
    759941      }
    760942    } else {
    761       if ($this->SingleTo === true && count($toArr) > 1) {
    762         foreach ($toArr as $key => $val) {
    763           $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
    764           // implement call back function if it exists
    765           $isSent = ($rt == 1) ? 1 : 0;
    766           $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
    767         }
    768       } else {
    769         $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
    770         // implement call back function if it exists
    771         $isSent = ($rt == 1) ? 1 : 0;
    772         $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
    773       }
     943      $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params);
     944      // implement call back function if it exists
     945      $isSent = ($rt == 1) ? 1 : 0;
     946      $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
    774947    }
    775948    if (isset($old_from)) {
     
    787960   * @param string $header The message headers
    788961   * @param string $body The message body
     962   * @throws phpmailerException
    789963   * @uses SMTP
    790964   * @access protected
     
    800974    $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
    801975    if(!$this->smtp->Mail($smtp_from)) {
    802       throw new phpmailerException($this->Lang('from_failed') . $smtp_from, self::STOP_CRITICAL);
     976      $this->SetError($this->Lang('from_failed') . $smtp_from . " : " . implode(",",$this->smtp->getError())) ;
     977      throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
    803978    }
    804979
     
    8511026    if($this->SMTPKeepAlive == true) {
    8521027      $this->smtp->Reset();
     1028    } else {
     1029        $this->smtp->Quit();
     1030        $this->smtp->Close();
    8531031    }
    8541032    return true;
     
    8601038   * @uses SMTP
    8611039   * @access public
     1040   * @throws phpmailerException
    8621041   * @return bool
    8631042   */
    8641043  public function SmtpConnect() {
    8651044    if(is_null($this->smtp)) {
    866       $this->smtp = new SMTP();
    867     }
    868 
     1045      $this->smtp = new SMTP;
     1046    }
     1047
     1048    $this->smtp->Timeout = $this->Timeout;
    8691049    $this->smtp->do_debug = $this->SMTPDebug;
    8701050    $hosts = explode(';', $this->Host);
     
    8941074          if ($tls) {
    8951075            if (!$this->smtp->StartTLS()) {
    896               throw new phpmailerException($this->Lang('tls'));
     1076              throw new phpmailerException($this->Lang('connect_host'));
    8971077            }
    8981078
     
    9031083          $connection = true;
    9041084          if ($this->SMTPAuth) {
    905             if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
     1085            if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType,
     1086                                           $this->Realm, $this->Workstation)) {
    9061087              throw new phpmailerException($this->Lang('authenticate'));
    9071088            }
     
    9091090        }
    9101091        $index++;
    911         if (!$connection) {
    912           throw new phpmailerException($this->Lang('connect_host'));
    913         }
     1092      if (!$connection) {
     1093        throw new phpmailerException($this->Lang('connect_host'));
     1094      }
    9141095      }
    9151096    } catch (phpmailerException $e) {
    9161097      $this->smtp->Reset();
    917       if ($this->exceptions) {
     1098      if ($this->exceptions) {
    9181099        throw $e;
    9191100      }
     
    9271108   */
    9281109  public function SmtpClose() {
    929     if(!is_null($this->smtp)) {
     1110    if ($this->smtp !== null) {
    9301111      if($this->smtp->Connected()) {
    9311112        $this->smtp->Quit();
     
    9401121  * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
    9411122  * @param string $lang_path Path to the language file directory
     1123   * @return bool
    9421124  * @access public
    9431125  */
     
    9451127    //Define full set of translatable strings
    9461128    $PHPMAILER_LANG = array(
    947       'provide_address' => 'You must provide at least one recipient email address.',
     1129      'authenticate'         => 'SMTP Error: Could not authenticate.',
     1130      'connect_host'         => 'SMTP Error: Could not connect to SMTP host.',
     1131      'data_not_accepted'    => 'SMTP Error: Data not accepted.',
     1132      'empty_message'        => 'Message body empty',
     1133      'encoding'             => 'Unknown encoding: ',
     1134      'execute'              => 'Could not execute: ',
     1135      'file_access'          => 'Could not access file: ',
     1136      'file_open'            => 'File Error: Could not open file: ',
     1137      'from_failed'          => 'The following From address failed: ',
     1138      'instantiate'          => 'Could not instantiate mail function.',
     1139      'invalid_address'      => 'Invalid address',
    9481140      'mailer_not_supported' => ' mailer is not supported.',
    949       'execute' => 'Could not execute: ',
    950       'instantiate' => 'Could not instantiate mail function.',
    951       'authenticate' => 'SMTP Error: Could not authenticate.',
    952       'from_failed' => 'The following From address failed: ',
    953       'recipients_failed' => 'SMTP Error: The following recipients failed: ',
    954       'data_not_accepted' => 'SMTP Error: Data not accepted.',
    955       'connect_host' => 'SMTP Error: Could not connect to SMTP host.',
    956       'file_access' => 'Could not access file: ',
    957       'file_open' => 'File Error: Could not open file: ',
    958       'encoding' => 'Unknown encoding: ',
    959       'signing' => 'Signing Error: ',
    960       'smtp_error' => 'SMTP server error: ',
    961       'empty_message' => 'Message body empty',
    962       'invalid_address' => 'Invalid address',
    963       'variable_set' => 'Cannot set or reset variable: '
     1141      'provide_address'      => 'You must provide at least one recipient email address.',
     1142      'recipients_failed'    => 'SMTP Error: The following recipients failed: ',
     1143      'signing'              => 'Signing Error: ',
     1144      'smtp_connect_failed'  => 'SMTP Connect() failed.',
     1145      'smtp_error'           => 'SMTP server error: ',
     1146      'variable_set'         => 'Cannot set or reset variable: '
    9641147    );
    9651148    //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
     
    9871170   * Creates recipient headers.
    9881171   * @access public
     1172   * @param string $type
     1173   * @param array $addr
    9891174   * @return string
    9901175   */
     
    10041189   * Formats an address correctly.
    10051190   * @access public
     1191   * @param string $addr
    10061192   * @return string
    10071193   */
     
    10291215    // split multibyte characters when we wrap
    10301216    $is_utf8 = (strtolower($this->CharSet) == "utf-8");
     1217    $lelen = strlen($this->LE);
     1218    $crlflen = strlen(self::CRLF);
    10311219
    10321220    $message = $this->FixEOL($message);
    1033     if (substr($message, -1) == $this->LE) {
    1034       $message = substr($message, 0, -1);
    1035     }
    1036 
    1037     $line = explode($this->LE, $message);
     1221    if (substr($message, -$lelen) == $this->LE) {
     1222      $message = substr($message, 0, -$lelen);
     1223    }
     1224
     1225    $line = explode($this->LE, $message);   // Magic. We know FixEOL uses $LE
    10381226    $message = '';
    10391227    for ($i = 0 ;$i < count($line); $i++) {
     
    10431231        $word = $line_part[$e];
    10441232        if ($qp_mode and (strlen($word) > $length)) {
    1045           $space_left = $length - strlen($buf) - 1;
     1233          $space_left = $length - strlen($buf) - $crlflen;
    10461234          if ($e != 0) {
    10471235            if ($space_left > 20) {
     
    10571245              $word = substr($word, $len);
    10581246              $buf .= ' ' . $part;
    1059               $message .= $buf . sprintf("=%s", $this->LE);
     1247              $message .= $buf . sprintf("=%s", self::CRLF);
    10601248            } else {
    10611249              $message .= $buf . $soft_break;
     
    10761264
    10771265            if (strlen($word) > 0) {
    1078               $message .= $part . sprintf("=%s", $this->LE);
     1266              $message .= $part . sprintf("=%s", self::CRLF);
    10791267            } else {
    10801268              $buf = $part;
     
    10911279        }
    10921280      }
    1093       $message .= $buf . $this->LE;
     1281      $message .= $buf . self::CRLF;
    10941282    }
    10951283
     
    11761364    $this->boundary[3] = 'b3_' . $uniq_id;
    11771365
    1178     $result .= $this->HeaderLine('Date', self::RFCDate());
    1179     if($this->Sender == '') {
     1366    if ($this->MessageDate == '') {
     1367      $result .= $this->HeaderLine('Date', self::RFCDate());
     1368    } else {
     1369      $result .= $this->HeaderLine('Date', $this->MessageDate);
     1370    }
     1371
     1372    if ($this->ReturnPath) {
     1373      $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath));
     1374    } elseif ($this->Sender == '') {
    11801375      $result .= $this->HeaderLine('Return-Path', trim($this->From));
    11811376    } else {
     
    11961391        }
    11971392      }
    1198     }
     1393    }
    11991394
    12001395    $from = array();
     
    12281423    }
    12291424    $result .= $this->HeaderLine('X-Priority', $this->Priority);
    1230     if($this->XMailer) {
    1231       $result .= $this->HeaderLine('X-Mailer', $this->XMailer);
     1425    if ($this->XMailer == '') {
     1426        $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
    12321427    } else {
    1233       $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
     1428      $myXmailer = trim($this->XMailer);
     1429      if ($myXmailer) {
     1430        $result .= $this->HeaderLine('X-Mailer', $myXmailer);
     1431      }
    12341432    }
    12351433
     
    12581456    $result = '';
    12591457    switch($this->message_type) {
    1260       case 'plain':
    1261         $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
    1262         $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset="'.$this->CharSet.'"');
    1263         break;
    12641458      case 'inline':
    12651459        $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
     
    12781472        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
    12791473        break;
     1474      default:
     1475        // Catches case 'plain': and case '':
     1476        $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
     1477        $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet);
     1478        break;
    12801479    }
    12811480
    12821481    if($this->Mailer != 'mail') {
    1283       $result .= $this->LE.$this->LE;
     1482      $result .= $this->LE;
    12841483    }
    12851484
     
    12931492   */
    12941493  public function GetSentMIMEMessage() {
    1295     return $this->SentMIMEMessage;
     1494    return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
    12961495  }
    12971496
     
    13001499   * Assembles the message body.  Returns an empty string on failure.
    13011500   * @access public
     1501   * @throws phpmailerException
    13021502   * @return string The assembled message body
    13031503   */
     
    13061506
    13071507    if ($this->sign_key_file) {
    1308       $body .= $this->GetMailMIME();
     1508      $body .= $this->GetMailMIME().$this->LE;
    13091509    }
    13101510
     
    13121512
    13131513    switch($this->message_type) {
    1314       case 'plain':
    1315         $body .= $this->EncodeString($this->Body, $this->Encoding);
    1316         break;
    13171514      case 'inline':
    13181515        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
     
    13991596        $body .= $this->AttachAll("attachment", $this->boundary[1]);
    14001597        break;
     1598      default:
     1599        // catch case 'plain' and case ''
     1600        $body .= $this->EncodeString($this->Body, $this->Encoding);
     1601        break;
    14011602    }
    14021603
     
    14311632   * Returns the start of a message boundary.
    14321633   * @access protected
     1634   * @param string $boundary
     1635   * @param string $charSet
     1636   * @param string $contentType
     1637   * @param string $encoding
    14331638   * @return string
    14341639   */
     
    14451650    }
    14461651    $result .= $this->TextLine('--' . $boundary);
    1447     $result .= sprintf("Content-Type: %s; charset=\"%s\"", $contentType, $charSet);
     1652    $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet);
    14481653    $result .= $this->LE;
    14491654    $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
     
    14561661   * Returns the end of a message boundary.
    14571662   * @access protected
     1663   * @param string $boundary
    14581664   * @return string
    14591665   */
     
    14791685   *  Returns a formatted header line.
    14801686   * @access public
     1687   * @param string $name
     1688   * @param string $value
    14811689   * @return string
    14821690   */
     
    14881696   * Returns a formatted mail line.
    14891697   * @access public
     1698   * @param string $value
    14901699   * @return string
    14911700   */
     
    15061715   * @param string $encoding File encoding (see $Encoding).
    15071716   * @param string $type File extension (MIME) type.
     1717   * @throws phpmailerException
    15081718   * @return bool
    15091719   */
     
    15341744        throw $e;
    15351745      }
    1536       if ($this->SMTPDebug) {
    1537         echo $e->getMessage()."\n";
     1746      if ($this->SMTPDebug) {
     1747        $this->edebug($e->getMessage()."\n");
    15381748      }
    15391749      if ( $e->getCode() == self::STOP_CRITICAL ) {
     
    15561766   * Returns an empty string on failure.
    15571767   * @access protected
     1768   * @param string $disposition_type
     1769   * @param string $boundary
    15581770   * @return string
    15591771   */
     
    15691781      if($attachment[6] == $disposition_type) {
    15701782        // Check for string attachment
     1783        $string = '';
     1784        $path = '';
    15711785        $bString = $attachment[5];
    15721786        if ($bString) {
     
    16251839   * @param string $path The full path to the file
    16261840   * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable'
     1841   * @throws phpmailerException
    16271842   * @see EncodeFile()
    16281843   * @access protected
     
    16341849        throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
    16351850      }
    1636       if (function_exists('get_magic_quotes')) {
    1637         function get_magic_quotes() {
    1638           return false;
    1639         }
    1640       }
    1641       $magic_quotes = get_magic_quotes_runtime();
    1642       if ($magic_quotes) {
     1851      //  if (!function_exists('get_magic_quotes')) {
     1852      //    function get_magic_quotes() {
     1853      //      return false;
     1854      //    }
     1855      //  }
     1856      $magic_quotes = get_magic_quotes_runtime();
     1857      if ($magic_quotes) {
    16431858        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    16441859          set_magic_quotes_runtime(0);
    16451860        } else {
    1646           ini_set('magic_quotes_runtime', 0);
    1647         }
    1648       }
     1861          ini_set('magic_quotes_runtime', 0);
     1862        }
     1863      }
    16491864      $file_buffer  = file_get_contents($path);
    16501865      $file_buffer  = $this->EncodeString($file_buffer, $encoding);
    1651       if ($magic_quotes) {
     1866      if ($magic_quotes) {
    16521867        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    16531868          set_magic_quotes_runtime($magic_quotes);
    16541869        } else {
    1655           ini_set('magic_quotes_runtime', $magic_quotes);
    1656         }
    1657       }
     1870          ini_set('magic_quotes_runtime', $magic_quotes);
     1871        }
     1872      }
    16581873      return $file_buffer;
    16591874    } catch (Exception $e) {
     
    17001915   * Encode a header string to best (shortest) of Q, B, quoted or none.
    17011916   * @access public
     1917   * @param string $str
     1918   * @param string $position
    17021919   * @return string
    17031920   */
     
    17381955        // Use a custom function which correctly encodes and wraps long
    17391956        // multibyte strings without breaking lines within a character
    1740         $encoded = $this->Base64EncodeWrapMB($str);
     1957        $encoded = $this->Base64EncodeWrapMB($str, "\n");
    17411958      } else {
    17421959        $encoded = base64_encode($str);
     
    17481965      $encoded = $this->EncodeQ($str, $position);
    17491966      $encoded = $this->WrapText($encoded, $maxlen, true);
    1750       $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
     1967      $encoded = str_replace('='.self::CRLF, "\n", trim($encoded));
    17511968    }
    17521969
     
    17771994   * @access public
    17781995   * @param string $str multi-byte text to wrap encode
     1996   * @param string $lf string to use as linefeed/end-of-line
    17791997   * @return string
    17801998   */
    1781   public function Base64EncodeWrapMB($str) {
     1999  public function Base64EncodeWrapMB($str, $lf=null) {
    17822000    $start = "=?".$this->CharSet."?B?";
    17832001    $end = "?=";
    17842002    $encoded = "";
     2003    if ($lf === null) {
     2004      $lf = $this->LE;
     2005    }
    17852006
    17862007    $mb_length = mb_strlen($str, $this->CharSet);
     
    18032024      while (strlen($chunk) > $length);
    18042025
    1805       $encoded .= $chunk . $this->LE;
     2026      $encoded .= $chunk . $lf;
    18062027    }
    18072028
    18082029    // Chomp the last linefeed
    1809     $encoded = substr($encoded, 0, -strlen($this->LE));
     2030    $encoded = substr($encoded, 0, -strlen($lf));
    18102031    return $encoded;
    18112032  }
     
    18152036  * Only uses standard PHP, slow, but will always work
    18162037  * @access public
    1817   * @param string $string the text to encode
     2038   * @param string $input
    18182039  * @param integer $line_max Number of chars allowed on a line before wrapping
     2040   * @param bool $space_conv
     2041   * @internal param string $string the text to encode
    18192042  * @return string
    18202043  */
     
    18412064          }
    18422065        } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
    1843           $h2 = floor($dec/16);
    1844           $h1 = floor($dec%16);
     2066          $h2 = (integer)floor($dec/16);
     2067          $h1 = (integer)floor($dec%16);
    18452068          $c = $escape.$hex[$h2].$hex[$h1];
    18462069        }
     
    19022125   */
    19032126  public function EncodeQ($str, $position = 'text') {
    1904     // There should not be any EOL in the string
    1905     $encoded = preg_replace('/[\r\n]*/', '', $str);
    1906 
     2127    //There should not be any EOL in the string
     2128    $pattern="";
     2129    $encoded = str_replace(array("\r", "\n"), '', $str);
    19072130    switch (strtolower($position)) {
    19082131      case 'phrase':
    1909         $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
     2132        $pattern = '^A-Za-z0-9!*+\/ -';
    19102133        break;
     2134
    19112135      case 'comment':
    1912         $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
     2136        $pattern = '\(\)"';
     2137        //note that we dont break here!
     2138        //for this reason we build the $pattern withoud including delimiters and []
     2139
    19132140      case 'text':
    19142141      default:
    1915         // Replace every high ascii, control =, ? and _ characters
    1916         //TODO using /e (equivalent to eval()) is probably not a good idea
    1917         $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
    1918                                 "'='.sprintf('%02X', ord(stripslashes('\\1')))", $encoded);
     2142        //Replace every high ascii, control =, ? and _ characters
     2143        //We put \075 (=) as first value to make sure it's the first one in being converted, preventing double encode
     2144        $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern;
    19192145        break;
    19202146    }
    1921 
    1922     // Replace every spaces to _ (more readable than =20)
    1923     $encoded = str_replace(' ', '_', $encoded);
    1924 
    1925     return $encoded;
    1926   }
     2147   
     2148    if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
     2149      foreach (array_unique($matches[0]) as $char) {
     2150        $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
     2151      }
     2152    }
     2153   
     2154    //Replace every spaces to _ (more readable than =20)
     2155    return str_replace(' ', '_', $encoded);
     2156}
     2157
    19272158
    19282159  /**
     
    19902221  }
    19912222
    1992   public function AddStringEmbeddedImage($string, $cid, $filename = '', $encoding = 'base64', $type = 'application/octet-stream') {
     2223  /**
     2224   * Adds an embedded stringified attachment.  This can include images, sounds, and
     2225   * just about any other document.  Make sure to set the $type to an
     2226   * image type.  For JPEG images use "image/jpeg" and for GIF images
     2227   * use "image/gif".
     2228   * @param string $string The attachment.
     2229   * @param string $cid Content ID of the attachment.  Use this to identify
     2230   *        the Id for accessing the image in an HTML form.
     2231   * @param string $name Overrides the attachment name.
     2232   * @param string $encoding File encoding (see $Encoding).
     2233   * @param string $type File extension (MIME) type.
     2234   * @return bool
     2235   */
     2236  public function AddStringEmbeddedImage($string, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
    19932237    // Append to $attachment array
    19942238    $this->attachment[] = array(
    19952239      0 => $string,
    1996       1 => $filename,
    1997       2 => basename($filename),
     2240      1 => $name,
     2241      2 => $name,
    19982242      3 => $encoding,
    19992243      4 => $type,
     
    20182262  }
    20192263
     2264  /**
     2265   * Returns true if an attachment (non-inline) is present.
     2266   * @return bool
     2267   */
    20202268  public function AttachmentExists() {
    20212269    foreach($this->attachment as $attachment) {
     
    20272275  }
    20282276
     2277  /**
     2278   * Does this message have an alternative body set?
     2279   * @return bool
     2280   */
    20292281  public function AlternativeExists() {
    2030     return strlen($this->AltBody)>0;
     2282    return !empty($this->AltBody);
    20312283  }
    20322284
     
    21122364   * Adds the error message to the error container.
    21132365   * @access protected
     2366   * @param string $msg
    21142367   * @return void
    21152368   */
     
    21612414   * Returns a message in the appropriate language.
    21622415   * @access protected
     2416   * @param string $key
    21632417   * @return string
    21642418   */
     
    21852439
    21862440  /**
    2187    * Changes every end of line from CR or LF to CRLF.
    2188    * @access public
     2441   * Changes every end of line from CRLF, CR or LF to $this->LE.
     2442   * @access public
     2443   * @param string $str String to FixEOL
    21892444   * @return string
    21902445   */
    21912446  public function FixEOL($str) {
    2192     $str = str_replace("\r\n", "\n", $str);
    2193     $str = str_replace("\r", "\n", $str);
    2194     $str = str_replace("\n", $this->LE, $str);
    2195     return $str;
    2196   }
    2197 
    2198   /**
    2199    * Adds a custom header.
    2200    * @access public
     2447    // condense down to \n
     2448    $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
     2449    // Now convert LE as needed
     2450    if ($this->LE !== "\n") {
     2451        $nstr = str_replace("\n", $this->LE, $nstr);
     2452    }
     2453    return  $nstr;
     2454  }
     2455
     2456  /**
     2457   * Adds a custom header. $name value can be overloaded to contain
     2458   * both header name and value (name:value)
     2459   * @access public
     2460   * @param string $name custom header name
     2461   * @param string $value header value
    22012462   * @return void
    22022463   */
    2203   public function AddCustomHeader($custom_header) {
    2204     $this->CustomHeader[] = explode(':', $custom_header, 2);
     2464  public function AddCustomHeader($name, $value=null) {
     2465    if ($value === null) {
     2466        // Value passed in as name:value
     2467        $this->CustomHeader[] = explode(':', $name, 2);
     2468    } else {
     2469        $this->CustomHeader[] = array($name, $value);
     2470    }
    22052471  }
    22062472
     
    22082474   * Evaluates the message and returns modifications for inline images and backgrounds
    22092475   * @access public
    2210    * @return $message
     2476   * @param string $message Text to be HTML modified
     2477   * @param string $basedir baseline directory for path
     2478   * @return string $message
    22112479   */
    22122480  public function MsgHTML($message, $basedir = '') {
     
    22182486          $filename = basename($url);
    22192487          $directory = dirname($url);
    2220           ($directory == '.') ? $directory='': '';
    2221           $cid = 'cid:' . md5($filename);
     2488          if ($directory == '.') {
     2489            $directory = '';
     2490          }
     2491          $cid = 'cid:' . md5($url);
    22222492          $ext = pathinfo($filename, PATHINFO_EXTENSION);
    22232493          $mimeType  = self::_mime_types($ext);
    22242494          if ( strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }
    22252495          if ( strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
    2226           if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType) ) {
     2496          if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($url), $filename, 'base64', $mimeType) ) {
    22272497            $message = preg_replace("/".$images[1][$i]."=[\"']".preg_quote($url, '/')."[\"']/Ui", $images[1][$i]."=\"".$cid."\"", $message);
    22282498          }
     
    22322502    $this->IsHTML(true);
    22332503    $this->Body = $message;
    2234     if (empty($this->AltBody)) {
    2235         $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
    2236         if (!empty($textMsg)) {
    2237             $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
    2238         }
    2239     }
     2504    if (empty($this->AltBody)) {
     2505        $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
     2506        if (!empty($textMsg)) {
     2507            $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
     2508        }
     2509    }
    22402510    if (empty($this->AltBody)) {
    22412511      $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
    22422512    }
    2243     return $message;
     2513    return $message;
    22442514  }
    22452515
    22462516  /**
    22472517   * Gets the MIME type of the embedded or inline image
    2248    * @param string File extension
     2518   * @param string $ext File extension
    22492519   * @access public
    22502520   * @return string MIME type of ext
     
    22532523  public static function _mime_types($ext = '') {
    22542524    $mimes = array(
     2525      'xl'    =>  'application/excel',
    22552526      'hqx'   =>  'application/mac-binhex40',
    22562527      'cpt'   =>  'application/mac-compactpro',
     2528      'bin'   =>  'application/macbinary',
    22572529      'doc'   =>  'application/msword',
    2258       'bin'   =>  'application/macbinary',
     2530      'word'  =>  'application/msword',
     2531      'class' =>  'application/octet-stream',
     2532      'dll'   =>  'application/octet-stream',
    22592533      'dms'   =>  'application/octet-stream',
     2534      'exe'   =>  'application/octet-stream',
    22602535      'lha'   =>  'application/octet-stream',
    22612536      'lzh'   =>  'application/octet-stream',
    2262       'exe'   =>  'application/octet-stream',
    2263       'class' =>  'application/octet-stream',
    22642537      'psd'   =>  'application/octet-stream',
     2538      'sea'   =>  'application/octet-stream',
    22652539      'so'    =>  'application/octet-stream',
    2266       'sea'   =>  'application/octet-stream',
    2267       'dll'   =>  'application/octet-stream',
    22682540      'oda'   =>  'application/oda',
    22692541      'pdf'   =>  'application/pdf',
     
    22832555      'dvi'   =>  'application/x-dvi',
    22842556      'gtar'  =>  'application/x-gtar',
     2557      'php3'  =>  'application/x-httpd-php',
     2558      'php4'  =>  'application/x-httpd-php',
    22852559      'php'   =>  'application/x-httpd-php',
    2286       'php4'  =>  'application/x-httpd-php',
    2287       'php3'  =>  'application/x-httpd-php',
    22882560      'phtml' =>  'application/x-httpd-php',
    22892561      'phps'  =>  'application/x-httpd-php-source',
     
    22932565      'tar'   =>  'application/x-tar',
    22942566      'tgz'   =>  'application/x-tar',
     2567      'xht'   =>  'application/xhtml+xml',
    22952568      'xhtml' =>  'application/xhtml+xml',
    2296       'xht'   =>  'application/xhtml+xml',
    22972569      'zip'   =>  'application/zip',
    22982570      'mid'   =>  'audio/midi',
    22992571      'midi'  =>  'audio/midi',
    2300       'mpga'  =>  'audio/mpeg',
    23012572      'mp2'   =>  'audio/mpeg',
    23022573      'mp3'   =>  'audio/mpeg',
     2574      'mpga'  =>  'audio/mpeg',
    23032575      'aif'   =>  'audio/x-aiff',
     2576      'aifc'  =>  'audio/x-aiff',
    23042577      'aiff'  =>  'audio/x-aiff',
    2305       'aifc'  =>  'audio/x-aiff',
    23062578      'ram'   =>  'audio/x-pn-realaudio',
    23072579      'rm'    =>  'audio/x-pn-realaudio',
    23082580      'rpm'   =>  'audio/x-pn-realaudio-plugin',
    23092581      'ra'    =>  'audio/x-realaudio',
    2310       'rv'    =>  'video/vnd.rn-realvideo',
    23112582      'wav'   =>  'audio/x-wav',
    23122583      'bmp'   =>  'image/bmp',
    23132584      'gif'   =>  'image/gif',
    23142585      'jpeg'  =>  'image/jpeg',
     2586      'jpe'   =>  'image/jpeg',
    23152587      'jpg'   =>  'image/jpeg',
    2316       'jpe'   =>  'image/jpeg',
    23172588      'png'   =>  'image/png',
    23182589      'tiff'  =>  'image/tiff',
    23192590      'tif'   =>  'image/tiff',
     2591      'eml'   =>  'message/rfc822',
    23202592      'css'   =>  'text/css',
    23212593      'html'  =>  'text/html',
    23222594      'htm'   =>  'text/html',
    23232595      'shtml' =>  'text/html',
     2596      'log'   =>  'text/plain',
     2597      'text'  =>  'text/plain',
    23242598      'txt'   =>  'text/plain',
    2325       'text'  =>  'text/plain',
    2326       'log'   =>  'text/plain',
    23272599      'rtx'   =>  'text/richtext',
    23282600      'rtf'   =>  'text/rtf',
     
    23302602      'xsl'   =>  'text/xml',
    23312603      'mpeg'  =>  'video/mpeg',
     2604      'mpe'   =>  'video/mpeg',
    23322605      'mpg'   =>  'video/mpeg',
    2333       'mpe'   =>  'video/mpeg',
     2606      'mov'   =>  'video/quicktime',
    23342607      'qt'    =>  'video/quicktime',
    2335       'mov'   =>  'video/quicktime',
     2608      'rv'    =>  'video/vnd.rn-realvideo',
    23362609      'avi'   =>  'video/x-msvideo',
    2337       'movie' =>  'video/x-sgi-movie',
    2338       'doc'   =>  'application/msword',
    2339       'word'  =>  'application/msword',
    2340       'xl'    =>  'application/excel',
    2341       'eml'   =>  'message/rfc822'
     2610      'movie' =>  'video/x-sgi-movie'
    23422611    );
    23432612    return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
     
    23542623  * @param mixed $value Parameter Value
    23552624  * NOTE: will not work with arrays, there are no arrays to set/reset
     2625   * @throws phpmailerException
     2626   * @return bool
    23562627  * @todo Should this not be using __set() magic function?
    23572628  */
     
    23792650   */
    23802651  public function SecureHeader($str) {
    2381     $str = str_replace("\r", '', $str);
    2382     $str = str_replace("\n", '', $str);
    2383     return trim($str);
     2652    return trim(str_replace(array("\r", "\n"), '', $str));
    23842653  }
    23852654
     
    23882657   *
    23892658   * @access public
     2659   * @param $cert_filename
    23902660   * @param string $key_filename Parameter File Name
    23912661   * @param string $key_pass Password for private key
     
    24012671   *
    24022672   * @access public
    2403    * @param string $key_filename Parameter File Name
    2404    * @param string $key_pass Password for private key
     2673   * @param string $txt
     2674   * @return string
    24052675   */
    24062676  public function DKIM_QP($txt) {
    2407     $tmp = '';
    24082677    $line = '';
    24092678    for ($i = 0; $i < strlen($txt); $i++) {
     
    24232692   * @access public
    24242693   * @param string $s Header
     2694   * @return string
    24252695   */
    24262696  public function DKIM_Sign($s) {
     
    24342704      return base64_encode($signature);
    24352705    }
     2706    return '';
    24362707  }
    24372708
     
    24412712   * @access public
    24422713   * @param string $s Header
     2714   * @return string
    24432715   */
    24442716  public function DKIM_HeaderC($s) {
     
    24602732   * @access public
    24612733   * @param string $body Message Body
     2734   * @return string
    24622735   */
    24632736  public function DKIM_BodyC($body) {
     
    24802753   * @param string $subject Subject
    24812754   * @param string $body Body
     2755   * @return string
    24822756   */
    24832757  public function DKIM_Add($headers_line, $subject, $body) {
     
    24882762    $subject_header       = "Subject: $subject";
    24892763    $headers              = explode($this->LE, $headers_line);
     2764    $from_header          = "";
     2765    $to_header            = "";
    24902766    foreach($headers as $header) {
    24912767      if (strpos($header, 'From:') === 0) {
     
    25132789    $toSign   = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
    25142790    $signed   = $this->DKIM_Sign($toSign);
    2515     return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
    2516   }
    2517 
    2518   protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) {
    2519     if (!empty($this->action_function) && function_exists($this->action_function)) {
    2520       $params = array($isSent, $to, $cc, $bcc, $subject, $body);
     2791    return "X-PHPMAILER-DKIM: code.google.com/a/apache-extras.org/p/phpmailer/\r\n".$dkimhdrs.$signed."\r\n";
     2792  }
     2793
     2794  /**
     2795   * Perform callback
     2796   * @param boolean $isSent
     2797   * @param string $to
     2798   * @param string $cc
     2799   * @param string $bcc
     2800   * @param string $subject
     2801   * @param string $body
     2802   * @param string $from
     2803   */
     2804  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) {
     2805    if (!empty($this->action_function) && is_callable($this->action_function)) {
     2806      $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
    25212807      call_user_func_array($this->action_function, $params);
    25222808    }
     
    25242810}
    25252811
     2812/**
     2813 * Exception handler for PHPMailer
     2814 * @package PHPMailer
     2815 */
    25262816class phpmailerException extends Exception {
     2817  /**
     2818   * Prettify error message output
     2819   * @return string
     2820   */
    25272821  public function errorMessage() {
    25282822    $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  • trunk/wp-includes/class-smtp.php

    r19849 r23522  
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 5.2.1                                                          |
     5|   Version: 5.2.4                                                          |
    66|      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
    77| ------------------------------------------------------------------------- |
     
    3333 * @copyright 2010 - 2012 Jim Jagielski
    3434 * @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
    35  * @version $Id: class.smtp.php 450 2010-06-23 16:46:33Z coolbru $
    3635 */
    3736
    3837/**
    39  * SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
    40  * commands except TURN which will always return a not implemented
    41  * error. SMTP also provides some utility methods for sending mail
    42  * to an SMTP server.
    43  * original author: Chris Ryan
     38 * PHP RFC821 SMTP client
     39 *
     40 * Implements all the RFC 821 SMTP commands except TURN which will always return a not implemented error.
     41 * SMTP also provides some utility methods for sending mail to an SMTP server.
     42 * @author Chris Ryan
     43 * @package PHPMailer
    4444 */
    4545
     
    5252
    5353  /**
    54    *  SMTP reply line ending
     54   *  SMTP reply line ending (don't change)
    5555   *  @var string
    5656   */
     
    6464
    6565  /**
     66   * Sets the function/method to use for debugging output.
     67   * Right now we only honor "echo" or "error_log"
     68   * @var string
     69   */
     70  public $Debugoutput     = "echo";
     71
     72  /**
    6673   *  Sets VERP use on/off (default is off)
    6774   *  @var bool
     
    7077
    7178  /**
     79   * Sets the SMTP timeout value for reads, in seconds
     80   * @var int
     81   */
     82  public $Timeout         = 15;
     83
     84  /**
     85   * Sets the SMTP timelimit value for reads, in seconds
     86   * @var int
     87   */
     88  public $Timelimit       = 30;
     89
     90  /**
    7291   * Sets the SMTP PHPMailer Version number
    7392   * @var string
    7493   */
    75   public $Version         = '5.2.1';
     94  public $Version         = '5.2.4';
    7695
    7796  /////////////////////////////////////////////////
     
    7998  /////////////////////////////////////////////////
    8099
    81   private $smtp_conn; // the socket to the server
    82   private $error;     // error if any on the last call
    83   private $helo_rply; // the reply the server sent to us for HELO
     100  /**
     101   * @var resource The socket to the server
     102   */
     103  private $smtp_conn;
     104  /**
     105   * @var string Error message, if any, for the last call
     106   */
     107  private $error;
     108  /**
     109   * @var string The reply the server sent to us for HELO
     110   */
     111  private $helo_rply;
     112
     113  /**
     114   * Outputs debugging info via user-defined method
     115   * @param string $str
     116   */
     117  private function edebug($str) {
     118    if ($this->Debugoutput == "error_log") {
     119        error_log($str);
     120    } else {
     121        echo $str;
     122    }
     123  }
    84124
    85125  /**
    86126   * Initialize the class so that the data is in a known state.
    87127   * @access public
    88    * @return void
     128   * @return SMTP
    89129   */
    90130  public function __construct() {
     
    111151   * SMTP CODE FAILURE: 421
    112152   * @access public
     153   * @param string $host
     154   * @param int $port
     155   * @param int $tval
    113156   * @return bool
    114157   */
     
    140183                           "errstr" => $errstr);
    141184      if($this->do_debug >= 1) {
    142         echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
     185        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />');
    143186      }
    144187      return false;
     
    147190    // SMTP server can take longer to respond, give longer timeout for first read
    148191    // Windows does not have support for this timeout function
    149     if(substr(PHP_OS, 0, 3) != "WIN")
    150      socket_set_timeout($this->smtp_conn, $tval, 0);
     192    if(substr(PHP_OS, 0, 3) != "WIN") {
     193     $max = ini_get('max_execution_time');
     194     if ($max != 0 && $tval > $max) { // don't bother if unlimited
     195      @set_time_limit($tval);
     196     }
     197     stream_set_timeout($this->smtp_conn, $tval, 0);
     198    }
    151199
    152200    // get any announcement
     
    154202
    155203    if($this->do_debug >= 2) {
    156       echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
     204      $this->edebug("SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />');
    157205    }
    158206
     
    183231
    184232    if($this->do_debug >= 2) {
    185       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     233      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    186234    }
    187235
     
    192240               "smtp_msg"  => substr($rply,4));
    193241      if($this->do_debug >= 1) {
    194         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     242        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    195243      }
    196244      return false;
     
    209257   * Hello() method.  Returns true if successfully authenticated.
    210258   * @access public
    211    * @return bool
    212    */
    213   public function Authenticate($username, $password) {
    214     // Start authentication
    215     fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
    216 
    217     $rply = $this->get_lines();
    218     $code = substr($rply,0,3);
    219 
    220     if($code != 334) {
    221       $this->error =
    222         array("error" => "AUTH not accepted from server",
    223               "smtp_code" => $code,
    224               "smtp_msg" => substr($rply,4));
    225       if($this->do_debug >= 1) {
    226         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    227       }
    228       return false;
    229     }
    230 
    231     // Send encoded username
    232     fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
    233 
    234     $rply = $this->get_lines();
    235     $code = substr($rply,0,3);
    236 
    237     if($code != 334) {
    238       $this->error =
    239         array("error" => "Username not accepted from server",
    240               "smtp_code" => $code,
    241               "smtp_msg" => substr($rply,4));
    242       if($this->do_debug >= 1) {
    243         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    244       }
    245       return false;
    246     }
    247 
    248     // Send encoded password
    249     fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
    250 
    251     $rply = $this->get_lines();
    252     $code = substr($rply,0,3);
    253 
    254     if($code != 235) {
    255       $this->error =
    256         array("error" => "Password not accepted from server",
    257               "smtp_code" => $code,
    258               "smtp_msg" => substr($rply,4));
    259       if($this->do_debug >= 1) {
    260         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
    261       }
    262       return false;
    263     }
    264 
     259   * @param string $username
     260   * @param string $password
     261   * @param string $authtype
     262   * @param string $realm
     263   * @param string $workstation
     264   * @return bool
     265   */
     266  public function Authenticate($username, $password, $authtype='LOGIN', $realm='', $workstation='') {
     267    if (empty($authtype)) {
     268      $authtype = 'LOGIN';
     269    }
     270
     271    switch ($authtype) {
     272      case 'PLAIN':
     273        // Start authentication
     274        fputs($this->smtp_conn,"AUTH PLAIN" . $this->CRLF);
     275   
     276        $rply = $this->get_lines();
     277        $code = substr($rply,0,3);
     278   
     279        if($code != 334) {
     280          $this->error =
     281            array("error" => "AUTH not accepted from server",
     282                  "smtp_code" => $code,
     283                  "smtp_msg" => substr($rply,4));
     284          if($this->do_debug >= 1) {
     285            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     286          }
     287          return false;
     288        }
     289        // Send encoded username and password
     290        fputs($this->smtp_conn, base64_encode("\0".$username."\0".$password) . $this->CRLF);
     291
     292        $rply = $this->get_lines();
     293        $code = substr($rply,0,3);
     294   
     295        if($code != 235) {
     296          $this->error =
     297            array("error" => "Authentication not accepted from server",
     298                  "smtp_code" => $code,
     299                  "smtp_msg" => substr($rply,4));
     300          if($this->do_debug >= 1) {
     301            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     302          }
     303          return false;
     304        }
     305        break;
     306      case 'LOGIN':
     307        // Start authentication
     308        fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
     309   
     310        $rply = $this->get_lines();
     311        $code = substr($rply,0,3);
     312   
     313        if($code != 334) {
     314          $this->error =
     315            array("error" => "AUTH not accepted from server",
     316                  "smtp_code" => $code,
     317                  "smtp_msg" => substr($rply,4));
     318          if($this->do_debug >= 1) {
     319            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     320          }
     321          return false;
     322        }
     323   
     324        // Send encoded username
     325        fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
     326   
     327        $rply = $this->get_lines();
     328        $code = substr($rply,0,3);
     329   
     330        if($code != 334) {
     331          $this->error =
     332            array("error" => "Username not accepted from server",
     333                  "smtp_code" => $code,
     334                  "smtp_msg" => substr($rply,4));
     335          if($this->do_debug >= 1) {
     336            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     337          }
     338          return false;
     339        }
     340   
     341        // Send encoded password
     342        fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
     343   
     344        $rply = $this->get_lines();
     345        $code = substr($rply,0,3);
     346   
     347        if($code != 235) {
     348          $this->error =
     349            array("error" => "Password not accepted from server",
     350                  "smtp_code" => $code,
     351                  "smtp_msg" => substr($rply,4));
     352          if($this->do_debug >= 1) {
     353            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     354          }
     355          return false;
     356        }
     357        break;
     358      case 'NTLM':
     359        /*
     360         * ntlm_sasl_client.php
     361         ** Bundled with Permission
     362         **
     363         ** How to telnet in windows: http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
     364         ** PROTOCOL Documentation http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
     365         */
     366        require_once('ntlm_sasl_client.php');
     367        $temp = new stdClass();
     368        $ntlm_client = new ntlm_sasl_client_class;
     369        if(! $ntlm_client->Initialize($temp)){//let's test if every function its available
     370            $this->error = array("error" => $temp->error);
     371            if($this->do_debug >= 1) {
     372                $this->edebug("You need to enable some modules in your php.ini file: " . $this->error["error"] . $this->CRLF);
     373            }
     374            return false;
     375        }
     376        $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);//msg1
     377       
     378        fputs($this->smtp_conn,"AUTH NTLM " . base64_encode($msg1) . $this->CRLF);
     379
     380        $rply = $this->get_lines();
     381        $code = substr($rply,0,3);
     382       
     383
     384        if($code != 334) {
     385            $this->error =
     386                array("error" => "AUTH not accepted from server",
     387                      "smtp_code" => $code,
     388                      "smtp_msg" => substr($rply,4));
     389            if($this->do_debug >= 1) {
     390                $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
     391            }
     392            return false;
     393        }
     394       
     395        $challange = substr($rply,3);//though 0 based, there is a white space after the 3 digit number....//msg2
     396        $challange = base64_decode($challange);
     397        $ntlm_res = $ntlm_client->NTLMResponse(substr($challange,24,8),$password);
     398        $msg3 = $ntlm_client->TypeMsg3($ntlm_res,$username,$realm,$workstation);//msg3
     399        // Send encoded username
     400        fputs($this->smtp_conn, base64_encode($msg3) . $this->CRLF);
     401
     402        $rply = $this->get_lines();
     403        $code = substr($rply,0,3);
     404
     405        if($code != 235) {
     406            $this->error =
     407                array("error" => "Could not authenticate",
     408                      "smtp_code" => $code,
     409                      "smtp_msg" => substr($rply,4));
     410            if($this->do_debug >= 1) {
     411                $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
     412            }
     413            return false;
     414        }
     415        break;
     416    }
    265417    return true;
    266418  }
     
    277429        // the socket is valid but we are not connected
    278430        if($this->do_debug >= 1) {
    279             echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
     431            $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected");
    280432        }
    281433        $this->Close();
     
    325477   * SMTP CODE ERROR  : 500,501,503,421
    326478   * @access public
     479   * @param string $msg_data
    327480   * @return bool
    328481   */
     
    342495
    343496    if($this->do_debug >= 2) {
    344       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     497      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    345498    }
    346499
     
    351504              "smtp_msg" => substr($rply,4));
    352505      if($this->do_debug >= 1) {
    353         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     506        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    354507      }
    355508      return false;
     
    436589
    437590    if($this->do_debug >= 2) {
    438       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     591      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    439592    }
    440593
     
    445598              "smtp_msg" => substr($rply,4));
    446599      if($this->do_debug >= 1) {
    447         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     600        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    448601      }
    449602      return false;
     
    462615   * SMTP CODE ERROR  : 500, 501, 504, 421
    463616   * @access public
     617   * @param string $host
    464618   * @return bool
    465619   */
     
    492646   * Sends a HELO/EHLO command.
    493647   * @access private
     648   * @param string $hello
     649   * @param string $host
    494650   * @return bool
    495651   */
     
    501657
    502658    if($this->do_debug >= 2) {
    503       echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
     659      $this->edebug("SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />');
    504660    }
    505661
     
    510666              "smtp_msg" => substr($rply,4));
    511667      if($this->do_debug >= 1) {
    512         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     668        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    513669      }
    514670      return false;
     
    532688   * SMTP CODE SUCCESS: 500,501,421
    533689   * @access public
     690   * @param string $from
    534691   * @return bool
    535692   */
     
    543700    }
    544701
    545     $useVerp = ($this->do_verp ? "XVERP" : "");
     702    $useVerp = ($this->do_verp ? " XVERP" : "");
    546703    fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
    547704
     
    550707
    551708    if($this->do_debug >= 2) {
    552       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     709      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    553710    }
    554711
     
    559716              "smtp_msg" => substr($rply,4));
    560717      if($this->do_debug >= 1) {
    561         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     718        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    562719      }
    563720      return false;
     
    575732   * SMTP CODE ERROR  : 500
    576733   * @access public
     734   * @param bool $close_on_error
    577735   * @return bool
    578736   */
     
    593751
    594752    if($this->do_debug >= 2) {
    595       echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
     753      $this->edebug("SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />');
    596754    }
    597755
     
    607765      $rval = false;
    608766      if($this->do_debug >= 1) {
    609         echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
     767        $this->edebug("SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />');
    610768      }
    611769    }
     
    628786   * SMTP CODE ERROR  : 500,501,503,421
    629787   * @access public
     788   * @param string $to
    630789   * @return bool
    631790   */
     
    645804
    646805    if($this->do_debug >= 2) {
    647       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     806      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    648807    }
    649808
     
    654813              "smtp_msg" => substr($rply,4));
    655814      if($this->do_debug >= 1) {
    656         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     815        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    657816      }
    658817      return false;
     
    688847
    689848    if($this->do_debug >= 2) {
    690       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     849      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    691850    }
    692851
     
    697856              "smtp_msg" => substr($rply,4));
    698857      if($this->do_debug >= 1) {
    699         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     858        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    700859      }
    701860      return false;
     
    719878   * SMTP CODE SUCCESS: 500,501,502,421
    720879   * @access public
     880   * @param string $from
    721881   * @return bool
    722882   */
     
    736896
    737897    if($this->do_debug >= 2) {
    738       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     898      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    739899    }
    740900
     
    745905              "smtp_msg" => substr($rply,4));
    746906      if($this->do_debug >= 1) {
    747         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     907        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    748908      }
    749909      return false;
     
    769929                                    "is not implemented");
    770930    if($this->do_debug >= 1) {
    771       echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
     931      $this->edebug("SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />');
    772932    }
    773933    return false;
     
    798958  private function get_lines() {
    799959    $data = "";
    800     while(!feof($this->smtp_conn)) {
     960    $endtime = 0;
     961    /* If for some reason the fp is bad, don't inf loop */
     962    if (!is_resource($this->smtp_conn)) {
     963      return $data;
     964    }
     965    stream_set_timeout($this->smtp_conn, $this->Timeout);
     966    if ($this->Timelimit > 0) {
     967      $endtime = time() + $this->Timelimit;
     968    }
     969    while(is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
    801970      $str = @fgets($this->smtp_conn,515);
    802971      if($this->do_debug >= 4) {
    803         echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
    804         echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
     972        $this->edebug("SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />');
     973        $this->edebug("SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />');
    805974      }
    806975      $data .= $str;
    807976      if($this->do_debug >= 4) {
    808         echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
     977        $this->edebug("SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />');
    809978      }
    810979      // if 4th character is a space, we are done reading, break the loop
    811980      if(substr($str,3,1) == " ") { break; }
     981      // Timed-out? Log and break
     982      $info = stream_get_meta_data($this->smtp_conn);
     983      if ($info['timed_out']) {
     984        if($this->do_debug >= 4) {
     985          $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " seconds) <br />");
     986        }
     987        break;
     988      }
     989      // Now check if reads took too long
     990      if ($endtime) {
     991        if (time() > $endtime) {
     992          if($this->do_debug >= 4) {
     993            $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " seconds) <br />");
     994          }
     995          break;
     996        }
     997      }
    812998    }
    813999    return $data;
     
    8151001
    8161002}
    817 
    8181003?>
Note: See TracChangeset for help on using the changeset viewer.