Changeset 974
- Timestamp:
- 07/25/08 18:50:21 (1 month ago)
- Files:
-
- trunk/vendor/pear/Auth/SASL.php (modified) (2 diffs)
- trunk/vendor/pear/Auth/SASL/DigestMD5.php (modified) (4 diffs)
- trunk/vendor/pear/Auth/SASL/Plain.php (modified) (1 diff)
- trunk/vendor/pear/Mail.php (modified) (8 diffs)
- trunk/vendor/pear/Mail/RFC822.php (modified) (3 diffs)
- trunk/vendor/pear/Mail/mail.php (modified) (6 diffs)
- trunk/vendor/pear/Mail/mimePart.php (modified) (1 diff)
- trunk/vendor/pear/Mail/mock.php (copied) (copied from branches/action_mailer/vendor/pear/Mail/mock.php)
- trunk/vendor/pear/Mail/sendmail.php (modified) (6 diffs)
- trunk/vendor/pear/Mail/smtp.php (modified) (8 diffs)
- trunk/vendor/pear/Mail/smtpmx.php (copied) (copied from branches/action_mailer/vendor/pear/Mail/smtpmx.php)
- trunk/vendor/pear/Net/SMTP.php (modified) (31 diffs)
- trunk/vendor/pear/Net/Socket.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/vendor/pear/Auth/SASL.php
r2 r974 33 33 // +-----------------------------------------------------------------------+ 34 34 // 35 // $Id: SASL.php,v 1. 4 2003/02/21 16:07:17 mjExp $35 // $Id: SASL.php,v 1.5 2006/03/22 05:20:11 amistry Exp $ 36 36 37 37 /** … … 92 92 93 93 require_once($filename); 94 return new $classname(); 94 $obj = new $classname(); 95 return $obj; 95 96 } 96 97 } trunk/vendor/pear/Auth/SASL/DigestMD5.php
r2 r974 33 33 // +-----------------------------------------------------------------------+ 34 34 // 35 // $Id: DigestMD5.php,v 1. 6 2003/02/21 16:07:17 mjExp $35 // $Id: DigestMD5.php,v 1.8 2006/03/22 05:20:11 amistry Exp $ 36 36 37 37 /** … … 75 75 $response_value = $this->_getResponseValue($authcid, $pass, $challenge['realm'], $challenge['nonce'], $cnonce, $digest_uri, $authzid); 76 76 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 } 78 83 } else { 79 84 return PEAR::raiseError('Invalid digest challenge'); … … 126 131 // Realm 127 132 if (empty($tokens['realm'])) { 128 $uname = posix_uname(); 129 $tokens['realm'] = $uname['nodename']; 133 $tokens['realm'] = ""; 130 134 } 131 135 132 136 // Maxbuf 133 137 if (empty($tokens['maxbuf'])) { 134 138 $tokens['maxbuf'] = 65536; 135 139 } 136 140 137 141 // Required: nonce, algorithm 138 142 if (empty($tokens['nonce']) OR empty($tokens['algorithm'])) { 139 143 return array(); 140 144 } 141 145 142 146 return $tokens; 143 147 } … … 175 179 function _getCnonce() 176 180 { 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)); 179 183 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)); 182 186 183 187 } else { trunk/vendor/pear/Auth/SASL/Plain.php
r2 r974 33 33 // +-----------------------------------------------------------------------+ 34 34 // 35 // $Id: Plain.php,v 1. 5 2003/02/21 16:07:17 mjExp $35 // $Id: Plain.php,v 1.6 2003/09/11 18:53:56 mbretter Exp $ 36 36 37 37 /** trunk/vendor/pear/Mail.php
r54 r974 17 17 // +----------------------------------------------------------------------+ 18 18 // 19 // $Id: Mail.php,v 1. 17 2006/09/15 03:41:18 jonExp $19 // $Id: Mail.php,v 1.20 2007/10/06 17:00:00 chagenbu Exp $ 20 20 21 21 require_once 'PEAR.php'; … … 27 27 * 28 28 * @access public 29 * @version $Revision: 1. 17$29 * @version $Revision: 1.20 $ 30 30 * @package Mail 31 31 */ … … 83 83 * containing a descriptive error message on 84 84 * failure. 85 * 85 86 * @access public 86 87 * @deprecated use Mail_mail::send instead … … 88 89 function send($recipients, $headers, $body) 89 90 { 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 } 91 99 92 100 // if we're passed an array of recipients, implode it. … … 104 112 105 113 // flatten the headers out. 106 list(, $text_headers) = Mail::prepareHeaders($headers);114 list(, $text_headers) = Mail::prepareHeaders($headers); 107 115 108 116 return mail($recipients, $subject, $body, $text_headers); 109 110 117 } 111 118 … … 152 159 if (strcasecmp($key, 'From') === 0) { 153 160 include_once 'Mail/RFC822.php'; 154 $parser = &new Mail_RFC822();161 $parser = new Mail_RFC822(); 155 162 $addresses = $parser->parseAddressList($value, 'localhost', false); 156 if ( PEAR::isError($addresses)) {163 if (is_a($addresses, 'PEAR_Error')) { 157 164 return $addresses; 158 165 } … … 162 169 // Reject envelope From: addresses with spaces. 163 170 if (strstr($from, ' ')) { 164 die('Aquiii');165 171 return false; 166 172 } … … 223 229 224 230 // If parseAddressList() returned a PEAR_Error object, just return it. 225 if ( PEAR::isError($addresses)) {231 if (is_a($addresses, 'PEAR_Error')) { 226 232 return $addresses; 227 233 } trunk/vendor/pear/Mail/RFC822.php
r2 r974 53 53 * @author Richard Heyes <richard@phpguru.org> 54 54 * @author Chuck Hagenbuch <chuck@horde.org> 55 * @version $Revision: 1.2 1$55 * @version $Revision: 1.24 $ 56 56 * @license BSD 57 57 * @package Mail … … 343 343 344 344 /** 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. 350 351 */ 351 352 function _hasUnclosedQuotes($string) 352 353 { 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; 361 378 } 362 379 … … 913 930 function isValidInetAddress($data, $strict = false) 914 931 { 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'; 916 933 if (preg_match($regex, trim($data), $matches)) { 917 934 return array($matches[1], $matches[2]); trunk/vendor/pear/Mail/mail.php
r2 r974 17 17 // +----------------------------------------------------------------------+ 18 18 // 19 // $Id: mail.php,v 1. 13 2004/09/09 02:08:55 jonExp $19 // $Id: mail.php,v 1.20 2007/10/06 17:00:00 chagenbu Exp $ 20 20 21 21 /** 22 22 * internal PHP-mail() implementation of the PEAR Mail:: interface. 23 23 * @package Mail 24 * @version $Revision: 1. 13$24 * @version $Revision: 1.20 $ 25 25 */ 26 26 class Mail_mail extends Mail { … … 42 42 function Mail_mail($params = null) 43 43 { 44 / *The other mail implementations accept parameters as arrays.45 *In the interest of being consistent, explode an array into46 * 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. 47 47 if (is_array($params)) { 48 48 $this->_params = join(' ', $params); … … 55 55 * "\r\n" separator. Instead, we use the system's native line 56 56 * 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 } 58 62 } 59 63 60 /**64 /** 61 65 * Implements Mail_mail::send() function using php's built-in mail() 62 66 * command. … … 86 90 function send($recipients, $headers, $body) 87 91 { 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 88 101 // If we're passed an array of recipients, implode it. 89 102 if (is_array($recipients)) { … … 99 112 } 100 113 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 101 118 // Flatten the headers out. 102 119 $headerElements = $this->prepareHeaders($headers); 103 if ( PEAR::isError($headerElements)) {120 if (is_a($headerElements, 'PEAR_Error')) { 104 121 return $headerElements; 105 122 } 106 123 list(, $text_headers) = $headerElements; 107 124 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. 112 127 if (empty($this->_params) || ini_get('safe_mode')) { 113 128 $result = mail($recipients, $subject, $body, $text_headers); … … 117 132 } 118 133 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. 123 136 if ($result === false) { 124 137 $result = PEAR::raiseError('mail() returned failure'); trunk/vendor/pear/Mail/mimePart.php
r54 r974 197 197 } 198 198 199 199 200 // Assign stuff to member variables 200 201 $this->_encoded = array(); trunk/vendor/pear/Mail/sendmail.php
r2 r974 21 21 * @access public 22 22 * @package Mail 23 * @version $Revision: 1.1 0$23 * @version $Revision: 1.19 $ 24 24 */ 25 25 class Mail_sendmail extends Mail { 26 26 27 /**27 /** 28 28 * The location of the sendmail or sendmail wrapper binary on the 29 29 * filesystem. … … 32 32 var $sendmail_path = '/usr/sbin/sendmail'; 33 33 34 /**34 /** 35 35 * Any extra command-line parameters to pass to the sendmail or 36 36 * sendmail wrapper binary. 37 37 * @var string 38 38 */ 39 var $sendmail_args = ' ';39 var $sendmail_args = '-i'; 40 40 41 /**41 /** 42 42 * Constructor. 43 43 * … … 59 59 function Mail_sendmail($params) 60 60 { 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 } 63 67 64 68 /* … … 67 71 * separator. Instead, we use the system's native line separator. 68 72 */ 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 } 70 78 } 71 79 72 /**80 /** 73 81 * Implements Mail::send() function using the sendmail 74 82 * command-line binary. … … 97 105 function send($recipients, $headers, $body) 98 106 { 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 99 116 $recipients = $this->parseRecipients($recipients); 100 if ( PEAR::isError($recipients)) {117 if (is_a($recipients, 'PEAR_Error')) { 101 118 return $recipients; 102 119 } … … 104 121 105 122 $headerElements = $this->prepareHeaders($headers); 106 if ( PEAR::isError($headerElements)) {123 if (is_a($headerElements, 'PEAR_Error')) { 107 124 return $headerElements; 108 125 } 109 126 list($from, $text_headers) = $headerElements; 110 127 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 111 135 if (!isset($from)) { 112 136 return PEAR::raiseError('No from address given.'); 113 } elseif (str str($from, ' ')||114 str str($from, ';')||115 str str($from, '&')||116 str str($from, '`')) {137 } elseif (strpos($from, ' ') !== false || 138 strpos($from, ';') !== false || 139 strpos($from, '&') !== false || 140 strpos($from, '`') !== false) { 117 141 return PEAR::raiseError('From address specified with dangerous characters.'); 118 142 } 119 143 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; 135 160 } 136 161 trunk/vendor/pear/Mail/smtp.php
r2 r974 18 18 // +----------------------------------------------------------------------+ 19 19 20 /** Error: Failed to create a Net_SMTP object */ 21 define('PEAR_MAIL_SMTP_ERROR_CREATE', 10000); 22 23 /** Error: Failed to connect to SMTP server */ 24 define('PEAR_MAIL_SMTP_ERROR_CONNECT', 10001); 25 26 /** Error: SMTP authentication failure */ 27 define('PEAR_MAIL_SMTP_ERROR_AUTH', 10002); 28 29 /** Error: No From: address has been provided */ 30 define('PEAR_MAIL_SMTP_ERROR_FROM', 10003); 31 32 /** Error: Failed to set sender */ 33 define('PEAR_MAIL_SMTP_ERROR_SENDER', 10004); 34 35 /** Error: Failed to add recipient */ 36 define('PEAR_MAIL_SMTP_ERROR_RECIPIENT', 10005); 37 38 /** Error: Failed to send data */ 39 define('PEAR_MAIL_SMTP_ERROR_DATA', 10006); 40 20 41 /** 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. 23 43 * @access public 24 44 * @package Mail 25 * @version $Revision: 1. 20$45 * @version $Revision: 1.33 $ 26 46 */ 27 47 class Mail_smtp extends Mail { 28 48 29 49 /** 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 /** 30 65 * The SMTP host to connect to. 31 66 * @var string … … 80 115 81 116 /** 82 * Whether to use VERP or not. If not a boolean, the string value83 * will be used as the VERP separators.84 *85 * @var mixed boolean or string86 */87 var $verp = false;88 89 /**90 117 * Turn on Net_SMTP debugging? 91 118 * … … 93 120 */ 94 121 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; 95 138 96 139 /** … … 107 150 * timeout The SMTP connection timeout. Defaults to none. 108 151 * verp Whether to use VERP or not. Defaults to false. 152 * DEPRECATED as of 1.2.0 (use setMailParams()). 109 153 * debug Activate SMTP debug mode? Defaults to false. 154 * persist Should the SMTP connection persist? 155 * pipelining Use SMTP command pipelining 110 156 * 111 157 * If a parameter is present in the $params array, it replaces the … … 125 171 if (isset($params['localhost'])) $this->localhost = $params['localhost']; 126 172 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(); 129 192 } 130 193 … … 146 209 * 147 210 * @param string $body The full text of the message body, including any 148 * M imeparts, etc.211 * MIME parts, etc. 149 212 * 150 213 * @return mixed Returns true on success, or a PEAR_Error … … 155 218 function send($recipients, $headers, $body) 156 219 { 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); 180 231 181 232 $headerElements = $this->prepareHeaders($headers); 182 if (PEAR::isError($headerElements)) { 233 if (is_a($headerElements, 'PEAR_Error')) { 234 $this->_smtp->rset(); 183 235 return $headerElements; 184 236 } 185 list($from, $text _headers) = $headerElements;237 list($from, $textHeaders) = $headerElements; 186 238 187 239 /* Since few MTAs are going to allow this header to be forged … … 193 245 194 246 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); 201 262 } 202 263 203 264 $recipients = $this->parseRecipients($recipients); 204 if (PEAR::isError($recipients)) { 265 if (is_a($recipients, 'PEAR_Error')) { 266 $this->_smtp->rset(); 205 267 return $recipients; 206 268 } 207 269 208 270 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); 212 276 } 213 277 } 214 278 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 220 292 return true; 221 293 } 222 294 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 223 407 } trunk/vendor/pear/Net/SMTP.php
r2 r974 18 18 // | Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar> | 19 19 // +----------------------------------------------------------------------+ 20 // 21 // $Id: SMTP.php,v 1.63 2008/06/10 05:39:12 jon Exp $ 20 22 21 23 require_once 'PEAR.php'; … … 64 66 65 67 /** 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 /** 66 88 * Should debugging output be enabled? 67 89 * @var boolean … … 102 124 * with parameters that are passed in. 103 125 * 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 107 137 * 108 138 * @access public 109 139 * @since 1.0 110 140 */ 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; 116 153 117 154 $this->_socket = new Net_Socket(); 118 155 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. */ 123 159 if ((@include_once 'Auth/SASL.php') === false) { 124 160 $pos = array_search('DIGEST-MD5', $this->auth_methods); … … 159 195 160 196 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. 172 211 * 173 212 * @param string $command The SMTP command to send to the server. … … 183 222 { 184 223 if (!empty($args)) { 185 return $this->_send($command . ' ' . $args . "\r\n"); 224 $command .= ' ' . $args; 225 } 226 227 if (strcspn($command, "\r\n") !== strlen($command)) { <
