diff options
Diffstat (limited to 'libs/Zend/Mail.php')
-rw-r--r-- | libs/Zend/Mail.php | 356 |
1 files changed, 75 insertions, 281 deletions
diff --git a/libs/Zend/Mail.php b/libs/Zend/Mail.php index 81d1b5051d..ca3641ea81 100644 --- a/libs/Zend/Mail.php +++ b/libs/Zend/Mail.php @@ -14,31 +14,31 @@ * * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Mail.php 20783 2010-01-31 08:06:30Z yoshida@zend.co.jp $ + * @version $Id: Mail.php 16207 2009-06-21 19:17:51Z thomas $ */ /** * @see Zend_Mail_Transport_Abstract */ -// require_once 'Zend/Mail/Transport/Abstract.php'; +require_once 'Zend/Mail/Transport/Abstract.php'; /** * @see Zend_Mime */ -// require_once 'Zend/Mime.php'; +require_once 'Zend/Mime.php'; /** * @see Zend_Mime_Message */ -// require_once 'Zend/Mime/Message.php'; +require_once 'Zend/Mime/Message.php'; /** * @see Zend_Mime_Part */ -// require_once 'Zend/Mime/Part.php'; +require_once 'Zend/Mime/Part.php'; /** @@ -46,7 +46,7 @@ * * @category Zend * @package Zend_Mail - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Mail extends Zend_Mime_Message @@ -62,18 +62,6 @@ class Zend_Mail extends Zend_Mime_Message protected static $_defaultTransport = null; /** - * @var array - * @static - */ - protected static $_defaultFrom; - - /** - * @var array - * @static - */ - protected static $_defaultReplyTo; - - /** * Mail character set * @var string */ @@ -110,12 +98,6 @@ class Zend_Mail extends Zend_Mime_Message protected $_recipients = array(); /** - * Reply-To header - * @var string - */ - protected $_replyTo = null; - - /** * Return-Path header * @var string */ @@ -186,26 +168,6 @@ class Zend_Mail extends Zend_Mime_Message } /** - * Gets the default mail transport for all following uses of - * unittests - * - * @todo Allow passing a string to indicate the transport to load - * @todo Allow passing in optional options for the transport to load - */ - public static function getDefaultTransport() - { - return self::$_defaultTransport; - } - - /** - * Clear the default transport property - */ - public static function clearDefaultTransport() - { - self::$_defaultTransport = null; - } - - /** * Public constructor * * @param string $charset @@ -245,7 +207,7 @@ class Zend_Mail extends Zend_Mime_Message /** * @see Zend_Mail_Exception */ - // require_once 'Zend/Mail/Exception.php'; + require_once 'Zend/Mail/Exception.php'; throw new Zend_Mail_Exception('Invalid content type "' . $type . '"'); } @@ -339,7 +301,7 @@ class Zend_Mail extends Zend_Mime_Message /** * @see Zend_Mail_Exception */ - // require_once 'Zend/Mail/Exception.php'; + require_once 'Zend/Mail/Exception.php'; throw new Zend_Mail_Exception('Invalid encoding "' . $encoding . '"'); } $this->_headerEncoding = $encoding; @@ -496,7 +458,7 @@ class Zend_Mail extends Zend_Mime_Message */ protected function _encodeHeader($value) { - if (Zend_Mime::isPrintable($value) === false) { + if (Zend_Mime::isPrintable($value) === false) { if ($this->getHeaderEncoding() === Zend_Mime::ENCODING_QUOTEDPRINTABLE) { $value = Zend_Mime::encodeQuotedPrintableHeader($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND); } else { @@ -560,62 +522,41 @@ class Zend_Mail extends Zend_Mime_Message } /** - * Adds To-header and recipient, $email can be an array, or a single string address + * Adds To-header and recipient * - * @param string|array $email + * @param string $email * @param string $name * @return Zend_Mail Provides fluent interface */ public function addTo($email, $name='') { - if (!is_array($email)) { - $email = array($name => $email); - } - - foreach ($email as $n => $recipient) { - $this->_addRecipientAndHeader('To', $recipient, is_int($n) ? '' : $n); - $this->_to[] = $recipient; - } - + $this->_addRecipientAndHeader('To', $email, $name); + $this->_to[] = $email; return $this; } /** - * Adds Cc-header and recipient, $email can be an array, or a single string address + * Adds Cc-header and recipient * - * @param string|array $email + * @param string $email * @param string $name * @return Zend_Mail Provides fluent interface */ public function addCc($email, $name='') { - if (!is_array($email)) { - $email = array($name => $email); - } - - foreach ($email as $n => $recipient) { - $this->_addRecipientAndHeader('Cc', $recipient, is_int($n) ? '' : $n); - } - + $this->_addRecipientAndHeader('Cc', $email, $name); return $this; } /** - * Adds Bcc recipient, $email can be an array, or a single string address + * Adds Bcc recipient * - * @param string|array $email + * @param string $email * @return Zend_Mail Provides fluent interface */ public function addBcc($email) { - if (!is_array($email)) { - $email = array($email); - } - - foreach ($email as $recipient) { - $this->_addRecipientAndHeader('Bcc', $recipient, ''); - } - + $this->_addRecipientAndHeader('Bcc', $email, ''); return $this; } @@ -656,19 +597,18 @@ class Zend_Mail extends Zend_Mime_Message */ public function setFrom($email, $name = null) { - if (null !== $this->_from) { + if ($this->_from === null) { + $email = $this->_filterEmail($email); + $name = $this->_filterName($name); + $this->_from = $email; + $this->_storeHeader('From', $this->_formatAddress($email, $name), true); + } else { /** * @see Zend_Mail_Exception */ - // require_once 'Zend/Mail/Exception.php'; + require_once 'Zend/Mail/Exception.php'; throw new Zend_Mail_Exception('From Header set twice'); } - - $email = $this->_filterEmail($email); - $name = $this->_filterName($name); - $this->_from = $email; - $this->_storeHeader('From', $this->_formatAddress($email, $name), true); - return $this; } @@ -678,23 +618,10 @@ class Zend_Mail extends Zend_Mime_Message * @param string $email * @param string $name * @return Zend_Mail - * @throws Zend_Mail_Exception if called more than one time */ - public function setReplyTo($email, $name = null) + public function setReplyTo($email, $name=null) { - if (null !== $this->_replyTo) { - /** - * @see Zend_Mail_Exception - */ - // require_once 'Zend/Mail/Exception.php'; - throw new Zend_Mail_Exception('Reply-To Header set twice'); - } - - $email = $this->_filterEmail($email); - $name = $this->_filterName($name); - $this->_replyTo = $email; - $this->_storeHeader('Reply-To', $this->_formatAddress($email, $name), true); - + $this->_addRecipientAndHeader('Reply-To', $email, $name); return $this; } @@ -709,16 +636,6 @@ class Zend_Mail extends Zend_Mime_Message } /** - * Returns the current Reply-To address of the message - * - * @return string|null Reply-To address, null when not set - */ - public function getReplyTo() - { - return $this->_replyTo; - } - - /** * Clears the sender from the mail * * @return Zend_Mail Provides fluent interface @@ -731,119 +648,6 @@ class Zend_Mail extends Zend_Mime_Message return $this; } - /** - * Clears the current Reply-To address from the message - * - * @return Zend_Mail Provides fluent interface - */ - public function clearReplyTo() - { - $this->_replyTo = null; - $this->_clearHeader('Reply-To'); - - return $this; - } - - /** - * Sets Default From-email and name of the message - * - * @param string $email - * @param string Optional $name - * @return void - */ - public static function setDefaultFrom($email, $name = null) - { - self::$_defaultFrom = array('email' => $email, 'name' => $name); - } - - /** - * Returns the default sender of the mail - * - * @return null|array Null if none was set. - */ - public static function getDefaultFrom() - { - return self::$_defaultFrom; - } - - /** - * Clears the default sender from the mail - * - * @return void - */ - public static function clearDefaultFrom() - { - self::$_defaultFrom = null; - } - - /** - * Sets From-name and -email based on the defaults - * - * @return Zend_Mail Provides fluent interface - */ - public function setFromToDefaultFrom() { - $from = self::getDefaultFrom(); - if($from === null) { - // require_once 'Zend/Mail/Exception.php'; - throw new Zend_Mail_Exception( - 'No default From Address set to use'); - } - - $this->setFrom($from['email'], $from['name']); - - return $this; - } - - /** - * Sets Default ReplyTo-address and -name of the message - * - * @param string $email - * @param string Optional $name - * @return void - */ - public static function setDefaultReplyTo($email, $name = null) - { - self::$_defaultReplyTo = array('email' => $email, 'name' => $name); - } - - /** - * Returns the default Reply-To Address and Name of the mail - * - * @return null|array Null if none was set. - */ - public static function getDefaultReplyTo() - { - return self::$_defaultReplyTo; - } - - /** - * Clears the default ReplyTo-address and -name from the mail - * - * @return void - */ - public static function clearDefaultReplyTo() - { - self::$_defaultReplyTo = null; - } - - /** - * Sets ReplyTo-name and -email based on the defaults - * - * @return Zend_Mail Provides fluent interface - */ - public function setReplyToFromDefault() { - $replyTo = self::getDefaultReplyTo(); - if($replyTo === null) { - // require_once 'Zend/Mail/Exception.php'; - throw new Zend_Mail_Exception( - 'No default Reply-To Address set to use'); - } - - $this->setReplyTo($replyTo['email'], $replyTo['name']); - - return $this; - } - /** * Sets the Return-Path header of the message * @@ -861,7 +665,7 @@ class Zend_Mail extends Zend_Mime_Message /** * @see Zend_Mail_Exception */ - // require_once 'Zend/Mail/Exception.php'; + require_once 'Zend/Mail/Exception.php'; throw new Zend_Mail_Exception('Return-Path Header set twice'); } return $this; @@ -913,7 +717,7 @@ class Zend_Mail extends Zend_Mime_Message /** * @see Zend_Mail_Exception */ - // require_once 'Zend/Mail/Exception.php'; + require_once 'Zend/Mail/Exception.php'; throw new Zend_Mail_Exception('Subject set twice'); } return $this; @@ -945,9 +749,9 @@ class Zend_Mail extends Zend_Mime_Message /** * Sets Date-header * - * @param timestamp|string|Zend_Date $date + * @param string $date * @return Zend_Mail Provides fluent interface - * @throws Zend_Mail_Exception if called subsequent times or wrong date format. + * @throws Zend_Mail_Exception if called subsequent times */ public function setDate($date = null) { @@ -959,22 +763,22 @@ class Zend_Mail extends Zend_Mime_Message } else if (is_string($date)) { $date = strtotime($date); if ($date === false || $date < 0) { - /** - * @see Zend_Mail_Exception - */ - // require_once 'Zend/Mail/Exception.php'; - throw new Zend_Mail_Exception('String representations of Date Header must be ' . + /** + * @see Zend_Mail_Exception + */ + require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('String representations of Date Header must be ' . 'strtotime()-compatible'); } $date = date('r', $date); } else if ($date instanceof Zend_Date) { $date = $date->get(Zend_Date::RFC_2822); } else { - /** - * @see Zend_Mail_Exception - */ - // require_once 'Zend/Mail/Exception.php'; - throw new Zend_Mail_Exception(__METHOD__ . ' only accepts UNIX timestamps, Zend_Date objects, ' . + /** + * @see Zend_Mail_Exception + */ + require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception(__METHOD__ . ' only accepts UNIX timestamps, Zend_Date objects, ' . ' and strtotime()-compatible strings'); } $this->_date = $date; @@ -983,8 +787,8 @@ class Zend_Mail extends Zend_Mime_Message /** * @see Zend_Mail_Exception */ - // require_once 'Zend/Mail/Exception.php'; - throw new Zend_Mail_Exception('Date Header set twice'); + require_once 'Zend/Mail/Exception.php'; + throw new Zend_Mail_Exception('Date Header set twice'); } return $this; } @@ -1019,27 +823,27 @@ class Zend_Mail extends Zend_Mime_Message * true :Auto * false :No set * null :No set - * string:Sets given string (Angle brackets is not necessary) + * string:Sets string * @return Zend_Mail Provides fluent interface * @throws Zend_Mail_Exception */ public function setMessageId($id = true) { - if ($id === null || $id === false) { - return $this; - } elseif ($id === true) { + if ($id === null || $id === false) { + return $this; + } elseif ($id === true) { $id = $this->createMessageId(); - } + } if ($this->_messageId === null) { - $id = $this->_filterOther($id); + $id = $this->_filterOther($id); $this->_messageId = $id; - $this->_storeHeader('Message-Id', '<' . $this->_messageId . '>'); + $this->_storeHeader('Message-Id', $this->_messageId); } else { /** * @see Zend_Mail_Exception */ - // require_once 'Zend/Mail/Exception.php'; + require_once 'Zend/Mail/Exception.php'; throw new Zend_Mail_Exception('Message-ID set twice'); } @@ -1080,25 +884,25 @@ class Zend_Mail extends Zend_Mime_Message $time = time(); if ($this->_from !== null) { - $user = $this->_from; + $user = $this->_from; } elseif (isset($_SERVER['REMOTE_ADDR'])) { - $user = $_SERVER['REMOTE_ADDR']; + $user = $_SERVER['REMOTE_ADDR']; } else { - $user = getmypid(); + $user = getmypid(); } - $rand = mt_rand(); + $rand = mt_rand(); - if ($this->_recipients !== array()) { + if ($this->_recipients !== array()) { $recipient = array_rand($this->_recipients); - } else { - $recipient = 'unknown'; - } + } else { + $recipient = 'unknown'; + } - if (isset($_SERVER["SERVER_NAME"])) { + if (isset($_SERVER["SERVER_NAME"])) { $hostName = $_SERVER["SERVER_NAME"]; } else { - $hostName = php_uname('n'); + $hostName = php_uname('n'); } return sha1($time . $user . $rand . $recipient) . '@' . $hostName; @@ -1116,14 +920,13 @@ class Zend_Mail extends Zend_Mime_Message public function addHeader($name, $value, $append = false) { $prohibit = array('to', 'cc', 'bcc', 'from', 'subject', - 'reply-to', 'return-path', - 'date', 'message-id', + 'return-path', 'date', 'message-id', ); if (in_array(strtolower($name), $prohibit)) { /** * @see Zend_Mail_Exception */ - // require_once 'Zend/Mail/Exception.php'; + require_once 'Zend/Mail/Exception.php'; throw new Zend_Mail_Exception('Cannot set standard header from addHeader()'); } @@ -1156,7 +959,7 @@ class Zend_Mail extends Zend_Mime_Message { if ($transport === null) { if (! self::$_defaultTransport instanceof Zend_Mail_Transport_Abstract) { - // require_once 'Zend/Mail/Transport/Sendmail.php'; + require_once 'Zend/Mail/Transport/Sendmail.php'; $transport = new Zend_Mail_Transport_Sendmail(); } else { $transport = self::$_defaultTransport; @@ -1167,14 +970,6 @@ class Zend_Mail extends Zend_Mime_Message $this->setDate(); } - if(null === $this->_from && null !== self::getDefaultFrom()) { - $this->setFromToDefaultFrom(); - } - - if(null === $this->_replyTo && null !== self::getDefaultReplyTo()) { - $this->setReplyToFromDefault(); - } - $transport->send($this); return $this; @@ -1188,14 +983,14 @@ class Zend_Mail extends Zend_Mime_Message */ protected function _filterEmail($email) { - $rule = array("\r" => '', - "\n" => '', - "\t" => '', + $rule = array("\r" => '', + "\n" => '', + "\t" => '', '"' => '', - ',' => '', + ',' => '', '<' => '', '>' => '', - ); + ); return strtr($email, $rule); } @@ -1208,13 +1003,13 @@ class Zend_Mail extends Zend_Mime_Message */ protected function _filterName($name) { - $rule = array("\r" => '', + $rule = array("\r" => '', "\n" => '', "\t" => '', '"' => "'", '<' => '[', - '>' => ']', - ); + '>' => ']', + ); return trim(strtr($name, $rule)); } @@ -1248,8 +1043,7 @@ class Zend_Mail extends Zend_Mime_Message return $email; } else { $encodedName = $this->_encodeHeader($name); - if ($encodedName === $name && - ((strpos($name, '@') !== false) || (strpos($name, ',') !== false))) { + if ($encodedName === $name && strpos($name, ',') !== false) { $format = '"%s" <%s>'; } else { $format = '%s <%s>'; |