WordPress.org

Make WordPress Core

Ticket #21074: 21074-phpmailer-5.2.2-beta1.patch

File 21074-phpmailer-5.2.2-beta1.patch, 48.3 KB (added by bpetty, 6 years ago)
  • wp-includes/class-phpmailer.php

    diff --git wp-includes/class-phpmailer.php wp-includes/class-phpmailer.php
    index df533c2..fabce41 100644
     
    22/*~ class.phpmailer.php
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 5.2.1                                                          |
     5|   Version: 5.2.2-beta1                                                          |
    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 { 
    235247  public $Password      = '';
    236248
    237249  /**
    238    * Sets the SMTP server timeout in seconds.
     250   *  Sets SMTP auth type.
     251   *  @var string
     252   */
     253  public $AuthType      = '';
     254 
     255  /**
     256   *  Sets SMTP realm.
     257   *  @var string
     258   */
     259  public $Realm         = '';
     260
     261  /**
     262   *  Sets SMTP workstation.
     263   *  @var string
     264   */
     265  public $Workstation   = '';
     266
     267  /**
     268   * Sets the SMTP server   in seconds.
    239269   * This function will not work with the win32 version.
    240270   * @var int
    241271   */
    class PHPMailer { 
    248278  public $SMTPDebug     = false;
    249279
    250280  /**
     281   * Sets the function/method to use for debugging output.
     282   * Right now we only honor "echo" or "error_log"
     283   * @var string
     284   */
     285  public $Debugoutput     = "echo";
     286
     287  /**
    251288   * Prevents the SMTP connection from being closed after each mail
    252289   * sending.  If this is set to true then to close the connection
    253290   * requires an explicit call to SmtpClose().
    class PHPMailer { 
    269306  public $SingleToArray = array();
    270307
    271308 /**
    272    * Provides the ability to change the line ending
     309   * Provides the ability to change the generic line ending
     310   * NOTE: The default is now the SMTP RFC line-ending sequence,
     311   *       however, we still allow for the end-user to reset to "\n"
     312   *       if need be. We force CRLF where we KNOW it must be used
     313   *       via self::CRLF
    273314   * @var string
    274315   */
    275   public $LE              = "\n";
     316  public $LE              = "\r\n";
    276317
    277   /**
     318   /**
    278319   * Used with DKIM DNS Resource Record
    279320   * @var string
    280321   */
    class PHPMailer { 
    308349  public $DKIM_private    = '';
    309350
    310351  /**
    311    * Callback Action function name
    312    * the function that handles the result of the send email action. Parameters:
     352   * Callback Action function name.
     353   * The function that handles the result of the send email action.
     354   * It is called out by Send() for each email sent.
     355   *
     356   * Value can be:
     357   * - 'function_name' for function names
     358   * - 'Class::Method' for static method calls
     359   * - array($object, 'Method') for calling methods on $object
     360   * See http://php.net/is_callable manual page for more details.
     361   *
     362   * Parameters:
    313363   *   bool    $result        result of the send action
    314364   *   string  $to            email address of the recipient
    315365   *   string  $cc            cc email addresses
    class PHPMailer { 
    324374   * Sets the PHPMailer Version number
    325375   * @var string
    326376   */
    327   public $Version         = '5.2.1';
     377  public $Version         = '5.2.2-beta1';
    328378
    329379  /**
    330380   * What to use in the X-Mailer header
    331    * @var string
     381   * @var string NULL for default, whitespace for None, or actual string to use
    332382   */
    333383  public $XMailer         = '';
    334384
    class PHPMailer { 
    360410  const STOP_MESSAGE  = 0; // message only, continue processing
    361411  const STOP_CONTINUE = 1; // message?, likely ok to continue processing
    362412  const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
    363 
     413  const CRLF = "\r\n";     // SMTP RFC specified EOL
     414 
    364415  /////////////////////////////////////////////////
    365416  // METHODS, VARIABLES
    366417  /////////////////////////////////////////////////
    367418
    368419  /**
     420   * Calls actual mail() function, but in a safe_mode aware fashion
     421   * Also, unless sendmail_path points to sendmail (or something that
     422   * claims to be sendmail), don't pass params (not a perfect fix,
     423   * but it will do)
     424   * @param string $to To
     425   * @param string $subject Subject
     426   * @param string $body Message Body
     427   * @param string $header Additional Header(s)
     428   * @param string $params Params
     429   * @access private
     430   * @return bool
     431   */
     432  private function mail_passthru($to, $subject, $body, $header, $params) {
     433    if ( ini_get('safe_mode') || !strstr(ini_get("sendmail_path"), 'sendmail') ) {
     434        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header);
     435    } else {
     436        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($subject)), $body, $header, $params);
     437    }
     438    return $rt;
     439  }
     440
     441  /**
     442   * Outputs debugging info via user-defined method
     443   * @param string $str
     444   */
     445  private function edebug($str) {
     446    if ($this->Debugoutput == "error_log") {
     447        error_log($str);
     448    } else {
     449        echo $str;
     450    }
     451  }
     452
     453  /**
    369454   * Constructor
    370455   * @param boolean $exceptions Should we throw external exceptions?
    371456   */
    class PHPMailer { 
    485570      if ($this->exceptions) {
    486571        throw new phpmailerException('Invalid recipient array: ' . $kind);
    487572      }
    488           if ($this->SMTPDebug) {
    489         echo $this->Lang('Invalid recipient array').': '.$kind;
     573      if ($this->SMTPDebug) {
     574        $this->edebug($this->Lang('Invalid recipient array').': '.$kind);
    490575      }
    491576      return false;
    492577    }
    class PHPMailer { 
    497582      if ($this->exceptions) {
    498583        throw new phpmailerException($this->Lang('invalid_address').': '.$address);
    499584      }
    500           if ($this->SMTPDebug) {
    501         echo $this->Lang('invalid_address').': '.$address;
     585      if ($this->SMTPDebug) {
     586        $this->edebug($this->Lang('invalid_address').': '.$address);
    502587      }
    503588      return false;
    504589    }
    class PHPMailer { 
    521606 * Set the From and FromName properties
    522607 * @param string $address
    523608 * @param string $name
     609 * @param int $auto Also set Reply-To and Sender
    524610 * @return boolean
    525611 */
    526612  public function SetFrom($address, $name = '', $auto = 1) {
    class PHPMailer { 
    531617      if ($this->exceptions) {
    532618        throw new phpmailerException($this->Lang('invalid_address').': '.$address);
    533619      }
    534           if ($this->SMTPDebug) {
    535         echo $this->Lang('invalid_address').': '.$address;
     620      if ($this->SMTPDebug) {
     621        $this->edebug($this->Lang('invalid_address').': '.$address);
    536622      }
    537623      return false;
    538624    }
    class PHPMailer { 
    587673      if(!$this->PreSend()) return false;
    588674      return $this->PostSend();
    589675    } catch (phpmailerException $e) {
    590           $this->SentMIMEMessage = '';
     676      $this->mailHeader = '';
    591677      $this->SetError($e->getMessage());
    592678      if ($this->exceptions) {
    593679        throw $e;
    class PHPMailer { 
    596682    }
    597683  }
    598684
    599   protected function PreSend() {
     685  /**
     686   * Prep mail by constructing all message entities
     687   * @return bool
     688   */
     689  public function PreSend() {
    600690    try {
    601           $mailHeader = "";
     691      $this->mailHeader = "";
    602692      if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
    603693        throw new phpmailerException($this->Lang('provide_address'), self::STOP_CRITICAL);
    604694      }
    class PHPMailer { 
    619709      $this->MIMEBody = $this->CreateBody();
    620710
    621711      // To capture the complete message when using mail(), create
    622           // an extra header list which CreateHeader() doesn't fold in
     712      // an extra header list which CreateHeader() doesn't fold in
    623713      if ($this->Mailer == 'mail') {
    624714        if (count($this->to) > 0) {
    625           $mailHeader .= $this->AddrAppend("To", $this->to);
     715          $this->mailHeader .= $this->AddrAppend("To", $this->to);
    626716        } else {
    627           $mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
     717          $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
    628718        }
    629         $mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
     719        $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
    630720        // if(count($this->cc) > 0) {
    631             // $mailHeader .= $this->AddrAppend("Cc", $this->cc);
     721            // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc);
    632722        // }
    633723      }
    634724
    class PHPMailer { 
    638728        $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
    639729      }
    640730
    641       $this->SentMIMEMessage = sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$mailHeader,$this->MIMEBody);
    642731      return true;
    643732
    644733    } catch (phpmailerException $e) {
    class PHPMailer { 
    650739    }
    651740  }
    652741
    653   protected function PostSend() {
     742  /**
     743   * Actual Email transport function
     744   * Send the email via the selected mechanism
     745   * @return bool
     746   */
     747  public function PostSend() {
     748    $rtn = false;
    654749    try {
    655750      // Choose the mailer and send through it
    656751      switch($this->Mailer) {
    657752        case 'sendmail':
    658           return $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
     753          $rtn = $this->SendmailSend($this->MIMEHeader, $this->MIMEBody);
     754          break;
    659755        case 'smtp':
    660           return $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
     756          $rtn = $this->SmtpSend($this->MIMEHeader, $this->MIMEBody);
     757          break;
    661758        case 'mail':
    662           return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
     759          $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody);
     760          break;
    663761        default:
    664           return $this->MailSend($this->MIMEHeader, $this->MIMEBody);
     762          $rtn = $this->MailSend($this->MIMEHeader, $this->MIMEBody);
     763          break;
    665764      }
    666765
    667766    } catch (phpmailerException $e) {
    class PHPMailer { 
    669768      if ($this->exceptions) {
    670769        throw $e;
    671770      }
    672           if ($this->SMTPDebug) {
    673         echo $e->getMessage()."\n";
     771      if ($this->SMTPDebug) {
     772        $this->edebug($e->getMessage()."\n");
    674773      }
    675774      return false;
    676775    }
     776    return $rtn;
    677777  }
    678778
    679779  /**
    class PHPMailer { 
    744844    if ($this->Sender != '' and !ini_get('safe_mode')) {
    745845      $old_from = ini_get('sendmail_from');
    746846      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);
     847    }
     848    if ($this->SingleTo === true && count($toArr) > 1) {
     849      foreach ($toArr as $key => $val) {
     850        $rt = $this->mail_passthru($val, $this->Subject, $body, $header, $params);
    756851        // implement call back function if it exists
    757852        $isSent = ($rt == 1) ? 1 : 0;
    758         $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
     853        $this->doCallback($isSent, $val, $this->cc, $this->bcc, $this->Subject, $body);
    759854      }
    760855    } 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       }
     856      $rt = $this->mail_passthru($to, $this->Subject, $body, $header, $params);
     857      // implement call back function if it exists
     858      $isSent = ($rt == 1) ? 1 : 0;
     859      $this->doCallback($isSent, $to, $this->cc, $this->bcc, $this->Subject, $body);
    774860    }
    775861    if (isset($old_from)) {
    776862      ini_set('sendmail_from', $old_from);
    class PHPMailer { 
    791877   * @return bool
    792878   */
    793879  protected function SmtpSend($header, $body) {
    794     require_once $this->PluginDir . 'class-smtp.php';
     880    require_once $this->PluginDir . 'class.smtp.php';
    795881    $bad_rcpt = array();
    796882
    797883    if(!$this->SmtpConnect()) {
    class PHPMailer { 
    866952      $this->smtp = new SMTP();
    867953    }
    868954
     955    $this->smtp->Timeout = $this->Timeout;
    869956    $this->smtp->do_debug = $this->SMTPDebug;
    870957    $hosts = explode(';', $this->Host);
    871958    $index = 0;
    872959    $connection = $this->smtp->Connected();
     960    $rtn = true;
    873961
    874962    // Retry while there is no connection
    875963    try {
    class PHPMailer { 
    893981
    894982          if ($tls) {
    895983            if (!$this->smtp->StartTLS()) {
     984              $rtn = false;
    896985              throw new phpmailerException($this->Lang('tls'));
    897986            }
    898987
    class PHPMailer { 
    902991
    903992          $connection = true;
    904993          if ($this->SMTPAuth) {
    905             if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
     994            if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType,
     995                                           $this->Realm, $this->Workstation)) {
     996              $rtn = false;
    906997              throw new phpmailerException($this->Lang('authenticate'));
    907998            }
    908999          }
    9091000        }
    9101001        $index++;
    9111002        if (!$connection) {
     1003          $rtn = false;
    9121004          throw new phpmailerException($this->Lang('connect_host'));
    9131005        }
    9141006      }
    9151007    } catch (phpmailerException $e) {
    9161008      $this->smtp->Reset();
    917           if ($this->exceptions) {
     1009      if ($this->exceptions) {
    9181010        throw $e;
    9191011      }
     1012      $rtn = false;
    9201013    }
    921     return true;
     1014    return $rtn;
    9221015  }
    9231016
    9241017  /**
    class PHPMailer { 
    10281121    // If utf-8 encoding is used, we will need to make sure we don't
    10291122    // split multibyte characters when we wrap
    10301123    $is_utf8 = (strtolower($this->CharSet) == "utf-8");
     1124    $lelen = strlen($this->LE);
     1125    $crlflen = strlen(self::CRLF);
    10311126
    10321127    $message = $this->FixEOL($message);
    1033     if (substr($message, -1) == $this->LE) {
    1034       $message = substr($message, 0, -1);
     1128    if (substr($message, -$lelen) == $this->LE) {
     1129      $message = substr($message, 0, -$lelen);
    10351130    }
    10361131
    1037     $line = explode($this->LE, $message);
     1132    $line = explode($this->LE, $message);   // Magic. We know FixEOL uses $LE
    10381133    $message = '';
    10391134    for ($i = 0 ;$i < count($line); $i++) {
    10401135      $line_part = explode(' ', $line[$i]);
    class PHPMailer { 
    10421137      for ($e = 0; $e<count($line_part); $e++) {
    10431138        $word = $line_part[$e];
    10441139        if ($qp_mode and (strlen($word) > $length)) {
    1045           $space_left = $length - strlen($buf) - 1;
     1140          $space_left = $length - strlen($buf) - $crlflen;
    10461141          if ($e != 0) {
    10471142            if ($space_left > 20) {
    10481143              $len = $space_left;
    class PHPMailer { 
    10561151              $part = substr($word, 0, $len);
    10571152              $word = substr($word, $len);
    10581153              $buf .= ' ' . $part;
    1059               $message .= $buf . sprintf("=%s", $this->LE);
     1154              $message .= $buf . sprintf("=%s", self::CRLF);
    10601155            } else {
    10611156              $message .= $buf . $soft_break;
    10621157            }
    class PHPMailer { 
    10751170            $word = substr($word, $len);
    10761171
    10771172            if (strlen($word) > 0) {
    1078               $message .= $part . sprintf("=%s", $this->LE);
     1173              $message .= $part . sprintf("=%s", self::CRLF);
    10791174            } else {
    10801175              $buf = $part;
    10811176            }
    class PHPMailer { 
    10901185          }
    10911186        }
    10921187      }
    1093       $message .= $buf . $this->LE;
     1188      $message .= $buf . self::CRLF;
    10941189    }
    10951190
    10961191    return $message;
    class PHPMailer { 
    11761271    $this->boundary[3] = 'b3_' . $uniq_id;
    11771272
    11781273    $result .= $this->HeaderLine('Date', self::RFCDate());
    1179     if($this->Sender == '') {
     1274    if ($this->ReturnPath) {
     1275      $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath));
     1276    } elseif ($this->Sender == '') {
    11801277      $result .= $this->HeaderLine('Return-Path', trim($this->From));
    11811278    } else {
    11821279      $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
    class PHPMailer { 
    11951292          $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
    11961293        }
    11971294      }
    1198         }
     1295    }
    11991296
    12001297    $from = array();
    12011298    $from[0][0] = trim($this->From);
    class PHPMailer { 
    12271324      $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
    12281325    }
    12291326    $result .= $this->HeaderLine('X-Priority', $this->Priority);
    1230     if($this->XMailer) {
    1231       $result .= $this->HeaderLine('X-Mailer', $this->XMailer);
     1327    if ($this->XMailer == '') {
     1328        $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
    12321329    } else {
    1233       $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
     1330      $myXmailer = trim($this->XMailer);
     1331      if ($myXmailer) {
     1332        $result .= $this->HeaderLine('X-Mailer', $myXmailer);
     1333      }
    12341334    }
    12351335
    12361336    if($this->ConfirmReadingTo != '') {
    class PHPMailer { 
    12571357  public function GetMailMIME() {
    12581358    $result = '';
    12591359    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;
    12641360      case 'inline':
    12651361        $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
    12661362        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
    class PHPMailer { 
    12771373        $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
    12781374        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
    12791375        break;
     1376      default:
     1377        // Catches case 'plain': and case '':
     1378        $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
     1379        $result .= $this->TextLine('Content-Type: '.$this->ContentType.'; charset='.$this->CharSet);
     1380        break;
    12801381    }
    12811382
    12821383    if($this->Mailer != 'mail') {
    class PHPMailer { 
    12921393   * @return string
    12931394   */
    12941395  public function GetSentMIMEMessage() {
    1295     return $this->SentMIMEMessage;
     1396    return sprintf("%s%s\r\n\r\n%s",$this->MIMEHeader,$this->mailHeader,$this->MIMEBody);
    12961397  }
    12971398
    12981399
    class PHPMailer { 
    13051406    $body = '';
    13061407
    13071408    if ($this->sign_key_file) {
    1308       $body .= $this->GetMailMIME();
     1409      $body .= $this->GetMailMIME().$this->LE;
    13091410    }
    13101411
    13111412    $this->SetWordWrap();
    13121413
    13131414    switch($this->message_type) {
    1314       case 'plain':
    1315         $body .= $this->EncodeString($this->Body, $this->Encoding);
    1316         break;
    13171415      case 'inline':
    13181416        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
    13191417        $body .= $this->EncodeString($this->Body, $this->Encoding);
    class PHPMailer { 
    13211419        $body .= $this->AttachAll("inline", $this->boundary[1]);
    13221420        break;
    13231421      case 'attach':
    1324         $body .= $this->GetBoundary($this->boundary[1], '', '', '');
     1422        $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
    13251423        $body .= $this->EncodeString($this->Body, $this->Encoding);
    13261424        $body .= $this->LE.$this->LE;
    13271425        $body .= $this->AttachAll("attachment", $this->boundary[1]);
    class PHPMailer { 
    13981496        $body .= $this->LE;
    13991497        $body .= $this->AttachAll("attachment", $this->boundary[1]);
    14001498        break;
     1499      default:
     1500        // catch case 'plain' and case ''
     1501        $body .= $this->EncodeString($this->Body, $this->Encoding);
     1502        break;
    14011503    }
    14021504
    14031505    if ($this->IsError()) {
    class PHPMailer { 
    14441546      $encoding = $this->Encoding;
    14451547    }
    14461548    $result .= $this->TextLine('--' . $boundary);
    1447     $result .= sprintf("Content-Type: %s; charset=\"%s\"", $contentType, $charSet);
     1549    $result .= sprintf("Content-Type: %s; charset=%s", $contentType, $charSet);
    14481550    $result .= $this->LE;
    14491551    $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
    14501552    $result .= $this->LE;
    class PHPMailer { 
    15331635      if ($this->exceptions) {
    15341636        throw $e;
    15351637      }
    1536           if ($this->SMTPDebug) {
    1537         echo $e->getMessage()."\n";
     1638      if ($this->SMTPDebug) {
     1639        $this->edebug($e->getMessage()."\n");
    15381640      }
    15391641      if ( $e->getCode() == self::STOP_CRITICAL ) {
    15401642        return false;
    class PHPMailer { 
    16331735      if (!is_readable($path)) {
    16341736        throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
    16351737      }
    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) {
     1738      //  if (!function_exists('get_magic_quotes')) {
     1739      //    function get_magic_quotes() {
     1740      //      return false;
     1741      //    }
     1742      //  }
     1743      $magic_quotes = get_magic_quotes_runtime();
     1744      if ($magic_quotes) {
    16431745        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    16441746          set_magic_quotes_runtime(0);
    16451747        } else {
    1646                   ini_set('magic_quotes_runtime', 0);
    1647                 }
    1648           }
     1748          ini_set('magic_quotes_runtime', 0);
     1749        }
     1750      }
    16491751      $file_buffer  = file_get_contents($path);
    16501752      $file_buffer  = $this->EncodeString($file_buffer, $encoding);
    1651           if ($magic_quotes) {
     1753      if ($magic_quotes) {
    16521754        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    16531755          set_magic_quotes_runtime($magic_quotes);
    16541756        } else {
    1655                   ini_set('magic_quotes_runtime', $magic_quotes);
    1656             }
    1657           }
     1757          ini_set('magic_quotes_runtime', $magic_quotes);
     1758        }
     1759      }
    16581760      return $file_buffer;
    16591761    } catch (Exception $e) {
    16601762      $this->SetError($e->getMessage());
    class PHPMailer { 
    20272129  }
    20282130
    20292131  public function AlternativeExists() {
    2030     return strlen($this->AltBody)>0;
     2132    return !empty($this->AltBody);
    20312133  }
    20322134
    20332135  /////////////////////////////////////////////////
    class PHPMailer { 
    21842286  }
    21852287
    21862288  /**
    2187    * Changes every end of line from CR or LF to CRLF.
     2289   * Changes every end of line from CR or LF to $this->LE.
    21882290   * @access public
    21892291   * @return string
    21902292   */
    21912293  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;
     2294    return str_replace(array("\r\n", "\r", "\n"), $this->LE, $str);
    21962295  }
    21972296
    21982297  /**
    class PHPMailer { 
    22312330    }
    22322331    $this->IsHTML(true);
    22332332    $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         }
     2333    if (empty($this->AltBody)) {
     2334        $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
     2335        if (!empty($textMsg)) {
     2336            $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
     2337        }
     2338    }
    22402339    if (empty($this->AltBody)) {
    22412340      $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
    22422341    }
    2243         return $message;
     2342    return $message;
    22442343  }
    22452344
    22462345  /**
    class PHPMailer { 
    22522351   */
    22532352  public static function _mime_types($ext = '') {
    22542353    $mimes = array(
     2354      'xl'    =>  'application/excel',
    22552355      'hqx'   =>  'application/mac-binhex40',
    22562356      'cpt'   =>  'application/mac-compactpro',
    2257       'doc'   =>  'application/msword',
    22582357      'bin'   =>  'application/macbinary',
     2358      'doc'   =>  'application/msword',
     2359      'doc'   =>  'application/msword',
     2360      'word'  =>  'application/msword',
     2361      'class' =>  'application/octet-stream',
     2362      'dll'   =>  'application/octet-stream',
    22592363      'dms'   =>  'application/octet-stream',
     2364      'exe'   =>  'application/octet-stream',
    22602365      'lha'   =>  'application/octet-stream',
    22612366      'lzh'   =>  'application/octet-stream',
    2262       'exe'   =>  'application/octet-stream',
    2263       'class' =>  'application/octet-stream',
    22642367      'psd'   =>  'application/octet-stream',
    2265       'so'    =>  'application/octet-stream',
    22662368      'sea'   =>  'application/octet-stream',
    2267       'dll'   =>  'application/octet-stream',
     2369      'so'    =>  'application/octet-stream',
    22682370      'oda'   =>  'application/oda',
    22692371      'pdf'   =>  'application/pdf',
    22702372      'ai'    =>  'application/postscript',
    class PHPMailer { 
    22822384      'dxr'   =>  'application/x-director',
    22832385      'dvi'   =>  'application/x-dvi',
    22842386      'gtar'  =>  'application/x-gtar',
    2285       'php'   =>  'application/x-httpd-php',
    2286       'php4'  =>  'application/x-httpd-php',
    22872387      'php3'  =>  'application/x-httpd-php',
     2388      'php4'  =>  'application/x-httpd-php',
     2389      'php'   =>  'application/x-httpd-php',
    22882390      'phtml' =>  'application/x-httpd-php',
    22892391      'phps'  =>  'application/x-httpd-php-source',
    22902392      'js'    =>  'application/x-javascript',
    class PHPMailer { 
    22922394      'sit'   =>  'application/x-stuffit',
    22932395      'tar'   =>  'application/x-tar',
    22942396      'tgz'   =>  'application/x-tar',
    2295       'xhtml' =>  'application/xhtml+xml',
    22962397      'xht'   =>  'application/xhtml+xml',
     2398      'xhtml' =>  'application/xhtml+xml',
    22972399      'zip'   =>  'application/zip',
    22982400      'mid'   =>  'audio/midi',
    22992401      'midi'  =>  'audio/midi',
    2300       'mpga'  =>  'audio/mpeg',
    23012402      'mp2'   =>  'audio/mpeg',
    23022403      'mp3'   =>  'audio/mpeg',
     2404      'mpga'  =>  'audio/mpeg',
    23032405      'aif'   =>  'audio/x-aiff',
    2304       'aiff'  =>  'audio/x-aiff',
    23052406      'aifc'  =>  'audio/x-aiff',
     2407      'aiff'  =>  'audio/x-aiff',
    23062408      'ram'   =>  'audio/x-pn-realaudio',
    23072409      'rm'    =>  'audio/x-pn-realaudio',
    23082410      'rpm'   =>  'audio/x-pn-realaudio-plugin',
    23092411      'ra'    =>  'audio/x-realaudio',
    2310       'rv'    =>  'video/vnd.rn-realvideo',
    23112412      'wav'   =>  'audio/x-wav',
    23122413      'bmp'   =>  'image/bmp',
    23132414      'gif'   =>  'image/gif',
    23142415      'jpeg'  =>  'image/jpeg',
    2315       'jpg'   =>  'image/jpeg',
    23162416      'jpe'   =>  'image/jpeg',
     2417      'jpg'   =>  'image/jpeg',
    23172418      'png'   =>  'image/png',
    23182419      'tiff'  =>  'image/tiff',
    23192420      'tif'   =>  'image/tiff',
     2421      'eml'   =>  'message/rfc822',
    23202422      'css'   =>  'text/css',
    23212423      'html'  =>  'text/html',
    23222424      'htm'   =>  'text/html',
    23232425      'shtml' =>  'text/html',
    2324       'txt'   =>  'text/plain',
    2325       'text'  =>  'text/plain',
    23262426      'log'   =>  'text/plain',
     2427      'text'  =>  'text/plain',
     2428      'txt'   =>  'text/plain',
    23272429      'rtx'   =>  'text/richtext',
    23282430      'rtf'   =>  'text/rtf',
    23292431      'xml'   =>  'text/xml',
    23302432      'xsl'   =>  'text/xml',
    23312433      'mpeg'  =>  'video/mpeg',
    2332       'mpg'   =>  'video/mpeg',
    23332434      'mpe'   =>  'video/mpeg',
    2334       'qt'    =>  'video/quicktime',
     2435      'mpg'   =>  'video/mpeg',
    23352436      'mov'   =>  'video/quicktime',
     2437      'qt'    =>  'video/quicktime',
     2438      'rv'    =>  'video/vnd.rn-realvideo',
    23362439      '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'
     2440      'movie' =>  'video/x-sgi-movie'
    23422441    );
    23432442    return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
    23442443  }
    class PHPMailer { 
    23782477   * @return string
    23792478   */
    23802479  public function SecureHeader($str) {
    2381     $str = str_replace("\r", '', $str);
    2382     $str = str_replace("\n", '', $str);
    2383     return trim($str);
     2480    return trim(str_replace(array("\r", "\n"), '', $str));
    23842481  }
    23852482
    23862483  /**
    class PHPMailer { 
    25152612    return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n".$dkimhdrs.$signed."\r\n";
    25162613  }
    25172614
     2615  /**
     2616   * Perform callback
     2617   */
    25182618  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body) {
    2519     if (!empty($this->action_function) && function_exists($this->action_function)) {
     2619    if (!empty($this->action_function) && is_callable($this->action_function)) {
    25202620      $params = array($isSent, $to, $cc, $bcc, $subject, $body);
    25212621      call_user_func_array($this->action_function, $params);
    25222622    }
    25232623  }
    25242624}
    25252625
     2626/**
     2627 * Exception handling
     2628 */
    25262629class phpmailerException extends Exception {
    25272630  public function errorMessage() {
    25282631    $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..49331c3 100644
     
    22/*~ class.smtp.php
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 5.2.1                                                          |
     5|   Version: 5.2.2-beta1                                                          |
    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 { 
    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-beta1';
    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 'LOGIN':
     256        // Start authentication
     257        fputs($this->smtp_conn,"AUTH LOGIN" . $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   
     273        // Send encoded username
     274        fputs($this->smtp_conn, base64_encode($username) . $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" => "Username 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   
     290        // Send encoded password
     291        fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
     292   
     293        $rply = $this->get_lines();
     294        $code = substr($rply,0,3);
     295   
     296        if($code != 235) {
     297          $this->error =
     298            array("error" => "Password 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        break;
     307      case 'NTLM':
     308        /*
     309         * ntlm_sasl_client.php
     310         ** Bundled with Permission
     311         **
     312         ** How to telnet in windows: http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
     313         ** PROTOCOL Documentation http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
     314         */
     315        require_once('ntlm_sasl_client.php');
     316        $temp = new stdClass();
     317        $ntlm_client = new ntlm_sasl_client_class;
     318        if(! $ntlm_client->Initialize($temp)){//let's test if every function its available
     319            $this->error = array("error" => $temp->error);
     320            if($this->do_debug >= 1) {
     321                $this->edebug("You need to enable some modules in your php.ini file: " . $this->error["error"] . $this->CRLF);
     322            }
     323            return false;
     324        }
     325        $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);//msg1
     326       
     327        fputs($this->smtp_conn,"AUTH NTLM " . base64_encode($msg1) . $this->CRLF);
     328
     329        $rply = $this->get_lines();
     330        $code = substr($rply,0,3);
     331       
     332
     333        if($code != 334) {
     334            $this->error =
     335                array("error" => "AUTH not accepted from server",
     336                      "smtp_code" => $code,
     337                      "smtp_msg" => substr($rply,4));
     338            if($this->do_debug >= 1) {
     339                $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
     340            }
     341            return false;
     342        }
     343       
     344        $challange = substr($rply,3);//though 0 based, there is a white space after the 3 digit number....//msg2
     345        $challange = base64_decode($challange);
     346        $ntlm_res = $ntlm_client->NTLMResponse(substr($challange,24,8),$password);
     347        $msg3 = $ntlm_client->TypeMsg3($ntlm_res,$username,$realm,$workstation);//msg3
     348        // Send encoded username
     349        fputs($this->smtp_conn, base64_encode($msg3) . $this->CRLF);
     350
     351        $rply = $this->get_lines();
     352        $code = substr($rply,0,3);
     353
     354        if($code != 235) {
     355            $this->error =
     356                array("error" => "Could not authenticate",
     357                      "smtp_code" => $code,
     358                      "smtp_msg" => substr($rply,4));
     359            if($this->do_debug >= 1) {
     360                $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
     361            }
     362            return false;
     363        }
     364        break;
    263365    }
    264 
    265366    return true;
    266367  }
    267368
    class SMTP { 
    276377      if($sock_status["eof"]) {
    277378        // the socket is valid but we are not connected
    278379        if($this->do_debug >= 1) {
    279             echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
     380            $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected");
    280381        }
    281382        $this->Close();
    282383        return false;
    class SMTP { 
    341442    $code = substr($rply,0,3);
    342443
    343444    if($this->do_debug >= 2) {
    344       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     445      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    345446    }
    346447
    347448    if($code != 354) {
    class SMTP { 
    350451              "smtp_code" => $code,
    351452              "smtp_msg" => substr($rply,4));
    352453      if($this->do_debug >= 1) {
    353         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     454        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    354455      }
    355456      return false;
    356457    }
    class SMTP { 
    435536    $code = substr($rply,0,3);
    436537
    437538    if($this->do_debug >= 2) {
    438       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     539      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    439540    }
    440541
    441542    if($code != 250) {
    class SMTP { 
    444545              "smtp_code" => $code,
    445546              "smtp_msg" => substr($rply,4));
    446547      if($this->do_debug >= 1) {
    447         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     548        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    448549      }
    449550      return false;
    450551    }
    class SMTP { 
    500601    $code = substr($rply,0,3);
    501602
    502603    if($this->do_debug >= 2) {
    503       echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
     604      $this->edebug("SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />');
    504605    }
    505606
    506607    if($code != 250) {
    class SMTP { 
    509610              "smtp_code" => $code,
    510611              "smtp_msg" => substr($rply,4));
    511612      if($this->do_debug >= 1) {
    512         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     613        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    513614      }
    514615      return false;
    515616    }
    class SMTP { 
    549650    $code = substr($rply,0,3);
    550651
    551652    if($this->do_debug >= 2) {
    552       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     653      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    553654    }
    554655
    555656    if($code != 250) {
    class SMTP { 
    558659              "smtp_code" => $code,
    559660              "smtp_msg" => substr($rply,4));
    560661      if($this->do_debug >= 1) {
    561         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     662        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    562663      }
    563664      return false;
    564665    }
    class SMTP { 
    592693    $byemsg = $this->get_lines();
    593694
    594695    if($this->do_debug >= 2) {
    595       echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
     696      $this->edebug("SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />');
    596697    }
    597698
    598699    $rval = true;
    class SMTP { 
    606707                 "smtp_rply" => substr($byemsg,4));
    607708      $rval = false;
    608709      if($this->do_debug >= 1) {
    609         echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
     710        $this->edebug("SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />');
    610711      }
    611712    }
    612713
    class SMTP { 
    644745    $code = substr($rply,0,3);
    645746
    646747    if($this->do_debug >= 2) {
    647       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     748      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    648749    }
    649750
    650751    if($code != 250 && $code != 251) {
    class SMTP { 
    653754              "smtp_code" => $code,
    654755              "smtp_msg" => substr($rply,4));
    655756      if($this->do_debug >= 1) {
    656         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     757        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    657758      }
    658759      return false;
    659760    }
    class SMTP { 
    687788    $code = substr($rply,0,3);
    688789
    689790    if($this->do_debug >= 2) {
    690       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     791      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    691792    }
    692793
    693794    if($code != 250) {
    class SMTP { 
    696797              "smtp_code" => $code,
    697798              "smtp_msg" => substr($rply,4));
    698799      if($this->do_debug >= 1) {
    699         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     800        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    700801      }
    701802      return false;
    702803    }
    class SMTP { 
    735836    $code = substr($rply,0,3);
    736837
    737838    if($this->do_debug >= 2) {
    738       echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
     839      $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
    739840    }
    740841
    741842    if($code != 250) {
    class SMTP { 
    744845              "smtp_code" => $code,
    745846              "smtp_msg" => substr($rply,4));
    746847      if($this->do_debug >= 1) {
    747         echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
     848        $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
    748849      }
    749850      return false;
    750851    }
    class SMTP { 
    768869    $this->error = array("error" => "This method, TURN, of the SMTP ".
    769870                                    "is not implemented");
    770871    if($this->do_debug >= 1) {
    771       echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
     872      $this->edebug("SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />');
    772873    }
    773874    return false;
    774875  }
    class SMTP { 
    797898   */
    798899  private function get_lines() {
    799900    $data = "";
     901    $endtime = 0;
     902    stream_set_timeout($this->smtp_conn, $this->Timeout);
     903    if ($this->Timelimit > 0) {
     904      $endtime = time() + $this->Timelimit;
     905    }
    800906    while(!feof($this->smtp_conn)) {
    801907      $str = @fgets($this->smtp_conn,515);
    802908      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 />';
     909        $this->edebug("SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />');
     910        $this->edebug("SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />');
    805911      }
    806912      $data .= $str;
    807913      if($this->do_debug >= 4) {
    808         echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
     914        $this->edebug("SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />');
    809915      }
    810916      // if 4th character is a space, we are done reading, break the loop
    811917      if(substr($str,3,1) == " ") { break; }
     918      // Timed-out? Log and break
     919      $info = stream_get_meta_data($this->smtp_conn);
     920      if ($info['timed_out']) {
     921        if($this->do_debug >= 4) {
     922          $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " seconds) <br />");
     923        }
     924        break;
     925      }
     926      // Now check if reads took too long
     927      if ($endtime) {
     928        if (time() > $endtime) {
     929          if($this->do_debug >= 4) {
     930            $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " seconds) <br />");
     931          }
     932          break;
     933        }
     934      }
    812935    }
    813936    return $data;
    814937  }