Changeset 19942 for branches/version-2_5-dev/data/module/Mail
- Timestamp:
- 2011/01/17 14:46:37 (16 years ago)
- Location:
- branches/version-2_5-dev/data/module/Mail
- Files:
-
- 2 added
- 5 edited
-
RFC822.php (modified) (6 diffs)
-
mail.php (modified) (6 diffs)
-
mock.php (added)
-
null.php (modified) (1 diff)
-
sendmail.php (modified) (6 diffs)
-
smtp.php (modified) (15 diffs)
-
smtpmx.php (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_5-dev/data/module/Mail/RFC822.php
r16302 r19942 1 1 <?php 2 // +-----------------------------------------------------------------------+ 3 // | Copyright (c) 2001-2002, Richard Heyes | 4 // | All rights reserved. | 5 // | | 6 // | Redistribution and use in source and binary forms, with or without | 7 // | modification, are permitted provided that the following conditions | 8 // | are met: | 9 // | | 10 // | o Redistributions of source code must retain the above copyright | 11 // | notice, this list of conditions and the following disclaimer. | 12 // | o Redistributions in binary form must reproduce the above copyright | 13 // | notice, this list of conditions and the following disclaimer in the | 14 // | documentation and/or other materials provided with the distribution.| 15 // | o The names of the authors may not be used to endorse or promote | 16 // | products derived from this software without specific prior written | 17 // | permission. | 18 // | | 19 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 20 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 21 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 22 // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 23 // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 24 // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 25 // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 // | | 31 // +-----------------------------------------------------------------------+ 32 // | Authors: Richard Heyes <[email protected]> | 33 // | Chuck Hagenbuch <[email protected]> | 34 // +-----------------------------------------------------------------------+ 2 /** 3 * RFC 822 Email address list validation Utility 4 * 5 * PHP versions 4 and 5 6 * 7 * LICENSE: 8 * 9 * Copyright (c) 2001-2010, Richard Heyes 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * o Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * o Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * o The names of the authors may not be used to endorse or promote 22 * products derived from this software without specific prior written 23 * permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * @category Mail 38 * @package Mail 39 * @author Richard Heyes <[email protected]> 40 * @author Chuck Hagenbuch <[email protected] 41 * @copyright 2001-2010 Richard Heyes 42 * @license http://opensource.org/licenses/bsd-license.php New BSD License 43 * @version CVS: $Id: RFC822.php 294749 2010-02-08 08:22:25Z clockwerx $ 44 * @link http://pear.php.net/package/Mail/ 45 */ 35 46 36 47 /** … … 53 64 * @author Richard Heyes <[email protected]> 54 65 * @author Chuck Hagenbuch <[email protected]> 55 * @version $Revision: 1.23$66 * @version $Revision: 294749 $ 56 67 * @license BSD 57 68 * @package Mail … … 185 196 186 197 if ($this->address === false || isset($this->error)) { 187 require_once dirname(__FILE__) . '/../PEAR.php';198 require_once 'PEAR.php'; 188 199 return PEAR::raiseError($this->error); 189 200 } … … 195 206 196 207 if ($valid === false || isset($this->error)) { 197 require_once dirname(__FILE__) . '/../PEAR.php';208 require_once 'PEAR.php'; 198 209 return PEAR::raiseError($this->error); 199 210 } … … 343 354 344 355 /** 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. 356 * Checks if a string has unclosed quotes or not. 357 * 358 * @access private 359 * @param string $string The string to check. 360 * @return boolean True if there are unclosed quotes inside the string, 361 * false otherwise. 350 362 */ 351 363 function _hasUnclosedQuotes($string) 352 364 { 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); 365 $string = trim($string); 366 $iMax = strlen($string); 367 $in_quote = false; 368 $i = $slashes = 0; 369 370 for (; $i < $iMax; ++$i) { 371 switch ($string[$i]) { 372 case '\\': 373 ++$slashes; 374 break; 375 376 case '"': 377 if ($slashes % 2 == 0) { 378 $in_quote = !$in_quote; 379 } 380 // Fall through to default action below. 381 382 default: 383 $slashes = 0; 384 break; 385 } 386 } 387 388 return $in_quote; 361 389 } 362 390 … … 619 647 $comments[] = $comment; 620 648 621 // + 1 is for the trailing )622 $_mailbox = substr($_mailbox, strpos($_mailbox, $comment)+strlen($comment)+1);649 // +2 is for the brackets 650 $_mailbox = substr($_mailbox, strpos($_mailbox, '('.$comment)+strlen($comment)+2); 623 651 } else { 624 652 break; -
branches/version-2_5-dev/data/module/Mail/mail.php
r16503 r19942 1 1 <?php 2 // 3 // +----------------------------------------------------------------------+ 4 // | PHP Version 4 | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 1997-2003 The PHP Group | 7 // +----------------------------------------------------------------------+ 8 // | This source file is subject to version 2.02 of the PHP license, | 9 // | that is bundled with this package in the file LICENSE, and is | 10 // | available at through the world-wide-web at | 11 // | http://www.php.net/license/2_02.txt. | 12 // | If you did not receive a copy of the PHP license and are unable to | 13 // | obtain it through the world-wide-web, please send a note to | 14 // | [email protected] so we can mail you a copy immediately. | 15 // +----------------------------------------------------------------------+ 16 // | Author: Chuck Hagenbuch <[email protected]> | 17 // +----------------------------------------------------------------------+ 18 // 19 // $Id$ 2 /** 3 * internal PHP-mail() implementation of the PEAR Mail:: interface. 4 * 5 * PHP versions 4 and 5 6 * 7 * LICENSE: 8 * 9 * Copyright (c) 2010 Chuck Hagenbuch 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * o Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * o Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * o The names of the authors may not be used to endorse or promote 22 * products derived from this software without specific prior written 23 * permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * @category Mail 38 * @package Mail 39 * @author Chuck Hagenbuch <[email protected]> 40 * @copyright 2010 Chuck Hagenbuch 41 * @license http://opensource.org/licenses/bsd-license.php New BSD License 42 * @version CVS: $Id$ 43 * @link http://pear.php.net/package/Mail/ 44 */ 20 45 21 46 /** … … 42 67 function Mail_mail($params = null) 43 68 { 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. */69 // The other mail implementations accept parameters as arrays. 70 // In the interest of being consistent, explode an array into 71 // a string of parameter arguments. 47 72 if (is_array($params)) { 48 73 $this->_params = join(' ', $params); … … 62 87 } 63 88 64 /**89 /** 65 90 * Implements Mail_mail::send() function using php's built-in mail() 66 91 * command. … … 90 115 function send($recipients, $headers, $body) 91 116 { 92 $this->_sanitizeHeaders($headers); 117 if (!is_array($headers)) { 118 return PEAR::raiseError('$headers must be an array'); 119 } 120 121 $result = $this->_sanitizeHeaders($headers); 122 if (is_a($result, 'PEAR_Error')) { 123 return $result; 124 } 93 125 94 126 // If we're passed an array of recipients, implode it. … … 105 137 } 106 138 107 /* 108 * Also remove the To: header. The mail() function will add its own 109 * To: header based on the contents of $recipients. 110 */ 139 // Also remove the To: header. The mail() function will add its own 140 // To: header based on the contents of $recipients. 111 141 unset($headers['To']); 112 142 113 143 // Flatten the headers out. 114 144 $headerElements = $this->prepareHeaders($headers); 115 if ( PEAR::isError($headerElements)) {145 if (is_a($headerElements, 'PEAR_Error')) { 116 146 return $headerElements; 117 147 } 118 148 list(, $text_headers) = $headerElements; 119 149 120 /* 121 * We only use mail()'s optional fifth parameter if the additional 122 * parameters have been provided and we're not running in safe mode. 123 */ 150 // We only use mail()'s optional fifth parameter if the additional 151 // parameters have been provided and we're not running in safe mode. 124 152 if (empty($this->_params) || ini_get('safe_mode')) { 125 153 $result = mail($recipients, $subject, $body, $text_headers); … … 129 157 } 130 158 131 /* 132 * If the mail() function returned failure, we need to create a 133 * PEAR_Error object and return it instead of the boolean result. 134 */ 159 // If the mail() function returned failure, we need to create a 160 // PEAR_Error object and return it instead of the boolean result. 135 161 if ($result === false) { 136 162 $result = PEAR::raiseError('mail() returned failure'); -
branches/version-2_5-dev/data/module/Mail/null.php
r16503 r19942 1 1 <?php 2 // 3 // +----------------------------------------------------------------------+ 4 // | PHP Version 4 | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 1997-2003 The PHP Group | 7 // +----------------------------------------------------------------------+ 8 // | This source file is subject to version 2.02 of the PHP license, | 9 // | that is bundled with this package in the file LICENSE, and is | 10 // | available at through the world-wide-web at | 11 // | http://www.php.net/license/2_02.txt. | 12 // | If you did not receive a copy of the PHP license and are unable to | 13 // | obtain it through the world-wide-web, please send a note to | 14 // | [email protected] so we can mail you a copy immediately. | 15 // +----------------------------------------------------------------------+ 16 // | Author: Phil Kernick <[email protected]> | 17 // +----------------------------------------------------------------------+ 18 // 19 // $Id$ 20 // 2 /** 3 * Null implementation of the PEAR Mail interface 4 * 5 * PHP versions 4 and 5 6 * 7 * LICENSE: 8 * 9 * Copyright (c) 2010 Phil Kernick 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * o Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * o Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * o The names of the authors may not be used to endorse or promote 22 * products derived from this software without specific prior written 23 * permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * @category Mail 38 * @package Mail 39 * @author Phil Kernick <[email protected]> 40 * @copyright 2010 Phil Kernick 41 * @license http://opensource.org/licenses/bsd-license.php New BSD License 42 * @version CVS: $Id$ 43 * @link http://pear.php.net/package/Mail/ 44 */ 21 45 22 46 /** -
branches/version-2_5-dev/data/module/Mail/sendmail.php
r16503 r19942 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. … … 39 39 var $sendmail_args = '-i'; 40 40 41 /**41 /** 42 42 * Constructor. 43 43 * … … 78 78 } 79 79 80 /**80 /** 81 81 * Implements Mail::send() function using the sendmail 82 82 * command-line binary. … … 105 105 function send($recipients, $headers, $body) 106 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 107 116 $recipients = $this->parseRecipients($recipients); 108 if ( PEAR::isError($recipients)) {117 if (is_a($recipients, 'PEAR_Error')) { 109 118 return $recipients; 110 119 } 111 $recipients = escapeShellCmd(implode('', $recipients));120 $recipients = implode(' ', array_map('escapeshellarg', $recipients)); 112 121 113 $this->_sanitizeHeaders($headers);114 122 $headerElements = $this->prepareHeaders($headers); 115 if ( PEAR::isError($headerElements)) {123 if (is_a($headerElements, 'PEAR_Error')) { 116 124 return $headerElements; 117 125 } 118 126 list($from, $text_headers) = $headerElements; 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 } 119 134 120 135 if (!isset($from)) { … … 127 142 } 128 143 129 $from = escapeShellCmd($from); 144 $from = escapeshellarg($from); // Security bug #16200 145 130 146 $mail = @popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w'); 131 147 if (!$mail) { -
branches/version-2_5-dev/data/module/Mail/smtp.php
r18253 r19942 1 1 <?php 2 // 3 // +----------------------------------------------------------------------+ 4 // | PHP Version 4 | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 1997-2003 The PHP Group | 7 // +----------------------------------------------------------------------+ 8 // | This source file is subject to version 2.02 of the PHP license, | 9 // | that is bundled with this package in the file LICENSE, and is | 10 // | available at through the world-wide-web at | 11 // | http://www.php.net/license/2_02.txt. | 12 // | If you did not receive a copy of the PHP license and are unable to | 13 // | obtain it through the world-wide-web, please send a note to | 14 // | [email protected] so we can mail you a copy immediately. | 15 // +----------------------------------------------------------------------+ 16 // | Authors: Chuck Hagenbuch <[email protected]> | 17 // | Jon Parise <[email protected]> | 18 // +----------------------------------------------------------------------+ 2 /** 3 * SMTP implementation of the PEAR Mail interface. Requires the Net_SMTP class. 4 * 5 * PHP versions 4 and 5 6 * 7 * LICENSE: 8 * 9 * Copyright (c) 2010, Chuck Hagenbuch 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * o Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * o Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * o The names of the authors may not be used to endorse or promote 22 * products derived from this software without specific prior written 23 * permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * @category HTTP 38 * @package HTTP_Request 39 * @author Jon Parise <[email protected]> 40 * @author Chuck Hagenbuch <[email protected]> 41 * @copyright 2010 Chuck Hagenbuch 42 * @license http://opensource.org/licenses/bsd-license.php New BSD License 43 * @version CVS: $Id: smtp.php 294747 2010-02-08 08:18:33Z clockwerx $ 44 * @link http://pear.php.net/package/Mail/ 45 */ 19 46 20 47 /** Error: Failed to create a Net_SMTP object */ … … 43 70 * @access public 44 71 * @package Mail 45 * @version $Revision: 1.28$72 * @version $Revision: 294747 $ 46 73 */ 47 74 class Mail_smtp extends Mail { … … 56 83 57 84 /** 85 * The list of service extension parameters to pass to the Net_SMTP 86 * mailFrom() command. 87 * @var array 88 */ 89 var $_extparams = array(); 90 91 /** 58 92 * The SMTP host to connect to. 59 93 * @var string … … 108 142 109 143 /** 110 * Whether to use VERP or not. If not a boolean, the string value111 * will be used as the VERP separators.112 *113 * @var mixed boolean or string114 */115 var $verp = false;116 117 /**118 144 * Turn on Net_SMTP debugging? 119 145 * … … 129 155 */ 130 156 var $persist = false; 157 158 /** 159 * Use SMTP command pipelining (specified in RFC 2920) if the SMTP server 160 * supports it. This speeds up delivery over high-latency connections. By 161 * default, use the default value supplied by Net_SMTP. 162 * @var bool 163 */ 164 var $pipelining; 131 165 132 166 /** … … 143 177 * timeout The SMTP connection timeout. Defaults to none. 144 178 * verp Whether to use VERP or not. Defaults to false. 179 * DEPRECATED as of 1.2.0 (use setMailParams()). 145 180 * debug Activate SMTP debug mode? Defaults to false. 146 181 * persist Should the SMTP connection persist? 182 * pipelining Use SMTP command pipelining 147 183 * 148 184 * If a parameter is present in the $params array, it replaces the … … 162 198 if (isset($params['localhost'])) $this->localhost = $params['localhost']; 163 199 if (isset($params['timeout'])) $this->timeout = $params['timeout']; 164 if (isset($params['verp'])) $this->verp = $params['verp']; 165 if (isset($params['debug'])) $this->debug = (boolean)$params['debug']; 166 if (isset($params['persist'])) $this->persist = (boolean)$params['persist']; 200 if (isset($params['debug'])) $this->debug = (bool)$params['debug']; 201 if (isset($params['persist'])) $this->persist = (bool)$params['persist']; 202 if (isset($params['pipelining'])) $this->pipelining = (bool)$params['pipelining']; 203 204 // Deprecated options 205 if (isset($params['verp'])) { 206 $this->addServiceExtensionParameter('XVERP', is_bool($params['verp']) ? null : $params['verp']); 207 } 167 208 168 209 register_shutdown_function(array(&$this, '_Mail_smtp')); … … 195 236 * 196 237 * @param string $body The full text of the message body, including any 197 * M imeparts, etc.238 * MIME parts, etc. 198 239 * 199 240 * @return mixed Returns true on success, or a PEAR_Error … … 204 245 function send($recipients, $headers, $body) 205 246 { 206 $include_dir = realpath(dirname( __FILE__));207 include_once $include_dir . "/../Net/SMTP.php";208 209 247 /* If we don't already have an SMTP object, create one. */ 210 if (is_object($this->_smtp) === false) { 211 $this->_smtp =& new Net_SMTP($this->host, $this->port, 212 $this->localhost); 213 214 /* If we still don't have an SMTP object at this point, fail. */ 215 if (is_object($this->_smtp) === false) { 216 return PEAR::raiseError('Failed to create a Net_SMTP object', 217 PEAR_MAIL_SMTP_ERROR_CREATE); 218 } 219 220 /* Configure the SMTP connection. */ 221 if ($this->debug) { 222 $this->_smtp->setDebug(true); 223 } 224 225 /* Attempt to connect to the configured SMTP server. */ 226 if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) { 227 $error = $this->_error('Failed to connect to ' . 228 $this->host . ':' . $this->port, 229 $res); 230 return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT); 231 } 232 233 /* Attempt to authenticate if authentication has been enabled. */ 234 if ($this->auth) { 235 $method = is_string($this->auth) ? $this->auth : ''; 236 237 if (PEAR::isError($res = $this->_smtp->auth($this->username, 238 $this->password, 239 $method))) { 240 $error = $this->_error("$method authentication failure", 241 $res); 242 $this->_smtp->rset(); 243 return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH); 244 } 245 } 248 $result = &$this->getSMTPObject(); 249 if (PEAR::isError($result)) { 250 return $result; 251 } 252 253 if (!is_array($headers)) { 254 return PEAR::raiseError('$headers must be an array'); 246 255 } 247 256 248 257 $this->_sanitizeHeaders($headers); 258 249 259 $headerElements = $this->prepareHeaders($headers); 250 if ( PEAR::isError($headerElements)) {260 if (is_a($headerElements, 'PEAR_Error')) { 251 261 $this->_smtp->rset(); 252 262 return $headerElements; … … 267 277 } 268 278 269 $args['verp'] = $this->verp; 270 if (PEAR::isError($res = $this->_smtp->mailFrom($from, $args))) { 279 $params = null; 280 if (!empty($this->_extparams)) { 281 foreach ($this->_extparams as $key => $val) { 282 $params .= ' ' . $key . (is_null($val) ? '' : '=' . $val); 283 } 284 } 285 if (PEAR::isError($res = $this->_smtp->mailFrom($from, ltrim($params)))) { 271 286 $error = $this->_error("Failed to set sender: $from", $res); 272 287 $this->_smtp->rset(); … … 275 290 276 291 $recipients = $this->parseRecipients($recipients); 277 if ( PEAR::isError($recipients)) {292 if (is_a($recipients, 'PEAR_Error')) { 278 293 $this->_smtp->rset(); 279 294 return $recipients; … … 281 296 282 297 foreach ($recipients as $recipient) { 283 if (PEAR::isError($res = $this->_smtp->rcptTo($recipient))) {284 $error = $this->_error("Failed to add recipient: $recipient",285 $res);298 $res = $this->_smtp->rcptTo($recipient); 299 if (is_a($res, 'PEAR_Error')) { 300 $error = $this->_error("Failed to add recipient: $recipient", $res); 286 301 $this->_smtp->rset(); 287 302 return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_RECIPIENT); … … 290 305 291 306 /* Send the message's headers and the body as SMTP data. */ 292 if (PEAR::isError($res = $this->_smtp->data($textHeaders . "\r\n\r\n" . $body))) { 307 $res = $this->_smtp->data($textHeaders . "\r\n\r\n" . $body); 308 list(,$args) = $this->_smtp->getResponse(); 309 310 if (preg_match("/Ok: queued as (.*)/", $args, $queued)) { 311 $this->queued_as = $queued[1]; 312 } 313 314 /* we need the greeting; from it we can extract the authorative name of the mail server we've really connected to. 315 * ideal if we're connecting to a round-robin of relay servers and need to track which exact one took the email */ 316 $this->greeting = $this->_smtp->getGreeting(); 317 318 if (is_a($res, 'PEAR_Error')) { 293 319 $error = $this->_error('Failed to send data', $res); 294 320 $this->_smtp->rset(); … … 305 331 306 332 /** 333 * Connect to the SMTP server by instantiating a Net_SMTP object. 334 * 335 * @return mixed Returns a reference to the Net_SMTP object on success, or 336 * a PEAR_Error containing a descriptive error message on 337 * failure. 338 * 339 * @since 1.2.0 340 * @access public 341 */ 342 function &getSMTPObject() 343 { 344 if (is_object($this->_smtp) !== false) { 345 return $this->_smtp; 346 } 347 348 include_once 'Net/SMTP.php'; 349 $this->_smtp = &new Net_SMTP($this->host, 350 $this->port, 351 $this->localhost); 352 353 /* If we still don't have an SMTP object at this point, fail. */ 354 if (is_object($this->_smtp) === false) { 355 return PEAR::raiseError('Failed to create a Net_SMTP object', 356 PEAR_MAIL_SMTP_ERROR_CREATE); 357 } 358 359 /* Configure the SMTP connection. */ 360 if ($this->debug) { 361 $this->_smtp->setDebug(true); 362 } 363 364 /* Attempt to connect to the configured SMTP server. */ 365 if (PEAR::isError($res = $this->_smtp->connect($this->timeout))) { 366 $error = $this->_error('Failed to connect to ' . 367 $this->host . ':' . $this->port, 368 $res); 369 return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_CONNECT); 370 } 371 372 /* Attempt to authenticate if authentication has been enabled. */ 373 if ($this->auth) { 374 $method = is_string($this->auth) ? $this->auth : ''; 375 376 if (PEAR::isError($res = $this->_smtp->auth($this->username, 377 $this->password, 378 $method))) { 379 $error = $this->_error("$method authentication failure", 380 $res); 381 $this->_smtp->rset(); 382 return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_AUTH); 383 } 384 } 385 386 return $this->_smtp; 387 } 388 389 /** 390 * Add parameter associated with a SMTP service extension. 391 * 392 * @param string Extension keyword. 393 * @param string Any value the keyword needs. 394 * 395 * @since 1.2.0 396 * @access public 397 */ 398 function addServiceExtensionParameter($keyword, $value = null) 399 { 400 $this->_extparams[$keyword] = $value; 401 } 402 403 /** 307 404 * Disconnect and destroy the current SMTP connection. 308 405 * … … 340 437 341 438 /* Build our standardized error string. */ 342 $msg = $text; 343 $msg .= ' [SMTP: ' . $error->getMessage(); 344 $msg .= " (code: $code, response: $response)]"; 345 346 return $msg; 439 return $text 440 . ' [SMTP: ' . $error->getMessage() 441 . " (code: $code, response: $response)]"; 347 442 } 348 443
Note: See TracChangeset
for help on using the changeset viewer.
