cvs: php4(PHP_4_3) /pear/packages DB-1.3.tar Mail-1.0.1.tar Mail-1.1.0.tar Net_SMTP-1.0.tar Net_SMTP-1.2.3.tar

From: Date: Sun, 22 Jun 2003 20:11:27 +0000
Subject: cvs: php4(PHP_4_3) /pear/packages DB-1.3.tar Mail-1.0.1.tar Mail-1.1.0.tar Net_SMTP-1.0.tar Net_SMTP-1.2.3.tar
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-11125@lists.php.net to get a copy of this message
pajoye Sun Jun 22 16:11:27 2003 EDT Added files: (Branch: PHP_4_3) /php4/pear/packages Mail-1.1.0.tar Net_SMTP-1.2.3.tar Removed files: /php4/pear/packages Mail-1.0.1.tar Net_SMTP-1.0.tar Modified files: /php4/pear/packages DB-1.3.tar Log: - MFH packages

Index: php4/pear/packages/DB-1.3.tar Index: php4/pear/packages/Mail-1.1.0.tar +++ php4/pear/packages/Mail-1.1.0.tar package.xml100644 1750 1750 4360 7674756403 6422 <?xml version="1.0" encoding="ISO-8859-1" ?> <package version="1.0"> <name>Mail</name> <summary>Class that provides multiple interfaces for sending emails</summary> <description>The PEAR's Mail:: interface, defines the interface for implementing</description> <maintainers> <maintainer> <user>chagenbu</user> <name>Chuck Hagenbuch</name> <email>chuck@horde.org</email> <role>lead</role> </maintainer> <maintainer> <user>richard</user> <name>Richard Heyes</name> <email>richard@phpguru.org</email> <role>developer</role> </maintainer> <maintainer> <user>jon</user> <name>Jon Parise</name> <email>jon@php.net</email> <role>developer</role> </maintainer> </maintainers> <release> <version>1.1.0</version> <date>2003-06-21</date> <license>PHP/BSD</license> <state>stable</state> <notes>The Mail package now depends on Net_SMTP 1.1.0 or greater for its SMTP authentication capabilities.</notes> <deps> <dep type="pkg" rel="ge" version="1.1.0">Net_SMTP</dep> </deps> <filelist> <file role="php" md5sum="65659ee0df8ca248ba37a5bc82523055" name="Mail.php"/> <file role="php" md5sum="a87e9ec2ad2a25bf2e5c43161ffa3ee1" name="Mail/mail.php"/> <file role="php" md5sum="6092f7acab87ca7910cac7ae799f9208" name="Mail/sendmail.php"/> <file role="php" md5sum="601e3f33396512cf86a95949665ed008" name="Mail/smtp.php"/> <file role="php" md5sum="a1e06ac3ce838cb81ed509792d487875" name="Mail/RFC822.php"/> </filelist> </release> <changelog> <release> <version>1.0.2</version> <date>2002-07-27</date> <state>stable</state> <notes>Minor additions and changes to RFC822.php. Fixed line terminator issue for smtp.php and set smtp.php to use Return-Path header in place of From header for MAIL FROM: (if supplied) </notes> </release> <release> <version>1.0.1</version> <date>2002-07-27</date> <state>stable</state> <notes>License change for RFC822.php </notes> </release> <release> <version>1.0</version> <date>2002-06-06</date> <state>stable</state> <notes>Initial release as PEAR package </notes> </release> </changelog> </package> Mail-1.1.0/Mail.php100644 1750 1750 16226 7674755463 7246 <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Chuck Hagenbuch <chuck@horde.org> | // +----------------------------------------------------------------------+ // // $Id: Mail.php,v 1.5 2003/06/20 05:08:03 jon Exp $ require_once 'PEAR.php'; /** * PEAR's Mail:: interface. Defines the interface for implementing * mailers under the PEAR hierarchy, and provides supporting functions * useful in multiple mailer backends. * * @access public * @version $Revision: 1.5 $ * @package Mail */ class Mail { /** * Line terminator used for separating header lines. * @var string */ var $sep = "\r\n"; /** * Provides an interface for generating Mail:: objects of various * types * * @param string $driver The kind of Mail:: object to instantiate. * @param array $params The parameters to pass to the Mail:: object. * @return object Mail a instance of the driver class or if fails a PEAR Error * @access public */ function factory($driver, $params = array()) { $driver = strtolower($driver); @include_once 'Mail/' . $driver . '.php'; $class = 'Mail_' . $driver; if (class_exists($class)) { return new $class($params); } else { return PEAR::raiseError('Unable to find class for driver ' . $driver); } } /** * Implements Mail::send() function using php's built-in mail() * command. * * @param mixed $recipients Either a comma-seperated list of recipients * (RFC822 compliant), or an array of recipients, * each RFC822 valid. This may contain recipients not * specified in the headers, for Bcc:, resending * messages, etc. * * @param array $headers The array of headers to send with the mail, in an * associative array, where the array key is the * header name (ie, 'Subject'), and the array value * is the header value (ie, 'test'). The header * produced from those values would be 'Subject: * test'. * * @param string $body The full text of the message body, including any * Mime parts, etc. * * @return mixed Returns true on success, or a PEAR_Error * containing a descriptive error message on * failure. * @access public * @deprecated use Mail_mail::send instead */ function send($recipients, $headers, $body) { // if we're passed an array of recipients, implode it. if (is_array($recipients)) { $recipients = implode(', ', $recipients); } // get the Subject out of the headers array so that we can // pass it as a seperate argument to mail(). $subject = ''; if (isset($headers['Subject'])) { $subject = $headers['Subject']; unset($headers['Subject']); } // flatten the headers out. list(,$text_headers) = Mail::prepareHeaders($headers); return mail($recipients, $subject, $body, $text_headers); } /** * Take an array of mail headers and return a string containing * text usable in sending a message. * * @param array $headers The array of headers to prepare, in an associative * array, where the array key is the header name (ie, * 'Subject'), and the array value is the header * value (ie, 'test'). The header produced from those * values would be 'Subject: test'. * * @return mixed Returns false if it encounters a bad address, * otherwise returns an array containing two * elements: Any From: address found in the headers, * and the plain text version of the headers. * @access private */ function prepareHeaders($headers) { $lines = array(); $from = null; foreach ($headers as $key => $value) { if ($key === 'From') { include_once 'Mail/RFC822.php'; $addresses = Mail_RFC822::parseAddressList($value, 'localhost', false); $from = $addresses[0]->mailbox . '@' . $addresses[0]->host; // Reject envelope From: addresses with spaces. if (strstr($from, ' ')) { return false; } $lines[] = $key . ': ' . $value; } elseif ($key === 'Received') { // Put Received: headers at the top. Spam detectors often // flag messages with Received: headers after the Subject: // as spam. array_unshift($lines, $key . ': ' . $value); } else { $lines[] = $key . ': ' . $value; } } return array($from, join($this->sep, $lines)); } /** * Take a set of recipients and parse them, returning an array of * bare addresses (forward paths) that can be passed to sendmail * or an smtp server with the rcpt to: command. * * @param mixed Either a comma-seperated list of recipients * (RFC822 compliant), or an array of recipients, * each RFC822 valid. * * @return array An array of forward paths (bare addresses). * @access private */ function parseRecipients($recipients) { include_once 'Mail/RFC822.php'; // if we're passed an array, assume addresses are valid and // implode them before parsing. if (is_array($recipients)) { $recipients = implode(', ', $recipients); } // Parse recipients, leaving out all personal info. This is // for smtp recipients, etc. All relevant personal information // should already be in the headers. $addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false); $recipients = array(); if (is_array($addresses)) { foreach ($addresses as $ob) { $recipients[] = $ob->mailbox . '@' . $ob->host; } } return $recipients; } } ?> Mail-1.1.0/Mail/mail.php100644 1750 1750 10233 7674755463 10160 <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Chuck Hagenbuch <chuck@horde.org> | // +----------------------------------------------------------------------+ // // $Id: mail.php,v 1.4 2003/06/20 05:08:03 jon Exp $ require_once 'Mail.php'; /** * internal PHP-mail() implementation of the PEAR Mail:: interface. * @access public * @package Mail * @version $Revision: 1.4 $ */ class Mail_mail extends Mail { /** * Any arguments to pass to the mail() function. * @var string */ var $_params = ''; /** * Constructor. * * Instantiates a new Mail_mail:: object based on the parameters * passed in. * * @param string $params Extra arguments for the mail() function. * * @access public */ function Mail_mail($params = '') { /* * The other mail implementations accept parameters as arrays. In the * interest of being consistent, explode an array into a string of * parameter arguments. */ if (is_array($params)) { $this->_params = join(' ', $params); } else { $this->_params = $params; } /* * Because the mail() function may pass headers as command line * arguments, we can't guarantee the use of the standard "\r\n" * separator. Instead, we use the system's native line separator. */ $this->sep = OS_WINDOWS ? "\r\n" : "\n"; } /** * Implements Mail_mail::send() function using php's built-in mail() * command. * * @param mixed $recipients Either a comma-seperated list of recipients * (RFC822 compliant), or an array of recipients, * each RFC822 valid. This may contain recipients not * specified in the headers, for Bcc:, resending * messages, etc. * * @param array $headers The array of headers to send with the mail, in an * associative array, where the array key is the * header name (ie, 'Subject'), and the array value * is the header value (ie, 'test'). The header * produced from those values would be 'Subject: * test'. * * @param string $body The full text of the message body, including any * Mime parts, etc. * * @return mixed Returns true on success, or a PEAR_Error * containing a descriptive error message on * failure. * @access public */ function send($recipients, $headers, $body) { // if we're passed an array of recipients, implode it. if (is_array($recipients)) { $recipients = implode(', ', $recipients); } // get the Subject out of the headers array so that we can // pass it as a seperate argument to mail(). $subject = ''; if (isset($headers['Subject'])) { $subject = $headers['Subject']; unset($headers['Subject']); } // flatten the headers out. list(,$text_headers) = Mail::prepareHeaders($headers); return mail($recipients, $subject, $body, $text_headers, $this->_params); } } Mail-1.1.0/Mail/sendmail.php100644 1750 1750 12444 7674755463 11040 <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Author: Chuck Hagenbuch <chuck@horde.org> | // +----------------------------------------------------------------------+ require_once 'Mail.php'; /** * Sendmail implementation of the PEAR Mail:: interface. * @access public * @package Mail * @version $Revision: 1.3 $ */ class Mail_sendmail extends Mail { /** * The location of the sendmail or sendmail wrapper binary on the * filesystem. * @var string */ var $sendmail_path = '/usr/sbin/sendmail'; /** * Any extra command-line parameters to pass to the sendmail or * sendmail wrapper binary. * @var string */ var $sendmail_args = ''; /** * Constructor. * * Instantiates a new Mail_sendmail:: object based on the parameters * passed in. It looks for the following parameters: * sendmail_path The location of the sendmail binary on the * filesystem. Defaults to '/usr/sbin/sendmail'. * * sendmail_args Any extra parameters to pass to the sendmail * or sendmail wrapper binary. * * If a parameter is present in the $params array, it replaces the * default. * * @param array $params Hash containing any parameters different from the * defaults. * @access public */ function Mail_sendmail($params) { if (isset($params['sendmail_path'])) $this->sendmail_path = $params['sendmail_path']; if (isset($params['sendmail_args'])) $this->sendmail_args = $params['sendmail_args']; /* * Because we need to pass message headers to the sendmail program on * the commandline, we can't guarantee the use of the standard "\r\n" * separator. Instead, we use the system's native line separator. */ $this->sep = OS_WINDOWS ? "\r\n" : "\n"; } /** * Implements Mail::send() function using the sendmail * command-line binary. * * @param mixed $recipients Either a comma-seperated list of recipients * (RFC822 compliant), or an array of recipients, * each RFC822 valid. This may contain recipients not * specified in the headers, for Bcc:, resending * messages, etc. * * @param array $headers The array of headers to send with the mail, in an * associative array, where the array key is the * header name (ie, 'Subject'), and the array value * is the header value (ie, 'test'). The header * produced from those values would be 'Subject: * test'. * * @param string $body The full text of the message body, including any * Mime parts, etc. * * @return mixed Returns true on success, or a PEAR_Error * containing a descriptive error message on * failure. * @access public */ function send($recipients, $headers, $body) { $recipients = escapeShellCmd(implode(' ', $this->parseRecipients($recipients))); list($from, $text_headers) = $this->prepareHeaders($headers); if (!isset($from)) { return new PEAR_Error('No from address given.'); } elseif (strstr($from, ' ') || strstr($from, ';') || strstr($from, '&') || strstr($from, '`')) { return new PEAR_Error('From address specified with dangerous characters.'); } $result = 0; if (@is_executable($this->sendmail_path)) { $from = escapeShellCmd($from); $mail = popen($this->sendmail_path . (!empty($this->sendmail_args) ? ' ' . $this->sendmail_args : '') . " -f$from -- $recipients", 'w'); fputs($mail, $text_headers); fputs($mail, $this->sep); // newline to end the headers section fputs($mail, $body); $result = pclose($mail) >> 8 & 0xFF; // need to shift the pclose result to get the exit code } else { return new PEAR_Error('sendmail [' . $this->sendmail_path . '] not executable'); } if ($result != 0) { return new PEAR_Error('sendmail returned error code ' . $result); } return true; } } ?> Mail-1.1.0/Mail/smtp.php100644 1750 1750 14145 7643053313 10204 <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Chuck Hagenbuch <chuck@horde.org> | // | Jon Parise <jon@php.net> | // +----------------------------------------------------------------------+ require_once 'Mail.php'; /** * SMTP implementation of the PEAR Mail:: interface. Requires the PEAR * Net_SMTP:: class. * @access public * @package Mail * @version $Revision: 1.10 $ */ class Mail_smtp extends Mail { /** * The SMTP host to connect to. * @var string */ var $host = 'localhost'; /** * The port the SMTP server is on. * @var integer */ var $port = 25; /** * Should SMTP authentication be used? * * This value may be set to true, false or the name of a specific * authentication method. * * If the value is set to true, the Net_SMTP package will attempt to use * the best authentication method advertised by the remote SMTP server. * * @var mixed */ var $auth = false; /** * The username to use if the SMTP server requires authentication. * @var string */ var $username = ''; /** * The password to use if the SMTP server requires authentication. * @var string */ var $password = ''; /** * Constructor. * * Instantiates a new Mail_smtp:: object based on the parameters * passed in. It looks for the following parameters: * host The server to connect to. Defaults to localhost. * port The port to connect to. Defaults to 25. * auth SMTP authentication. Defaults to none. * username The username to use for SMTP auth. No default. * password The password to use for SMTP auth. No default. * * If a parameter is present in the $params array, it replaces the * default. * * @param array Hash containing any parameters different from the * defaults. * @access public */ function Mail_smtp($params) { if (isset($params['host'])) $this->host = $params['host']; if (isset($params['port'])) $this->port = $params['port']; if (isset($params['auth'])) $this->auth = $params['auth']; if (isset($params['username'])) $this->username = $params['username']; if (isset($params['password'])) $this->password = $params['password']; } /** * Implements Mail::send() function using SMTP. * * @param mixed $recipients Either a comma-seperated list of recipients * (RFC822 compliant), or an array of recipients, * each RFC822 valid. This may contain recipients not * specified in the headers, for Bcc:, resending * messages, etc. * * @param array $headers The array of headers to send with the mail, in an * associative array, where the array key is the * header name (e.g., 'Subject'), and the array value * is the header value (e.g., 'test'). The header * produced from those values would be 'Subject: * test'. * * @param string $body The full text of the message body, including any * Mime parts, etc. * * @return mixed Returns true on success, or a PEAR_Error * containing a descriptive error message on * failure. * @access public */ function send($recipients, $headers, $body) { include_once 'Net/SMTP.php'; if (!($smtp = new Net_SMTP($this->host, $this->port))) { return new PEAR_Error('unable to instantiate Net_SMTP object'); } if (PEAR::isError($smtp->connect())) { return new PEAR_Error('unable to connect to smtp server ' . $this->host . ':' . $this->port); } if ($this->auth) { $method = is_string($this->auth) ? $this->auth : ''; if (PEAR::isError($smtp->auth($this->username, $this->password, $method))) { return new PEAR_Error('unable to authenticate to smtp server'); } } list($from, $text_headers) = $this->prepareHeaders($headers); /* * Since few MTAs are going to allow this header to be forged unless * it's in the MAIL FROM: exchange, we'll use Return-Path instead of * From: if it's set. */ if (!empty($headers['Return-Path'])) { $from = $headers['Return-Path']; } if (!isset($from)) { return new PEAR_Error('No from address given'); } if (PEAR::isError($smtp->mailFrom($from))) { return new PEAR_Error('unable to set sender to [' . $from . ']'); } $recipients = $this->parseRecipients($recipients); foreach($recipients as $recipient) { if (PEAR::isError($res = $smtp->rcptTo($recipient))) { return new PEAR_Error('unable to add recipient [' . $recipient . ']: ' . $res->getMessage()); } } if (PEAR::isError($smtp->data($text_headers . "\r\n" . $body))) { return new PEAR_Error('unable to send data'); } $smtp->disconnect(); return true; } } ?> Mail-1.1.0/Mail/RFC822.php100644 1750 1750 75160 7672640135 10101 <?php // +-----------------------------------------------------------------------+ // | Copyright (c) 2001-2002, Richard Heyes | // | All rights reserved. | // | | // | Redistribution and use in source and binary forms, with or without | // | modification, are permitted provided that the following conditions | // | are met: | // | | // | o Redistributions of source code must retain the above copyright | // | notice, this list of conditions and the following disclaimer. | // | o Redistributions in binary form must reproduce the above copyright | // | notice, this list of conditions and the following disclaimer in the | // | documentation and/or other materials provided with the distribution.| // | o The names of the authors may not be used to endorse or promote | // | products derived from this software without specific prior written | // | permission. | // | | // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | // | | // +-----------------------------------------------------------------------+ // | Authors: Richard Heyes <richard@phpguru.org> | // | Chuck Hagenbuch <chuck@horde.org> | // +-----------------------------------------------------------------------+ /** * RFC 822 Email address list validation Utility * * What is it? * * This class will take an address string, and parse it into it's consituent * parts, be that either addresses, groups, or combinations. Nested groups * are not supported. The structure it returns is pretty straight forward, * and is similar to that provided by the imap_rfc822_parse_adrlist(). Use * print_r() to view the structure. * * How do I use it? * * $address_string = 'My Group: "Richard" <richard@localhost> (A comment), ted@example.com (Ted Bloggs), Barney;'; * $structure = Mail_RFC822::parseAddressList($address_string, 'example.com', true) * print_r($structure); * * @author Richard Heyes <richard@phpguru.org> * @author Chuck Hagenbuch <chuck@horde.org> * @version $Revision: 1.7 $ * @license BSD * @package Mail */ class Mail_RFC822 { /** * The address being parsed by the RFC822 object. * @var string $address */ var $address = ''; /** * The default domain to use for unqualified addresses. * @var string $default_domain */ var $default_domain = 'localhost'; /** * Should we return a nested array showing groups, or flatten everything? * @var boolean $nestGroups */ var $nestGroups = true; /** * Whether or not to validate atoms for non-ascii characters. * @var boolean $validate */ var $validate = true; /** * The array of raw addresses built up as we parse. * @var array $addresses */ var $addresses = array(); /** * The final array of parsed address information that we build up. * @var array $structure */ var $structure = array(); /** * The current error message, if any. * @var string $error */ var $error = null; /** * An internal counter/pointer. * @var integer $index */ var $index = null; /** * The number of groups that have been found in the address list. * @var integer $num_groups * @access public */ var $num_groups = 0; /** * A variable so that we can tell whether or not we're inside a * Mail_RFC822 object. * @var boolean $mailRFC822 */ var $mailRFC822 = true; /** * A limit after which processing stops * @var int $limit */ var $limit = null; /** * Sets up the object. The address must either be set here or when * calling parseAddressList(). One or the other. * * @access public * @param string $address The address(es) to validate. * @param string $default_domain Default domain/host etc. If not supplied, will be set to localhost. * @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing. * @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance. * * @return object Mail_RFC822 A new Mail_RFC822 object. */ function Mail_RFC822($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null) { if (isset($address)) $this->address = $address; if (isset($default_domain)) $this->default_domain = $default_domain; if (isset($nest_groups)) $this->nestGroups = $nest_groups; if (isset($validate)) $this->validate = $validate; if (isset($limit)) $this->limit = $limit; } /** * Starts the whole process. The address must either be set here * or when creating the object. One or the other. * * @access public * @param string $address The address(es) to validate. * @param string $default_domain Default domain/host etc. * @param boolean $nest_groups Whether to return the structure with groups nested for easier viewing. * @param boolean $validate Whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance. * * @return array A structured array of addresses. */ function parseAddressList($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null) { if (!isset($this->mailRFC822)) { $obj = new Mail_RFC822($address, $default_domain, $nest_groups, $validate, $limit); return $obj->parseAddressList(); } if (isset($address)) $this->address = $address; if (isset($default_domain)) $this->default_domain = $default_domain; if (isset($nest_groups)) $this->nestGroups = $nest_groups; if (isset($validate)) $this->validate = $validate; if (isset($limit)) $this->limit = $limit; $this->structure = array(); $this->addresses = array(); $this->error = null; $this->index = null; while ($this->address = $this->_splitAddresses($this->address)) { continue; } if ($this->address === false || isset($this->error)) { return $this->raiseError($this->error); } // Loop through all the addresses for ($i = 0; $i < count($this->addresses); $i++){ if (($return = $this->_validateAddress($this->addresses[$i])) === false || isset($this->error)) { return $this->raiseError($this->error); } if (!$this->nestGroups) { $this->structure = array_merge($this->structure, $return); } else { $this->structure[] = $return; } } return $this->structure; } /** * Splits an address into seperate addresses. * * @access private * @param string $address The addresses to split. * @return boolean Success or failure. */ function _splitAddresses($address) { if (!empty($this->limit) AND count($this->addresses) == $this->limit) { return ''; } if ($this->_isGroup($address) && !isset($this->error)) { $split_char = ';'; $is_group = true; } elseif (!isset($this->error)) { $split_char = ','; $is_group = false; } elseif (isset($this->error)) { return false; } // Split the string based on the above ten or so lines. $parts = explode($split_char, $address); $string = $this->_splitCheck($parts, $split_char); // If a group... if ($is_group) { // If $string does not contain a colon outside of // brackets/quotes etc then something's fubar. // First check there's a colon at all: if (strpos($string, ':') === false) { $this->error = 'Invalid address: ' . $string; return false; } // Now check it's outside of brackets/quotes: if (!$this->_splitCheck(explode(':', $string), ':')) return false; // We must have a group at this point, so increase the counter: $this->num_groups++; } // $string now contains the first full address/group. // Add to the addresses array. $this->addresses[] = array( 'address' => trim($string), 'group' => $is_group ); // Remove the now stored address from the initial line, the +1 // is to account for the explode character. $address = trim(substr($address, strlen($string) + 1)); // If the next char is a comma and this was a group, then // there are more addresses, otherwise, if there are any more // chars, then there is another address. if ($is_group && substr($address, 0, 1) == ','){ $address = trim(substr($address, 1)); return $address; } elseif (strlen($address) > 0) { return $address; } else { return ''; } // If you got here then something's off return false; } /** * Checks for a group at the start of the string. * * @access private * @param string $address The address to check. * @return boolean Whether or not there is a group at the start of the string. */ function _isGroup($address) { // First comma not in quotes, angles or escaped: $parts = explode(',', $address); $string = $this->_splitCheck($parts, ','); // Now we have the first address, we can reliably check for a // group by searching for a colon that's not escaped or in // quotes or angle brackets. if (count($parts = explode(':', $string)) > 1) { $string2 = $this->_splitCheck($parts, ':'); return ($string2 !== $string); } else { return false; } } /** * A common function that will check an exploded string. * * @access private * @param array $parts The exloded string. * @param string $char The char that was exploded on. * @return mixed False if the string contains unclosed quotes/brackets, or the string on success. */ function _splitCheck($parts, $char) { $string = $parts[0]; for ($i = 0; $i < count($parts); $i++) { if ($this->_hasUnclosedQuotes($string) || $this->_hasUnclosedBrackets($string, '<>') || $this->_hasUnclosedBrackets($string, '[]') || $this->_hasUnclosedBrackets($string, '()') || substr($string, -1) == '\\') { if (isset($parts[$i + 1])) { $string = $string . $char . $parts[$i + 1]; } else { $this->error = 'Invalid address spec. Unclosed bracket or quotes'; return false; } } else { $this->index = $i; break; } } return $string; } /** * Checks if a string has an unclosed quotes or not. * * @access private * @param string $string The string to check. * @return boolean True if there are unclosed quotes inside the string, false otherwise. */ function _hasUnclosedQuotes($string) { $string = explode('"', $string); $string_cnt = count($string); for ($i = 0; $i < (count($string) - 1); $i++) if (substr($string[$i], -1) == '\\') $string_cnt--; return ($string_cnt % 2 === 0); } /** * Checks if a string has an unclosed brackets or not. IMPORTANT: * This function handles both angle brackets and square brackets; * * @access private * @param string $string The string to check. * @param string $chars The characters to check for. * @return boolean True if there are unclosed brackets inside the string, false otherwise. */ function _hasUnclosedBrackets($string, $chars) { $num_angle_start = substr_count($string, $chars[0]); $num_angle_end = substr_count($string, $chars[1]); $this->_hasUnclosedBracketsSub($string, $num_angle_start, $chars[0]); $this->_hasUnclosedBracketsSub($string, $num_angle_end, $chars[1]); if ($num_angle_start < $num_angle_end) { $this->error = 'Invalid address spec. Unmatched quote or bracket (' . $chars . ')'; return false; } else { return ($num_angle_start > $num_angle_end); } } /** * Sub function that is used only by hasUnclosedBrackets(). * * @access private * @param string $string The string to check. * @param integer &$num The number of occurences. * @param string $char The character to count. * @return integer The number of occurences of $char in $string, adjusted for backslashes. */ function _hasUnclosedBracketsSub($string, &$num, $char) { $parts = explode($char, $string); for ($i = 0; $i < count($parts); $i++){ if (substr($parts[$i], -1) == '\\' || $this->_hasUnclosedQuotes($parts[$i])) $num--; if (isset($parts[$i + 1])) $parts[$i + 1] = $parts[$i] . $char . $parts[$i + 1]; } return $num; } /** * Function to begin checking the address. * * @access private * @param string $address The address to validate. * @return mixed False on failure, or a structured array of address information on success. */ function _validateAddress($address) { $is_group = false; if ($address['group']) { $is_group = true; // Get the group part of the name $parts = explode(':', $address['address']); $groupname = $this->_splitCheck($parts, ':'); $structure = array(); // And validate the group part of the name. if (!$this->_validatePhrase($groupname)){ $this->error = 'Group name did not validate.'; return false; } else { // Don't include groups if we are not nesting // them. This avoids returning invalid addresses. if ($this->nestGroups) { $structure = new stdClass; $structure->groupname = $groupname; } } $address['address'] = ltrim(substr($address['address'], strlen($groupname . ':'))); } // If a group then split on comma and put into an array. // Otherwise, Just put the whole address in an array. if ($is_group) { while (strlen($address['address']) > 0) { $parts = explode(',', $address['address']); $addresses[] = $this->_splitCheck($parts, ','); $address['address'] = trim(substr($address['address'], strlen(end($addresses) . ','))); } } else { $addresses[] = $address['address']; } // Check that $addresses is set, if address like this: // Groupname:; // Then errors were appearing. if (!isset($addresses)){ $this->error = 'Empty group.'; return false; } for ($i = 0; $i < count($addresses); $i++) { $addresses[$i] = trim($addresses[$i]); } // Validate each mailbox. // Format could be one of: name <geezer@domain.com> // geezer@domain.com // geezer // ... or any other format valid by RFC 822. array_walk($addresses, array($this, 'validateMailbox')); // Nested format if ($this->nestGroups) { if ($is_group) { $structure->addresses = $addresses; } else { $structure = $addresses[0]; } // Flat format } else { if ($is_group) { $structure = array_merge($structure, $addresses); } else { $structure = $addresses; } } return $structure; } /** * Function to validate a phrase. * * @access private * @param string $phrase The phrase to check. * @return boolean Success or failure. */ function _validatePhrase($phrase) { // Splits on one or more Tab or space. $parts = preg_split('/[ \\x09]+/', $phrase, -1, PREG_SPLIT_NO_EMPTY); $phrase_parts = array(); while (count($parts) > 0){ $phrase_parts[] = $this->_splitCheck($parts, ' '); for ($i = 0; $i < $this->index + 1; $i++) array_shift($parts); } for ($i = 0; $i < count($phrase_parts); $i++) { // If quoted string: if (substr($phrase_parts[$i], 0, 1) == '"') { if (!$this->_validateQuotedString($phrase_parts[$i])) return false; continue; } // Otherwise it's an atom: if (!$this->_validateAtom($phrase_parts[$i])) return false; } return true; } /** * Function to validate an atom which from rfc822 is: * atom = 1*<any CHAR except specials, SPACE and CTLs> * * If validation ($this->validate) has been turned off, then * validateAtom() doesn't actually check anything. This is so that you * can split a list of addresses up before encoding personal names * (umlauts, etc.), for example. * * @access private * @param string $atom The string to check. * @return boolean Success or failure. */ function _validateAtom($atom) { if (!$this->validate) { // Validation has been turned off; assume the atom is okay. return true; } // Check for any char from ASCII 0 - ASCII 127 if (!preg_match('/^[\\x00-\\x7E]+$/i', $atom, $matches)) { return false; } // Check for specials: if (preg_match('/[][()<>@,;\\:". ]/', $atom)) { return false; } // Check for control characters (ASCII 0-31): if (preg_match('/[\\x00-\\x1F]+/', $atom)) { return false; } return true; } /** * Function to validate quoted string, which is: * quoted-string = <"> *(qtext/quoted-pair) <"> * * @access private * @param string $qstring The string to check * @return boolean Success or failure. */ function _validateQuotedString($qstring) { // Leading and trailing " $qstring = substr($qstring, 1, -1); // Perform check. return !(preg_match('/(.)[\x0D\\\\"]/', $qstring, $matches) && $matches[1] != '\\'); } /** * Function to validate a mailbox, which is: * mailbox = addr-spec ; simple address * / phrase route-addr ; name and route-addr * * @access public * @param string &$mailbox The string to check. * @return boolean Success or failure. */ function validateMailbox(&$mailbox) { // A couple of defaults. $phrase = ''; $comment = ''; // Catch any RFC822 comments and store them separately $_mailbox = $mailbox; while (strlen(trim($_mailbox)) > 0) { $parts = explode('(', $_mailbox); $before_comment = $this->_splitCheck($parts, '('); if ($before_comment != $_mailbox) { // First char should be a ( $comment = substr(str_replace($before_comment, '', $_mailbox), 1); $parts = explode(')', $comment); $comment = $this->_splitCheck($parts, ')'); $comments[] = $comment; // +1 is for the trailing ) $_mailbox = substr($_mailbox, strpos($_mailbox, $comment)+strlen($comment)+1); } else { break; } } for($i=0; $i<count(@$comments); $i++){ $mailbox = str_replace('('.$comments[$i].')', '', $mailbox); } $mailbox = trim($mailbox); // Check for name + route-addr if (substr($mailbox, -1) == '>' && substr($mailbox, 0, 1) != '<') { $parts = explode('<', $mailbox); $name = $this->_splitCheck($parts, '<'); $phrase = trim($name); $route_addr = trim(substr($mailbox, strlen($name.'<'), -1)); if ($this->_validatePhrase($phrase) === false || ($route_addr = $this->_validateRouteAddr($route_addr)) === false) return false; // Only got addr-spec } else { // First snip angle brackets if present. if (substr($mailbox,0,1) == '<' && substr($mailbox,-1) == '>') $addr_spec = substr($mailbox,1,-1); else $addr_spec = $mailbox; if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) return false; } // Construct the object that will be returned. $mbox = new stdClass(); // Add the phrase (even if empty) and comments $mbox->personal = $phrase; $mbox->comment = isset($comments) ? $comments : array(); if (isset($route_addr)) { $mbox->mailbox = $route_addr['local_part']; $mbox->host = $route_addr['domain']; $route_addr['adl'] !== '' ? $mbox->adl = $route_addr['adl'] : ''; } else { $mbox->mailbox = $addr_spec['local_part']; $mbox->host = $addr_spec['domain']; } $mailbox = $mbox; return true; } /** * This function validates a route-addr which is: * route-addr = "<" [route] addr-spec ">" * * Angle brackets have already been removed at the point of * getting to this function. * * @access private * @param string $route_addr The string to check. * @return mixed False on failure, or an array containing validated address/route information on success. */ function _validateRouteAddr($route_addr) { // Check for colon. if (strpos($route_addr, ':') !== false) { $parts = explode(':', $route_addr); $route = $this->_splitCheck($parts, ':'); } else { $route = $route_addr; } // If $route is same as $route_addr then the colon was in // quotes or brackets or, of course, non existent. if ($route === $route_addr){ unset($route); $addr_spec = $route_addr; if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) { return false; } } else { // Validate route part. if (($route = $this->_validateRoute($route)) === false) { return false; } $addr_spec = substr($route_addr, strlen($route . ':')); // Validate addr-spec part. if (($addr_spec = $this->_validateAddrSpec($addr_spec)) === false) { return false; } } if (isset($route)) { $return['adl'] = $route; } else { $return['adl'] = ''; } $return = array_merge($return, $addr_spec); return $return; } /** * Function to validate a route, which is: * route = 1#("@" domain) ":" * * @access private * @param string $route The string to check. * @return mixed False on failure, or the validated $route on success. */ function _validateRoute($route) { // Split on comma. $domains = explode(',', trim($route)); for ($i = 0; $i < count($domains); $i++) { $domains[$i] = str_replace('@', '', trim($domains[$i])); if (!$this->_validateDomain($domains[$i])) return false; } return $route; } /** * Function to validate a domain, though this is not quite what * you expect of a strict internet domain. * * domain = sub-domain *("." sub-domain) * * @access private * @param string $domain The string to check. * @return mixed False on failure, or the validated domain on success. */ function _validateDomain($domain) { // Note the different use of $subdomains and $sub_domains $subdomains = explode('.', $domain); while (count($subdomains) > 0) { $sub_domains[] = $this->_splitCheck($subdomains, '.'); for ($i = 0; $i < $this->index + 1; $i++) array_shift($subdomains); } for ($i = 0; $i < count($sub_domains); $i++) { if (!$this->_validateSubdomain(trim($sub_domains[$i]))) return false; } // Managed to get here, so return input. return $domain; } /** * Function to validate a subdomain: * subdomain = domain-ref / domain-literal * * @access private * @param string $subdomain The string to check. * @return boolean Success or failure. */ function _validateSubdomain($subdomain) { if (preg_match('|^\[(.*)]$|', $subdomain, $arr)){ if (!$this->_validateDliteral($arr[1])) return false; } else { if (!$this->_validateAtom($subdomain)) return false; } // Got here, so return successful. return true; } /** * Function to validate a domain literal: * domain-literal = "[" *(dtext / quoted-pair) "]" * * @access private * @param string $dliteral The string to check. * @return boolean Success or failure. */ function _validateDliteral($dliteral) { return !preg_match('/(.)[][\x0D\\\\]/', $dliteral, $matches) && $matches[1] != '\\'; } /** * Function to validate an addr-spec. * * addr-spec = local-part "@" domain * * @access private * @param string $addr_spec The string to check. * @return mixed False on failure, or the validated addr-spec on success. */ function _validateAddrSpec($addr_spec) { $addr_spec = trim($addr_spec); // Split on @ sign if there is one. if (strpos($addr_spec, '@') !== false) { $parts = explode('@', $addr_spec); $local_part = $this->_splitCheck($parts, '@'); $domain = substr($addr_spec, strlen($local_part . '@')); // No @ sign so assume the default domain. } else { $local_part = $addr_spec; $domain = $this->default_domain; } if (($local_part = $this->_validateLocalPart($local_part)) === false) return false; if (($domain = $this->_validateDomain($domain)) === false) return false; // Got here so return successful. return array('local_part' => $local_part, 'domain' => $domain); } /** * Function to validate the local part of an address: * local-part = word *("." word) * * @access private * @param string $local_part * @return mixed False on failure, or the validated local part on success. */ function _validateLocalPart($local_part) { $parts = explode('.', $local_part); // Split the local_part into words. while (count($parts) > 0){ $words[] = $this->_splitCheck($parts, '.'); for ($i = 0; $i < $this->index + 1; $i++) { array_shift($parts); } } // Validate each word. for ($i = 0; $i < count($words); $i++) { if ($this->_validatePhrase(trim($words[$i])) === false) return false; } // Managed to get here, so return the input. return $local_part; } /** * Returns an approximate count of how many addresses are * in the given string. This is APPROXIMATE as it only splits * based on a comma which has no preceding backslash. Could be * useful as large amounts of addresses will end up producing * *large* structures when used with parseAddressList(). * * @param string $data Addresses to count * @return int Approximate count */ function approximateCount($data) { return count(preg_split('/(?<!\\\\),/', $data)); } /** * This is a email validating function seperate to the rest * of the class. It simply validates whether an email is of * the common internet form: <user>@<domain>. This can be * sufficient for most people. Optional stricter mode can * be utilised which restricts mailbox characters allowed * to alphanumeric, full stop, hyphen and underscore. * * @param string $data Address to check * @param boolean $strict Optional stricter mode * @return mixed False if it fails, an indexed array * username/domain if it matches */ function isValidInetAddress($data, $strict = false) { $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'; if (preg_match($regex, trim($data), $matches)) { return array($matches[1], $matches[2]); } else { return false; } } } ?> Index: php4/pear/packages/Net_SMTP-1.2.3.tar +++ php4/pear/packages/Net_SMTP-1.2.3.tar package.xml100644 1750 24 10400 7657522764 6365 <?xml version="1.0" encoding="ISO-8859-1" ?> <package version="1.0"> <name>Net_SMTP</name> <summary>Provides an implementation of the SMTP protocol</summary> <description>Provides an implementation of the SMTP protocol using PEAR's Net_Socket class.</description> <maintainers> <maintainer> <user>chagenbu</user> <name>Chuck Hagenbuch</name> <email>chuck@horde.org</email> <role>lead</role> </maintainer> <maintainer> <user>jon</user> <name>Jon Parise</name> <email>jon@php.net</email> <role>lead</role> </maintainer> </maintainers> <release> <version>1.2.3</version> <date>2003-05-11</date> <license>PHP License</license> <state>stable</state> <notes>Both 235 (Authentication successful) and 503 (Error: already authenticated) are now accepted as valid AUTH responses. 503 (Error: already authenticated) is now considered a valid EHLO response.</notes> <deps> <dep type="pkg" rel="has">Net_Socket</dep> </deps> <provides type="class" name="Net_SMTP" /> <provides type="function" name="Net_SMTP::setDebug" /> <provides type="function" name="Net_SMTP::getResponse" /> <provides type="function" name="Net_SMTP::connect" /> <provides type="function" name="Net_SMTP::disconnect" /> <provides type="function" name="Net_SMTP::auth" /> <provides type="function" name="Net_SMTP::helo" /> <provides type="function" name="Net_SMTP::mailFrom" /> <provides type="function" name="Net_SMTP::rcptTo" /> <provides type="function" name="Net_SMTP::quotedata" /> <provides type="function" name="Net_SMTP::data" /> <provides type="function" name="Net_SMTP::send_from" /> <provides type="function" name="Net_SMTP::soml_from" /> <provides type="function" name="Net_SMTP::saml_from" /> <provides type="function" name="Net_SMTP::rset" /> <provides type="function" name="Net_SMTP::vrfy" /> <provides type="function" name="Net_SMTP::noop" /> <provides type="function" name="Net_SMTP::identifySender" /> <filelist> <file role="php" baseinstalldir="Net" md5sum="f23ac82b7b992d52032580e05babfba9" name="SMTP.php"/> </filelist> </release> <changelog> <release> <version>1.2.2</version> <date>2003-05-02</date> <state>stable</state> <notes>Fix a call-time pass-by-reference problem that was raising a warning if call-time pass-by-reference was disabled. </notes> </release> <release> <version>1.2.1</version> <date>2003-04-26</date> <state>stable</state> <notes>The Auth_SASL package is no longer absolutely required, but it will be used if it is available. Otherwise, the authentication methods that depend upon it will be disabled. </notes> </release> <release> <version>1.2.0</version> <date>2003-04-06</date> <state>stable</state> <notes>- Perform data quoting in its own routine: quotedata() </notes> </release> <release> <version>1.1.2</version> <date>2003-02-17</date> <state>stable</state> <notes>- Correctly handle the case where the server's ESMTP response includes a SIZE keyword with no specific value. </notes> </release> <release> <version>1.1.1</version> <date>2003-01-30</date> <state>stable</state> <notes>- Don't enforce a maximum message size if the SIZE parameter is zero. </notes> </release> <release> <version>1.1.0</version> <date>2003-01-18</date> <state>stable</state> <notes>- The SMTP server's SIZE capability is now honored. - Improved support for SMTP authentication (LOGIN, PLAIN, CRAM-MD5, DIGEST-MD5). - Overhauled the server response parsing system. - Added optional debugging output (enabled via setDebug()). - A timeout value can now be specified for the socket connection. </notes> </release> <release> <version>1.0.1</version> <date>2003-01-02</date> <state>stable</state> <notes>Corrected an off-by-one bug that corrupted the list of ESMTP capabilities. </notes> </release> <release> <version>1.0</version> <date>2002-06-11</date> <state>stable</state> <notes>Initial release as PEAR package </notes> </release> </changelog> </package> Net_SMTP-1.2.3/SMTP.php100644 1750 24 65717 7657522547 7620 <?php /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2003 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Chuck Hagenbuch <chuck@horde.org> | // | Jon Parise <jon@php.net> | // | Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar> | // +----------------------------------------------------------------------+ require_once 'PEAR.php'; require_once 'Net/Socket.php'; /** * Provides an implementation of the SMTP protocol using PEAR's * Net_Socket:: class. * * @package Net_SMTP * @author Chuck Hagenbuch <chuck@horde.org> * @author Jon Parise <jon@php.net> * @author Damian Alejandro Fernandez Sosa <damlists@cnba.uba.ar> */ class Net_SMTP { /** * The server to connect to. * @var string * @access public */ var $host = 'localhost'; /** * The port to connect to. * @var int * @access public */ var $port = 25; /** * The value to give when sending EHLO or HELO. * @var string * @access public */ var $localhost = 'localhost'; /** * List of supported authentication methods, in preferential order. * @var array * @access public */ var $auth_methods = array('DIGEST-MD5', 'CRAM-MD5', 'LOGIN', 'PLAIN'); /** * Should debugging output be enabled? * @var boolean * @access private */ var $_debug = false; /** * The socket resource being used to connect to the SMTP server. * @var resource * @access private */ var $_socket = null; /** * The most recent server response code. * @var int * @access private */ var $_code = -1; /** * The most recent server response arguments. * @var array * @access private */ var $_arguments = array(); /** * Stores detected features of the SMTP server. * @var array * @access private */ var $_esmtp = array(); /** * Instantiates a new Net_SMTP object, overriding any defaults * with parameters that are passed in. * * @param string The server to connect to. * @param int The port to connect to. * @param string The value to give when sending EHLO or HELO. * * @access public * @since 1.0 */ function Net_SMTP($host = null, $port = null, $localhost = null) { if (isset($host)) $this->host = $host; if (isset($port)) $this->port = $port; if (isset($localhost)) $this->localhost = $localhost; $this->_socket = new Net_Socket(); /* * Include the Auth_SASL package. If the package is not available, * we disable the authentication methods that depend upon it. */ if ((@include_once 'Auth/SASL.php') === false) { $pos = array_search('DIGEST-MD5', $this->auth_methods); unset($this->auth_methods[$pos]); $pos = array_search('CRAM-MD5', $this->auth_methods); unset($this->auth_methods[$pos]); } } /** * Set the value of the debugging flag. * * @param boolean $debug New value for the debugging flag. * * @access public * @since 1.1.0 */ function setDebug($debug) { $this->_debug = $debug; } /** * Send the given string of data to the server. * * @param string $data The string of data to send. * * @return mixed True on success or a PEAR_Error object on failure. * * @access private * @since 1.1.0 */ function _send($data) { if ($this->_debug) { echo "DEBUG: Send: $data\n"; } if (PEAR::isError($error = $this->_socket->write($data))) { return new PEAR_Error('Failed to write to socket: ' . $error->getMessage()); } return true; } /** * Send a command to the server with an optional string of arguments. * A carriage return / linefeed (CRLF) sequence will be appended to each * command string before it is sent to the SMTP server. * * @param string $command The SMTP command to send to the server. * @param string $args A string of optional arguments to append * to the command. * * @return mixed The result of the _send() call. * * @access private * @since 1.1.0 */ function _put($command, $args = '') { if (!empty($args)) { return $this->_send($command . ' ' . $args . "\r\n"); } return $this->_send($command . "\r\n"); } /** * Read a reply from the SMTP server. The reply consists of a response * code and a response message. * * @param mixed $valid The set of valid response codes. These * may be specified as an array of integer * values or as a single integer value. * * @return mixed True if the server returned a valid response code or * a PEAR_Error object is an error condition is reached. * * @access private * @since 1.1.0 * * @see getResponse */ function _parseResponse($valid) { $this->_code = -1; $this->_arguments = array(); while ($line = $this->_socket->readLine()) { if ($this->_debug) { echo "DEBUG: Recv: $line\n"; } /* If we receive an empty line, the connection has been closed. */ if (empty($line)) { $this->disconnect(); return new PEAR_Error("Connection was unexpectedly closed"); } /* Read the code and store the rest in the arguments array. */ $code = substr($line, 0, 3); $this->_arguments[] = trim(substr($line, 4)); /* Check the syntax of the response code. */ if (is_numeric($code)) { $this->_code = (int)$code; } else { $this->_code = -1; break; } /* If this is not a multiline response, we're done. */ if (substr($line, 3, 1) != '-') { break; } } /* Compare the server's response code with the valid code. */ if (is_int($valid) && ($this->_code === $valid)) { return true; } /* If we were given an array of valid response codes, check each one. */ if (is_array($valid)) { foreach ($valid as $valid_code) { if ($this->_code === $valid_code) { return true; } } } return new PEAR_Error("Invalid response code received from server"); } /** * Return a 2-tuple containing the last response from the SMTP server. * * @return array A two-element array: the first element contains the * response code as an integer and the second element * contains the response's arguments as a string. * * @access public * @since 1.1.0 */ function getResponse() { return array($this->_code, join("\n", $this->_arguments)); } /** * Attempt to connect to the SMTP server. * * @param int $timeout The timeout value (in seconds) for the * socket connection. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function connect($timeout = null) { $result = $this->_socket->connect($this->host, $this->port, false, $timeout); if (PEAR::isError($result)) { return new PEAR_Error('Failed to connect socket: ' . $result->getMessage()); } if (PEAR::isError($error = $this->_parseResponse(220))) { return $error; } if (PEAR::isError($error = $this->_negotiate())) { return $error; } return true; } /** * Attempt to disconnect from the SMTP server. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function disconnect() { if (PEAR::isError($error = $this->_put('QUIT'))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(221))) { return $error; } if (PEAR::isError($error = $this->_socket->disconnect())) { return new PEAR_Error('Failed to disconnect socket: ' . $error->getMessage()); } return true; } /** * Attempt to send the EHLO command and obtain a list of ESMTP * extensions available, and failing that just send HELO. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * * @access private * @since 1.1.0 */ function _negotiate() { if (PEAR::isError($error = $this->_put('EHLO', $this->localhost))) { return $error; } if (PEAR::isError($this->_parseResponse(250))) { /* If we receive a 503 response, we're already authenticated. */ if ($this->_code === 503) { return true; } /* If the EHLO failed, try the simpler HELO command. */ if (PEAR::isError($error = $this->_put('HELO', $this->localhost))) { return $error; } if (PEAR::isError($this->_parseResponse(250))) { return new PEAR_Error('HELO was not accepted: ', $this->_code); } return true; } foreach ($this->_arguments as $argument) { $verb = strtok($argument, ' '); $arguments = substr($argument, strlen($verb) + 1, strlen($argument) - strlen($verb) - 1); $this->_esmtp[$verb] = $arguments; } return true; } /** * Returns the name of the best authentication method that the server * has advertised. * * @return mixed Returns a string containing the name of the best * supported authentication method or a PEAR_Error object * if a failure condition is encountered. * @access private * @since 1.1.0 */ function _getBestAuthMethod() { $available_methods = explode(' ', $this->_esmtp['AUTH']); foreach ($this->auth_methods as $method) { if (in_array($method, $available_methods)) { return $method; } } return new PEAR_Error('No supported authentication methods'); } /** * Attempt to do SMTP authentication. * * @param string The userid to authenticate as. * @param string The password to authenticate with. * @param string The requested authentication method. If none is * specified, the best supported method will be used. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function auth($uid, $pwd , $method = '') { if (empty($this->_esmtp['AUTH'])) { return new PEAR_Error('SMTP server does no support authentication'); } /* * If no method has been specified, get the name of the best supported * method advertised by the SMTP server. */ if (empty($method)) { if (PEAR::isError($method = $this->_getBestAuthMethod())) { /* Return the PEAR_Error object from _getBestAuthMethod(). */ return $method; } } else { $method = strtoupper($method); if (!in_array($method, $this->auth_methods)) { return new PEAR_Error("$method is not a supported authentication method"); } } switch ($method) { case 'DIGEST-MD5': $result = $this->_authDigest_MD5($uid, $pwd); break; case 'CRAM-MD5': $result = $this->_authCRAM_MD5($uid, $pwd); break; case 'LOGIN': $result = $this->_authLogin($uid, $pwd); break; case 'PLAIN': $result = $this->_authPlain($uid, $pwd); break; default: $result = new PEAR_Error("$method is not a supported authentication method"); break; } /* If an error was encountered, return the PEAR_Error object. */ if (PEAR::isError($result)) { return $result; } /* RFC-2554 requires us to re-negotiate ESMTP after an AUTH. */ if (PEAR::isError($error = $this->_negotiate())) { return $error; } return true; } /* Authenticates the user using the DIGEST-MD5 method. * * @param string The userid to authenticate as. * @param string The password to authenticate with. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access private * @since 1.1.0 */ function _authDigest_MD5($uid, $pwd) { if (PEAR::isError($error = $this->_put('AUTH', 'DIGEST-MD5'))) { return $error; } /* 334: Continue authentication request */ if (PEAR::isError($error = $this->_parseResponse(334))) { /* 503: Error: already authenticated */ if ($this->_code === 503) { return true; } return $error; } $challenge = base64_decode($this->_arguments[0]); $digest = &Auth_SASL::factory('digestmd5'); $auth_str = base64_encode($digest->getResponse($uid, $pwd, $challenge, $this->host, "smtp")); if (PEAR::isError($error = $this->_put($auth_str))) { return $error; } /* 334: Continue authentication request */ if (PEAR::isError($error = $this->_parseResponse(334))) { return $error; } /* * We don't use the protocol's third step because SMTP doesn't allow * subsequent authentication, so we just silently ignore it. */ if (PEAR::isError($error = $this->_put(' '))) { return $error; } /* 235: Authentication successful */ if (PEAR::isError($error = $this->_parseResponse(235))) { return $error; } } /* Authenticates the user using the CRAM-MD5 method. * * @param string The userid to authenticate as. * @param string The password to authenticate with. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access private * @since 1.1.0 */ function _authCRAM_MD5($uid, $pwd) { if (PEAR::isError($error = $this->_put('AUTH', 'CRAM-MD5'))) { return $error; } /* 334: Continue authentication request */ if (PEAR::isError($error = $this->_parseResponse(334))) { /* 503: Error: already authenticated */ if ($this->_code === 503) { return true; } return $error; } $challenge = base64_decode($this->_arguments[0]); $cram = &Auth_SASL::factory('crammd5'); $auth_str = base64_encode($cram->getResponse($uid, $pwd, $challenge)); if (PEAR::isError($error = $this->_put($auth_str))) { return $error; } /* 235: Authentication successful */ if (PEAR::isError($error = $this->_parseResponse(235))) { return $error; } } /** * Authenticates the user using the LOGIN method. * * @param string The userid to authenticate as. * @param string The password to authenticate with. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access private * @since 1.1.0 */ function _authLogin($uid, $pwd) { if (PEAR::isError($error = $this->_put('AUTH', 'LOGIN'))) { return $error; } /* 334: Continue authentication request */ if (PEAR::isError($error = $this->_parseResponse(334))) { /* 503: Error: already authenticated */ if ($this->_code === 503) { return true; } return $error; } if (PEAR::isError($error = $this->_put(base64_encode($uid)))) { return $error; } /* 334: Continue authentication request */ if (PEAR::isError($error = $this->_parseResponse(334))) { return $error; } if (PEAR::isError($error = $this->_put(base64_encode($pwd)))) { return $error; } /* 235: Authentication successful */ if (PEAR::isError($error = $this->_parseResponse(235))) { return $error; } return true; } /** * Authenticates the user using the PLAIN method. * * @param string The userid to authenticate as. * @param string The password to authenticate with. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access private * @since 1.1.0 */ function _authPlain($uid, $pwd) { if (PEAR::isError($error = $this->_put('AUTH', 'PLAIN'))) { return $error; } /* 334: Continue authentication request */ if (PEAR::isError($error = $this->_parseResponse(334))) { /* 503: Error: already authenticated */ if ($this->_code === 503) { return true; } return $error; } $auth_str = base64_encode(chr(0) . $uid . chr(0) . $pwd); if (PEAR::isError($error = $this->_put($auth_str))) { return $error; } /* 235: Authentication successful */ if (PEAR::isError($error = $this->_parseResponse(235))) { return $error; } return true; } /** * Send the HELO command. * * @param string The domain name to say we are. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function helo($domain) { if (PEAR::isError($error = $this->_put('HELO', $domain))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(250))) { return $error; } return true; } /** * Send the MAIL FROM: command. * * @param string The sender (reverse path) to set. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function mailFrom($sender) { if (PEAR::isError($error = $this->_put('MAIL', "FROM:<$sender>"))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(250))) { return $error; } return true; } /** * Send the RCPT TO: command. * * @param string The recipient (forward path) to add. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function rcptTo($recipient) { if (PEAR::isError($error = $this->_put('RCPT', "TO:<$recipient>"))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(array(250, 251)))) { return $error; } return true; } /** * Quote the data so that it meets SMTP standards. * * This is provided as a separate public function to facilitate easier * overloading for the cases where it is desirable to customize the * quoting behavior. * * @param string The message text to quote. The string must be passed * by reference, and the text will be modified in place. * * @access public * @since 1.2 */ function quotedata(&$data) { /* * Change Unix (\n) and Mac (\r) linefeeds into Internet-standard CRLF * (\r\n) linefeeds. */ $data = preg_replace("/([^\r]{1})\n/", "\\1\r\n", $data); $data = preg_replace("/\n\n/", "\n\r\n", $data); /* * Because a single leading period (.) signifies an end to the data, * legitimate leading periods need to be "doubled" (e.g. '..'). */ $data = preg_replace("/\n\./", "\n..", $data); } /** * Send the DATA command. * * @param string The message body to send. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function data($data) { /* * RFC 1870, section 3, subsection 3 states "a value of zero indicates * that no fixed maximum message size is in force". Furthermore, it * says that if "the parameter is omitted no information is conveyed * about the server's fixed maximum message size". */ if (isset($this->_esmtp['SIZE']) && ($this->_esmtp['SIZE'] > 0)) { if (strlen($data) >= $this->_esmtp['SIZE']) { $this->disconnect(); return new PEAR_Error('Message size excedes the server limit'); } } /* Quote the data based on the SMTP standards. */ $this->quotedata($data); if (PEAR::isError($error = $this->_put('DATA'))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(354))) { return $error; } if (PEAR::isError($this->_send($data . "\r\n.\r\n"))) { return new PEAR_Error('write to socket failed'); } if (PEAR::isError($error = $this->_parseResponse(250))) { return $error; } return true; } /** * Send the SEND FROM: command. * * @param string The reverse path to send. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function send_from($path) { if (PEAR::isError($error = $this->_put('SEND', "FROM:<$path>"))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(250))) { return $error; } return true; } /** * Send the SOML FROM: command. * * @param string The reverse path to send. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function soml_from($path) { if (PEAR::isError($error = $this->_put('SOML', "FROM:<$path>"))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(250))) { return $error; } return true; } /** * Send the SAML FROM: command. * * @param string The reverse path to send. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function saml_from($path) { if (PEAR::isError($error = $this->_put('SAML', "FROM:<$path>"))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(250))) { return $error; } return true; } /** * Send the RSET command. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function rset() { if (PEAR::isError($error = $this->_put('RSET'))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(250))) { return $error; } return true; } /** * Send the VRFY command. * * @param string The string to verify * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function vrfy($string) { /* Note: 251 is also a valid response code */ if (PEAR::isError($error = $this->_put('VRFY', $string))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(250))) { return $error; } return true; } /** * Send the NOOP command. * * @return mixed Returns a PEAR_Error with an error message on any * kind of failure, or true on success. * @access public * @since 1.0 */ function noop() { if (PEAR::isError($error = $this->_put('NOOP'))) { return $error; } if (PEAR::isError($error = $this->_parseResponse(250))) { return $error; } return true; } /** * Backwards-compatibility method. identifySender()'s functionality is * now handled internally. * * @return boolean This method always return true. * * @access public * @since 1.0 */ function identifySender() { return true; } } ?>
« previous php.pear.cvs (#11125) next »