chagenbu Thu Feb 22 08:01:15 2001 EDT Removed files: /php4/pear/Mail SMTP.php Sendmail.php Modified files: /php4/pear Mail.php Makefile.in /php4/pear/Mail sendmail.php smtp.php Log: factory-generated classes have lowercase subclass names by our (newly revised) standards.
Index: php4/pear/Mail.php diff -u php4/pear/Mail.php:1.9 php4/pear/Mail.php:1.10 --- php4/pear/Mail.php:1.9 Wed Feb 7 12:22:59 2001 +++ php4/pear/Mail.php Thu Feb 22 08:01:14 2001 @@ -35,15 +35,9 @@ */ function factory($driver, $params = array()) { + $driver = strtolower($driver); if (@include_once 'Mail/' . $driver . '.php') { $class = 'Mail_' . $driver; - } elseif (@include_once 'Mail/' . strtoupper($driver) . '.php') { - $class = 'Mail_' . strtoupper($driver); - } elseif (@include_once 'Mail/' . ucfirst($driver) . '.php') { - $class = 'Mail_' . ucfirst($driver); - } - - if (isset($class)) { return new $class($params); } else { return new PEAR_Error('Unable to find class for driver ' . $driver); Index: php4/pear/Makefile.in diff -u php4/pear/Makefile.in:1.67 php4/pear/Makefile.in:1.68 --- php4/pear/Makefile.in:1.67 Wed Feb 7 12:22:59 2001 +++ php4/pear/Makefile.in Thu Feb 22 08:01:14 2001 @@ -69,8 +69,8 @@ Log/syslog.php \ Mail.php \ Mail/RFC822.php \ - Mail/Sendmail.php \ - Mail/SMTP.php \ + Mail/sendmail.php \ + Mail/smtp.php \ Math/Fraction.php \ Math/Util.php \ Net/Curl.php \ Index: php4/pear/Mail/sendmail.php diff -u /dev/null php4/pear/Mail/sendmail.php:1.5 --- /dev/null Thu Feb 22 08:01:15 2001 +++ php4/pear/Mail/sendmail.php Thu Feb 22 08:01:15 2001 @@ -0,0 +1,111 @@ +<?php +// +// +----------------------------------------------------------------------+ +// | PHP version 4.0 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2001 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 | +// | [EMAIL PROTECTED] so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Chuck Hagenbuch <[EMAIL PROTECTED]> | +// +----------------------------------------------------------------------+ + +require_once 'Mail.php'; + +/** + * Sendmail implementation of the PEAR Mail:: interface. + */ +class Mail_sendmail extends Mail { + + /** + * The location of the sendmail binary on the filesystem. + * @var string + */ + var $sendmail_path = '/usr/sbin/sendmail'; + + /** + * 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'. + * + * If a parameter is present in the $params array, it replaces the + * default. + * + * @param array Hash containing any parameters different from the + * defaults. + */ + function Mail_sendmail($params) + { + if (isset($params['sendmail_path'])) $this->sendmail_path = +$params['sendmail_path']; + } + + /** + * Implements Mail::send() function using the sendmail + * command-line binary. + * + * @param mixed 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 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 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 . " -i -f$from -- $recipients", 'w'); + fputs($mail, $text_headers); + fputs($mail, "\n"); // 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'); + } + + // Return. + if ($result != 0) { + return new PEAR_Error('sendmail returned error code ' . $result); + } + + return true; + } + +} +?> Index: php4/pear/Mail/smtp.php diff -u /dev/null php4/pear/Mail/smtp.php:1.5 --- /dev/null Thu Feb 22 08:01:15 2001 +++ php4/pear/Mail/smtp.php Thu Feb 22 08:01:15 2001 @@ -0,0 +1,138 @@ +<?php +// +// +----------------------------------------------------------------------+ +// | PHP version 4.0 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2001 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 | +// | [EMAIL PROTECTED] so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Chuck Hagenbuch <[EMAIL PROTECTED]> | +// +----------------------------------------------------------------------+ + +require_once 'Mail.php'; + +/** + * SMTP implementation of the PEAR Mail:: interface. Requires the PEAR + * Net_SMTP:: class. + */ +class Mail_smtp extends Mail { + + /** + * The SMTP host to connect to. + * @var string + */ + var $host = 'localhost'; + + /** + * The port the SMTP server is on. + * @var int + */ + var $port = 25; + + /** + * Whether or not to attempt to authenticate to the SMTP server. + * @var boolean + */ + 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 Whether or not to use SMTP auth. Defaults to false. + * 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. + */ + 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 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 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 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 (!$smtp->connect()) { return new PEAR_Error('unable to connect to smtp +server ' . $this->host . ':' . $this->port); } + + if ($this->auth) { + if (!$smtp->auth($this->username, $this->password)) { return new +PEAR_Error('unable to authenticate to smtp server'); } + if (!$smtp->identifySender()) { return new PEAR_Error('unable to identify +smtp server'); } + } + + list($from, $text_headers) = $this->prepareHeaders($headers); + if (!isset($from)) { + return new PEAR_Error('No from address given'); + } + + if (!($smtp->mailFrom($from))) { return new PEAR_Error('unable to set sender +to [' . $from . ']'); } + + $recipients = $this->parseRecipients($recipients); + foreach($recipients as $recipient) { + if (!$smtp->rcptTo($recipient)) { return new PEAR_Error('unable to add +recipient [' . $recipient . ']'); } + } + + if (!$smtp->data($text_headers . "\n" . $body)) { return new +PEAR_Error('unable to send data'); } + + $smtp->disconnect(); + return true; + } + +} +?>
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]