WordPress.org

Make WordPress Core

Ticket #21074: 21074-phpmailer-5.2.2-rc2-r22509.patch

File 21074-phpmailer-5.2.2-rc2-r22509.patch, 66.4 KB (added by bpetty, 6 years ago)

Refreshed patch based on PHPMailer 5.2.2-rc2 release.

  • wp-includes/class-phpmailer.php

    diff --git wp-includes/class-phpmailer.php wp-includes/class-phpmailer.php
    index df533c2..bb66770 100644
     
    22/*~ class.phpmailer.php
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 5.2.1                                                          |
     5|   Version: 5.2.2                                                          |
    66|      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
    77| ------------------------------------------------------------------------- |
    88|     Admin: Jim Jagielski (project admininistrator)                        |
     
    3131 * @author Jim Jagielski
    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 */
    3736
     37
    3838if (version_compare(PHP_VERSION, '5.0.0', '<') ) exit("Sorry, this version of PHPMailer will only run on PHP version 5 or greater!\n");
    3939
     40/**
     41 * Main PHPMailer class definition
     42 */
    4043class PHPMailer {
    4144
    4245  /////////////////////////////////////////////////
    class PHPMailer { 
    8790  public $FromName          = 'Root User';
    8891
    8992  /**
    90    * Sets the Sender email (Return-Path) of the message.  If not empty,
     93   * Sets the Sender email of the message.  If not empty,
    9194   * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
     95   * If not empty, and ReturnPath is empty, will also be the
     96   * Return-Path header.
    9297   * @var string
    9398   */
    9499  public $Sender            = '';
    95100
    96101  /**
     102   * Sets the Return-Path of the message.  If empty, it will
     103   * be set to either From or Sender.
     104   * @var string
     105   */
     106  public $ReturnPath        = '';
     107
     108  /**
    97109   * Sets the Subject of the message.
    98110   * @var string
    99111   */
    class PHPMailer { 
    130142  protected $MIMEHeader     = '';
    131143
    132144  /**
    133    * Stores the complete sent MIME message (Body and Headers)
     145   * Stores the extra header list which CreateHeader() doesn't fold in
    134146   * @var string
    135147   * @access protected
    136148  */
    137   protected $SentMIMEMessage     = '';
     149  protected $mailHeader     = '';
    138150
    139151  /**
    140152   * Sets word wrapping on the body of the message to a given number of
    class PHPMailer { 
    156168  public $Sendmail          = '/usr/sbin/sendmail';
    157169
    158170  /**
     171   * Determine if mail() uses a fully sendmail compatible MTA that
     172   * supports sendmail's "-oi -f" options
     173   * @var boolean
     174   */
     175  public $UseSendmailOptions    = true;
     176 
     177  /**
    159178   * Path to PHPMailer plugins.  Useful if the SMTP class
    160179   * is in a different directory than the PHP include path.
    161180   * @var string
    class PHPMailer { 
    183202   */
    184203  public $MessageID         = '';
    185204
     205  /**
     206   * Sets the message Date to be used in the Date header.
     207   * If empty, the current date will be added.
     208   * @var string
     209   */
     210  public $MessageDate       = '';
     211
    186212  /////////////////////////////////////////////////
    187213  // PROPERTIES FOR SMTP
    188214  /////////////////////////////////////////////////
    189215
    190216  /**
    191    * Sets the SMTP hosts.  All hosts must be separated by a
     217   * Sets the SMTP hosts.
     218   *
     219   * All hosts must be separated by a
    192220   * semicolon.  You can also specify a different port
    193221   * for each host by using this format: [hostname:port]
    194222   * (e.g. "smtp1.example.com:25;smtp2.example.com").
    class PHPMailer { 
    210238  public $Helo          = '';
    211239
    212240  /**
    213    * Sets connection prefix.
    214    * Options are "", "ssl" or "tls"
     241   * Sets connection prefix. Options are "", "ssl" or "tls"
    215242   * @var string
    216243   */
    217244  public $SMTPSecure    = '';
    class PHPMailer { 
    235262  public $Password      = '';
    236263
    237264  /**
    238    * Sets the SMTP server timeout in seconds.
     265   *  Sets SMTP auth type. Options are LOGIN | PLAIN | NTLM  (default LOGIN)
     266   *  @var string
     267   */
     268  public $AuthType      = '';
     269 
     270  /**
     271   *  Sets SMTP realm.
     272   *  @var string
     273   */
     274  public $Realm         = '';
     275
     276  /**
     277   *  Sets SMTP workstation.
     278   *  @var string
     279   */
     280  public $Workstation   = '';
     281
     282  /**
     283   * Sets the SMTP server   in seconds.
    239284   * This function will not work with the win32 version.
    240285   * @var int
    241286   */
    class PHPMailer { 
    248293  public $SMTPDebug     = false;
    249294
    250295  /**
     296   * Sets the function/method to use for debugging output.
     297   * Right now we only honor "echo" or "error_log"
     298   * @var string
     299   */
     300  public $Debugoutput     = "echo";
     301
     302  /**
    251303   * Prevents the SMTP connection from being closed after each mail
    252304   * sending.  If this is set to true then to close the connection
    253305   * requires an explicit call to SmtpClose().
    class PHPMailer { 
    269321  public $SingleToArray = array();
    270322
    271323 /**
    272    * Provides the ability to change the line ending
     324   * Provides the ability to change the generic line ending
     325   * NOTE: The default remains '\n'. We force CRLF where we KNOW
     326   *        it must be used via self::CRLF
    273327   * @var string
    274328   */
    275329  public $LE              = "\n";
    276330
    277   /**
    278    * Used with DKIM DNS Resource Record
     331   /**
     332   * Used with DKIM Signing
     333   * required parameter if DKIM is enabled
     334   *
     335   * domain selector example domainkey
    279336   * @var string
    280337   */
    281   public $DKIM_selector   = 'phpmailer';
     338  public $DKIM_selector   = '';
    282339
    283340  /**
    284    * Used with DKIM DNS Resource Record
    285    * optional, in format of email address 'you@yourdomain.com'
     341   * Used with DKIM Signing
     342   * required if DKIM is enabled, in format of email address 'you@yourdomain.com' typically used as the source of the email
    286343   * @var string
    287344   */
    288345  public $DKIM_identity   = '';
    289346
    290347  /**
    291    * Used with DKIM DNS Resource Record
     348   * Used with DKIM Signing
     349   * optional parameter if your private key requires a passphras
    292350   * @var string
    293351   */
    294352  public $DKIM_passphrase   = '';
    295353
    296354  /**
    297    * Used with DKIM DNS Resource Record
    298    * optional, in format of email address 'you@yourdomain.com'
     355   * Used with DKIM Singing
     356   * required if DKIM is enabled, in format of email address 'domain.com'
    299357   * @var string
    300358   */
    301359  public $DKIM_domain     = '';
    302360
    303361  /**
    304    * Used with DKIM DNS Resource Record
    305    * optional, in format of email address 'you@yourdomain.com'
     362   * Used with DKIM Signing
     363   * required if DKIM is enabled, path to private key file
    306364   * @var string
    307365   */
    308366  public $DKIM_private    = '';
    309367
    310368  /**
    311    * Callback Action function name
    312    * the function that handles the result of the send email action. Parameters:
     369   * Callback Action function name.
     370   * The function that handles the result of the send email action.
     371   * It is called out by Send() for each email sent.
     372   *
     373   * Value can be:
     374   * - 'function_name' for function names
     375   * - 'Class::Method' for static method calls
     376   * - array($object, 'Method') for calling methods on $object
     377   * See http://php.net/is_callable manual page for more details.
     378   *
     379   * Parameters:
    313380   *   bool    $result        result of the send action
    314381   *   string  $to            email address of the recipient
    315382   *   string  $cc            cc email addresses
    316383   *   string  $bcc           bcc email addresses
    317384   *   string  $subject       the subject
    318385   *   string  $body          the email body
     386   *   string  $from          email address of sender
    319387   * @var string
    320388   */
    321389  public $action_function = ''; //'callbackAction';
    class PHPMailer { 
    324392   * Sets the PHPMailer Version number
    325393   * @var string
    326394   */
    327   public $Version         = '5.2.1';
     395  public $Version         = '5.2.2-rc2';
    328396
    329397  /**
    330398   * What to use in the X-Mailer header
    331    * @var string
     399   * @var string NULL for default, whitespace for None, or actual string to use
    332400   */
    333401  public $XMailer         = '';
    334402
    class PHPMailer { 
    360428  const STOP_MESSAGE  = 0; // message only, continue processing
    361429  const STOP_CONTINUE = 1; // message?, likely ok to continue processing
    362430  const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
    363 
     431  const CRLF = "\r\n";     // SMTP RFC specified EOL
     432 
    364433  /////////////////////////////////////////////////
    365434  // METHODS, VARIABLES
    366435  /////////////////////////////////////////////////
    367436
    368437  /**
     438   * Calls actual mail() function, but in a safe_mode aware fashion
     439   * Also, unless sendmail_path points to sendmail (or something that
     440   * claims to be sendmail), don't pass params (not a perfect fix,
     441   * but it will do)
     442   * @param string $to To
     443   * @param string $subject Subject
     444   * @param string $body Message Body
     445   * @param string $header Additional Header(s)
     446   * @param string $params Params
     447   * @access private
     448   * @return bool
     449   */
     450  private function mail_passthru($to, $subject, $body, $header, $params) {
     451    if ( ini_get('safe_mode') || !($this->UseSendmailOptions) ) {
     452        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header);
     453    } else {
     454        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params);
     455    }
     456    return $rt;
     457  }
     458
     459  /**
     460   * Outputs debugging info via user-defined method
     461   * @param string $str
     462   */
     463  private function edebug($str) {
     464    if ($this->Debugoutput == "error_log") {
     465        error_log($str);
     466    } else {
     467        echo $str;
     468    }
     469  }
     470
     471  /**
    369472   * Constructor
    370473   * @param boolean $exceptions Should we throw external exceptions?
    371474   */
    class PHPMailer { 
    389492  /**
    390493   * Sets Mailer to send message using SMTP.
    391494   * @return void
     495   * @deprecated
    392496   */
    393497  public function IsSMTP() {
    394498    $this->Mailer = 'smtp';
    class PHPMailer { 
    397501  /**
    398502   * Sets Mailer to send message using PHP mail() function.
    399503   * @return void
     504   * @deprecated
    400505   */
    401506  public function IsMail() {
    402507    $this->Mailer = 'mail';
    class PHPMailer { 
    405510  /**
    406511   * Sets Mailer to send message using the $Sendmail program.
    407512   * @return void
     513   * @deprecated
    408514   */
    409515  public function IsSendmail() {
    410516    if (!stristr(ini_get('sendmail_path'), 'sendmail')) {
    class PHPMailer { 
    416522  /**
    417523   * Sets Mailer to send message using the qmail MTA.
    418524   * @return void
     525   * @deprecated
    419526   */
    420527  public function IsQmail() {
    421528    if (stristr(ini_get('sendmail_path'), 'qmail')) {
    class PHPMailer { 
    485592      if ($this->exceptions) {
    486593        throw new phpmailerException('Invalid recipient array: ' . $kind);
    487594      }
    488           if ($this->SMTPDebug) {
    489         echo $this->Lang('Invalid recipient array').': '.$kind;
     595      if ($this->SMTPDebug) {
     596        $this->edebug($this->Lang('Invalid recipient array').': '.$kind);
    490597      }
    491598      return false;
    492599    }
    493600    $address = trim($address);
    494601    $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
    495     if (!self::ValidateAddress($address)) {
     602    if (!$this->ValidateAddress($address)) {
    496603      $this->SetError($this->Lang('invalid_address').': '. $address);
    497604      if ($this->exceptions) {
    498605        throw new phpmailerException($this->Lang('invalid_address').': '.$address);
    499606      }
    500           if ($this->SMTPDebug) {
    501         echo $this->Lang('invalid_address').': '.$address;
     607      if ($this->SMTPDebug) {
     608        $this->edebug($this->Lang('invalid_address').': '.$address);
    502609      }
    503610      return false;
    504611    }
    class PHPMailer { 
    521628 * Set the From and FromName properties
    522629 * @param string $address
    523630 * @param string $name
     631 * @param int $auto Also set Reply-To and Sender
    524632 * @return boolean
    525633 */
    526634  public function SetFrom($address, $name = '', $auto = 1) {
    527635    $address = trim($address);
    528636    $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
    529     if (!self::ValidateAddress($address)) {
     637    if (!$this->ValidateAddress($address)) {
    530638      $this->SetError($this->Lang('invalid_address').': '. $address);
    531639      if ($this->exceptions) {
    532640        throw new phpmailerException($this->Lang('invalid_address').': '.$address);
    533641      }
    534           if ($this->SMTPDebug) {
    535         echo $this->Lang('invalid_address').': '.$address;
     642      if ($this->SMTPDebug) {
     643        $this->edebug($this->Lang('invalid_address').': '.$address);
    536644      }
    537645      return false;
    538646    }
    class PHPMailer { 
    551659
    552660  /**
    553661   * 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
     662   * Static so it can be used without instantiation, public so people can overload
     663   * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is
     664   * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to
     665   * not allow a@b type valid addresses :(
     666   * @link http://squiloople.com/2009/12/20/email-address-validation/
     667   * @copyright regex Copyright Michael Rushton 2009-10 | http://squiloople.com/ | Feel free to use and redistribute this code. But please keep this copyright notice.
    558668   * @param string $address The email address to check
    559669   * @return boolean
    560670   * @static
    561671   * @access public
    562672   */
    563673  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       }
    570     } 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     }
     674        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);
    573675  }
    574676
    575677  /////////////////////////////////////////////////
    class PHPMailer { 
    587689      if(!$this->PreSend()) return false;
    588690      return $this->PostSend();
    589691    } catch (phpmailerException $e) {
    590           $this->SentMIMEMessage = '';
     692      $this->mailHeader = '';
    591693      $this->SetError($e->getMessage());
    592694      if ($this->exceptions) {
    593695        throw $e;
    class PHPMailer { 
    596698    }
    597699  }
    598700
    599   protected function PreSend() {
     701  /**
     702   * Prep mail by constructing all message entities
     703   * @return bool
     704   */
     705  public function PreSend() {
    600706    try {
    601           $mailHeader = "";
     707      $this->mailHeader = "";
    602708      if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
    603709        throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
    604710      }
    class PHPMailer { 
    619725      $this->MIMEBody = $this->CreateBody();
    620726
    621727      // To capture the complete message when using mail(), create
    622           // an extra header list which CreateHeader() doesn't fold in
     728      // an extra header list which CreateHeader() doesn't fold in
    623729      if ($this->Mailer == 'mail') {
    624730        if (count($this->to) > 0) {
    625           $mailHeader .= $this->AddrAppend("To", $this->to);
     731          $this->mailHeader .= $this->AddrAppend("To", $this->to);
    626732        } else {
    627           $mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
     733          $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
    628734        }
    629         $mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
     735        $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
    630736        // if(count($this->cc) > 0) {
    631             // $mailHeader .= $this->AddrAppend("Cc", $this->cc);
     737            // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc);
    632738        // }
    633739      }
    634740
    635741      // digitally sign with DKIM if enabled
    636       if ($this->DKIM_domain && $this->DKIM_private) {
     742      if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) {
    637743        $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
    638744        $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
    639745      }
    640746
    641       $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);
    642747      return true;
    643748
    644749    } catch (phpmailerException $e) {
    class PHPMailer { 
    650755    }
    651756  }
    652757
    653   protected function PostSend() {
     758  /**
     759   * Actual Email transport function
     760   * Send the email via the selected mechanism
     761   * @return bool
     762   */
     763  public function PostSend() {
     764    $rtn = false;
    654765    try {
    655766      // Choose the mailer and send through it
    656767      switch($this->Mailer) {
    657768        case 'sendmail':
    658           return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
     769          $rtn = $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
     770          break;
    659771        case 'smtp':
    660           return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
     772          $rtn = $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
     773          break;
    661774        case 'mail':
    662           return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
     775          $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody);
     776          break;
    663777        default:
    664           return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
     778          $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody);
     779          break;
    665780      }
    666781
    667782    } catch (phpmailerException $e) {
    class PHPMailer { 
    669784      if ($this->exceptions) {
    670785        throw $e;
    671786      }
    672           if ($this->SMTPDebug) {
    673         echo $e->getMessage()."\n";
     787      if ($this->SMTPDebug) {
     788        $this->edebug($e->getMessage()."\n");
    674789      }
    675790      return false;
    676791    }
     792    return $rtn;
    677793  }
    678794
    679795  /**
    class PHPMailer { 
    685801   */
    686802  protected function SendmailSend($header, $body) {
    687803    if ($this->Sender != '') {
    688       $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
     804      $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
    689805    } else {
    690806      $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
    691807    }
    class PHPMailer { 
    739855    if (empty($this->Sender)) {
    740856      $params = "-oi ";
    741857    } else {
    742       $params = sprintf("-oi -f %s", $this->Sender);
     858      $params = sprintf("-oi -f%s", $this->Sender);
    743859    }
    744860    if ($this->Sender != '' and !ini_get('safe_mode')) {
    745861      $old_from = ini_get('sendmail_from');
    746862      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);
     863    }
     864    if ($this->SingleTo === true && count($toArr) > 1) {
     865      foreach ($toArr as $key => $val) {
     866        $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params);
    756867        // implement call back function if it exists
    757868        $isSent = ($rt == 1) ? 1 : 0;
    758         $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
     869        $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
    759870      }
    760871    } 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       }
     872      $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params);
     873      // implement call back function if it exists
     874      $isSent = ($rt == 1) ? 1 : 0;
     875      $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
    774876    }
    775877    if (isset($old_from)) {
    776878      ini_set('sendmail_from', $old_from);
    class PHPMailer { 
    862964   * @return bool
    863965   */
    864966  public function SmtpConnect() {
    865     if(is_null($this->smtp)) {
     967    if ($this->smtp === null) {
    866968      $this->smtp = new SMTP();
    867969    }
    868970
     971    $this->smtp->Timeout = $this->Timeout;
    869972    $this->smtp->do_debug = $this->SMTPDebug;
    870973    $hosts = explode(';', $this->Host);
    871974    $index = 0;
    872975    $connection = $this->smtp->Connected();
     976    $rtn = true;
    873977
    874978    // Retry while there is no connection
    875979    try {
    class PHPMailer { 
    893997
    894998          if ($tls) {
    895999            if (!$this->smtp->StartTLS()) {
     1000              $rtn = false;
    8961001              throw new phpmailerException($this->Lang('tls'));
    8971002            }
    8981003
    class PHPMailer { 
    9021007
    9031008          $connection = true;
    9041009          if ($this->SMTPAuth) {
    905             if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
     1010            if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType,
     1011                                           $this->Realm, $this->Workstation)) {
     1012              $rtn = false;
    9061013              throw new phpmailerException($this->Lang('authenticate'));
    9071014            }
    9081015          }
    9091016        }
    9101017        $index++;
    911         if (!$connection) {
    912           throw new phpmailerException($this->Lang('connect_host'));
    913         }
     1018      }
     1019      if (!$connection) {
     1020        $rtn = false;
     1021        throw new phpmailerException($this->Lang('connect_host'));
    9141022      }
    9151023    } catch (phpmailerException $e) {
    9161024      $this->smtp->Reset();
    917           if ($this->exceptions) {
     1025      if ($this->exceptions) {
    9181026        throw $e;
    9191027      }
     1028      $rtn = false;
    9201029    }
    921     return true;
     1030    return $rtn;
    9221031  }
    9231032
    9241033  /**
    class PHPMailer { 
    9261035   * @return void
    9271036   */
    9281037  public function SmtpClose() {
    929     if(!is_null($this->smtp)) {
     1038    if ($this->smtp !== null) {
    9301039      if($this->smtp->Connected()) {
    9311040        $this->smtp->Quit();
    9321041        $this->smtp->Close();
    class PHPMailer { 
    9441053  function SetLanguage($langcode = 'en', $lang_path = 'language/') {
    9451054    //Define full set of translatable strings
    9461055    $PHPMAILER_LANG = array(
    947       'provide_address' => 'You must provide at least one recipient email address.',
     1056      'authenticate'         => 'SMTP Error: Could not authenticate.',
     1057      'connect_host'         => 'SMTP Error: Could not connect to SMTP host.',
     1058      'data_not_accepted'    => 'SMTP Error: Data not accepted.',
     1059      'empty_message'        => 'Message body empty',
     1060      'encoding'             => 'Unknown encoding: ',
     1061      'execute'              => 'Could not execute: ',
     1062      'file_access'          => 'Could not access file: ',
     1063      'file_open'            => 'File Error: Could not open file: ',
     1064      'from_failed'          => 'The following From address failed: ',
     1065      'instantiate'          => 'Could not instantiate mail function.',
     1066      'invalid_address'      => 'Invalid address',
    9481067      '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: '
     1068      'provide_address'      => 'You must provide at least one recipient email address.',
     1069      'recipients_failed'    => 'SMTP Error: The following recipients failed: ',
     1070      'signing'              => 'Signing Error: ',
     1071      'smtp_connect_failed'  => 'SMTP Connect() failed.',
     1072      'smtp_error'           => 'SMTP server error: ',
     1073      'variable_set'         => 'Cannot set or reset variable: '
    9641074    );
    9651075    //Overwrite language-specific strings. This way we'll never have missing translations - no more "language string failed to load"!
    9661076    $l = true;
    class PHPMailer { 
    10281138    // If utf-8 encoding is used, we will need to make sure we don't
    10291139    // split multibyte characters when we wrap
    10301140    $is_utf8 = (strtolower($this->CharSet) == "utf-8");
     1141    $lelen = strlen($this->LE);
     1142    $crlflen = strlen(self::CRLF);
    10311143
    10321144    $message = $this->FixEOL($message);
    1033     if (substr($message, -1) == $this->LE) {
    1034       $message = substr($message, 0, -1);
     1145    if (substr($message, -$lelen) == $this->LE) {
     1146      $message = substr($message, 0, -$lelen);
    10351147    }
    10361148
    1037     $line = explode($this->LE, $message);
     1149    $line = explode($this->LE, $message);   // Magic. We know FixEOL uses $LE
    10381150    $message = '';
    10391151    for ($i = 0 ;$i < count($line); $i++) {
    10401152      $line_part = explode(' ', $line[$i]);
    class PHPMailer { 
    10421154      for ($e = 0; $e<count($line_part); $e++) {
    10431155        $word = $line_part[$e];
    10441156        if ($qp_mode and (strlen($word) > $length)) {
    1045           $space_left = $length - strlen($buf) - 1;
     1157          $space_left = $length - strlen($buf) - $crlflen;
    10461158          if ($e != 0) {
    10471159            if ($space_left > 20) {
    10481160              $len = $space_left;
    class PHPMailer { 
    10561168              $part = substr($word, 0, $len);
    10571169              $word = substr($word, $len);
    10581170              $buf .= ' ' . $part;
    1059               $message .= $buf . sprintf("=%s", $this->LE);
     1171              $message .= $buf . sprintf("=%s", self::CRLF);
    10601172            } else {
    10611173              $message .= $buf . $soft_break;
    10621174            }
    class PHPMailer { 
    10751187            $word = substr($word, $len);
    10761188
    10771189            if (strlen($word) > 0) {
    1078               $message .= $part . sprintf("=%s", $this->LE);
     1190              $message .= $part . sprintf("=%s", self::CRLF);
    10791191            } else {
    10801192              $buf = $part;
    10811193            }
    class PHPMailer { 
    10901202          }
    10911203        }
    10921204      }
    1093       $message .= $buf . $this->LE;
     1205      $message .= $buf . self::CRLF;
    10941206    }
    10951207
    10961208    return $message;
    class PHPMailer { 
    11751287    $this->boundary[2] = 'b2_' . $uniq_id;
    11761288    $this->boundary[3] = 'b3_' . $uniq_id;
    11771289
    1178     $result .= $this->HeaderLine('Date', self::RFCDate());
    1179     if($this->Sender == '') {
     1290    if ($this->MessageDate == '') {
     1291      $result .= $this->HeaderLine('Date', self::RFCDate());
     1292    } else {
     1293      $result .= $this->HeaderLine('Date', $this->MessageDate);
     1294    }
     1295
     1296    if ($this->ReturnPath) {
     1297      $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath));
     1298    } elseif ($this->Sender == '') {
    11801299      $result .= $this->HeaderLine('Return-Path', trim($this->From));
    11811300    } else {
    11821301      $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
    class PHPMailer { 
    11951314          $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
    11961315        }
    11971316      }
    1198         }
     1317    }
    11991318
    12001319    $from = array();
    12011320    $from[0][0] = trim($this->From);
    class PHPMailer { 
    12271346      $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
    12281347    }
    12291348    $result .= $this->HeaderLine('X-Priority', $this->Priority);
    1230     if($this->XMailer) {
    1231       $result .= $this->HeaderLine('X-Mailer', $this->XMailer);
     1349    if ($this->XMailer == '') {
     1350        $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
    12321351    } else {
    1233       $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
     1352      $myXmailer = trim($this->XMailer);
     1353      if ($myXmailer) {
     1354        $result .= $this->HeaderLine('X-Mailer', $myXmailer);
     1355      }
    12341356    }
    12351357
    12361358    if($this->ConfirmReadingTo != '') {
    class PHPMailer { 
    12571379  public function GetMailMIME() {
    12581380    $result = '';
    12591381    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;
    12641382      case 'inline':
    12651383        $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
    12661384        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
    class PHPMailer { 
    12771395        $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
    12781396        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
    12791397        break;
     1398      default:
     1399        // Catches case 'plain': and case '':
     1400        $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
     1401        $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet);
     1402        break;
    12801403    }
    12811404
    12821405    if($this->Mailer != 'mail') {
    1283       $result .= $this->LE.$this->LE;
     1406      $result .= $this->LE;
    12841407    }
    12851408
    12861409    return $result;
    class PHPMailer { 
    12921415   * @return string
    12931416   */
    12941417  public function GetSentMIMEMessage() {
    1295     return $this->SentMIMEMessage;
     1418    return $this->MIMEHeader . $this->mailHeader . self::CRLF . $this->MIMEBody;
    12961419  }
    12971420
    12981421
    class PHPMailer { 
    13051428    $body = '';
    13061429
    13071430    if ($this->sign_key_file) {
    1308       $body .= $this->GetMailMIME();
     1431      $body .= $this->GetMailMIME().$this->LE;
    13091432    }
    13101433
    13111434    $this->SetWordWrap();
    13121435
    13131436    switch($this->message_type) {
    1314       case 'plain':
    1315         $body .= $this->EncodeString($this->Body, $this->Encoding);
    1316         break;
    13171437      case 'inline':
    13181438        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
    13191439        $body .= $this->EncodeString($this->Body, $this->Encoding);
    class PHPMailer { 
    13981518        $body .= $this->LE;
    13991519        $body .= $this->AttachAll("attachment", $this->boundary[1]);
    14001520        break;
     1521      default:
     1522        // catch case 'plain' and case ''
     1523        $body .= $this->EncodeString($this->Body, $this->Encoding);
     1524        break;
    14011525    }
    14021526
    14031527    if ($this->IsError()) {
    class PHPMailer { 
    14441568      $encoding = $this->Encoding;
    14451569    }
    14461570    $result .= $this->TextLine('--' . $boundary);
    1447     $result .= sprintf("Content-Type: %s; charset=\"%s\"", $contentType, $charSet);
     1571    $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet);
    14481572    $result .= $this->LE;
    14491573    $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
    14501574    $result .= $this->LE;
    class PHPMailer { 
    15331657      if ($this->exceptions) {
    15341658        throw $e;
    15351659      }
    1536           if ($this->SMTPDebug) {
    1537         echo $e->getMessage()."\n";
     1660      if ($this->SMTPDebug) {
     1661        $this->edebug($e->getMessage()."\n");
    15381662      }
    15391663      if ( $e->getCode() == self::STOP_CRITICAL ) {
    15401664        return false;
    class PHPMailer { 
    16331757      if (!is_readable($path)) {
    16341758        throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
    16351759      }
    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) {
     1760      //  if (!function_exists('get_magic_quotes')) {
     1761      //    function get_magic_quotes() {
     1762      //      return false;
     1763      //    }
     1764      //  }
     1765      $magic_quotes = get_magic_quotes_runtime();
     1766      if ($magic_quotes) {
    16431767        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    16441768          set_magic_quotes_runtime(0);
    16451769        } else {
    1646                   ini_set('magic_quotes_runtime', 0);
    1647                 }
    1648           }
     1770          ini_set('magic_quotes_runtime', 0);
     1771        }
     1772      }
    16491773      $file_buffer  = file_get_contents($path);
    16501774      $file_buffer  = $this->EncodeString($file_buffer, $encoding);
    1651           if ($magic_quotes) {
     1775      if ($magic_quotes) {
    16521776        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    16531777          set_magic_quotes_runtime($magic_quotes);
    16541778        } else {
    1655                   ini_set('magic_quotes_runtime', $magic_quotes);
    1656             }
    1657           }
     1779          ini_set('magic_quotes_runtime', $magic_quotes);
     1780        }
     1781      }
    16581782      return $file_buffer;
    16591783    } catch (Exception $e) {
    16601784      $this->SetError($e->getMessage());
    class PHPMailer { 
    17371861      if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
    17381862        // Use a custom function which correctly encodes and wraps long
    17391863        // multibyte strings without breaking lines within a character
    1740         $encoded = $this->Base64EncodeWrapMB($str);
     1864        $encoded = $this->Base64EncodeWrapMB($str, "\n");
    17411865      } else {
    17421866        $encoded = base64_encode($str);
    17431867        $maxlen -= $maxlen % 4;
    class PHPMailer { 
    17471871      $encoding = 'Q';
    17481872      $encoded = $this->EncodeQ($str, $position);
    17491873      $encoded = $this->WrapText($encoded, $maxlen, true);
    1750       $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
     1874      $encoded = str_replace('='.self::CRLF, "\n", trim($encoded));
    17511875    }
    17521876
    17531877    $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
    class PHPMailer { 
    17761900   * Adapted from a function by paravoid at http://uk.php.net/manual/en/function.mb-encode-mimeheader.php
    17771901   * @access public
    17781902   * @param string $str multi-byte text to wrap encode
     1903   * @param string $lf string to use as linefeed/end-of-line
    17791904   * @return string
    17801905   */
    1781   public function Base64EncodeWrapMB($str) {
     1906  public function Base64EncodeWrapMB($str, $lf=null) {
    17821907    $start = "=?".$this->CharSet."?B?";
    17831908    $end = "?=";
    17841909    $encoded = "";
     1910    if ($lf === null) {
     1911      $lf = $this->LE;
     1912    }
    17851913
    17861914    $mb_length = mb_strlen($str, $this->CharSet);
    17871915    // Each line must have length <= 75, including $start and $end
    class PHPMailer { 
    18021930      }
    18031931      while (strlen($chunk) > $length);
    18041932
    1805       $encoded .= $chunk . $this->LE;
     1933      $encoded .= $chunk . $lf;
    18061934    }
    18071935
    18081936    // Chomp the last linefeed
    1809     $encoded = substr($encoded, 0, -strlen($this->LE));
     1937    $encoded = substr($encoded, 0, -strlen($lf));
    18101938    return $encoded;
    18111939  }
    18121940
    class PHPMailer { 
    19012029   * @return string
    19022030   */
    19032031  public function EncodeQ($str, $position = 'text') {
    1904     // There should not be any EOL in the string
    1905     $encoded = preg_replace('/[\r\n]*/', '', $str);
    1906 
     2032    //There should not be any EOL in the string
     2033        $pattern="";
     2034    $encoded = str_replace(array("\r", "\n"), '', $str);
    19072035    switch (strtolower($position)) {
    19082036      case 'phrase':
    1909         $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
     2037        $pattern = '^A-Za-z0-9!*+\/ -';
    19102038        break;
     2039
    19112040      case 'comment':
    1912         $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
     2041        $pattern = '\(\)"';
     2042        //note that we dont break here!
     2043        //for this reason we build the $pattern withoud including delimiters and []
     2044
    19132045      case 'text':
    19142046      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);
     2047        //Replace every high ascii, control =, ? and _ characters
     2048        //We put \075 (=) as first value to make sure it's the first one in being converted, preventing double encode
     2049        $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern;
    19192050        break;
    19202051    }
     2052   
     2053    if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
     2054      foreach (array_unique($matches[0]) as $char) {
     2055        $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
     2056      }
     2057    }
     2058   
     2059    //Replace every spaces to _ (more readable than =20)
     2060    return str_replace(' ', '_', $encoded);
     2061}
    19212062
    1922     // Replace every spaces to _ (more readable than =20)
    1923     $encoded = str_replace(' ', '_', $encoded);
    1924 
    1925     return $encoded;
    1926   }
    19272063
    19282064  /**
    19292065   * Adds a string or binary attachment (non-filesystem) to the list.
    class PHPMailer { 
    20272163  }
    20282164
    20292165  public function AlternativeExists() {
    2030     return strlen($this->AltBody)>0;
     2166    return !empty($this->AltBody);
    20312167  }
    20322168
    20332169  /////////////////////////////////////////////////
    class PHPMailer { 
    21152251   */
    21162252  protected function SetError($msg) {
    21172253    $this->error_count++;
    2118     if ($this->Mailer == 'smtp' and !is_null($this->smtp)) {
     2254    if (($this->Mailer == 'smtp') and ($this->smtp !== null)) {
    21192255      $lasterror = $this->smtp->getError();
    21202256      if (!empty($lasterror) and array_key_exists('smtp_msg', $lasterror)) {
    21212257        $msg .= '<p>' . $this->Lang('smtp_error') . $lasterror['smtp_msg'] . "</p>\n";
    class PHPMailer { 
    21842320  }
    21852321
    21862322  /**
    2187    * Changes every end of line from CR or LF to CRLF.
     2323   * Changes every end of line from CRLF, CR or LF to $this->LE.
    21882324   * @access public
     2325   * @param string $str String to FixEOL
    21892326   * @return string
    21902327   */
    21912328  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;
     2329        // condense down to \n
     2330        $nstr = str_replace(array("\r\n", "\r"), "\n", $str);
     2331        // Now convert LE as needed
     2332        if ($this->LE !== "\n") {
     2333                $nstr = str_replace("\n", $this->LE, $nstr);
     2334        }
     2335    return  $nstr;
    21962336  }
    21972337
    21982338  /**
    2199    * Adds a custom header.
     2339   * Adds a custom header. $name value can be overloaded to contain
     2340   * both header name and value (name:value)
    22002341   * @access public
     2342   * @param string $name custom header name
     2343   * @param string $value header value
    22012344   * @return void
    22022345   */
    2203   public function AddCustomHeader($custom_header) {
    2204     $this->CustomHeader[] = explode(':', $custom_header, 2);
     2346  public function AddCustomHeader($name, $value=null) {
     2347        if ($value === null) {
     2348                // Value passed in as name:value
     2349                $this->CustomHeader[] = explode(':', $name, 2);
     2350        } else {
     2351                $this->CustomHeader[] = array($name, $value);
     2352        }
    22052353  }
    22062354
    22072355  /**
    22082356   * Evaluates the message and returns modifications for inline images and backgrounds
    22092357   * @access public
     2358   * @param string $message Text to be HTML modified
     2359   * @param string $basedir baseline directory for path
    22102360   * @return $message
    22112361   */
    22122362  public function MsgHTML($message, $basedir = '') {
    class PHPMailer { 
    22312381    }
    22322382    $this->IsHTML(true);
    22332383    $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         }
     2384    if (empty($this->AltBody)) {
     2385        $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
     2386        if (!empty($textMsg)) {
     2387            $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
     2388        }
     2389    }
    22402390    if (empty($this->AltBody)) {
    22412391      $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
    22422392    }
    2243         return $message;
     2393    return $message;
    22442394  }
    22452395
    22462396  /**
    22472397   * Gets the MIME type of the embedded or inline image
    2248    * @param string File extension
     2398   * @param string $ext File extension
    22492399   * @access public
    22502400   * @return string MIME type of ext
    22512401   * @static
    22522402   */
    22532403  public static function _mime_types($ext = '') {
    22542404    $mimes = array(
     2405      'xl'    =>  'application/excel',
    22552406      'hqx'   =>  'application/mac-binhex40',
    22562407      'cpt'   =>  'application/mac-compactpro',
    2257       'doc'   =>  'application/msword',
    22582408      'bin'   =>  'application/macbinary',
     2409      'doc'   =>  'application/msword',
     2410      'doc'   =>  'application/msword',
     2411      'word'  =>  'application/msword',
     2412      'class' =>  'application/octet-stream',
     2413      'dll'   =>  'application/octet-stream',
    22592414      'dms'   =>  'application/octet-stream',
     2415      'exe'   =>  'application/octet-stream',
    22602416      'lha'   =>  'application/octet-stream',
    22612417      'lzh'   =>  'application/octet-stream',
    2262       'exe'   =>  'application/octet-stream',
    2263       'class' =>  'application/octet-stream',
    22642418      'psd'   =>  'application/octet-stream',
    2265       'so'    =>  'application/octet-stream',
    22662419      'sea'   =>  'application/octet-stream',
    2267       'dll'   =>  'application/octet-stream',
     2420      'so'    =>  'application/octet-stream',
    22682421      'oda'   =>  'application/oda',
    22692422      'pdf'   =>  'application/pdf',
    22702423      'ai'    =>  'application/postscript',
    class PHPMailer { 
    22822435      'dxr'   =>  'application/x-director',
    22832436      'dvi'   =>  'application/x-dvi',
    22842437      'gtar'  =>  'application/x-gtar',
    2285       'php'   =>  'application/x-httpd-php',
    2286       'php4'  =>  'application/x-httpd-php',
    22872438      'php3'  =>  'application/x-httpd-php',
     2439      'php4'  =>  'application/x-httpd-php',
     2440      'php'   =>  'application/x-httpd-php',
    22882441      'phtml' =>  'application/x-httpd-php',
    22892442      'phps'  =>  'application/x-httpd-php-source',
    22902443      'js'    =>  'application/x-javascript',
    class PHPMailer { 
    22922445      'sit'   =>  'application/x-stuffit',
    22932446      'tar'   =>  'application/x-tar',
    22942447      'tgz'   =>  'application/x-tar',
    2295       'xhtml' =>  'application/xhtml+xml',
    22962448      'xht'   =>  'application/xhtml+xml',
     2449      'xhtml' =>  'application/xhtml+xml',
    22972450      'zip'   =>  'application/zip',
    22982451      'mid'   =>  'audio/midi',
    22992452      'midi'  =>  'audio/midi',
    2300       'mpga'  =>  'audio/mpeg',
    23012453      'mp2'   =>  'audio/mpeg',
    23022454      'mp3'   =>  'audio/mpeg',
     2455      'mpga'  =>  'audio/mpeg',
    23032456      'aif'   =>  'audio/x-aiff',
    2304       'aiff'  =>  'audio/x-aiff',
    23052457      'aifc'  =>  'audio/x-aiff',
     2458      'aiff'  =>  'audio/x-aiff',
    23062459      'ram'   =>  'audio/x-pn-realaudio',
    23072460      'rm'    =>  'audio/x-pn-realaudio',
    23082461      'rpm'   =>  'audio/x-pn-realaudio-plugin',
    23092462      'ra'    =>  'audio/x-realaudio',
    2310       'rv'    =>  'video/vnd.rn-realvideo',
    23112463      'wav'   =>  'audio/x-wav',
    23122464      'bmp'   =>  'image/bmp',
    23132465      'gif'   =>  'image/gif',
    23142466      'jpeg'  =>  'image/jpeg',
    2315       'jpg'   =>  'image/jpeg',
    23162467      'jpe'   =>  'image/jpeg',
     2468      'jpg'   =>  'image/jpeg',
    23172469      'png'   =>  'image/png',
    23182470      'tiff'  =>  'image/tiff',
    23192471      'tif'   =>  'image/tiff',
     2472      'eml'   =>  'message/rfc822',
    23202473      'css'   =>  'text/css',
    23212474      'html'  =>  'text/html',
    23222475      'htm'   =>  'text/html',
    23232476      'shtml' =>  'text/html',
    2324       'txt'   =>  'text/plain',
    2325       'text'  =>  'text/plain',
    23262477      'log'   =>  'text/plain',
     2478      'text'  =>  'text/plain',
     2479      'txt'   =>  'text/plain',
    23272480      'rtx'   =>  'text/richtext',
    23282481      'rtf'   =>  'text/rtf',
    23292482      'xml'   =>  'text/xml',
    23302483      'xsl'   =>  'text/xml',
    23312484      'mpeg'  =>  'video/mpeg',
    2332       'mpg'   =>  'video/mpeg',
    23332485      'mpe'   =>  'video/mpeg',
    2334       'qt'    =>  'video/quicktime',
     2486      'mpg'   =>  'video/mpeg',
    23352487      'mov'   =>  'video/quicktime',
     2488      'qt'    =>  'video/quicktime',
     2489      'rv'    =>  'video/vnd.rn-realvideo',
    23362490      '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'
     2491      'movie' =>  'video/x-sgi-movie'
    23422492    );
    23432493    return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
    23442494  }
    class PHPMailer { 
    23782528   * @return string
    23792529   */
    23802530  public function SecureHeader($str) {
    2381     $str = str_replace("\r", '', $str);
    2382     $str = str_replace("\n", '', $str);
    2383     return trim($str);
     2531    return trim(str_replace(array("\r", "\n"), '', $str));
    23842532  }
    23852533
    23862534  /**
    class PHPMailer { 
    24872635    $DKIMtime             = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
    24882636    $subject_header       = "Subject: $subject";
    24892637    $headers              = explode($this->LE, $headers_line);
     2638        $from_header          = "";
     2639        $to_header            = "";
    24902640    foreach($headers as $header) {
    24912641      if (strpos($header, 'From:') === 0) {
    24922642        $from_header = $header;
    class PHPMailer { 
    25122662                "\tb=";
    25132663    $toSign   = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
    25142664    $signed   = $this->DKIM_Sign($toSign);
    2515     return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
     2665    return "X-PHPMAILER-DKIM: code.google.com/a/apache-extras.org/p/phpmailer/\r\n".$dkimhdrs.$signed."\r\n";
    25162666  }
    25172667
    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);
     2668  /**
     2669   * Perform callback
     2670   */
     2671  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) {
     2672    if (!empty($this->action_function) && is_callable($this->action_function)) {
     2673      $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
    25212674      call_user_func_array($this->action_function, $params);
    25222675    }
    25232676  }
    25242677}
    25252678
     2679/**
     2680 * Exception handling
     2681 */
    25262682class phpmailerException extends Exception {
    25272683  public function errorMessage() {
    25282684    $errorMsg = '<strong>' . $this->getMessage() . "</strong><br />\n";
  • wp-includes/class-smtp.php

    diff --git wp-includes/class-smtp.php wp-includes/class-smtp.php
    index 6977bff..cccaeae 100644
     
    22/*~ class.smtp.php
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 5.2.1                                                          |
     5|   Version: 5.2.2                                                          |
    66|      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
    77| ------------------------------------------------------------------------- |
    88|     Admin: Jim Jagielski (project admininistrator)                        |
     
    3232 * @author Jim Jagielski
    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/**
    class SMTP { 
    5150  public $SMTP_PORT = 25;
    5251
    5352  /**
    54    *  SMTP reply line ending
     53   *  SMTP reply line ending (don't change)
    5554   *  @var string
    5655   */
    5756  public $CRLF = "\r\n";
    class SMTP { 
    6362  public $do_debug;       // the level of debug to perform
    6463
    6564  /**
     65   * Sets the function/method to use for debugging output.
     66   * Right now we only honor "echo" or "error_log"
     67   * @var string
     68   */
     69  public $Debugoutput     = "echo";
     70
     71  /**
    6672   *  Sets VERP use on/off (default is off)
    6773   *  @var bool
    6874   */
    6975  public $do_verp = false;
    7076
    7177  /**
     78   * Sets the SMTP timeout value for reads, in seconds
     79   * @var int
     80   */
     81  public $Timeout         = 15;
     82
     83  /**
     84   * Sets the SMTP timelimit value for reads, in seconds
     85   * @var int
     86   */
     87  public $Timelimit       = 30;
     88
     89  /**
    7290   * Sets the SMTP PHPMailer Version number
    7391   * @var string
    7492   */
    75   public $Version         = '5.2.1';
     93  public $Version         = '5.2.2-rc2';
    7694
    7795  /////////////////////////////////////////////////
    7896  // PROPERTIES, PRIVATE AND PROTECTED
    class SMTP { 
    83101  private $helo_rply; // the reply the server sent to us for HELO
    84102
    85103  /**
     104   * Outputs debugging info via user-defined method
     105   * @param string $str
     106   */
     107  private function edebug($str) {
     108    if ($this->Debugoutput == "error_log") {
     109        error_log($str);
     110    } else {
     111        echo $str;
     112    }
     113  }
     114
     115  /**
    86116   * Initialize the class so that the data is in a known state.
    87117   * @access public
    88118   * @return void
    class SMTP { 
    139169                           "errno" => $errno,
    140170                           "errstr" => $errstr);
    141171      if($this->do_debug >= 1) {
    142         echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
     172        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />');
    143173      }
    144174      return false;
    145175    }
    146176
    147177    // SMTP server can take longer to respond, give longer timeout for first read
    148178    // 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);
     179    if(substr(PHP_OS, 0, 3) != "WIN") {
     180     $max = ini_get('max_execution_time');
     181     if ($max != 0 && $tval > $max) { // don't bother if unlimited
     182      @set_time_limit($tval);
     183     }
     184     stream_set_timeout($this->smtp_conn, $tval, 0);
     185    }
    151186
    152187    // get any announcement
    153188    $announce = $this->get_lines();
    154189
    155190    if($this->do_debug >= 2) {
    156       echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
     191      $this->edebug("SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />');
    157192    }
    158193
    159194    return true;
    class SMTP { 
    182217    $code = substr($rply,0,3);
    183218
    184219    if($this->do_debug >= 2) {
    185       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     220      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    186221    }
    187222
    188223    if($code != 220) {
    class SMTP { 
    191226               "smtp_code" => $code,
    192227               "smtp_msg"  => substr($rply,4));
    193228      if($this->do_debug >= 1) {
    194         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     229        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    195230      }
    196231      return false;
    197232    }
    class SMTP { 
    210245   * @access public
    211246   * @return bool
    212247   */
    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;
     248  public function Authenticate($username, $password, $authtype='LOGIN', $realm='',
     249                               $workstation='') {
     250    if (empty($authtype)) {
     251      $authtype = 'LOGIN';
     252    }
     253
     254    switch ($authtype) {
     255      case 'PLAIN':
     256        // Start authentication
     257        fputs($this->smtp_conn,"AUTH PLAIN" . $this->CRLF);
     258   
     259        $rply = $this->get_lines();
     260        $code = substr($rply,0,3);
     261   
     262        if($code != 334) {
     263          $this->error =
     264            array("error" => "AUTH not accepted from server",
     265                  "smtp_code" => $code,
     266                  "smtp_msg" => substr($rply,4));
     267          if($this->do_debug >= 1) {
     268            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     269          }
     270          return false;
     271        }
     272        // Send encoded username and password
     273        fputs($this->smtp_conn, base64_encode("\0".$username."\0".$password) . $this->CRLF);
     274
     275        $rply = $this->get_lines();
     276        $code = substr($rply,0,3);
     277   
     278        if($code != 235) {
     279          $this->error =
     280            array("error" => "Authentication not accepted from server",
     281                  "smtp_code" => $code,
     282                  "smtp_msg" => substr($rply,4));
     283          if($this->do_debug >= 1) {
     284            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     285          }
     286          return false;
     287        }
     288        break;
     289      case 'LOGIN':
     290        // Start authentication
     291        fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
     292   
     293        $rply = $this->get_lines();
     294        $code = substr($rply,0,3);
     295   
     296        if($code != 334) {
     297          $this->error =
     298            array("error" => "AUTH not accepted from server",
     299                  "smtp_code" => $code,
     300                  "smtp_msg" => substr($rply,4));
     301          if($this->do_debug >= 1) {
     302            $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     303          }
     304          return false;
     305        }
     306   
     307        // Send encoded username
     308        fputs($this->smtp_conn, base64_encode($username) . $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" => "Username 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 password
     325        fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
     326   
     327        $rply = $this->get_lines();
     328        $code = substr($rply,0,3);
     329   
     330        if($code != 235) {
     331          $this->error =
     332            array("error" => "Password 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        break;
     341      case 'NTLM':
     342        /*
     343         * ntlm_sasl_client.php
     344         ** Bundled with Permission
     345         **
     346         ** How to telnet in windows: http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
     347         ** PROTOCOL Documentation http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
     348         */
     349        require_once('ntlm_sasl_client.php');
     350        $temp = new stdClass();
     351        $ntlm_client = new ntlm_sasl_client_class;
     352        if(! $ntlm_client->Initialize($temp)){//let's test if every function its available
     353            $this->error = array("error" => $temp->error);
     354            if($this->do_debug >= 1) {
     355                $this->edebug("You need to enable some modules in your php.ini file: " . $this->error["error"] . $this->CRLF);
     356            }
     357            return false;
     358        }
     359        $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);//msg1
     360       
     361        fputs($this->smtp_conn,"AUTH NTLM " . base64_encode($msg1) . $this->CRLF);
     362
     363        $rply = $this->get_lines();
     364        $code = substr($rply,0,3);
     365       
     366
     367        if($code != 334) {
     368            $this->error =
     369                array("error" => "AUTH not accepted from server",
     370                      "smtp_code" => $code,
     371                      "smtp_msg" => substr($rply,4));
     372            if($this->do_debug >= 1) {
     373                $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
     374            }
     375            return false;
     376        }
     377       
     378        $challange = substr($rply,3);//though 0 based, there is a white space after the 3 digit number....//msg2
     379        $challange = base64_decode($challange);
     380        $ntlm_res = $ntlm_client->NTLMResponse(substr($challange,24,8),$password);
     381        $msg3 = $ntlm_client->TypeMsg3($ntlm_res,$username,$realm,$workstation);//msg3
     382        // Send encoded username
     383        fputs($this->smtp_conn, base64_encode($msg3) . $this->CRLF);
     384
     385        $rply = $this->get_lines();
     386        $code = substr($rply,0,3);
     387
     388        if($code != 235) {
     389            $this->error =
     390                array("error" => "Could not authenticate",
     391                      "smtp_code" => $code,
     392                      "smtp_msg" => substr($rply,4));
     393            if($this->do_debug >= 1) {
     394                $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
     395            }
     396            return false;
     397        }
     398        break;
    263399    }
    264 
    265400    return true;
    266401  }
    267402
    class SMTP { 
    276411      if($sock_status["eof"]) {
    277412        // the socket is valid but we are not connected
    278413        if($this->do_debug >= 1) {
    279             echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
     414            $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected");
    280415        }
    281416        $this->Close();
    282417        return false;
    class SMTP { 
    341476    $code = substr($rply,0,3);
    342477
    343478    if($this->do_debug >= 2) {
    344       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     479      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    345480    }
    346481
    347482    if($code != 354) {
    class SMTP { 
    350485              "smtp_code" => $code,
    351486              "smtp_msg" => substr($rply,4));
    352487      if($this->do_debug >= 1) {
    353         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     488        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    354489      }
    355490      return false;
    356491    }
    class SMTP { 
    435570    $code = substr($rply,0,3);
    436571
    437572    if($this->do_debug >= 2) {
    438       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     573      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    439574    }
    440575
    441576    if($code != 250) {
    class SMTP { 
    444579              "smtp_code" => $code,
    445580              "smtp_msg" => substr($rply,4));
    446581      if($this->do_debug >= 1) {
    447         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     582        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    448583      }
    449584      return false;
    450585    }
    class SMTP { 
    500635    $code = substr($rply,0,3);
    501636
    502637    if($this->do_debug >= 2) {
    503       echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
     638      $this->edebug("SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />');
    504639    }
    505640
    506641    if($code != 250) {
    class SMTP { 
    509644              "smtp_code" => $code,
    510645              "smtp_msg" => substr($rply,4));
    511646      if($this->do_debug >= 1) {
    512         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     647        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    513648      }
    514649      return false;
    515650    }
    class SMTP { 
    542677      return false;
    543678    }
    544679
    545     $useVerp = ($this->do_verp ? "XVERP" : "");
     680    $useVerp = ($this->do_verp ? " XVERP" : "");
    546681    fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
    547682
    548683    $rply = $this->get_lines();
    549684    $code = substr($rply,0,3);
    550685
    551686    if($this->do_debug >= 2) {
    552       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     687      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    553688    }
    554689
    555690    if($code != 250) {
    class SMTP { 
    558693              "smtp_code" => $code,
    559694              "smtp_msg" => substr($rply,4));
    560695      if($this->do_debug >= 1) {
    561         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     696        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    562697      }
    563698      return false;
    564699    }
    class SMTP { 
    592727    $byemsg = $this->get_lines();
    593728
    594729    if($this->do_debug >= 2) {
    595       echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
     730      $this->edebug("SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />');
    596731    }
    597732
    598733    $rval = true;
    class SMTP { 
    606741                 "smtp_rply" => substr($byemsg,4));
    607742      $rval = false;
    608743      if($this->do_debug >= 1) {
    609         echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
     744        $this->edebug("SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />');
    610745      }
    611746    }
    612747
    class SMTP { 
    644779    $code = substr($rply,0,3);
    645780
    646781    if($this->do_debug >= 2) {
    647       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     782      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    648783    }
    649784
    650785    if($code != 250 && $code != 251) {
    class SMTP { 
    653788              "smtp_code" => $code,
    654789              "smtp_msg" => substr($rply,4));
    655790      if($this->do_debug >= 1) {
    656         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     791        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    657792      }
    658793      return false;
    659794    }
    class SMTP { 
    687822    $code = substr($rply,0,3);
    688823
    689824    if($this->do_debug >= 2) {
    690       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     825      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    691826    }
    692827
    693828    if($code != 250) {
    class SMTP { 
    696831              "smtp_code" => $code,
    697832              "smtp_msg" => substr($rply,4));
    698833      if($this->do_debug >= 1) {
    699         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     834        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    700835      }
    701836      return false;
    702837    }
    class SMTP { 
    735870    $code = substr($rply,0,3);
    736871
    737872    if($this->do_debug >= 2) {
    738       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     873      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    739874    }
    740875
    741876    if($code != 250) {
    class SMTP { 
    744879              "smtp_code" => $code,
    745880              "smtp_msg" => substr($rply,4));
    746881      if($this->do_debug >= 1) {
    747         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     882        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    748883      }
    749884      return false;
    750885    }
    class SMTP { 
    768903    $this->error = array("error" => "This method, TURN, of the SMTP ".
    769904                                    "is not implemented");
    770905    if($this->do_debug >= 1) {
    771       echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
     906      $this->edebug("SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />');
    772907    }
    773908    return false;
    774909  }
    class SMTP { 
    797932   */
    798933  private function get_lines() {
    799934    $data = "";
    800     while(!feof($this->smtp_conn)) {
     935    $endtime = 0;
     936    /* If for some reason the fp is bad, don't inf loop */
     937    if (!is_resource($this->smtp_conn)) {
     938      return $data;
     939    }
     940    stream_set_timeout($this->smtp_conn, $this->Timeout);
     941    if ($this->Timelimit > 0) {
     942      $endtime = time() + $this->Timelimit;
     943    }
     944    while(is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
    801945      $str = @fgets($this->smtp_conn,515);
    802946      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 />';
     947        $this->edebug("SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />');
     948        $this->edebug("SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />');
    805949      }
    806950      $data .= $str;
    807951      if($this->do_debug >= 4) {
    808         echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
     952        $this->edebug("SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />');
    809953      }
    810954      // if 4th character is a space, we are done reading, break the loop
    811955      if(substr($str,3,1) == " ") { break; }
     956      // Timed-out? Log and break
     957      $info = stream_get_meta_data($this->smtp_conn);
     958      if ($info['timed_out']) {
     959        if($this->do_debug >= 4) {
     960          $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " seconds) <br />");
     961        }
     962        break;
     963      }
     964      // Now check if reads took too long
     965      if ($endtime) {
     966        if (time() > $endtime) {
     967          if($this->do_debug >= 4) {
     968            $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " seconds) <br />");
     969          }
     970          break;
     971        }
     972      }
    812973    }
    813974    return $data;
    814975  }