Changeset 974

Show
Ignore:
Timestamp:
07/25/08 18:50:21 (1 month ago)
Author:
bermiferrer
Message:

Updating PEAR Mail, Net and Auth

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/vendor/pear/Auth/SASL.php

    r2 r974  
    3333// +-----------------------------------------------------------------------+  
    3434//  
    35 // $Id: SASL.php,v 1.4 2003/02/21 16:07:17 mj Exp $ 
     35// $Id: SASL.php,v 1.5 2006/03/22 05:20:11 amistry Exp $ 
    3636 
    3737/** 
     
    9292 
    9393        require_once($filename); 
    94         return new $classname(); 
     94        $obj = new $classname(); 
     95        return $obj; 
    9596    } 
    9697} 
  • trunk/vendor/pear/Auth/SASL/DigestMD5.php

    r2 r974  
    3333// +-----------------------------------------------------------------------+  
    3434//  
    35 // $Id: DigestMD5.php,v 1.6 2003/02/21 16:07:17 mj Exp $ 
     35// $Id: DigestMD5.php,v 1.8 2006/03/22 05:20:11 amistry Exp $ 
    3636 
    3737/** 
     
    7575            $response_value = $this->_getResponseValue($authcid, $pass, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $authzid); 
    7676 
    77             return sprintf('username="%s",realm="%s"' . $authzid_string  . ',nonce="%s",cnonce="%s",nc="00000001",qop=auth,digest-uri="%s",response=%s,%d', $authcid, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']); 
     77            if ($challenge['realm']) { 
     78                return sprintf('username="%s",realm="%s"' . $authzid_string  . 
     79',nonce="%s",cnonce="%s",nc=00000001,qop=auth,digest-uri="%s",response=%s,maxbuf=%d', $authcid, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']); 
     80            } else { 
     81                return sprintf('username="%s"' . $authzid_string  . ',nonce="%s",cnonce="%s",nc=00000001,qop=auth,digest-uri="%s",response=%s,maxbuf=%d', $authcid, $challenge['nonce'], $cnonce, $digest_uri, $response_value, $challenge['maxbuf']); 
     82            } 
    7883        } else { 
    7984            return PEAR::raiseError('Invalid digest challenge'); 
     
    126131        // Realm 
    127132        if (empty($tokens['realm'])) { 
    128             $uname = posix_uname(); 
    129             $tokens['realm'] = $uname['nodename']; 
     133            $tokens['realm'] = ""; 
    130134        } 
    131          
     135 
    132136        // Maxbuf 
    133137        if (empty($tokens['maxbuf'])) { 
    134138            $tokens['maxbuf'] = 65536; 
    135139        } 
    136          
     140 
    137141        // Required: nonce, algorithm 
    138142        if (empty($tokens['nonce']) OR empty($tokens['algorithm'])) { 
    139143            return array(); 
    140144        } 
    141          
     145 
    142146        return $tokens; 
    143147    } 
     
    175179    function _getCnonce() 
    176180    { 
    177         if (file_exists('/dev/urandom')) { 
    178             return base64_encode(fread(fopen('/dev/urandom', 'r'), 32)); 
     181        if (file_exists('/dev/urandom') && $fd = @fopen('/dev/urandom', 'r')) { 
     182            return base64_encode(fread($fd, 32)); 
    179183 
    180         } elseif (file_exists('/dev/random')) { 
    181             return base64_encode(fread(fopen('/dev/random', 'r'), 32)); 
     184        } elseif (file_exists('/dev/random') && $fd = @fopen('/dev/random', 'r')) { 
     185            return base64_encode(fread($fd, 32)); 
    182186 
    183187        } else { 
  • trunk/vendor/pear/Auth/SASL/Plain.php

    r2 r974  
    3333// +-----------------------------------------------------------------------+  
    3434//  
    35 // $Id: Plain.php,v 1.5 2003/02/21 16:07:17 mj Exp $ 
     35// $Id: Plain.php,v 1.6 2003/09/11 18:53:56 mbretter Exp $ 
    3636 
    3737/** 
  • trunk/vendor/pear/Mail.php

    r54 r974  
    1717// +----------------------------------------------------------------------+ 
    1818// 
    19 // $Id: Mail.php,v 1.17 2006/09/15 03:41:18 jon Exp $ 
     19// $Id: Mail.php,v 1.20 2007/10/06 17:00:00 chagenbu Exp $ 
    2020 
    2121require_once 'PEAR.php'; 
     
    2727 * 
    2828 * @access public 
    29  * @version $Revision: 1.17
     29 * @version $Revision: 1.20
    3030 * @package Mail 
    3131 */ 
     
    8383     *               containing a descriptive error message on 
    8484     *               failure. 
     85     * 
    8586     * @access public 
    8687     * @deprecated use Mail_mail::send instead 
     
    8889    function send($recipients, $headers, $body) 
    8990    { 
    90         $this->_sanitizeHeaders($headers); 
     91        if (!is_array($headers)) { 
     92            return PEAR::raiseError('$headers must be an array'); 
     93        } 
     94 
     95        $result = $this->_sanitizeHeaders($headers); 
     96        if (is_a($result, 'PEAR_Error')) { 
     97            return $result; 
     98        } 
    9199 
    92100        // if we're passed an array of recipients, implode it. 
     
    104112 
    105113        // flatten the headers out. 
    106         list(,$text_headers) = Mail::prepareHeaders($headers); 
     114        list(, $text_headers) = Mail::prepareHeaders($headers); 
    107115 
    108116        return mail($recipients, $subject, $body, $text_headers); 
    109  
    110117    } 
    111118 
     
    152159            if (strcasecmp($key, 'From') === 0) { 
    153160                include_once 'Mail/RFC822.php'; 
    154                 $parser = &new Mail_RFC822(); 
     161                $parser = new Mail_RFC822(); 
    155162                $addresses = $parser->parseAddressList($value, 'localhost', false); 
    156                 if (PEAR::isError($addresses)) { 
     163                if (is_a($addresses, 'PEAR_Error')) { 
    157164                    return $addresses; 
    158165                } 
     
    162169                // Reject envelope From: addresses with spaces. 
    163170                if (strstr($from, ' ')) { 
    164                     die('Aquiii'); 
    165171                    return false; 
    166172                } 
     
    223229 
    224230        // If parseAddressList() returned a PEAR_Error object, just return it. 
    225         if (PEAR::isError($addresses)) { 
     231        if (is_a($addresses, 'PEAR_Error')) { 
    226232            return $addresses; 
    227233        } 
  • trunk/vendor/pear/Mail/RFC822.php

    r2 r974  
    5353 * @author  Richard Heyes <richard@phpguru.org> 
    5454 * @author  Chuck Hagenbuch <chuck@horde.org> 
    55  * @version $Revision: 1.21
     55 * @version $Revision: 1.24
    5656 * @license BSD 
    5757 * @package Mail 
     
    343343 
    344344    /** 
    345      * Checks if a string has an unclosed quotes or not. 
    346      * 
    347      * @access private 
    348      * @param string $string The string to check. 
    349      * @return boolean True if there are unclosed quotes inside the string, false otherwise. 
     345     * Checks if a string has unclosed quotes or not. 
     346     * 
     347     * @access private 
     348     * @param string $string  The string to check. 
     349     * @return boolean  True if there are unclosed quotes inside the string, 
     350     *                  false otherwise. 
    350351     */ 
    351352    function _hasUnclosedQuotes($string) 
    352353    { 
    353         $string     = explode('"', $string); 
    354         $string_cnt = count($string); 
    355  
    356         for ($i = 0; $i < (count($string) - 1); $i++) 
    357             if (substr($string[$i], -1) == '\\') 
    358                 $string_cnt--; 
    359  
    360         return ($string_cnt % 2 === 0); 
     354        $string = trim($string); 
     355        $iMax = strlen($string); 
     356        $in_quote = false; 
     357        $i = $slashes = 0; 
     358 
     359        for (; $i < $iMax; ++$i) { 
     360            switch ($string[$i]) { 
     361            case '\\': 
     362                ++$slashes; 
     363                break; 
     364 
     365            case '"': 
     366                if ($slashes % 2 == 0) { 
     367                    $in_quote = !$in_quote; 
     368                } 
     369                // Fall through to default action below. 
     370 
     371            default: 
     372                $slashes = 0; 
     373                break; 
     374            } 
     375        } 
     376 
     377        return $in_quote; 
    361378    } 
    362379 
     
    913930    function isValidInetAddress($data, $strict = false) 
    914931    { 
    915         $regex = $strict ? '/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i' : '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i'; 
     932        $regex = $strict ? '/^([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i' : '/^([*+!.&#$|\'\\%\/0-9a-z^_`{}=?~:-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i'; 
    916933        if (preg_match($regex, trim($data), $matches)) { 
    917934            return array($matches[1], $matches[2]); 
  • trunk/vendor/pear/Mail/mail.php

    r2 r974  
    1717// +----------------------------------------------------------------------+ 
    1818// 
    19 // $Id: mail.php,v 1.13 2004/09/09 02:08:55 jon Exp $ 
     19// $Id: mail.php,v 1.20 2007/10/06 17:00:00 chagenbu Exp $ 
    2020 
    2121/** 
    2222 * internal PHP-mail() implementation of the PEAR Mail:: interface. 
    2323 * @package Mail 
    24  * @version $Revision: 1.13
     24 * @version $Revision: 1.20
    2525 */ 
    2626class Mail_mail extends Mail { 
     
    4242    function Mail_mail($params = null) 
    4343    { 
    44         /* The other mail implementations accept parameters as arrays. 
    45         * In the interest of being consistent, explode an array into 
    46         * a string of parameter arguments. */ 
     44        // The other mail implementations accept parameters as arrays. 
     45        // In the interest of being consistent, explode an array into 
     46        // a string of parameter arguments. 
    4747        if (is_array($params)) { 
    4848            $this->_params = join(' ', $params); 
     
    5555         * "\r\n" separator.  Instead, we use the system's native line 
    5656         * separator. */ 
    57         $this->sep = (strstr(PHP_OS, 'WIN')) ? "\r\n" : "\n"; 
     57        if (defined('PHP_EOL')) { 
     58            $this->sep = PHP_EOL; 
     59        } else { 
     60            $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n"; 
     61        } 
    5862    } 
    5963 
    60        /** 
     64    /** 
    6165     * Implements Mail_mail::send() function using php's built-in mail() 
    6266     * command. 
     
    8690    function send($recipients, $headers, $body) 
    8791    { 
     92        if (!is_array($headers)) { 
     93            return PEAR::raiseError('$headers must be an array'); 
     94        } 
     95 
     96        $result = $this->_sanitizeHeaders($headers); 
     97        if (is_a($result, 'PEAR_Error')) { 
     98            return $result; 
     99        } 
     100 
    88101        // If we're passed an array of recipients, implode it. 
    89102        if (is_array($recipients)) { 
     
    99112        } 
    100113 
     114        // Also remove the To: header.  The mail() function will add its own 
     115        // To: header based on the contents of $recipients. 
     116        unset($headers['To']); 
     117 
    101118        // Flatten the headers out. 
    102119        $headerElements = $this->prepareHeaders($headers); 
    103         if (PEAR::isError($headerElements)) { 
     120        if (is_a($headerElements, 'PEAR_Error')) { 
    104121            return $headerElements; 
    105122        } 
    106123        list(, $text_headers) = $headerElements; 
    107124 
    108         /* 
    109          * We only use mail()'s optional fifth parameter if the additional 
    110          * parameters have been provided and we're not running in safe mode. 
    111          */ 
     125        // We only use mail()'s optional fifth parameter if the additional 
     126        // parameters have been provided and we're not running in safe mode. 
    112127        if (empty($this->_params) || ini_get('safe_mode')) { 
    113128            $result = mail($recipients, $subject, $body, $text_headers); 
     
    117132        } 
    118133 
    119         /* 
    120          * If the mail() function returned failure, we need to create a 
    121          * PEAR_Error object and return it instead of the boolean result. 
    122          */ 
     134        // If the mail() function returned failure, we need to create a 
     135        // PEAR_Error object and return it instead of the boolean result. 
    123136        if ($result === false) { 
    124137            $result = PEAR::raiseError('mail() returned failure'); 
  • trunk/vendor/pear/Mail/mimePart.php

    r54 r974  
    197197        } 
    198198 
     199         
    199200        // Assign stuff to member variables 
    200201        $this->_encoded  = array(); 
  • trunk/vendor/pear/Mail/sendmail.php

    r2 r974  
    2121 * @access public 
    2222 * @package Mail 
    23  * @version $Revision: 1.10
     23 * @version $Revision: 1.19
    2424 */ 
    2525class Mail_sendmail extends Mail { 
    2626 
    27        /** 
     27    /** 
    2828     * The location of the sendmail or sendmail wrapper binary on the 
    2929     * filesystem. 
     
    3232    var $sendmail_path = '/usr/sbin/sendmail'; 
    3333 
    34        /** 
     34    /** 
    3535     * Any extra command-line parameters to pass to the sendmail or 
    3636     * sendmail wrapper binary. 
    3737     * @var string 
    3838     */ 
    39     var $sendmail_args = ''; 
     39    var $sendmail_args = '-i'; 
    4040 
    41        /** 
     41    /** 
    4242     * Constructor. 
    4343     * 
     
    5959    function Mail_sendmail($params) 
    6060    { 
    61         if (isset($params['sendmail_path'])) $this->sendmail_path = $params['sendmail_path']; 
    62         if (isset($params['sendmail_args'])) $this->sendmail_args = $params['sendmail_args']; 
     61        if (isset($params['sendmail_path'])) { 
     62            $this->sendmail_path = $params['sendmail_path']; 
     63        } 
     64        if (isset($params['sendmail_args'])) { 
     65            $this->sendmail_args = $params['sendmail_args']; 
     66        } 
    6367 
    6468        /* 
     
    6771         * separator.  Instead, we use the system's native line separator. 
    6872         */ 
    69         $this->sep = (strstr(PHP_OS, 'WIN')) ? "\r\n" : "\n"; 
     73        if (defined('PHP_EOL')) { 
     74            $this->sep = PHP_EOL; 
     75        } else { 
     76            $this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\n"; 
     77        } 
    7078    } 
    7179 
    72        /** 
     80    /** 
    7381     * Implements Mail::send() function using the sendmail 
    7482     * command-line binary. 
     
    97105    function send($recipients, $headers, $body) 
    98106    { 
     107        if (!is_array($headers)) { 
     108            return PEAR::raiseError('$headers must be an array'); 
     109        } 
     110 
     111        $result = $this->_sanitizeHeaders($headers); 
     112        if (is_a($result, 'PEAR_Error')) { 
     113            return $result; 
     114        } 
     115 
    99116        $recipients = $this->parseRecipients($recipients); 
    100         if (PEAR::isError($recipients)) { 
     117        if (is_a($recipients, 'PEAR_Error')) { 
    101118            return $recipients; 
    102119        } 
     
    104121 
    105122        $headerElements = $this->prepareHeaders($headers); 
    106         if (PEAR::isError($headerElements)) { 
     123        if (is_a($headerElements, 'PEAR_Error')) { 
    107124            return $headerElements; 
    108125        } 
    109126        list($from, $text_headers) = $headerElements; 
    110127 
     128        /* Since few MTAs are going to allow this header to be forged 
     129         * unless it's in the MAIL FROM: exchange, we'll use 
     130         * Return-Path instead of From: if it's set. */ 
     131        if (!empty($headers['Return-Path'])) { 
     132            $from = $headers['Return-Path']; 
     133        } 
     134 
    111135        if (!isset($from)) { 
    112136            return PEAR::raiseError('No from address given.'); 
    113         } elseif (strstr($from, ' ') || 
    114                   strstr($from, ';') || 
    115                   strstr($from, '&') || 
    116                   strstr($from, '`')) { 
     137        } elseif (strpos($from, ' ') !== false || 
     138                  strpos($from, ';') !== false || 
     139                  strpos($from, '&') !== false || 
     140                  strpos($from, '`') !== false) { 
    117141            return PEAR::raiseError('From address specified with dangerous characters.'); 
    118142        } 
    119143 
    120         $result = 0; 
    121         if (@is_file($this->sendmail_path)) { 
    122             $from = escapeShellCmd($from); 
    123             $mail = popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w'); 
    124             fputs($mail, $text_headers); 
    125             fputs($mail, $this->sep);  // newline to end the headers section 
    126             fputs($mail, $body); 
    127             $result = pclose($mail); 
    128             if (version_compare(phpversion(), '4.2.3') == -1) { 
    129                 // With older php versions, we need to shift the 
    130                 // pclose result to get the exit code. 
    131                 $result = $result >> 8 & 0xFF; 
    132             } 
    133         } else { 
    134             return PEAR::raiseError('sendmail [' . $this->sendmail_path . '] is not a valid file'); 
     144        $from = escapeShellCmd($from); 
     145        $mail = @popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w'); 
     146        if (!$mail) { 
     147            return PEAR::raiseError('Failed to open sendmail [' . $this->sendmail_path . '] for execution.'); 
     148        } 
     149 
     150        // Write the headers following by two newlines: one to end the headers 
     151        // section and a second to separate the headers block from the body. 
     152        fputs($mail, $text_headers . $this->sep . $this->sep); 
     153 
     154        fputs($mail, $body); 
     155        $result = pclose($mail); 
     156        if (version_compare(phpversion(), '4.2.3') == -1) { 
     157            // With older php versions, we need to shift the pclose 
     158            // result to get the exit code. 
     159            $result = $result >> 8 & 0xFF; 
    135160        } 
    136161 
  • trunk/vendor/pear/Mail/smtp.php

    r2 r974  
    1818// +----------------------------------------------------------------------+ 
    1919 
     20/** Error: Failed to create a Net_SMTP object */ 
     21define('PEAR_MAIL_SMTP_ERROR_CREATE', 10000); 
     22 
     23/** Error: Failed to connect to SMTP server */ 
     24define('PEAR_MAIL_SMTP_ERROR_CONNECT', 10001); 
     25 
     26/** Error: SMTP authentication failure */ 
     27define('PEAR_MAIL_SMTP_ERROR_AUTH', 10002); 
     28 
     29/** Error: No From: address has been provided */ 
     30define('PEAR_MAIL_SMTP_ERROR_FROM', 10003); 
     31 
     32/** Error: Failed to set sender */ 
     33define('PEAR_MAIL_SMTP_ERROR_SENDER', 10004); 
     34 
     35/** Error: Failed to add recipient */ 
     36define('PEAR_MAIL_SMTP_ERROR_RECIPIENT', 10005); 
     37 
     38/** Error: Failed to send data */ 
     39define('PEAR_MAIL_SMTP_ERROR_DATA', 10006); 
     40 
    2041/** 
    21  * SMTP implementation of the PEAR Mail:: interface. Requires the PEAR 
    22  * Net_SMTP:: class. 
     42 * SMTP implementation of the PEAR Mail interface. Requires the Net_SMTP class. 
    2343 * @access public 
    2444 * @package Mail 
    25  * @version $Revision: 1.20
     45 * @version $Revision: 1.33
    2646 */ 
    2747class Mail_smtp extends Mail { 
    2848 
    2949    /** 
     50     * SMTP connection object. 
     51     * 
     52     * @var object 
     53     * @access private 
     54     */ 
     55    var $_smtp = null; 
     56 
     57    /** 
     58     * The list of service extension parameters to pass to the Net_SMTP 
     59     * mailFrom() command. 
     60     * @var array 
     61     */ 
     62    var $_extparams = array(); 
     63 
     64    /** 
    3065     * The SMTP host to connect to. 
    3166     * @var string 
     
    80115 
    81116    /** 
    82      * Whether to use VERP or not. If not a boolean, the string value 
    83      * will be used as the VERP separators. 
    84      * 
    85      * @var mixed boolean or string 
    86      */ 
    87     var $verp = false; 
    88  
    89     /** 
    90117     * Turn on Net_SMTP debugging? 
    91118     * 
     
    93120     */ 
    94121    var $debug = false; 
     122 
     123    /** 
     124     * Indicates whether or not the SMTP connection should persist over 
     125     * multiple calls to the send() method. 
     126     * 
     127     * @var boolean 
     128     */ 
     129    var $persist = false; 
     130 
     131    /** 
     132     * Use SMTP command pipelining (specified in RFC 2920) if the SMTP server 
     133     * supports it. This speeds up delivery over high-latency connections. By 
     134     * default, use the default value supplied by Net_SMTP. 
     135     * @var bool 
     136     */ 
     137    var $pipelining; 
    95138 
    96139    /** 
     
    107150     *     timeout     The SMTP connection timeout. Defaults to none. 
    108151     *     verp        Whether to use VERP or not. Defaults to false. 
     152     *                 DEPRECATED as of 1.2.0 (use setMailParams()). 
    109153     *     debug       Activate SMTP debug mode? Defaults to false. 
     154     *     persist     Should the SMTP connection persist? 
     155     *     pipelining  Use SMTP command pipelining 
    110156     * 
    111157     * If a parameter is present in the $params array, it replaces the 
     
    125171        if (isset($params['localhost'])) $this->localhost = $params['localhost']; 
    126172        if (isset($params['timeout'])) $this->timeout = $params['timeout']; 
    127         if (isset($params['verp'])) $this->verp = $params['verp']; 
    128         if (isset($params['debug'])) $this->debug = (boolean)$params['debug']; 
     173        if (isset($params['debug'])) $this->debug = (bool)$params['debug']; 
     174        if (isset($params['persist'])) $this->persist = (bool)$params['persist']; 
     175        if (isset($params['pipelining'])) $this->pipelining = (bool)$params['pipelining']; 
     176 
     177        // Deprecated options 
     178        if (isset($params['verp'])) { 
     179            $this->addServiceExtensionParameter('XVERP', is_bool($params['verp']) ? null : $params['verp']); 
     180        } 
     181 
     182        register_shutdown_function(array(&$this, '_Mail_smtp')); 
     183    } 
     184 
     185    /** 
     186     * Destructor implementation to ensure that we disconnect from any 
     187     * potentially-alive persistent SMTP connections. 
     188     */ 
     189    function _Mail_smtp() 
     190    { 
     191        $this->disconnect(); 
    129192    } 
    130193 
     
    146209     * 
    147210     * @param string $body The full text of the message body, including any 
    148      *               Mime parts, etc. 
     211     *               MIME parts, etc. 
    149212     * 
    150213     * @return mixed Returns true on success, or a PEAR_Error 
     
    155218    function send($recipients, $headers, $body) 
    156219    { 
    157         include_once 'Net/SMTP.php'; 
    158  
    159         if (!($smtp = &new Net_SMTP($this->host, $this->port, $this->localhost))) { 
    160             return PEAR::raiseError('unable to instantiate Net_SMTP object'); 
    161         } 
    162  
    163         if ($this->debug) { 
    164             $smtp->setDebug(true); 
    165         } 
    166  
    167         if (PEAR::isError($smtp->connect($this->timeout))) { 
    168             return PEAR::raiseError('unable to connect to smtp server ' . 
    169                                     $this->host . ':' . $this->port); 
    170         } 
    171  
    172         if ($this->auth) { 
    173             $method = is_string($this->auth) ? $this->auth : ''; 
    174  
    175             if (PEAR::isError($smtp->auth($this->username, $this->password, 
    176                               $method))) { 
    177                 return PEAR::raiseError('unable to authenticate to smtp server'); 
    178             } 
    179         } 
     220        /* If we don't already have an SMTP object, create one. */ 
     221        $result = &$this->getSMTPObject(); 
     222        if (PEAR::isError($result)) { 
     223            return $result; 
     224        } 
     225 
     226        if (!is_array($headers)) { 
     227            return PEAR::raiseError('$headers must be an array'); 
     228        } 
     229 
     230        $this->_sanitizeHeaders($headers); 
    180231 
    181232        $headerElements = $this->prepareHeaders($headers); 
    182         if (PEAR::isError($headerElements)) { 
     233        if (is_a($headerElements, 'PEAR_Error')) { 
     234            $this->_smtp->rset(); 
    183235            return $headerElements; 
    184236        } 
    185         list($from, $text_headers) = $headerElements; 
     237        list($from, $textHeaders) = $headerElements; 
    186238 
    187239        /* Since few MTAs are going to allow this header to be forged 
     
    193245 
    194246        if (!isset($from)) { 
    195             return PEAR::raiseError('No from address given'); 
    196         } 
    197  
    198         $args['verp'] = $this->verp; 
    199         if (PEAR::isError($smtp->mailFrom($from, $args))) { 
    200             return PEAR::raiseError('unable to set sender to [' . $from . ']'); 
     247            $this->_smtp->rset(); 
     248            return PEAR::raiseError('No From: address has been provided', 
     249                                    PEAR_MAIL_SMTP_ERROR_FROM); 
     250        } 
     251 
     252        $params = null; 
     253        if (!empty($this->_extparams)) { 
     254            foreach ($this->_extparams as $key => $val) { 
     255                $params .= ' ' . $key . (is_null($val) ? '' : '=' . $val); 
     256            } 
     257        } 
     258        if (PEAR::isError($res = $this->_smtp->mailFrom($from, ltrim($params)))) { 
     259            $error = $this->_error("Failed to set sender: $from", $res); 
     260            $this->_smtp->rset(); 
     261            return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_SENDER); 
    201262        } 
    202263 
    203264        $recipients = $this->parseRecipients($recipients); 
    204         if (PEAR::isError($recipients)) { 
     265        if (is_a($recipients, 'PEAR_Error')) { 
     266            $this->_smtp->rset(); 
    205267            return $recipients; 
    206268        } 
    207269 
    208270        foreach ($recipients as $recipient) { 
    209             if (PEAR::isError($res = $smtp->rcptTo($recipient))) { 
    210                 return PEAR::raiseError('unable to add recipient [' . 
    211                                         $recipient . ']: ' . $res->getMessage()); 
     271            $res = $this->_smtp->rcptTo($recipient); 
     272            if (is_a($res, 'PEAR_Error')) { 
     273                $error = $this->_error("Failed to add recipient: $recipient", $res); 
     274                $this->_smtp->rset(); 
     275                return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_RECIPIENT); 
    212276            } 
    213277        } 
    214278 
    215         if (PEAR::isError($smtp->data($text_headers . "\r\n" . $body))) { 
    216             return PEAR::raiseError('unable to send data'); 
    217         } 
    218  
    219         $smtp->disconnect(); 
     279        /* Send the message's headers and the body as SMTP data. */ 
     280        $res = $this->_smtp->data($textHeaders . "\r\n\r\n" . $body); 
     281        if (is_a($res, 'PEAR_Error')) { 
     282            $error = $this->_error('Failed to send data', $res); 
     283            $this->_smtp->rset(); 
     284            return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_DATA); 
     285        } 
     286 
     287        /* If persistent connections are disabled, destroy our SMTP object. */ 
     288        if ($this->persist === false) { 
     289            $this->disconnect(); 
     290        } 
     291 
    220292        return true; 
    221293    } 
    222294 
     295    /** 
     296     * Connect to the SMTP server by instantiating a Net_SMTP object. 
     297     * 
     298     * @return mixed Returns a reference to the Net_SMTP object on success, or 
     299     *               a PEAR_Error containing a descriptive error message on 
     300     *               failure. 
     301     * 
     302     * @since  1.2.0 
     303     * @access public 
     304     */ 
     305    function &getSMTPObject() 
     306    { 
     307        if (is_object($this->_smtp) !== false) { 
     308            return $this->_smtp; 
     309        } 
     310 
     311        include_once 'Net/SMTP.php'; 
     312        $this->_smtp = &new Net_SMTP($this->host, 
     313                                     $this->port, 
     314                                     $this->localhost); 
     315 
     316        /* If we still don't have an SMTP object at this point, fail. */ 
     317        if (is_object($this->_smtp) === false) { 
     318            return PEAR::raiseError('Failed to create a Net_SMTP object', 
     319                                    PEAR_MAIL_SMTP_ERROR_CREATE); 
     320        } 
     321 
     322        /* Configure the SMTP connection. */ 
     323        if ($this->debug) { 
     324            $this->_smtp->setDebug(true); 
     325        } 
     326 
     327        /* Attempt to connect to the configured SMTP server. */ 
     328        if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) { 
     329            $error = $this->_error('Failed to connect to ' . 
     330                                   $this->host . ':' . $this->port, 
     331                                   $res); 
     332            return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT); 
     333        } 
     334 
     335        /* Attempt to authenticate if authentication has been enabled. */ 
     336        if ($this->auth) { 
     337            $method = is_string($this->auth) ? $this->auth : ''; 
     338 
     339            if (PEAR::isError($res = $this->_smtp->auth($this->username, 
     340                                                        $this->password, 
     341                                                        $method))) { 
     342                $error = $this->_error("$method authentication failure", 
     343                                       $res); 
     344                $this->_smtp->rset(); 
     345                return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH); 
     346            } 
     347        } 
     348 
     349        return $this->_smtp; 
     350    } 
     351 
     352    /** 
     353     * Add parameter associated with a SMTP service extension. 
     354     * 
     355     * @param string Extension keyword. 
     356     * @param string Any value the keyword needs. 
     357     * 
     358     * @since 1.2.0 
     359     * @access public 
     360     */ 
     361    function addServiceExtensionParameter($keyword, $value = null) 
     362    { 
     363        $this->_extparams[$keyword] = $value; 
     364    } 
     365 
     366    /** 
     367     * Disconnect and destroy the current SMTP connection. 
     368     * 
     369     * @return boolean True if the SMTP connection no longer exists. 
     370     * 
     371     * @since  1.1.9 
     372     * @access public 
     373     */ 
     374    function disconnect() 
     375    { 
     376        /* If we have an SMTP object, disconnect and destroy it. */ 
     377        if (is_object($this->_smtp) && $this->_smtp->disconnect()) { 
     378            $this->_smtp = null; 
     379        } 
     380 
     381        /* We are disconnected if we no longer have an SMTP object. */ 
     382        return ($this->_smtp === null); 
     383    } 
     384 
     385    /** 
     386     * Build a standardized string describing the current SMTP error. 
     387     * 
     388     * @param string $text  Custom string describing the error context. 
     389     * @param object $error Reference to the current PEAR_Error object. 
     390     * 
     391     * @return string       A string describing the current SMTP error. 
     392     * 
     393     * @since  1.1.7 
     394     * @access private 
     395     */ 
     396    function _error($text, &$error) 
     397    { 
     398        /* Split the SMTP response into a code and a response string. */ 
     399        list($code, $response) = $this->_smtp->getResponse(); 
     400 
     401        /* Build our standardized error string. */ 
     402        return $text 
     403            . ' [SMTP: ' . $error->getMessage() 
     404            . " (code: $code, response: $response)]"; 
     405    } 
     406 
    223407} 
  • trunk/vendor/pear/Net/SMTP.php

    <
    r2 r974  
    1818// |          Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar>      | 
    1919// +----------------------------------------------------------------------+ 
     20// 
     21// $Id: SMTP.php,v 1.63 2008/06/10 05:39:12 jon Exp $ 
    2022 
    2123require_once 'PEAR.php'; 
     
    6466 
    6567    /** 
     68     * Use SMTP command pipelining (specified in RFC 2920) if the SMTP 
     69     * server supports it. 
     70     * 
     71     * When pipeling is enabled, rcptTo(), mailFrom(), sendFrom(), 
     72     * somlFrom() and samlFrom() do not wait for a response from the 
     73     * SMTP server but return immediately. 
     74     * 
     75     * @var bool 
     76     * @access public 
     77     */ 
     78    var $pipelining = false; 
     79 
     80    /** 
     81     * Number of pipelined commands. 
     82     * @var int 
     83     * @access private 
     84     */ 
     85    var $_pipelined_commands = 0; 
     86 
     87    /** 
    6688     * Should debugging output be enabled? 
    6789     * @var boolean 
     
    102124     * with parameters that are passed in. 
    103125     * 
    104      * @param string The server to connect to. 
    105      * @param int The port to connect to. 
    106      * @param string The value to give when sending EHLO or HELO. 
     126     * If you have SSL support in PHP, you can connect to a server 
     127     * over SSL using an 'ssl://' prefix: 
     128     * 
     129     *   // 465 is a common smtps port. 
     130     *   $smtp = new Net_SMTP('ssl://mail.host.com', 465); 
     131     *   $smtp->connect(); 
     132     * 
     133     * @param string  $host       The server to connect to. 
     134     * @param integer $port       The port to connect to. 
     135     * @param string  $localhost  The value to give when sending EHLO or HELO. 
     136     * @param boolean $pipeling   Use SMTP command pipelining 
    107137     * 
    108138     * @access  public 
    109139     * @since   1.0 
    110140     */ 
    111     function Net_SMTP($host = null, $port = null, $localhost = null) 
    112     { 
    113         if (isset($host)) $this->host = $host; 
    114         if (isset($port)) $this->port = $port; 
    115         if (isset($localhost)) $this->localhost = $localhost; 
     141    function Net_SMTP($host = null, $port = null, $localhost = null, $pipelining = false) 
     142    { 
     143        if (isset($host)) { 
     144            $this->host = $host; 
     145        } 
     146        if (isset($port)) { 
     147            $this->port = $port; 
     148        } 
     149        if (isset($localhost)) { 
     150            $this->localhost = $localhost; 
     151        } 
     152        $this->pipelining = $pipelining; 
    116153 
    117154        $this->_socket = new Net_Socket(); 
    118155 
    119         /* 
    120          * Include the Auth_SASL package.  If the package is not available, 
    121          * we disable the authentication methods that depend upon it. 
    122          */ 
     156        /* Include the Auth_SASL package.  If the package is not 
     157         * available, we disable the authentication methods that 
     158         * depend upon it. */ 
    123159        if ((@include_once 'Auth/SASL.php') === false) { 
    124160            $pos = array_search('DIGEST-MD5', $this->auth_methods); 
     
    159195 
    160196        if (PEAR::isError($error = $this->_socket->write($data))) { 
    161             return new PEAR_Error('Failed to write to socket: ' . 
    162                                   $error->getMessage()); 
    163         } 
    164  
    165         return true; 
    166     } 
    167  
    168     /** 
    169      * Send a command to the server with an optional string of arguments. 
    170      * A carriage return / linefeed (CRLF) sequence will be appended to each 
    171      * command string before it is sent to the SMTP server. 
     197            return PEAR::raiseError('Failed to write to socket: ' . 
     198                                    $error->getMessage()); 
     199        } 
     200 
     201        return true; 
     202    } 
     203 
     204    /** 
     205     * Send a command to the server with an optional string of 
     206     * arguments.  A carriage return / linefeed (CRLF) sequence will 
     207     * be appended to each command string before it is sent to the 
     208     * SMTP server - an error will be thrown if the command string 
     209     * already contains any newline characters. Use _send() for 
     210     * commands that must contain newlines. 
    172211     * 
    173212     * @param   string  $command    The SMTP command to send to the server. 
     
    183222    { 
    184223        if (!empty($args)) { 
    185             return $this->_send($command . ' ' . $args . "\r\n"); 
     224            $command .= ' ' . $args; 
     225        } 
     226 
     227        if (strcspn($command, "\r\n") !== strlen($command)) {