WordPress.org

Make WordPress Core

Ticket #25014: 25014.2.patch

File 25014.2.patch, 72.3 KB (added by bpetty, 7 years ago)
  • wp-includes/class-phpmailer.php

    diff --git wp-includes/class-phpmailer.php wp-includes/class-phpmailer.php
    index 38ac376..693eebd 100644
     
    22/*~ class.phpmailer.php
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 5.2.4                                                          |
    6 |      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
     5|   Version: 5.2.6                                                          |
     6|      Site: https://github.com/PHPMailer/PHPMailer/                        |
    77| ------------------------------------------------------------------------- |
    8 |     Admin: Jim Jagielski (project admininistrator)                        |
     8|    Admins: Marcus Bointon                                                 |
     9|    Admins: Jim Jagielski                                                  |
    910|   Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
    10 |          : Marcus Bointon (coolbru) coolbru@users.sourceforge.net         |
     11|          : Marcus Bointon (coolbru) phpmailer@synchromedia.co.uk          |
    1112|          : Jim Jagielski (jimjag) jimjag@gmail.com                        |
    1213|   Founder: Brent R. Matzelle (original founder)                           |
    1314| Copyright (c) 2010-2012, Jim Jagielski. All Rights Reserved.              |
    class PHPMailer { 
    143144   * Stores the extra header list which CreateHeader() doesn't fold in
    144145   * @var string
    145146   * @access protected
    146   */
     147   */
    147148  protected $mailHeader     = '';
    148149
    149150  /**
    class PHPMailer { 
    171172   * @var boolean
    172173   */
    173174  public $UseSendmailOptions    = true;
    174  
     175
    175176  /**
    176177   * Path to PHPMailer plugins.  Useful if the SMTP class
    177178   * is in a different directory than the PHP include path.
    class PHPMailer { 
    260261  public $Password      = '';
    261262
    262263  /**
    263    *  Sets SMTP auth type. Options are LOGIN | PLAIN | NTLM (default LOGIN)
     264   *  Sets SMTP auth type. Options are LOGIN | PLAIN | NTLM | CRAM-MD5 (default LOGIN)
    264265   *  @var string
    265266   */
    266267  public $AuthType      = '';
    267  
     268
    268269  /**
    269270   *  Sets SMTP realm.
    270271   *  @var string
    class PHPMailer { 
    318319   */
    319320  public $SingleToArray = array();
    320321
    321  /**
     322  /**
     323   * Should we allow sending messages with empty body?
     324   * @var bool
     325   */
     326  public $AllowEmpty = false;
     327
     328    /**
    322329   * Provides the ability to change the generic line ending
    323330   * NOTE: The default remains '\n'. We force CRLF where we KNOW
    324331   *        it must be used via self::CRLF
    class PHPMailer { 
    390397   * Sets the PHPMailer Version number
    391398   * @var string
    392399   */
    393   public $Version         = '5.2.4';
     400  public $Version         = '5.2.6';
    394401
    395402  /**
    396403   * What to use in the X-Mailer header
    class PHPMailer { 
    491498  const STOP_CONTINUE = 1; // message?, likely ok to continue processing
    492499  const STOP_CRITICAL = 2; // message, plus full stop, critical error reached
    493500  const CRLF = "\r\n";     // SMTP RFC specified EOL
    494  
     501
    495502  /////////////////////////////////////////////////
    496503  // METHODS, VARIABLES
    497504  /////////////////////////////////////////////////
    class PHPMailer { 
    539546  }
    540547
    541548  /**
     549   * Destructor
     550   */
     551  public function __destruct() {
     552      if ($this->Mailer == 'smtp') { //Close any open SMTP connection nicely
     553          $this->SmtpClose();
     554      }
     555  }
     556
     557  /**
    542558   * Sets message type to HTML.
    543559   * @param bool $ishtml
    544560   * @return void
    class PHPMailer { 
    683699  return false;
    684700}
    685701
    686 /**
    687  * Set the From and FromName properties
    688  * @param string $address
    689  * @param string $name
    690  * @param int $auto Also set Reply-To and Sender
     702  /**
     703   * Set the From and FromName properties
     704   * @param string $address
     705   * @param string $name
     706   * @param int $auto Also set Reply-To and Sender
    691707   * @throws phpmailerException
    692  * @return boolean
    693  */
     708   * @return boolean
     709   */
    694710  public function SetFrom($address, $name = '', $auto = 1) {
    695711    $address = trim($address);
    696712    $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim
    class PHPMailer { 
    723739   * Conforms to RFC5322: Uses *correct* regex on which FILTER_VALIDATE_EMAIL is
    724740   * based; So why not use FILTER_VALIDATE_EMAIL? Because it was broken to
    725741   * not allow a@b type valid addresses :(
    726    * Some Versions of PHP break on the regex though, likely due to PCRE, so use
    727    * the older validation method for those users. (http://php.net/manual/en/pcre.installation.php)
    728742   * @link http://squiloople.com/2009/12/20/email-address-validation/
    729743   * @copyright regex Copyright Michael Rushton 2009-10 | http://squiloople.com/ | Feel free to use and redistribute this code. But please keep this copyright notice.
    730744   * @param string $address The email address to check
    class PHPMailer { 
    733747   * @access public
    734748   */
    735749  public static function ValidateAddress($address) {
    736         if ((defined('PCRE_VERSION')) && (version_compare(PCRE_VERSION, '8.0') >= 0)) {
    737           return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[     ])+|(?>[        ]*\x0D\x0A)?[   ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
    738         } elseif (function_exists('filter_var')) { //Introduced in PHP 5.2
    739         if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
    740           return false;
    741         } else {
    742           return true;
    743         }
    744     } else {
    745         return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
    746         }
     750      if (defined('PCRE_VERSION')) { //Check this instead of extension_loaded so it works when that function is disabled
     751          if (version_compare(PCRE_VERSION, '8.0') >= 0) {
     752              return (boolean)preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[\t ])+|(?>[\t ]*\x0D\x0A)?[\t ]+)?)(\((?>(?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][:\]]){8,})((?6)(?>:(?6)){0,6})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){6,})(?8)?::(?>((?6)(?>:(?6)){0,4}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
     753          } else {
     754              //Fall back to an older regex that doesn't need a recent PCRE
     755              return (boolean)preg_match('/^(?!(?>"?(?>\\\[ -~]|[^"])"?){255,})(?!(?>"?(?>\\\[ -~]|[^"])"?){65,}@)(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*")(?>\.(?>[!#-\'*+\/-9=?^-~-]+|"(?>(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\xFF]))*"))*@(?>(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>\.(?![a-z0-9-]{64,})(?>[a-z0-9](?>[a-z0-9-]*[a-z0-9])?)){0,126}|\[(?:(?>IPv6:(?>(?>[a-f0-9]{1,4})(?>:[a-f0-9]{1,4}){7}|(?!(?:.*[a-f0-9][:\]]){8,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?::(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,6})?))|(?>(?>IPv6:(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){5}:|(?!(?:.*[a-f0-9]:){6,})(?>[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4})?::(?>(?:[a-f0-9]{1,4}(?>:[a-f0-9]{1,4}){0,4}):)?))?(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?>25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}))\])$/isD', $address);
     756          }
     757      } else {
     758          //No PCRE! Do something _very_ approximate!
     759          //Check the address is 3 chars or longer and contains an @ that's not the first or last char
     760          return (strlen($address) >= 3 and strpos($address, '@') >= 1 and strpos($address, '@') != strlen($address) - 1);
     761      }
    747762  }
    748763
    749764  /////////////////////////////////////////////////
    class PHPMailer { 
    790805
    791806      $this->error_count = 0; // reset errors
    792807      $this->SetMessageType();
    793       //Refuse to send an empty message
    794       if (empty($this->Body)) {
     808      //Refuse to send an empty message unless we are specifically allowing it
     809      if (!$this->AllowEmpty and empty($this->Body)) {
    795810        throw new phpmailerException($this->Lang('empty_message'), self::STOP_CRITICAL);
    796811      }
    797812
    class PHPMailer { 
    807822          $this->mailHeader .= $this->HeaderLine("To", "undisclosed-recipients:;");
    808823        }
    809824        $this->mailHeader .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader(trim($this->Subject))));
    810         // if(count($this->cc) > 0) {
    811             // $this->mailHeader .= $this->AddrAppend("Cc", $this->cc);
    812         // }
    813825      }
    814826
    815827      // digitally sign with DKIM if enabled
    816828      if (!empty($this->DKIM_domain) && !empty($this->DKIM_private) && !empty($this->DKIM_selector) && !empty($this->DKIM_domain) && file_exists($this->DKIM_private)) {
    817         $header_dkim = $this->DKIM_Add($this->MIMEHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
     829        $header_dkim = $this->DKIM_Add($this->MIMEHeader . $this->mailHeader, $this->EncodeHeader($this->SecureHeader($this->Subject)), $this->MIMEBody);
    818830        $this->MIMEHeader = str_replace("\r\n", "\n", $header_dkim) . $this->MIMEHeader;
    819831      }
    820832
    class PHPMailer { 
    911923   * Sends mail using the PHP mail() function.
    912924   * @param string $header The message headers
    913925   * @param string $body The message body
    914      * @throws phpmailerException
     926   * @throws phpmailerException
    915927   * @access protected
    916928   * @return bool
    917929   */
    class PHPMailer { 
    923935    $to = implode(', ', $toArr);
    924936
    925937    if (empty($this->Sender)) {
    926       $params = "-oi ";
     938      $params = " ";
    927939    } else {
    928       $params = sprintf("-oi -f%s", $this->Sender);
     940      $params = sprintf("-f%s", $this->Sender);
    929941    }
    930942    if ($this->Sender != '' and !ini_get('safe_mode')) {
    931943      $old_from = ini_get('sendmail_from');
    class PHPMailer { 
    973985    }
    974986    $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
    975987    if(!$this->smtp->Mail($smtp_from)) {
    976       $this->SetError($this->Lang('from_failed') . $smtp_from . " : " . implode(",",$this->smtp->getError())) ;
     988      $this->SetError($this->Lang('from_failed') . $smtp_from . ' : ' .implode(',', $this->smtp->getError()));
    977989      throw new phpmailerException($this->ErrorInfo, self::STOP_CRITICAL);
    978990    }
    979991
    class PHPMailer { 
    10821094
    10831095          $connection = true;
    10841096          if ($this->SMTPAuth) {
    1085             if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType,
    1086                                            $this->Realm, $this->Workstation)) {
     1097            if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType, $this->Realm, $this->Workstation)) {
    10871098              throw new phpmailerException($this->Lang('authenticate'));
    10881099            }
    10891100          }
    10901101        }
    10911102        $index++;
    1092       if (!$connection) {
    1093         throw new phpmailerException($this->Lang('connect_host'));
    1094       }
     1103        if (!$connection) {
     1104          throw new phpmailerException($this->Lang('connect_host'));
     1105        }
    10951106      }
    10961107    } catch (phpmailerException $e) {
    10971108      $this->smtp->Reset();
    class PHPMailer { 
    11161127  }
    11171128
    11181129  /**
    1119   * Sets the language for all class error messages.
    1120   * Returns false if it cannot load the language file.  The default language is English.
    1121   * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
    1122   * @param string $lang_path Path to the language file directory
     1130   * Sets the language for all class error messages.
     1131   * Returns false if it cannot load the language file.  The default language is English.
     1132   * @param string $langcode ISO 639-1 2-character language code (e.g. Portuguese: "br")
     1133   * @param string $lang_path Path to the language file directory
    11231134   * @return bool
    1124   * @access public
    1125   */
     1135   * @access public
     1136   */
    11261137  function SetLanguage($langcode = 'en', $lang_path = 'language/') {
    11271138    //Define full set of translatable strings
    11281139    $PHPMAILER_LANG = array(
    class PHPMailer { 
    12511262            $buf = '';
    12521263          }
    12531264          while (strlen($word) > 0) {
     1265            if ($length <= 0) {
     1266                break;
     1267            }
    12541268            $len = $length;
    12551269            if ($is_utf8) {
    12561270              $len = $this->UTF8CharBoundary($word, $len);
    class PHPMailer { 
    13701384    }
    13711385
    13721386    if ($this->ReturnPath) {
    1373       $result .= $this->HeaderLine('Return-Path', trim($this->ReturnPath));
     1387      $result .= $this->HeaderLine('Return-Path', '<'.trim($this->ReturnPath).'>');
    13741388    } elseif ($this->Sender == '') {
    1375       $result .= $this->HeaderLine('Return-Path', trim($this->From));
     1389      $result .= $this->HeaderLine('Return-Path', '<'.trim($this->From).'>');
    13761390    } else {
    1377       $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
     1391      $result .= $this->HeaderLine('Return-Path', '<'.trim($this->Sender).'>');
    13781392    }
    13791393
    13801394    // To be created automatically by mail()
    class PHPMailer { 
    14231437    }
    14241438    $result .= $this->HeaderLine('X-Priority', $this->Priority);
    14251439    if ($this->XMailer == '') {
    1426         $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (http://code.google.com/a/apache-extras.org/p/phpmailer/)');
     1440        $result .= $this->HeaderLine('X-Mailer', 'PHPMailer '.$this->Version.' (https://github.com/PHPMailer/PHPMailer/)');
    14271441    } else {
    14281442      $myXmailer = trim($this->XMailer);
    14291443      if ($myXmailer) {
    class PHPMailer { 
    15151529        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
    15161530        $body .= $this->EncodeString($this->Body, $this->Encoding);
    15171531        $body .= $this->LE.$this->LE;
    1518         $body .= $this->AttachAll("inline", $this->boundary[1]);
     1532        $body .= $this->AttachAll('inline', $this->boundary[1]);
    15191533        break;
    15201534      case 'attach':
    15211535        $body .= $this->GetBoundary($this->boundary[1], '', '', '');
    15221536        $body .= $this->EncodeString($this->Body, $this->Encoding);
    15231537        $body .= $this->LE.$this->LE;
    1524         $body .= $this->AttachAll("attachment", $this->boundary[1]);
     1538        $body .= $this->AttachAll('attachment', $this->boundary[1]);
    15251539        break;
    15261540      case 'inline_attach':
    1527         $body .= $this->TextLine("--" . $this->boundary[1]);
     1541        $body .= $this->TextLine('--' . $this->boundary[1]);
    15281542        $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
    15291543        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
    15301544        $body .= $this->LE;
    15311545        $body .= $this->GetBoundary($this->boundary[2], '', '', '');
    15321546        $body .= $this->EncodeString($this->Body, $this->Encoding);
    15331547        $body .= $this->LE.$this->LE;
    1534         $body .= $this->AttachAll("inline", $this->boundary[2]);
     1548        $body .= $this->AttachAll('inline', $this->boundary[2]);
    15351549        $body .= $this->LE;
    1536         $body .= $this->AttachAll("attachment", $this->boundary[1]);
     1550        $body .= $this->AttachAll('attachment', $this->boundary[1]);
    15371551        break;
    15381552      case 'alt':
    15391553        $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
    class PHPMailer { 
    15481562        $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
    15491563        $body .= $this->EncodeString($this->AltBody, $this->Encoding);
    15501564        $body .= $this->LE.$this->LE;
    1551         $body .= $this->TextLine("--" . $this->boundary[1]);
     1565        $body .= $this->TextLine('--' . $this->boundary[1]);
    15521566        $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
    15531567        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
    15541568        $body .= $this->LE;
    15551569        $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
    15561570        $body .= $this->EncodeString($this->Body, $this->Encoding);
    15571571        $body .= $this->LE.$this->LE;
    1558         $body .= $this->AttachAll("inline", $this->boundary[2]);
     1572        $body .= $this->AttachAll('inline', $this->boundary[2]);
    15591573        $body .= $this->LE;
    15601574        $body .= $this->EndBoundary($this->boundary[1]);
    15611575        break;
    15621576      case 'alt_attach':
    1563         $body .= $this->TextLine("--" . $this->boundary[1]);
     1577        $body .= $this->TextLine('--' . $this->boundary[1]);
    15641578        $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
    15651579        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
    15661580        $body .= $this->LE;
    class PHPMailer { 
    15721586        $body .= $this->LE.$this->LE;
    15731587        $body .= $this->EndBoundary($this->boundary[2]);
    15741588        $body .= $this->LE;
    1575         $body .= $this->AttachAll("attachment", $this->boundary[1]);
     1589        $body .= $this->AttachAll('attachment', $this->boundary[1]);
    15761590        break;
    15771591      case 'alt_inline_attach':
    1578         $body .= $this->TextLine("--" . $this->boundary[1]);
     1592        $body .= $this->TextLine('--' . $this->boundary[1]);
    15791593        $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
    15801594        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
    15811595        $body .= $this->LE;
    15821596        $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
    15831597        $body .= $this->EncodeString($this->AltBody, $this->Encoding);
    15841598        $body .= $this->LE.$this->LE;
    1585         $body .= $this->TextLine("--" . $this->boundary[2]);
     1599        $body .= $this->TextLine('--' . $this->boundary[2]);
    15861600        $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
    15871601        $body .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"');
    15881602        $body .= $this->LE;
    15891603        $body .= $this->GetBoundary($this->boundary[3], '', 'text/html', '');
    15901604        $body .= $this->EncodeString($this->Body, $this->Encoding);
    15911605        $body .= $this->LE.$this->LE;
    1592         $body .= $this->AttachAll("inline", $this->boundary[3]);
     1606        $body .= $this->AttachAll('inline', $this->boundary[3]);
    15931607        $body .= $this->LE;
    15941608        $body .= $this->EndBoundary($this->boundary[2]);
    15951609        $body .= $this->LE;
    1596         $body .= $this->AttachAll("attachment", $this->boundary[1]);
     1610        $body .= $this->AttachAll('attachment', $this->boundary[1]);
    15971611        break;
    15981612      default:
    15991613        // catch case 'plain' and case ''
    class PHPMailer { 
    16051619      $body = '';
    16061620    } elseif ($this->sign_key_file) {
    16071621      try {
    1608         $file = tempnam('', 'mail');
     1622        if (!defined('PKCS7_TEXT')) {
     1623            throw new phpmailerException($this->Lang('signing').' OpenSSL extension missing.');
     1624        }
     1625        $file = tempnam(sys_get_temp_dir(), 'mail');
    16091626        file_put_contents($file, $body); //TODO check this worked
    1610         $signed = tempnam("", "signed");
    1611         if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), NULL)) {
     1627        $signed = tempnam(sys_get_temp_dir(), 'signed');
     1628        if (@openssl_pkcs7_sign($file, $signed, 'file://'.realpath($this->sign_cert_file), array('file://'.realpath($this->sign_key_file), $this->sign_key_pass), null)) {
    16121629          @unlink($file);
    16131630          $body = file_get_contents($signed);
    16141631          @unlink($signed);
    16151632        } else {
    16161633          @unlink($file);
    16171634          @unlink($signed);
    1618           throw new phpmailerException($this->Lang("signing").openssl_error_string());
     1635          throw new phpmailerException($this->Lang('signing').openssl_error_string());
    16191636        }
    16201637      } catch (phpmailerException $e) {
    16211638        $body = '';
    class PHPMailer { 
    16241641        }
    16251642      }
    16261643    }
    1627 
    16281644    return $body;
    16291645  }
    16301646
    class PHPMailer { 
    16821698  }
    16831699
    16841700  /**
    1685    *  Returns a formatted header line.
     1701   * Returns a formatted header line.
    16861702   * @access public
    16871703   * @param string $name
    16881704   * @param string $value
    class PHPMailer { 
    18481864      if (!is_readable($path)) {
    18491865        throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
    18501866      }
    1851       //  if (!function_exists('get_magic_quotes')) {
    1852       //    function get_magic_quotes() {
    1853       //      return false;
    1854       //    }
    1855       //  }
    18561867      $magic_quotes = get_magic_quotes_runtime();
    18571868      if ($magic_quotes) {
    18581869        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    18591870          set_magic_quotes_runtime(0);
    18601871        } else {
    1861           ini_set('magic_quotes_runtime', 0); 
     1872          ini_set('magic_quotes_runtime', 0);
    18621873        }
    18631874      }
    18641875      $file_buffer  = file_get_contents($path);
    class PHPMailer { 
    18671878        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    18681879          set_magic_quotes_runtime($magic_quotes);
    18691880        } else {
    1870           ini_set('magic_quotes_runtime', $magic_quotes); 
     1881          ini_set('magic_quotes_runtime', $magic_quotes);
    18711882        }
    18721883      }
    18731884      return $file_buffer;
    class PHPMailer { 
    19431954        break;
    19441955    }
    19451956
    1946     if ($x == 0) {
     1957    if ($x == 0) { //There are no chars that need encoding
    19471958      return ($str);
    19481959    }
    19491960
    19501961    $maxlen = 75 - 7 - strlen($this->CharSet);
    19511962    // Try to select the encoding which should produce the shortest output
    1952     if (strlen($str)/3 < $x) {
     1963    if ($x > strlen($str)/3) { //More than a third of the content will need encoding, so B encoding will be most efficient
    19531964      $encoding = 'B';
    19541965      if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
    19551966        // Use a custom function which correctly encodes and wraps long
    class PHPMailer { 
    20322043  }
    20332044
    20342045  /**
    2035   * Encode string to quoted-printable.
    2036   * Only uses standard PHP, slow, but will always work
    2037   * @access public
    2038    * @param string $input
    2039   * @param integer $line_max Number of chars allowed on a line before wrapping
    2040    * @param bool $space_conv
    2041    * @internal param string $string the text to encode
    2042   * @return string
    2043   */
    2044   public function EncodeQPphp( $input = '', $line_max = 76, $space_conv = false) {
    2045     $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
    2046     $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
    2047     $eol = "\r\n";
    2048     $escape = '=';
    2049     $output = '';
    2050     while( list(, $line) = each($lines) ) {
    2051       $linlen = strlen($line);
    2052       $newline = '';
    2053       for($i = 0; $i < $linlen; $i++) {
    2054         $c = substr( $line, $i, 1 );
    2055         $dec = ord( $c );
    2056         if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
    2057           $c = '=2E';
    2058         }
    2059         if ( $dec == 32 ) {
    2060           if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
    2061             $c = '=20';
    2062           } else if ( $space_conv ) {
    2063             $c = '=20';
    2064           }
    2065         } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
    2066           $h2 = (integer)floor($dec/16);
    2067           $h1 = (integer)floor($dec%16);
    2068           $c = $escape.$hex[$h2].$hex[$h1];
    2069         }
    2070         if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
    2071           $output .= $newline.$escape.$eol; //  soft line break; " =\r\n" is okay
    2072           $newline = '';
    2073           // check if newline first character will be point or not
    2074           if ( $dec == 46 ) {
    2075             $c = '=2E';
    2076           }
    2077         }
    2078         $newline .= $c;
    2079       } // end of for
    2080       $output .= $newline.$eol;
    2081     } // end of while
    2082     return $output;
    2083   }
    2084 
    2085   /**
    2086   * Encode string to RFC2045 (6.7) quoted-printable format
    2087   * Uses a PHP5 stream filter to do the encoding about 64x faster than the old version
    2088   * Also results in same content as you started with after decoding
    2089   * @see EncodeQPphp()
    2090   * @access public
    2091   * @param string $string the text to encode
    2092   * @param integer $line_max Number of chars allowed on a line before wrapping
    2093   * @param boolean $space_conv Dummy param for compatibility with existing EncodeQP function
    2094   * @return string
    2095   * @author Marcus Bointon
    2096   */
    2097   public function EncodeQP($string, $line_max = 76, $space_conv = false) {
     2046   * Encode string to RFC2045 (6.7) quoted-printable format
     2047   * @access public
     2048   * @param string $string The text to encode
     2049   * @param integer $line_max Number of chars allowed on a line before wrapping
     2050   * @return string
     2051   * @link PHP version adapted from http://www.php.net/manual/en/function.quoted-printable-decode.php#89417
     2052   */
     2053  public function EncodeQP($string, $line_max = 76) {
    20982054    if (function_exists('quoted_printable_encode')) { //Use native function if it's available (>= PHP5.3)
    20992055      return quoted_printable_encode($string);
    21002056    }
    2101     $filters = stream_get_filters();
    2102     if (!in_array('convert.*', $filters)) { //Got convert stream filter?
    2103       return $this->EncodeQPphp($string, $line_max, $space_conv); //Fall back to old implementation
    2104     }
    2105     $fp = fopen('php://temp/', 'r+');
    2106     $string = preg_replace('/\r\n?/', $this->LE, $string); //Normalise line breaks
    2107     $params = array('line-length' => $line_max, 'line-break-chars' => $this->LE);
    2108     $s = stream_filter_append($fp, 'convert.quoted-printable-encode', STREAM_FILTER_READ, $params);
    2109     fputs($fp, $string);
    2110     rewind($fp);
    2111     $out = stream_get_contents($fp);
    2112     stream_filter_remove($s);
    2113     $out = preg_replace('/^\./m', '=2E', $out); //Encode . if it is first char on a line, workaround for bug in Exchange
    2114     fclose($fp);
    2115     return $out;
     2057    //Fall back to a pure PHP implementation
     2058    $string = str_replace(array('%20', '%0D%0A.', '%0D%0A', '%'), array(' ', "\r\n=2E", "\r\n", '='), rawurlencode($string));
     2059    $string = preg_replace('/[^\r\n]{'.($line_max - 3).'}[^=\r\n]{2}/', "$0=\r\n", $string);
     2060    return $string;
     2061  }
     2062
     2063  /**
     2064   * Wrapper to preserve BC for old QP encoding function that was removed
     2065   * @see EncodeQP()
     2066   * @access public
     2067   * @param string $string
     2068   * @param integer $line_max
     2069   * @param bool $space_conv
     2070   * @return string
     2071   */
     2072  public function EncodeQPphp($string, $line_max = 76, $space_conv = false) {
     2073    return $this->EncodeQP($string, $line_max);
    21162074  }
    21172075
    21182076  /**
    class PHPMailer { 
    21342092
    21352093      case 'comment':
    21362094        $pattern = '\(\)"';
    2137         //note that we dont break here!
    2138         //for this reason we build the $pattern withoud including delimiters and []
     2095        //note that we don't break here!
     2096        //for this reason we build the $pattern without including delimiters and []
    21392097
    21402098      case 'text':
    21412099      default:
    class PHPMailer { 
    21442102        $pattern = '\075\000-\011\013\014\016-\037\077\137\177-\377' . $pattern;
    21452103        break;
    21462104    }
    2147    
     2105
    21482106    if (preg_match_all("/[{$pattern}]/", $encoded, $matches)) {
    21492107      foreach (array_unique($matches[0]) as $char) {
    21502108        $encoded = str_replace($char, '=' . sprintf('%02X', ord($char)), $encoded);
    21512109      }
    21522110    }
    2153    
     2111
    21542112    //Replace every spaces to _ (more readable than =20)
    21552113    return str_replace(' ', '_', $encoded);
    21562114}
    class PHPMailer { 
    21812139  }
    21822140
    21832141  /**
    2184    * Adds an embedded attachment.  This can include images, sounds, and
    2185    * just about any other document.  Make sure to set the $type to an
    2186    * image type.  For JPEG images use "image/jpeg" and for GIF images
    2187    * use "image/gif".
     2142   * Add an embedded attachment from a file.
     2143   * This can include images, sounds, and just about any other document type.
     2144   * Be sure to set the $type to an image type for images:
     2145   * JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.
    21882146   * @param string $path Path to the attachment.
    2189    * @param string $cid Content ID of the attachment.  Use this to identify
    2190    *        the Id for accessing the image in an HTML form.
     2147   * @param string $cid Content ID of the attachment; Use this to reference
     2148   *        the content when using an embedded image in HTML.
    21912149   * @param string $name Overrides the attachment name.
    21922150   * @param string $encoding File encoding (see $Encoding).
    2193    * @param string $type File extension (MIME) type.
    2194    * @return bool
     2151   * @param string $type File MIME type.
     2152   * @return bool True on successfully adding an attachment
    21952153   */
    21962154  public function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
    21972155
    class PHPMailer { 
    22162174      6 => 'inline',
    22172175      7 => $cid
    22182176    );
    2219 
    22202177    return true;
    22212178  }
    22222179
     2180
    22232181  /**
    2224    * Adds an embedded stringified attachment.  This can include images, sounds, and
    2225    * just about any other document.  Make sure to set the $type to an
    2226    * image type.  For JPEG images use "image/jpeg" and for GIF images
    2227    * use "image/gif".
    2228    * @param string $string The attachment.
    2229    * @param string $cid Content ID of the attachment.  Use this to identify
    2230    *        the Id for accessing the image in an HTML form.
    2231    * @param string $name Overrides the attachment name.
     2182   * Add an embedded stringified attachment.
     2183   * This can include images, sounds, and just about any other document type.
     2184   * Be sure to set the $type to an image type for images:
     2185   * JPEG images use 'image/jpeg', GIF uses 'image/gif', PNG uses 'image/png'.
     2186   * @param string $string The attachment binary data.
     2187   * @param string $cid Content ID of the attachment; Use this to reference
     2188   *        the content when using an embedded image in HTML.
     2189   * @param string $name
    22322190   * @param string $encoding File encoding (see $Encoding).
    2233    * @param string $type File extension (MIME) type.
    2234    * @return bool
     2191   * @param string $type MIME type.
     2192   * @return bool True on successfully adding an attachment
    22352193   */
    22362194  public function AddStringEmbeddedImage($string, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
    22372195    // Append to $attachment array
    class PHPMailer { 
    22452203      6 => 'inline',
    22462204      7 => $cid
    22472205    );
     2206    return true;
    22482207  }
    22492208
    22502209  /**
    class PHPMailer { 
    23842343   * @static
    23852344   */
    23862345  public static function RFCDate() {
    2387     $tz = date('Z');
    2388     $tzs = ($tz < 0) ? '-' : '+';
    2389     $tz = abs($tz);
    2390     $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
    2391     $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
    2392 
    2393     return $result;
     2346    //Set the time zone to whatever the default is to avoid 500 errors
     2347    //Will default to UTC if it's not set properly in php.ini
     2348    date_default_timezone_set(@date_default_timezone_get());
     2349    return date('D, j M Y H:i:s O');
    23942350  }
    23952351
    23962352  /**
    class PHPMailer { 
    24712427  }
    24722428
    24732429  /**
    2474    * Evaluates the message and returns modifications for inline images and backgrounds
     2430   * Creates a message from an HTML string, making modifications for inline images and backgrounds
     2431   * and creates a plain-text version by converting the HTML
     2432   * Overwrites any existing values in $this->Body and $this->AltBody
    24752433   * @access public
    2476    * @param string $message Text to be HTML modified
     2434   * @param string $message HTML message string
    24772435   * @param string $basedir baseline directory for path
     2436   * @param bool $advanced Whether to use the advanced HTML to text converter
    24782437   * @return string $message
    24792438   */
    2480   public function MsgHTML($message, $basedir = '') {
     2439  public function MsgHTML($message, $basedir = '', $advanced = false) {
    24812440    preg_match_all("/(src|background)=[\"'](.*)[\"']/Ui", $message, $images);
    24822441    if(isset($images[2])) {
    24832442      foreach($images[2] as $i => $url) {
    class PHPMailer { 
    25012460    }
    25022461    $this->IsHTML(true);
    25032462    $this->Body = $message;
    2504     if (empty($this->AltBody)) {
    2505         $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
    2506         if (!empty($textMsg)) {
    2507             $this->AltBody = html_entity_decode($textMsg, ENT_QUOTES, $this->CharSet);
    2508         }
    2509     }
     2463    $this->AltBody = $this->html2text($message, $advanced);
    25102464    if (empty($this->AltBody)) {
    25112465      $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n";
    25122466    }
    25132467    return $message;
    25142468  }
    25152469
     2470    /**
     2471     * Convert an HTML string into a plain text version
     2472     * @param string $html The HTML text to convert
     2473     * @param bool $advanced Should this use the more complex html2text converter or just a simple one?
     2474     * @return string
     2475     */
     2476  public function html2text($html, $advanced = false) {
     2477    if ($advanced) {
     2478      require_once 'extras/class.html2text.php';
     2479      $h = new html2text($html);
     2480      return $h->get_text();
     2481    }
     2482    return html_entity_decode(trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $html))), ENT_QUOTES, $this->CharSet);
     2483  }
     2484
    25162485  /**
    25172486   * Gets the MIME type of the embedded or inline image
    25182487   * @param string $ext File extension
    class PHPMailer { 
    26132582  }
    26142583
    26152584  /**
    2616   * Set (or reset) Class Objects (variables)
    2617   *
    2618   * Usage Example:
    2619   * $page->set('X-Priority', '3');
    2620   *
    2621   * @access public
    2622   * @param string $name Parameter Name
    2623   * @param mixed $value Parameter Value
    2624   * NOTE: will not work with arrays, there are no arrays to set/reset
     2585   * Set (or reset) Class Objects (variables)
     2586   *
     2587   * Usage Example:
     2588   * $page->set('X-Priority', '3');
     2589   *
     2590   * @access public
     2591   * @param string $name
     2592   * @param mixed $value
     2593   * NOTE: will not work with arrays, there are no arrays to set/reset
    26252594   * @throws phpmailerException
    26262595   * @return bool
    2627   * @todo Should this not be using __set() magic function?
    2628   */
     2596   * @todo Should this not be using __set() magic function?
     2597   */
    26292598  public function set($name, $value = '') {
    26302599    try {
    26312600      if (isset($this->$name) ) {
    class PHPMailer { 
    26452614  /**
    26462615   * Strips newlines to prevent header injection.
    26472616   * @access public
    2648    * @param string $str String
     2617   * @param string $str
    26492618   * @return string
    26502619   */
    26512620  public function SecureHeader($str) {
    class PHPMailer { 
    26562625   * Set the private key file and password to sign the message.
    26572626   *
    26582627   * @access public
    2659    * @param $cert_filename
    2660    * @param string $key_filename Parameter File Name
     2628   * @param string $cert_filename
     2629   * @param string $key_filename
    26612630   * @param string $key_pass Password for private key
    26622631   */
    26632632  public function Sign($cert_filename, $key_filename, $key_pass) {
    class PHPMailer { 
    26912660   *
    26922661   * @access public
    26932662   * @param string $s Header
     2663   * @throws phpmailerException
    26942664   * @return string
    26952665   */
    26962666  public function DKIM_Sign($s) {
     2667    if (!defined('PKCS7_TEXT')) {
     2668        if ($this->exceptions) {
     2669            throw new phpmailerException($this->Lang("signing").' OpenSSL extension missing.');
     2670        }
     2671        return '';
     2672    }
    26972673    $privKeyStr = file_get_contents($this->DKIM_private);
    26982674    if ($this->DKIM_passphrase != '') {
    26992675      $privKey = openssl_pkey_get_private($privKeyStr, $this->DKIM_passphrase);
    class PHPMailer { 
    27612737    $DKIMtime             = time() ; // Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
    27622738    $subject_header       = "Subject: $subject";
    27632739    $headers              = explode($this->LE, $headers_line);
    2764         $from_header          = "";
    2765         $to_header            = "";
     2740    $from_header          = '';
     2741    $to_header            = '';
     2742    $current = '';
    27662743    foreach($headers as $header) {
    27672744      if (strpos($header, 'From:') === 0) {
    27682745        $from_header = $header;
     2746        $current = 'from_header';
    27692747      } elseif (strpos($header, 'To:') === 0) {
    27702748        $to_header = $header;
     2749        $current = 'to_header';
     2750      } else {
     2751        if($current && strpos($header, ' =?') === 0){
     2752          $$current .= $header;
     2753        } else {
     2754          $current = '';
     2755        }
    27712756      }
    27722757    }
    27732758    $from     = str_replace('|', '=7C', $this->DKIM_QP($from_header));
    class PHPMailer { 
    27882773                "\tb=";
    27892774    $toSign   = $this->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
    27902775    $signed   = $this->DKIM_Sign($toSign);
    2791     return "X-PHPMAILER-DKIM: code.google.com/a/apache-extras.org/p/phpmailer/\r\n".$dkimhdrs.$signed."\r\n";
     2776    return $dkimhdrs.$signed."\r\n";
    27922777  }
    27932778
    27942779  /**
    class PHPMailer { 
    28012786   * @param string $body
    28022787   * @param string $from
    28032788   */
    2804   protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from=null) {
     2789  protected function doCallback($isSent, $to, $cc, $bcc, $subject, $body, $from = null) {
    28052790    if (!empty($this->action_function) && is_callable($this->action_function)) {
    28062791      $params = array($isSent, $to, $cc, $bcc, $subject, $body, $from);
    28072792      call_user_func_array($this->action_function, $params);
    class phpmailerException extends Exception { 
    28232808    return $errorMsg;
    28242809  }
    28252810}
    2826 ?>
  • wp-includes/class-smtp.php

    diff --git wp-includes/class-smtp.php wp-includes/class-smtp.php
    index 72361bb..8444eb8 100644
     
    22/*~ class.smtp.php
    33.---------------------------------------------------------------------------.
    44|  Software: PHPMailer - PHP email class                                    |
    5 |   Version: 5.2.4                                                          |
    6 |      Site: https://code.google.com/a/apache-extras.org/p/phpmailer/       |
     5|   Version: 5.2.6                                                          |
     6|      Site: https://github.com/PHPMailer/PHPMailer/                        |
    77| ------------------------------------------------------------------------- |
    8 |     Admin: Jim Jagielski (project admininistrator)                        |
     8|    Admins: Marcus Bointon                                                 |
     9|    Admins: Jim Jagielski                                                  |
    910|   Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
    10 |          : Marcus Bointon (coolbru) coolbru@users.sourceforge.net         |
     11|          : Marcus Bointon (coolbru) phpmailer@synchromedia.co.uk          |
    1112|          : Jim Jagielski (jimjag) jimjag@gmail.com                        |
    1213|   Founder: Brent R. Matzelle (original founder)                           |
    1314| Copyright (c) 2010-2012, Jim Jagielski. All Rights Reserved.              |
    class SMTP { 
    5758  public $CRLF = "\r\n";
    5859
    5960  /**
    60    *  Sets whether debugging is turned on
    61    *  @var bool
     61   *  Debug output level; 0 for no output
     62   *  @var int
    6263   */
    63   public $do_debug;       // the level of debug to perform
     64  public $do_debug = 0;
    6465
    6566  /**
    6667   * Sets the function/method to use for debugging output.
    67    * Right now we only honor "echo" or "error_log"
     68   * Right now we only honor 'echo' or 'error_log'
    6869   * @var string
    6970   */
    70   public $Debugoutput     = "echo";
     71  public $Debugoutput     = 'echo';
    7172
    7273  /**
    7374   *  Sets VERP use on/off (default is off)
    class SMTP { 
    9192   * Sets the SMTP PHPMailer Version number
    9293   * @var string
    9394   */
    94   public $Version         = '5.2.4';
     95  public $Version         = '5.2.6';
    9596
    9697  /////////////////////////////////////////////////
    9798  // PROPERTIES, PRIVATE AND PROTECTED
    class SMTP { 
    115116   * @param string $str
    116117   */
    117118  private function edebug($str) {
    118     if ($this->Debugoutput == "error_log") {
     119    if ($this->Debugoutput == 'error_log') {
    119120        error_log($str);
    120121    } else {
    121122        echo $str;
    class SMTP { 
    162163    // make sure we are __not__ connected
    163164    if($this->connected()) {
    164165      // already connected, generate error
    165       $this->error = array("error" => "Already connected to a server");
     166      $this->error = array('error' => 'Already connected to a server');
    166167      return false;
    167168    }
    168169
    class SMTP { 
    178179                                 $tval);   // give up after ? secs
    179180    // verify we connected properly
    180181    if(empty($this->smtp_conn)) {
    181       $this->error = array("error" => "Failed to connect to server",
    182                            "errno" => $errno,
    183                            "errstr" => $errstr);
     182      $this->error = array('error' => 'Failed to connect to server',
     183                           'errno' => $errno,
     184                           'errstr' => $errstr);
    184185      if($this->do_debug >= 1) {
    185         $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />');
     186        $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ": $errstr ($errno)" . $this->CRLF . '<br />');
    186187      }
    187188      return false;
    188189    }
    189190
    190191    // SMTP server can take longer to respond, give longer timeout for first read
    191192    // Windows does not have support for this timeout function
    192     if(substr(PHP_OS, 0, 3) != "WIN") {
     193    if(substr(PHP_OS, 0, 3) != 'WIN') {
    193194     $max = ini_get('max_execution_time');
    194195     if ($max != 0 && $tval > $max) { // don't bother if unlimited
    195196      @set_time_limit($tval);
    class SMTP { 
    201202    $announce = $this->get_lines();
    202203
    203204    if($this->do_debug >= 2) {
    204       $this->edebug("SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />');
     205      $this->edebug('SMTP -> FROM SERVER:' . $announce . $this->CRLF . '<br />');
    205206    }
    206207
    207208    return true;
    class SMTP { 
    220221    $this->error = null; # to avoid confusion
    221222
    222223    if(!$this->connected()) {
    223       $this->error = array("error" => "Called StartTLS() without being connected");
     224      $this->error = array('error' => 'Called StartTLS() without being connected');
    224225      return false;
    225226    }
    226227
    227     fputs($this->smtp_conn,"STARTTLS" . $this->CRLF);
     228    $this->client_send('STARTTLS' . $this->CRLF);
    228229
    229230    $rply = $this->get_lines();
    230     $code = substr($rply,0,3);
     231    $code = substr($rply, 0, 3);
    231232
    232233    if($this->do_debug >= 2) {
    233       $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     234      $this->edebug('SMTP -> FROM SERVER:' . $rply . $this->CRLF . '<br />');
    234235    }
    235236
    236237    if($code != 220) {
    237238      $this->error =
    238          array("error"     => "STARTTLS not accepted from server",
    239                "smtp_code" => $code,
    240                "smtp_msg"  => substr($rply,4));
     239         array('error'     => 'STARTTLS not accepted from server',
     240               'smtp_code' => $code,
     241               'smtp_msg'  => substr($rply, 4));
    241242      if($this->do_debug >= 1) {
    242         $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     243        $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    243244      }
    244245      return false;
    245246    }
    class SMTP { 
    271272    switch ($authtype) {
    272273      case 'PLAIN':
    273274        // Start authentication
    274         fputs($this->smtp_conn,"AUTH PLAIN" . $this->CRLF);
    275    
     275        $this->client_send('AUTH PLAIN' . $this->CRLF);
     276
    276277        $rply = $this->get_lines();
    277         $code = substr($rply,0,3);
    278    
     278        $code = substr($rply, 0, 3);
     279
    279280        if($code != 334) {
    280281          $this->error =
    281             array("error" => "AUTH not accepted from server",
    282                   "smtp_code" => $code,
    283                   "smtp_msg" => substr($rply,4));
     282            array('error' => 'AUTH not accepted from server',
     283                  'smtp_code' => $code,
     284                  'smtp_msg' => substr($rply, 4));
    284285          if($this->do_debug >= 1) {
    285             $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     286            $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    286287          }
    287288          return false;
    288289        }
    289290        // Send encoded username and password
    290         fputs($this->smtp_conn, base64_encode("\0".$username."\0".$password) . $this->CRLF);
     291          $this->client_send(base64_encode("\0".$username."\0".$password) . $this->CRLF);
    291292
    292293        $rply = $this->get_lines();
    293         $code = substr($rply,0,3);
    294    
     294        $code = substr($rply, 0, 3);
     295
    295296        if($code != 235) {
    296297          $this->error =
    297             array("error" => "Authentication not accepted from server",
    298                   "smtp_code" => $code,
    299                   "smtp_msg" => substr($rply,4));
     298            array('error' => 'Authentication not accepted from server',
     299                  'smtp_code' => $code,
     300                  'smtp_msg' => substr($rply, 4));
    300301          if($this->do_debug >= 1) {
    301             $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     302            $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    302303          }
    303304          return false;
    304305        }
    305306        break;
    306307      case 'LOGIN':
    307308        // Start authentication
    308         fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
    309    
     309        $this->client_send('AUTH LOGIN' . $this->CRLF);
     310
    310311        $rply = $this->get_lines();
    311         $code = substr($rply,0,3);
    312    
     312        $code = substr($rply, 0, 3);
     313
    313314        if($code != 334) {
    314315          $this->error =
    315             array("error" => "AUTH not accepted from server",
    316                   "smtp_code" => $code,
    317                   "smtp_msg" => substr($rply,4));
     316            array('error' => 'AUTH not accepted from server',
     317                  'smtp_code' => $code,
     318                  'smtp_msg' => substr($rply, 4));
    318319          if($this->do_debug >= 1) {
    319             $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     320            $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    320321          }
    321322          return false;
    322323        }
    323    
     324
    324325        // Send encoded username
    325         fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
    326    
     326        $this->client_send(base64_encode($username) . $this->CRLF);
     327
    327328        $rply = $this->get_lines();
    328         $code = substr($rply,0,3);
    329    
     329        $code = substr($rply, 0, 3);
     330
    330331        if($code != 334) {
    331332          $this->error =
    332             array("error" => "Username not accepted from server",
    333                   "smtp_code" => $code,
    334                   "smtp_msg" => substr($rply,4));
     333            array('error' => 'Username not accepted from server',
     334                  'smtp_code' => $code,
     335                  'smtp_msg' => substr($rply, 4));
    335336          if($this->do_debug >= 1) {
    336             $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     337            $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    337338          }
    338339          return false;
    339340        }
    340    
     341
    341342        // Send encoded password
    342         fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
    343    
     343        $this->client_send(base64_encode($password) . $this->CRLF);
     344
    344345        $rply = $this->get_lines();
    345         $code = substr($rply,0,3);
    346    
     346        $code = substr($rply, 0, 3);
     347
    347348        if($code != 235) {
    348349          $this->error =
    349             array("error" => "Password not accepted from server",
    350                   "smtp_code" => $code,
    351                   "smtp_msg" => substr($rply,4));
     350            array('error' => 'Password not accepted from server',
     351                  'smtp_code' => $code,
     352                  'smtp_msg' => substr($rply, 4));
    352353          if($this->do_debug >= 1) {
    353             $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     354            $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    354355          }
    355356          return false;
    356357        }
    class SMTP { 
    363364         ** How to telnet in windows: http://technet.microsoft.com/en-us/library/aa995718%28EXCHG.65%29.aspx
    364365         ** PROTOCOL Documentation http://curl.haxx.se/rfc/ntlm.html#ntlmSmtpAuthentication
    365366         */
    366         require_once('ntlm_sasl_client.php');
     367        require_once 'extras/ntlm_sasl_client.php';
    367368        $temp = new stdClass();
    368369        $ntlm_client = new ntlm_sasl_client_class;
    369370        if(! $ntlm_client->Initialize($temp)){//let's test if every function its available
    370             $this->error = array("error" => $temp->error);
     371            $this->error = array('error' => $temp->error);
    371372            if($this->do_debug >= 1) {
    372                 $this->edebug("You need to enable some modules in your php.ini file: " . $this->error["error"] . $this->CRLF);
     373                $this->edebug('You need to enable some modules in your php.ini file: ' . $this->error['error'] . $this->CRLF);
    373374            }
    374375            return false;
    375376        }
    376377        $msg1 = $ntlm_client->TypeMsg1($realm, $workstation);//msg1
    377        
    378         fputs($this->smtp_conn,"AUTH NTLM " . base64_encode($msg1) . $this->CRLF);
     378
     379        $this->client_send('AUTH NTLM ' . base64_encode($msg1) . $this->CRLF);
    379380
    380381        $rply = $this->get_lines();
    381         $code = substr($rply,0,3);
    382        
     382        $code = substr($rply, 0, 3);
     383
    383384
    384385        if($code != 334) {
    385386            $this->error =
    386                 array("error" => "AUTH not accepted from server",
    387                       "smtp_code" => $code,
    388                       "smtp_msg" => substr($rply,4));
     387                array('error' => 'AUTH not accepted from server',
     388                      'smtp_code' => $code,
     389                      'smtp_msg' => substr($rply, 4));
    389390            if($this->do_debug >= 1) {
    390                 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
     391                $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF);
    391392            }
    392393            return false;
    393394        }
    394        
    395         $challange = substr($rply,3);//though 0 based, there is a white space after the 3 digit number....//msg2
    396         $challange = base64_decode($challange);
    397         $ntlm_res = $ntlm_client->NTLMResponse(substr($challange,24,8),$password);
    398         $msg3 = $ntlm_client->TypeMsg3($ntlm_res,$username,$realm,$workstation);//msg3
     395
     396        $challenge = substr($rply, 3);//though 0 based, there is a white space after the 3 digit number....//msg2
     397        $challenge = base64_decode($challenge);
     398        $ntlm_res = $ntlm_client->NTLMResponse(substr($challenge, 24, 8), $password);
     399        $msg3 = $ntlm_client->TypeMsg3($ntlm_res, $username, $realm, $workstation);//msg3
    399400        // Send encoded username
    400         fputs($this->smtp_conn, base64_encode($msg3) . $this->CRLF);
     401        $this->client_send(base64_encode($msg3) . $this->CRLF);
    401402
    402403        $rply = $this->get_lines();
    403         $code = substr($rply,0,3);
     404        $code = substr($rply, 0, 3);
    404405
    405406        if($code != 235) {
    406407            $this->error =
    407                 array("error" => "Could not authenticate",
    408                       "smtp_code" => $code,
    409                       "smtp_msg" => substr($rply,4));
     408                array('error' => 'Could not authenticate',
     409                      'smtp_code' => $code,
     410                      'smtp_msg' => substr($rply, 4));
    410411            if($this->do_debug >= 1) {
    411                 $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF);
     412                $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF);
    412413            }
    413414            return false;
    414415        }
    415416        break;
     417      case 'CRAM-MD5':
     418        // Start authentication
     419        $this->client_send('AUTH CRAM-MD5' . $this->CRLF);
     420
     421        $rply = $this->get_lines();
     422        $code = substr($rply, 0, 3);
     423
     424        if($code != 334) {
     425          $this->error =
     426            array('error' => 'AUTH not accepted from server',
     427                  'smtp_code' => $code,
     428                  'smtp_msg' => substr($rply, 4));
     429          if($this->do_debug >= 1) {
     430            $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
     431          }
     432          return false;
     433        }
     434
     435        // Get the challenge
     436        $challenge = base64_decode(substr($rply, 4));
     437
     438        // Build the response
     439        $response = $username . ' ' . $this->hmac($challenge, $password);
     440
     441        // Send encoded credentials
     442        $this->client_send(base64_encode($response) . $this->CRLF);
     443
     444        $rply = $this->get_lines();
     445        $code = substr($rply, 0, 3);
     446
     447        if($code != 334) {
     448          $this->error =
     449            array('error' => 'Credentials not accepted from server',
     450                  'smtp_code' => $code,
     451                  'smtp_msg' => substr($rply, 4));
     452          if($this->do_debug >= 1) {
     453            $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
     454          }
     455          return false;
     456        }
     457        break;
    416458    }
    417459    return true;
    418460  }
    419461
    420462  /**
     463   * Works like hash_hmac('md5', $data, $key) in case that function is not available
     464   * @access private
     465   * @param string $data
     466   * @param string $key
     467   * @return string
     468   */
     469  private function hmac($data, $key) {
     470      if (function_exists('hash_hmac')) {
     471          return hash_hmac('md5', $data, $key);
     472      }
     473
     474      // The following borrowed from http://php.net/manual/en/function.mhash.php#27225
     475
     476      // RFC 2104 HMAC implementation for php.
     477      // Creates an md5 HMAC.
     478      // Eliminates the need to install mhash to compute a HMAC
     479      // Hacked by Lance Rushing
     480
     481      $b = 64; // byte length for md5
     482      if (strlen($key) > $b) {
     483          $key = pack('H*', md5($key));
     484      }
     485      $key  = str_pad($key, $b, chr(0x00));
     486      $ipad = str_pad('', $b, chr(0x36));
     487      $opad = str_pad('', $b, chr(0x5c));
     488      $k_ipad = $key ^ $ipad ;
     489      $k_opad = $key ^ $opad;
     490
     491      return md5($k_opad  . pack('H*', md5($k_ipad . $data)));
     492  }
     493
     494  /**
    421495   * Returns true if connected to a server otherwise false
    422496   * @access public
    423497   * @return bool
    424498   */
    425499  public function Connected() {
    426500    if(!empty($this->smtp_conn)) {
    427       $sock_status = socket_get_status($this->smtp_conn);
    428       if($sock_status["eof"]) {
     501      $sock_status = stream_get_meta_data($this->smtp_conn);
     502      if($sock_status['eof']) {
    429503        // the socket is valid but we are not connected
    430504        if($this->do_debug >= 1) {
    431             $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected");
     505            $this->edebug('SMTP -> NOTICE:' . $this->CRLF . 'EOF caught while checking if connected');
    432506        }
    433507        $this->Close();
    434508        return false;
    class SMTP { 
    472546   *     [data]
    473547   *     <CRLF>.<CRLF>
    474548   *     SMTP CODE SUCCESS: 250
    475    *     SMTP CODE FAILURE: 552,554,451,452
    476    * SMTP CODE FAILURE: 451,554
    477    * SMTP CODE ERROR  : 500,501,503,421
     549   *     SMTP CODE FAILURE: 552, 554, 451, 452
     550   * SMTP CODE FAILURE: 451, 554
     551   * SMTP CODE ERROR  : 500, 501, 503, 421
    478552   * @access public
    479553   * @param string $msg_data
    480554   * @return bool
    class SMTP { 
    484558
    485559    if(!$this->connected()) {
    486560      $this->error = array(
    487               "error" => "Called Data() without being connected");
     561              'error' => 'Called Data() without being connected');
    488562      return false;
    489563    }
    490564
    491     fputs($this->smtp_conn,"DATA" . $this->CRLF);
     565    $this->client_send('DATA' . $this->CRLF);
    492566
    493567    $rply = $this->get_lines();
    494     $code = substr($rply,0,3);
     568    $code = substr($rply, 0, 3);
    495569
    496570    if($this->do_debug >= 2) {
    497       $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     571      $this->edebug('SMTP -> FROM SERVER:' . $rply . $this->CRLF . '<br />');
    498572    }
    499573
    500574    if($code != 354) {
    501575      $this->error =
    502         array("error" => "DATA command not accepted from server",
    503               "smtp_code" => $code,
    504               "smtp_msg" => substr($rply,4));
     576        array('error' => 'DATA command not accepted from server',
     577              'smtp_code' => $code,
     578              'smtp_msg' => substr($rply, 4));
    505579      if($this->do_debug >= 1) {
    506         $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     580        $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    507581      }
    508582      return false;
    509583    }
    class SMTP { 
    520594     */
    521595
    522596    // normalize the line breaks so we know the explode works
    523     $msg_data = str_replace("\r\n","\n",$msg_data);
    524     $msg_data = str_replace("\r","\n",$msg_data);
    525     $lines = explode("\n",$msg_data);
     597    $msg_data = str_replace("\r\n", "\n", $msg_data);
     598    $msg_data = str_replace("\r", "\n", $msg_data);
     599    $lines = explode("\n", $msg_data);
    526600
    527601    /* we need to find a good way to determine is headers are
    528602     * in the msg_data or if it is a straight msg body
    class SMTP { 
    533607     * headers.
    534608     */
    535609
    536     $field = substr($lines[0],0,strpos($lines[0],":"));
     610    $field = substr($lines[0], 0, strpos($lines[0], ':'));
    537611    $in_headers = false;
    538     if(!empty($field) && !strstr($field," ")) {
     612    if(!empty($field) && !strstr($field, ' ')) {
    539613      $in_headers = true;
    540614    }
    541615
    542616    $max_line_length = 998; // used below; set here for ease in change
    543617
    544     while(list(,$line) = @each($lines)) {
     618    while(list(, $line) = @each($lines)) {
    545619      $lines_out = null;
    546       if($line == "" && $in_headers) {
     620      if($line == '' && $in_headers) {
    547621        $in_headers = false;
    548622      }
    549623      // ok we need to break this line up into several smaller lines
    550624      while(strlen($line) > $max_line_length) {
    551         $pos = strrpos(substr($line,0,$max_line_length)," ");
     625        $pos = strrpos(substr($line, 0, $max_line_length), ' ');
    552626
    553627        // Patch to fix DOS attack
    554628        if(!$pos) {
    555629          $pos = $max_line_length - 1;
    556           $lines_out[] = substr($line,0,$pos);
    557           $line = substr($line,$pos);
     630          $lines_out[] = substr($line, 0, $pos);
     631          $line = substr($line, $pos);
    558632        } else {
    559           $lines_out[] = substr($line,0,$pos);
    560           $line = substr($line,$pos + 1);
     633          $lines_out[] = substr($line, 0, $pos);
     634          $line = substr($line, $pos + 1);
    561635        }
    562636
    563637        /* if processing headers add a LWSP-char to the front of new line
    class SMTP { 
    570644      $lines_out[] = $line;
    571645
    572646      // send the lines to the server
    573       while(list(,$line_out) = @each($lines_out)) {
     647      while(list(, $line_out) = @each($lines_out)) {
    574648        if(strlen($line_out) > 0)
    575649        {
    576           if(substr($line_out, 0, 1) == ".") {
    577             $line_out = "." . $line_out;
     650          if(substr($line_out, 0, 1) == '.') {
     651            $line_out = '.' . $line_out;
    578652          }
    579653        }
    580         fputs($this->smtp_conn,$line_out . $this->CRLF);
     654        $this->client_send($line_out . $this->CRLF);
    581655      }
    582656    }
    583657
    584658    // message data has been sent
    585     fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
     659    $this->client_send($this->CRLF . '.' . $this->CRLF);
    586660
    587661    $rply = $this->get_lines();
    588     $code = substr($rply,0,3);
     662    $code = substr($rply, 0, 3);
    589663
    590664    if($this->do_debug >= 2) {
    591       $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     665      $this->edebug('SMTP -> FROM SERVER:' . $rply . $this->CRLF . '<br />');
    592666    }
    593667
    594668    if($code != 250) {
    595669      $this->error =
    596         array("error" => "DATA not accepted from server",
    597               "smtp_code" => $code,
    598               "smtp_msg" => substr($rply,4));
     670        array('error' => 'DATA not accepted from server',
     671              'smtp_code' => $code,
     672              'smtp_msg' => substr($rply, 4));
    599673      if($this->do_debug >= 1) {
    600         $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     674        $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    601675      }
    602676      return false;
    603677    }
    class SMTP { 
    622696
    623697    if(!$this->connected()) {
    624698      $this->error = array(
    625             "error" => "Called Hello() without being connected");
     699            'error' => 'Called Hello() without being connected');
    626700      return false;
    627701    }
    628702
    629703    // if hostname for HELO was not specified send default
    630704    if(empty($host)) {
    631705      // determine appropriate default to send to server
    632       $host = "localhost";
     706      $host = 'localhost';
    633707    }
    634708
    635709    // Send extended hello first (RFC 2821)
    636     if(!$this->SendHello("EHLO", $host)) {
    637       if(!$this->SendHello("HELO", $host)) {
     710    if(!$this->SendHello('EHLO', $host)) {
     711      if(!$this->SendHello('HELO', $host)) {
    638712        return false;
    639713      }
    640714    }
    class SMTP { 
    650724   * @return bool
    651725   */
    652726  private function SendHello($hello, $host) {
    653     fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
     727    $this->client_send($hello . ' ' . $host . $this->CRLF);
    654728
    655729    $rply = $this->get_lines();
    656     $code = substr($rply,0,3);
     730    $code = substr($rply, 0, 3);
    657731
    658732    if($this->do_debug >= 2) {
    659       $this->edebug("SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />');
     733      $this->edebug('SMTP -> FROM SERVER: ' . $rply . $this->CRLF . '<br />');
    660734    }
    661735
    662736    if($code != 250) {
    663737      $this->error =
    664         array("error" => $hello . " not accepted from server",
    665               "smtp_code" => $code,
    666               "smtp_msg" => substr($rply,4));
     738        array('error' => $hello . ' not accepted from server',
     739              'smtp_code' => $code,
     740              'smtp_msg' => substr($rply, 4));
    667741      if($this->do_debug >= 1) {
    668         $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     742        $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    669743      }
    670744      return false;
    671745    }
    class SMTP { 
    684758   * Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
    685759   *
    686760   * SMTP CODE SUCCESS: 250
    687    * SMTP CODE SUCCESS: 552,451,452
    688    * SMTP CODE SUCCESS: 500,501,421
     761   * SMTP CODE SUCCESS: 552, 451, 452
     762   * SMTP CODE SUCCESS: 500, 501, 421
    689763   * @access public
    690764   * @param string $from
    691765   * @return bool
    class SMTP { 
    695769
    696770    if(!$this->connected()) {
    697771      $this->error = array(
    698               "error" => "Called Mail() without being connected");
     772              'error' => 'Called Mail() without being connected');
    699773      return false;
    700774    }
    701775
    702     $useVerp = ($this->do_verp ? " XVERP" : "");
    703     fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
     776    $useVerp = ($this->do_verp ? ' XVERP' : '');
     777    $this->client_send('MAIL FROM:<' . $from . '>' . $useVerp . $this->CRLF);
    704778
    705779    $rply = $this->get_lines();
    706     $code = substr($rply,0,3);
     780    $code = substr($rply, 0, 3);
    707781
    708782    if($this->do_debug >= 2) {
    709       $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     783      $this->edebug('SMTP -> FROM SERVER:' . $rply . $this->CRLF . '<br />');
    710784    }
    711785
    712786    if($code != 250) {
    713787      $this->error =
    714         array("error" => "MAIL not accepted from server",
    715               "smtp_code" => $code,
    716               "smtp_msg" => substr($rply,4));
     788        array('error' => 'MAIL not accepted from server',
     789              'smtp_code' => $code,
     790              'smtp_msg' => substr($rply, 4));
    717791      if($this->do_debug >= 1) {
    718         $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     792        $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    719793      }
    720794      return false;
    721795    }
    class SMTP { 
    739813
    740814    if(!$this->connected()) {
    741815      $this->error = array(
    742               "error" => "Called Quit() without being connected");
     816              'error' => 'Called Quit() without being connected');
    743817      return false;
    744818    }
    745819
    746820    // send the quit command to the server
    747     fputs($this->smtp_conn,"quit" . $this->CRLF);
     821    $this->client_send('quit' . $this->CRLF);
    748822
    749823    // get any good-bye messages
    750824    $byemsg = $this->get_lines();
    751825
    752826    if($this->do_debug >= 2) {
    753       $this->edebug("SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />');
     827      $this->edebug('SMTP -> FROM SERVER:' . $byemsg . $this->CRLF . '<br />');
    754828    }
    755829
    756830    $rval = true;
    757831    $e = null;
    758832
    759     $code = substr($byemsg,0,3);
     833    $code = substr($byemsg, 0, 3);
    760834    if($code != 221) {
    761835      // use e as a tmp var cause Close will overwrite $this->error
    762       $e = array("error" => "SMTP server rejected quit command",
    763                  "smtp_code" => $code,
    764                  "smtp_rply" => substr($byemsg,4));
     836      $e = array('error' => 'SMTP server rejected quit command',
     837                 'smtp_code' => $code,
     838                 'smtp_rply' => substr($byemsg, 4));
    765839      $rval = false;
    766840      if($this->do_debug >= 1) {
    767         $this->edebug("SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />');
     841        $this->edebug('SMTP -> ERROR: ' . $e['error'] . ': ' . $byemsg . $this->CRLF . '<br />');
    768842      }
    769843    }
    770844
    class SMTP { 
    781855   *
    782856   * Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
    783857   *
    784    * SMTP CODE SUCCESS: 250,251
    785    * SMTP CODE FAILURE: 550,551,552,553,450,451,452
    786    * SMTP CODE ERROR  : 500,501,503,421
     858   * SMTP CODE SUCCESS: 250, 251
     859   * SMTP CODE FAILURE: 550, 551, 552, 553, 450, 451, 452
     860   * SMTP CODE ERROR  : 500, 501, 503, 421
    787861   * @access public
    788862   * @param string $to
    789863   * @return bool
    class SMTP { 
    793867
    794868    if(!$this->connected()) {
    795869      $this->error = array(
    796               "error" => "Called Recipient() without being connected");
     870              'error' => 'Called Recipient() without being connected');
    797871      return false;
    798872    }
    799873
    800     fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
     874    $this->client_send('RCPT TO:<' . $to . '>' . $this->CRLF);
    801875
    802876    $rply = $this->get_lines();
    803     $code = substr($rply,0,3);
     877    $code = substr($rply, 0, 3);
    804878
    805879    if($this->do_debug >= 2) {
    806       $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     880      $this->edebug('SMTP -> FROM SERVER:' . $rply . $this->CRLF . '<br />');
    807881    }
    808882
    809883    if($code != 250 && $code != 251) {
    810884      $this->error =
    811         array("error" => "RCPT not accepted from server",
    812               "smtp_code" => $code,
    813               "smtp_msg" => substr($rply,4));
     885        array('error' => 'RCPT not accepted from server',
     886              'smtp_code' => $code,
     887              'smtp_msg' => substr($rply, 4));
    814888      if($this->do_debug >= 1) {
    815         $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     889        $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    816890      }
    817891      return false;
    818892    }
    class SMTP { 
    827901   * Implements rfc 821: RSET <CRLF>
    828902   *
    829903   * SMTP CODE SUCCESS: 250
    830    * SMTP CODE ERROR  : 500,501,504,421
     904   * SMTP CODE ERROR  : 500, 501, 504, 421
    831905   * @access public
    832906   * @return bool
    833907   */
    class SMTP { 
    835909    $this->error = null; // so no confusion is caused
    836910
    837911    if(!$this->connected()) {
    838       $this->error = array(
    839               "error" => "Called Reset() without being connected");
     912      $this->error = array('error' => 'Called Reset() without being connected');
    840913      return false;
    841914    }
    842915
    843     fputs($this->smtp_conn,"RSET" . $this->CRLF);
     916    $this->client_send('RSET' . $this->CRLF);
    844917
    845918    $rply = $this->get_lines();
    846     $code = substr($rply,0,3);
     919    $code = substr($rply, 0, 3);
    847920
    848921    if($this->do_debug >= 2) {
    849       $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     922      $this->edebug('SMTP -> FROM SERVER:' . $rply . $this->CRLF . '<br />');
    850923    }
    851924
    852925    if($code != 250) {
    853926      $this->error =
    854         array("error" => "RSET failed",
    855               "smtp_code" => $code,
    856               "smtp_msg" => substr($rply,4));
     927        array('error' => 'RSET failed',
     928              'smtp_code' => $code,
     929              'smtp_msg' => substr($rply, 4));
    857930      if($this->do_debug >= 1) {
    858         $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     931        $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    859932      }
    860933      return false;
    861934    }
    class SMTP { 
    874947   * Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
    875948   *
    876949   * SMTP CODE SUCCESS: 250
    877    * SMTP CODE SUCCESS: 552,451,452
    878    * SMTP CODE SUCCESS: 500,501,502,421
     950   * SMTP CODE SUCCESS: 552, 451, 452
     951   * SMTP CODE SUCCESS: 500, 501, 502, 421
    879952   * @access public
    880953   * @param string $from
    881954   * @return bool
    class SMTP { 
    885958
    886959    if(!$this->connected()) {
    887960      $this->error = array(
    888           "error" => "Called SendAndMail() without being connected");
     961          'error' => 'Called SendAndMail() without being connected');
    889962      return false;
    890963    }
    891964
    892     fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
     965    $this->client_send('SAML FROM:' . $from . $this->CRLF);
    893966
    894967    $rply = $this->get_lines();
    895     $code = substr($rply,0,3);
     968    $code = substr($rply, 0, 3);
    896969
    897970    if($this->do_debug >= 2) {
    898       $this->edebug("SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />');
     971      $this->edebug('SMTP -> FROM SERVER:' . $rply . $this->CRLF . '<br />');
    899972    }
    900973
    901974    if($code != 250) {
    902975      $this->error =
    903         array("error" => "SAML not accepted from server",
    904               "smtp_code" => $code,
    905               "smtp_msg" => substr($rply,4));
     976        array('error' => 'SAML not accepted from server',
     977              'smtp_code' => $code,
     978              'smtp_msg' => substr($rply, 4));
    906979      if($this->do_debug >= 1) {
    907         $this->edebug("SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />');
     980        $this->edebug('SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />');
    908981      }
    909982      return false;
    910983    }
    class SMTP { 
    925998   * @return bool
    926999   */
    9271000  public function Turn() {
    928     $this->error = array("error" => "This method, TURN, of the SMTP ".
    929                                     "is not implemented");
     1001    $this->error = array('error' => 'This method, TURN, of the SMTP '.
     1002                                    'is not implemented');
    9301003    if($this->do_debug >= 1) {
    931       $this->edebug("SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />');
     1004      $this->edebug('SMTP -> NOTICE: ' . $this->error['error'] . $this->CRLF . '<br />');
    9321005    }
    9331006    return false;
    9341007  }
    9351008
    9361009  /**
     1010  * Sends data to the server
     1011  * @param string $data
     1012  * @access public
     1013  * @return Integer number of bytes sent to the server or FALSE on error
     1014  */
     1015  public function client_send($data) {
     1016      if ($this->do_debug >= 1) {
     1017          $this->edebug("CLIENT -> SMTP: $data" . $this->CRLF . '<br />');
     1018      }
     1019      return fwrite($this->smtp_conn, $data);
     1020  }
     1021
     1022  /**
    9371023  * Get the current error
    9381024  * @access public
    9391025  * @return array
    class SMTP { 
    9561042   * @return string
    9571043   */
    9581044  private function get_lines() {
    959     $data = "";
     1045    $data = '';
    9601046    $endtime = 0;
    9611047    /* If for some reason the fp is bad, don't inf loop */
    9621048    if (!is_resource($this->smtp_conn)) {
    class SMTP { 
    9671053      $endtime = time() + $this->Timelimit;
    9681054    }
    9691055    while(is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
    970       $str = @fgets($this->smtp_conn,515);
     1056      $str = @fgets($this->smtp_conn, 515);
    9711057      if($this->do_debug >= 4) {
    9721058        $this->edebug("SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />');
    9731059        $this->edebug("SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />');
    class SMTP { 
    9771063        $this->edebug("SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />');
    9781064      }
    9791065      // if 4th character is a space, we are done reading, break the loop
    980       if(substr($str,3,1) == " ") { break; }
     1066      if(substr($str, 3, 1) == ' ') { break; }
    9811067      // Timed-out? Log and break
    9821068      $info = stream_get_meta_data($this->smtp_conn);
    9831069      if ($info['timed_out']) {
    9841070        if($this->do_debug >= 4) {
    985           $this->edebug("SMTP -> get_lines(): timed-out (" . $this->Timeout . " seconds) <br />");
     1071          $this->edebug('SMTP -> get_lines(): timed-out (' . $this->Timeout . ' seconds) <br />');
    9861072        }
    9871073        break;
    9881074      }
    class SMTP { 
    9901076      if ($endtime) {
    9911077        if (time() > $endtime) {
    9921078          if($this->do_debug >= 4) {
    993             $this->edebug("SMTP -> get_lines(): timelimit reached (" . $this->Timelimit . " seconds) <br />");
     1079            $this->edebug('SMTP -> get_lines(): timelimit reached (' . $this->Timelimit . ' seconds) <br />');
    9941080          }
    9951081          break;
    9961082        }
    class SMTP { 
    10001086  }
    10011087
    10021088}
    1003 ?>