Commit version 24.12.13800
This commit is contained in:
@ -1,267 +1,267 @@
|
||||
<?php
|
||||
/**
|
||||
* PEAR's Mail:: interface.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 1997-2017, Chuck Hagenbuch & 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:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may 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
|
||||
* HOLDER 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.
|
||||
*
|
||||
* @category Mail
|
||||
* @package Mail
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
* @copyright 1997-2017 Chuck Hagenbuch
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause New BSD License
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/Mail/
|
||||
*/
|
||||
|
||||
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.
|
||||
*
|
||||
* @version $Revision$
|
||||
* @package Mail
|
||||
*/
|
||||
class Mail
|
||||
{
|
||||
/**
|
||||
* Line terminator used for separating header lines.
|
||||
* @var string
|
||||
*/
|
||||
public $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
|
||||
*/
|
||||
public static function factory($driver, $params = array())
|
||||
{
|
||||
$driver = strtolower($driver);
|
||||
@include_once 'Mail/' . $driver . '.php';
|
||||
$class = 'Mail_' . $driver;
|
||||
if (class_exists($class)) {
|
||||
$mailer = new $class($params);
|
||||
return $mailer;
|
||||
} 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.
|
||||
*
|
||||
* @deprecated use Mail_mail::send instead
|
||||
*/
|
||||
public function send($recipients, $headers, $body)
|
||||
{
|
||||
if (!is_array($headers)) {
|
||||
return PEAR::raiseError('$headers must be an array');
|
||||
}
|
||||
|
||||
$result = $this->_sanitizeHeaders($headers);
|
||||
if (is_a($result, 'PEAR_Error')) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize an array of mail headers by removing any additional header
|
||||
* strings present in a legitimate header's value. The goal of this
|
||||
* filter is to prevent mail injection attacks.
|
||||
*
|
||||
* @param array $headers The associative array of headers to sanitize.
|
||||
*/
|
||||
protected function _sanitizeHeaders(&$headers)
|
||||
{
|
||||
foreach ($headers as $key => $value) {
|
||||
$headers[$key] =
|
||||
preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i',
|
||||
null, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
protected function prepareHeaders($headers)
|
||||
{
|
||||
$lines = array();
|
||||
$from = null;
|
||||
|
||||
foreach ($headers as $key => $value) {
|
||||
if (strcasecmp($key, 'From') === 0) {
|
||||
include_once 'Mail/RFC822.php';
|
||||
$parser = new Mail_RFC822();
|
||||
$addresses = $parser->parseAddressList($value, 'localhost', false);
|
||||
if (is_a($addresses, 'PEAR_Error')) {
|
||||
return $addresses;
|
||||
}
|
||||
|
||||
$from = $addresses[0]->mailbox . '@' . $addresses[0]->host;
|
||||
|
||||
// Reject envelope From: addresses with spaces.
|
||||
if (strstr($from, ' ')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lines[] = $key . ': ' . $value;
|
||||
} elseif (strcasecmp($key, 'Received') === 0) {
|
||||
$received = array();
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $line) {
|
||||
$received[] = $key . ': ' . $line;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$received[] = $key . ': ' . $value;
|
||||
}
|
||||
// Put Received: headers at the top. Spam detectors often
|
||||
// flag messages with Received: headers after the Subject:
|
||||
// as spam.
|
||||
$lines = array_merge($received, $lines);
|
||||
} else {
|
||||
// If $value is an array (i.e., a list of addresses), convert
|
||||
// it to a comma-delimited string of its elements (addresses).
|
||||
if (is_array($value)) {
|
||||
$value = implode(', ', $value);
|
||||
}
|
||||
$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 mixed An array of forward paths (bare addresses) or a PEAR_Error
|
||||
* object if the address list could not be parsed.
|
||||
*/
|
||||
protected 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.
|
||||
$Mail_RFC822 = new Mail_RFC822();
|
||||
$addresses = $Mail_RFC822->parseAddressList($recipients, 'localhost', false);
|
||||
|
||||
// If parseAddressList() returned a PEAR_Error object, just return it.
|
||||
if (is_a($addresses, 'PEAR_Error')) {
|
||||
return $addresses;
|
||||
}
|
||||
|
||||
$recipients = array();
|
||||
if (is_array($addresses)) {
|
||||
foreach ($addresses as $ob) {
|
||||
$recipients[] = $ob->mailbox . '@' . $ob->host;
|
||||
}
|
||||
}
|
||||
|
||||
return $recipients;
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* PEAR's Mail:: interface.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 1997-2017, Chuck Hagenbuch & 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:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may 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
|
||||
* HOLDER 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.
|
||||
*
|
||||
* @category Mail
|
||||
* @package Mail
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
* @copyright 1997-2017 Chuck Hagenbuch
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause New BSD License
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/Mail/
|
||||
*/
|
||||
|
||||
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.
|
||||
*
|
||||
* @version $Revision$
|
||||
* @package Mail
|
||||
*/
|
||||
class Mail
|
||||
{
|
||||
/**
|
||||
* Line terminator used for separating header lines.
|
||||
* @var string
|
||||
*/
|
||||
public $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
|
||||
*/
|
||||
public static function factory($driver, $params = array())
|
||||
{
|
||||
$driver = strtolower($driver);
|
||||
@include_once 'Mail/' . $driver . '.php';
|
||||
$class = 'Mail_' . $driver;
|
||||
if (class_exists($class)) {
|
||||
$mailer = new $class($params);
|
||||
return $mailer;
|
||||
} 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.
|
||||
*
|
||||
* @deprecated use Mail_mail::send instead
|
||||
*/
|
||||
public function send($recipients, $headers, $body)
|
||||
{
|
||||
if (!is_array($headers)) {
|
||||
return PEAR::raiseError('$headers must be an array');
|
||||
}
|
||||
|
||||
$result = $this->_sanitizeHeaders($headers);
|
||||
if (is_a($result, 'PEAR_Error')) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize an array of mail headers by removing any additional header
|
||||
* strings present in a legitimate header's value. The goal of this
|
||||
* filter is to prevent mail injection attacks.
|
||||
*
|
||||
* @param array $headers The associative array of headers to sanitize.
|
||||
*/
|
||||
protected function _sanitizeHeaders(&$headers)
|
||||
{
|
||||
foreach ($headers as $key => $value) {
|
||||
$headers[$key] =
|
||||
preg_replace('=((<CR>|<LF>|0x0A/%0A|0x0D/%0D|\\n|\\r)\S).*=i',
|
||||
'', $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
protected function prepareHeaders($headers)
|
||||
{
|
||||
$lines = array();
|
||||
$from = null;
|
||||
|
||||
foreach ($headers as $key => $value) {
|
||||
if (strcasecmp($key, 'From') === 0) {
|
||||
include_once 'Mail/RFC822.php';
|
||||
$parser = new Mail_RFC822();
|
||||
$addresses = $parser->parseAddressList($value, 'localhost', false);
|
||||
if (is_a($addresses, 'PEAR_Error')) {
|
||||
return $addresses;
|
||||
}
|
||||
|
||||
$from = $addresses[0]->mailbox . '@' . $addresses[0]->host;
|
||||
|
||||
// Reject envelope From: addresses with spaces.
|
||||
if (strstr($from, ' ')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$lines[] = $key . ': ' . $value;
|
||||
} elseif (strcasecmp($key, 'Received') === 0) {
|
||||
$received = array();
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $line) {
|
||||
$received[] = $key . ': ' . $line;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$received[] = $key . ': ' . $value;
|
||||
}
|
||||
// Put Received: headers at the top. Spam detectors often
|
||||
// flag messages with Received: headers after the Subject:
|
||||
// as spam.
|
||||
$lines = array_merge($received, $lines);
|
||||
} else {
|
||||
// If $value is an array (i.e., a list of addresses), convert
|
||||
// it to a comma-delimited string of its elements (addresses).
|
||||
if (is_array($value)) {
|
||||
$value = implode(', ', $value);
|
||||
}
|
||||
$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 mixed An array of forward paths (bare addresses) or a PEAR_Error
|
||||
* object if the address list could not be parsed.
|
||||
*/
|
||||
protected 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.
|
||||
$Mail_RFC822 = new Mail_RFC822();
|
||||
$addresses = $Mail_RFC822->parseAddressList($recipients, 'localhost', false);
|
||||
|
||||
// If parseAddressList() returned a PEAR_Error object, just return it.
|
||||
if (is_a($addresses, 'PEAR_Error')) {
|
||||
return $addresses;
|
||||
}
|
||||
|
||||
$recipients = array();
|
||||
if (is_array($addresses)) {
|
||||
foreach ($addresses as $ob) {
|
||||
$recipients[] = $ob->mailbox . '@' . $ob->host;
|
||||
}
|
||||
}
|
||||
|
||||
return $recipients;
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,168 +1,158 @@
|
||||
<?php
|
||||
/**
|
||||
* internal PHP-mail() implementation of the PEAR Mail:: interface.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2010-2017, Chuck Hagenbuch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may 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
|
||||
* HOLDER 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.
|
||||
*
|
||||
* @category Mail
|
||||
* @package Mail
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
* @copyright 2010-2017 Chuck Hagenbuch
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause New BSD License
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/Mail/
|
||||
*/
|
||||
|
||||
/**
|
||||
* internal PHP-mail() implementation of the PEAR Mail:: interface.
|
||||
* @package Mail
|
||||
* @version $Revision$
|
||||
*/
|
||||
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 array $params Extra arguments for the mail() function.
|
||||
*/
|
||||
public function __construct($params = null)
|
||||
{
|
||||
// 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. */
|
||||
if (defined('PHP_EOL')) {
|
||||
$this->sep = PHP_EOL;
|
||||
} else {
|
||||
$this->sep = (strpos(PHP_OS, 'WIN') === false) ? "\n" : "\r\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.
|
||||
*/
|
||||
public function send($recipients, $headers, $body)
|
||||
{
|
||||
if (!is_array($headers)) {
|
||||
return PEAR::raiseError('$headers must be an array');
|
||||
}
|
||||
|
||||
$result = $this->_sanitizeHeaders($headers);
|
||||
if (is_a($result, 'PEAR_Error')) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 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']);
|
||||
}
|
||||
|
||||
// Also remove the To: header. The mail() function will add its own
|
||||
// To: header based on the contents of $recipients.
|
||||
unset($headers['To']);
|
||||
|
||||
// Flatten the headers out.
|
||||
$headerElements = $this->prepareHeaders($headers);
|
||||
if (is_a($headerElements, 'PEAR_Error')) {
|
||||
return $headerElements;
|
||||
}
|
||||
list(, $text_headers) = $headerElements;
|
||||
|
||||
// We only use mail()'s optional fifth parameter if the additional
|
||||
// parameters have been provided and we're not running in safe mode.
|
||||
if (empty($this->_params)) {
|
||||
$result = mail($recipients, $subject, $body, $text_headers);
|
||||
} else {
|
||||
$result = mail($recipients, $subject, $body, $text_headers,
|
||||
$this->_params);
|
||||
}
|
||||
|
||||
// If the mail() function returned failure, we need to create a
|
||||
// PEAR_Error object and return it instead of the boolean result.
|
||||
if ($result === false) {
|
||||
$result = PEAR::raiseError('mail() returned failure');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
/**
|
||||
* internal PHP-mail() implementation of the PEAR Mail:: interface.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2010-2017, Chuck Hagenbuch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. 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.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may 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
|
||||
* HOLDER 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.
|
||||
*
|
||||
* @category Mail
|
||||
* @package Mail
|
||||
* @author Chuck Hagenbuch <chuck@horde.org>
|
||||
* @copyright 2010-2017 Chuck Hagenbuch
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause New BSD License
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/Mail/
|
||||
*/
|
||||
|
||||
/**
|
||||
* internal PHP-mail() implementation of the PEAR Mail:: interface.
|
||||
* @package Mail
|
||||
* @version $Revision$
|
||||
*/
|
||||
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 array $params Extra arguments for the mail() function.
|
||||
*/
|
||||
public function __construct($params = null)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public function send($recipients, $headers, $body)
|
||||
{
|
||||
if (!is_array($headers)) {
|
||||
return PEAR::raiseError('$headers must be an array');
|
||||
}
|
||||
|
||||
$result = $this->_sanitizeHeaders($headers);
|
||||
if (is_a($result, 'PEAR_Error')) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 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']);
|
||||
}
|
||||
|
||||
// Also remove the To: header. The mail() function will add its own
|
||||
// To: header based on the contents of $recipients.
|
||||
unset($headers['To']);
|
||||
|
||||
// Flatten the headers out.
|
||||
$headerElements = $this->prepareHeaders($headers);
|
||||
if (is_a($headerElements, 'PEAR_Error')) {
|
||||
return $headerElements;
|
||||
}
|
||||
list(, $text_headers) = $headerElements;
|
||||
|
||||
// We only use mail()'s optional fifth parameter if the additional
|
||||
// parameters have been provided and we're not running in safe mode.
|
||||
if (empty($this->_params) || ini_get('safe_mode')) {
|
||||
$result = mail($recipients, $subject, $body, $text_headers);
|
||||
} else {
|
||||
$result = mail($recipients, $subject, $body, $text_headers,
|
||||
$this->_params);
|
||||
}
|
||||
|
||||
// If the mail() function returned failure, we need to create a
|
||||
// PEAR_Error object and return it instead of the boolean result.
|
||||
if ($result === false) {
|
||||
$result = PEAR::raiseError('mail() returned failure');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -483,6 +483,9 @@ class Mail_mime
|
||||
protected function file2str($file_name)
|
||||
{
|
||||
// Check state of file and raise an error properly
|
||||
if (!is_string($file_name)) {
|
||||
return self::raiseError('Invalid or empty file name');
|
||||
}
|
||||
if (!file_exists($file_name)) {
|
||||
return self::raiseError('File not found: ' . $file_name);
|
||||
}
|
||||
@ -514,7 +517,7 @@ class Mail_mime
|
||||
* @param mixed $obj The object to add the part to, or
|
||||
* anything else if a new object is to be created.
|
||||
*
|
||||
* @return object The text mimePart object
|
||||
* @return Mail_mimePart The text mimePart object
|
||||
*/
|
||||
protected function addTextPart($obj = null)
|
||||
{
|
||||
@ -528,7 +531,7 @@ class Mail_mime
|
||||
* @param mixed $obj The object to add the part to, or
|
||||
* anything else if a new object is to be created.
|
||||
*
|
||||
* @return object The html mimePart object
|
||||
* @return Mail_mimePart The html mimePart object
|
||||
*/
|
||||
protected function addHtmlPart($obj = null)
|
||||
{
|
||||
@ -542,7 +545,7 @@ class Mail_mime
|
||||
* @param mixed $obj The object to add the part to, or
|
||||
* anything else if a new object is to be created.
|
||||
*
|
||||
* @return object The text mimePart object
|
||||
* @return Mail_mimePart The text mimePart object
|
||||
*/
|
||||
protected function addCalendarPart($obj = null)
|
||||
{
|
||||
@ -558,7 +561,7 @@ class Mail_mime
|
||||
*
|
||||
* @param array $params Additional part parameters
|
||||
*
|
||||
* @return object The multipart/mixed mimePart object
|
||||
* @return Mail_mimePart The multipart/mixed mimePart object
|
||||
*/
|
||||
protected function addMixedPart($params = array())
|
||||
{
|
||||
@ -577,7 +580,7 @@ class Mail_mime
|
||||
* @param mixed $obj The object to add the part to, or
|
||||
* anything else if a new object is to be created.
|
||||
*
|
||||
* @return object The multipart/mixed mimePart object
|
||||
* @return Mail_mimePart The multipart/mixed mimePart object
|
||||
*/
|
||||
protected function addAlternativePart($obj = null)
|
||||
{
|
||||
@ -601,7 +604,7 @@ class Mail_mime
|
||||
* @param mixed $obj The object to add the part to, or
|
||||
* anything else if a new object is to be created
|
||||
*
|
||||
* @return object The multipart/mixed mimePart object
|
||||
* @return Mail_mimePart The multipart/mixed mimePart object
|
||||
*/
|
||||
protected function addRelatedPart($obj = null)
|
||||
{
|
||||
@ -624,7 +627,7 @@ class Mail_mime
|
||||
* @param object $obj The mimePart to add the image to
|
||||
* @param array $value The image information
|
||||
*
|
||||
* @return object The image mimePart object
|
||||
* @return Mail_mimePart The image mimePart object
|
||||
*/
|
||||
protected function addHtmlImagePart($obj, $value)
|
||||
{
|
||||
@ -653,7 +656,7 @@ class Mail_mime
|
||||
* @param object $obj The mimePart to add the image to
|
||||
* @param mixed $value The attachment information array or Mail_mimePart object
|
||||
*
|
||||
* @return object The image mimePart object
|
||||
* @return Mail_mimePart The image mimePart object
|
||||
*/
|
||||
protected function addAttachmentPart($obj, $value)
|
||||
{
|
||||
@ -844,12 +847,12 @@ class Mail_mime
|
||||
* Builds the multipart message from the list ($this->parts) and
|
||||
* returns the mime content.
|
||||
*
|
||||
* @param array $params Build parameters that change the way the email
|
||||
* is built. Should be associative. See $_build_params.
|
||||
* @param mixed $filename Output filename or file pointer where to save
|
||||
* the message instead of returning it
|
||||
* @param boolean $skip_head True if you want to return/save only the message
|
||||
* without headers
|
||||
* @param array $params Build parameters that change the way the email
|
||||
* is built. Should be associative. See $_build_params.
|
||||
* @param mixed $filename Output filename or file pointer where to save
|
||||
* the message instead of returning it
|
||||
* @param bool $skip_head True if you want to return/save only the message
|
||||
* without headers
|
||||
*
|
||||
* @return mixed The MIME message content string, null or PEAR error object
|
||||
*/
|
||||
@ -975,9 +978,9 @@ class Mail_mime
|
||||
* part when no parent_part is
|
||||
* received.
|
||||
*
|
||||
* @return null|object The main part built inside the method. It will be an
|
||||
* alternative part or text, html, or calendar part.
|
||||
* Null if no body texts are found.
|
||||
* @return null|Mail_mimePart The main part built inside the method. It will be an
|
||||
* alternative part or text, html, or calendar part.
|
||||
* Null if no body texts are found.
|
||||
*/
|
||||
protected function buildAlternativeParts($parent_part, $mixed_params = null)
|
||||
{
|
||||
@ -1540,7 +1543,7 @@ class Mail_mime
|
||||
* @param string $ctype Part content type
|
||||
* @param string $type Internal part type
|
||||
*
|
||||
* @return object The mimePart object
|
||||
* @return Mail_mimePart The mimePart object
|
||||
*/
|
||||
protected function addBodyPart($obj, $body, $ctype, $type)
|
||||
{
|
||||
|
@ -302,11 +302,11 @@ class Mail_mimePart
|
||||
*
|
||||
* @param string $boundary Pre-defined boundary string
|
||||
*
|
||||
* @return An associative array containing two elements,
|
||||
* body and headers. The headers element is itself
|
||||
* an indexed array. On error returns PEAR error object.
|
||||
* @return array An associative array containing two elements,
|
||||
* body and headers. The headers element is itself
|
||||
* an indexed array. On error returns PEAR error object.
|
||||
*/
|
||||
public function encode($boundary=null)
|
||||
public function encode($boundary = null)
|
||||
{
|
||||
$encoded =& $this->encoded;
|
||||
|
||||
@ -365,10 +365,10 @@ class Mail_mimePart
|
||||
* Encodes and saves the email into file or stream.
|
||||
* Data will be appended to the file/stream.
|
||||
*
|
||||
* @param mixed $filename Existing file location
|
||||
* or file pointer resource
|
||||
* @param string $boundary Pre-defined boundary string
|
||||
* @param boolean $skip_head True if you don't want to save headers
|
||||
* @param mixed $filename Existing file location
|
||||
* or file pointer resource
|
||||
* @param string $boundary Pre-defined boundary string
|
||||
* @param bool $skip_head True if you don't want to save headers
|
||||
*
|
||||
* @return array An associative array containing message headers
|
||||
* or PEAR error object
|
||||
@ -411,9 +411,9 @@ class Mail_mimePart
|
||||
/**
|
||||
* Encodes given email part into file
|
||||
*
|
||||
* @param string $fh Output file handle
|
||||
* @param string $boundary Pre-defined boundary string
|
||||
* @param boolean $skip_head True if you don't want to save headers
|
||||
* @param string $fh Output file handle
|
||||
* @param string $boundary Pre-defined boundary string
|
||||
* @param bool $skip_head True if you don't want to save headers
|
||||
*
|
||||
* @return array True on sucess or PEAR error object
|
||||
*/
|
||||
|
Reference in New Issue
Block a user