* @param string $defserver The default domain to append to mailboxes.
*
* @return string The text, encoded only if it contains non-ASCII
- * characters, or PEAR_Error on error.
+ * characters.
+ * @throws Horde_Mime_Exception
*/
static public function encodeAddress($addresses, $charset = null,
$defserver = null)
}
$addresses = Horde_Mime_Address::parseAddressList($addresses, array('defserver' => $defserver, 'nestgroups' => true));
- if (is_a($addresses, 'PEAR_Error')) {
- return $addresses;
- }
}
$text = '';
* to.
*
* @return string The decoded text.
+ * @throw Horde_Mime_Exception
*/
static public function decodeAddrString($string, $to_charset = null)
{
{
$addressList = array();
- $from = self::parseAddressList($address, array('defserver' => $defserver));
- if (is_a($from, 'PEAR_Error')) {
+ try {
+ $from = self::parseAddressList($address, array('defserver' => $defserver));
+ } catch (Horde_Mime_Exception $e) {
return $multiple ? array() : '';
}
* 'nestgroups' - (boolean) Nest the groups? (Will appear under the
* 'groupname' key)
* DEFAULT: No.
- * 'reterror' - (boolean) Return a PEAR_Error object on error?
- * DEFAULT: Returns an empty array on error.
* 'validate' - (boolean) Validate the address(es)?
* DEFAULT: No.
* </pre>
*
- * @return mixed If 'reterror' is true, returns a PEAR_Error object on
- * error. Otherwise, a list of arrays with the possible
- * keys: 'mailbox', 'host', 'personal', 'adl', 'groupname',
- * and 'comment'.
+ * @return array A list of arrays with the possible keys: 'mailbox',
+ * 'host', 'personal', 'adl', 'groupname', and 'comment'.
+ * @throws Horde_Mime_Exception
*/
static public function parseAddressList($address, $options = array())
{
$options = array_merge(array(
'defserver' => null,
'nestgroups' => false,
- 'reterror' => false,
'validate' => false
), $options);
static $parser;
if (!isset($parser)) {
- require_once 'Mail/RFC822.php';
$parser = new Mail_RFC822();
}
$ret = $parser->parseAddressList($address, $options['defserver'], $options['nestgroups'], $options['validate']);
if (is_a($ret, 'PEAR_Error')) {
- return empty($options['reterror']) ? array() : $ret;
+ throw new Horde_Mime_Exception($ret);
}
/* Convert objects to arrays. */
--- /dev/null
+<?php
+/**
+ * Exception handler for the Horde_Mime class.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package Horde_Mime
+ */
+class Horde_Mime_Exception extends Horde_Exception {}
foreach (array_keys($val) as $key) {
if (in_array($header, $address_keys) ) {
/* Address encoded headers. */
- $text = Horde_Mime::encodeAddress($val[$key], $charset, empty($options['defserver']) ? null : $options['defserver']);
- if (is_a($text, 'PEAR_Error')) {
+ try {
+ $text = Horde_Mime::encodeAddress($val[$key], $charset, empty($options['defserver']) ? null : $options['defserver']);
+ } catch (Horde_Mime_Exception $e) {
$text = $val[$key];
}
} elseif (in_array($header, $mime) && !empty($ob['params'])) {
if (!empty($options['decode'])) {
// Fields defined in RFC 2822 that contain address information
if (in_array($lcHeader, $this->addressFields())) {
- $value = Horde_Mime::decodeAddrString($value);
+ try {
+ $value = Horde_Mime::decodeAddrString($value);
+ } catch (Horde_Mime_Exception $e) {
+ $value = '';
+ }
} else {
$value = Horde_Mime::decode($value);
}
public function getOb($field)
{
$val = $this->getValue($field);
- return is_null($val)
- ? array()
- : Horde_Mime_Address::parseAddressList($val);
+ if (!is_null($val)) {
+ try {
+ return Horde_Mime_Address::parseAddressList($val);
+ } catch (Horde_Mime_Exception $e) {}
+ }
+ return array();
}
/**
* @param array $header Hash with header names as keys and header
* contents as values.
* @param string $charset The header value's charset.
+ *
+ * @throws Horde_Mime_Exception
*/
public function addHeaders($headers = array(), $charset = 'iso-8859-1')
{
foreach ($headers as $header => $value) {
- if (is_a($added = $this->addHeader($header, $value, $charset), 'PEAR_Error')) {
- return $added;
- }
+ $this->addHeader($header, $value, $charset);
}
}
* headers are added; if null, the correct
* behaviour is automatically chosen depending
* on the header name.
+ *
+ * @throws Horde_Mime_Exception
*/
public function addHeader($header, $value, $charset = 'iso-8859-1',
$overwrite = null)
$value = $this->_headers->getValue($header);
$this->_headers->removeHeader($header);
if (in_array(String::lower($header), array('to', 'cc', 'bcc'))) {
- $this->removeRecipients($value);
+ try {
+ $this->removeRecipients($value);
+ } catch (Horde_Mime_Exception $e) {}
}
}
*
* @param string|array List of recipients, either as a comma separated
* list or as an array of email addresses.
+ *
+ * @throws Horde_Mime_Exception
*/
public function addRecipients($recipients)
{
- $recipients = $this->_buildRecipients($recipients);
- if (is_a($recipients, 'PEAR_Error')) {
- return $recipients;
- }
- $this->_recipients = array_merge($this->_recipients, $recipients);
+ $this->_recipients = array_merge($this->_recipients, $this->_buildRecipients($recipients));
}
/**
*
* @param string|array List of recipients, either as a comma separated
* list or as an array of email addresses.
+ *
+ * @throws Horde_Mime_Exception
*/
public function removeRecipients($recipients)
{
- $recipients = $this->_buildRecipients($recipients);
- if (is_a($recipients, 'PEAR_Error')) {
- return $recipients;
- }
- $this->_recipients = array_diff($this->_recipients, $recipients);
+ $this->_recipients = array_diff($this->_recipients, $this->_buildRecipients($recipients));
}
/**
* @param string|array List of recipients, either as a comma separated
* list or as an array of email addresses.
*
- * @return array Normalized list of recipients or PEAR_Error on failure.
+ * @return array Normalized list of recipients.
+ * @throws Horde_Mime_Exception
*/
protected function _buildRecipients($recipients)
{
foreach (Horde_Mime_Address::bareAddress(implode(', ', $addrlist), null, true) as $val) {
if (Horde_Mime::is8bit($val)) {
- return PEAR::raiseError(sprintf(_("Invalid character in e-mail address: %s."), $val));
+ throw new Horde_Mime_Exception(sprintf(_("Invalid character in e-mail address: %s."), $val));
}
}
* @param array $params Any parameters necessary for the Mail driver.
* @param boolean $resend If true, the message id and date are re-used;
* If false, they will be updated.
- * @param boolean $flowed Send message in flowed text format. @since
- * Horde 3.2.1
+ * @param boolean $flowed Send message in flowed text format.
*
- * @return mixed True on success, PEAR_Error on error.
+ * @throws Horde_Mime_Exception
*/
public function send($driver = null, $params = array(), $resend = false,
$flowed = true)
}
/* Send message. */
- return $basepart->send(implode(', ', $this->_recipients),
+ $res = $basepart->send(implode(', ', $this->_recipients),
$this->_headers, $this->_mailer_driver,
$this->_mailer_params);
+ if (is_a($res, 'PEAR_Error')) {
+ throw new Horde_Mime_Exception($res);
+ }
+
+ return $res;
}
/**
/* RFC 3798 [2.1]: Explicit confirmation is needed if there is more
* than one distinct address in the Disposition-Notification-To
* header. */
- $addr_arr = Horde_Mime_Address::parseAddressList($this->getMdnReturnAddr());
+ try {
+ $addr_arr = Horde_Mime_Address::parseAddressList($this->getMdnReturnAddr());
+ } catch (Horde_Mime_Exception $e) {
+ return false;
+ }
+
if (count($addr_arr) > 1) {
return true;
}
* from the address in the Return-Path header." This comparison is
* case-sensitive for the mailbox part and case-insensitive for the
* host part. */
- $ret_arr = Horde_Mime_Address::parseAddressList($return_path);
+ try {
+ $ret_arr = Horde_Mime_Address::parseAddressList($return_path);
+ } catch (Horde_Mime_Exception $e) {
+ return false;
+ }
+
return ($addr_arr[0]['mailbox'] == $ret_arr[0]['mailbox']) &&
(String::lower($addr_arr[0]['host']) == String::lower($ret_arr[0]['host']));
}
* information to provide. Key is the type of
* modification, value is the text.
*
- * @return mixed True on success, PEAR_Error object on error.
+ * @throws Horde_Mime_Exception
*/
public function generate($action, $sending, $type, $maildriver,
$mailparams = array(), $mod = array(),
* @param array $params Any parameters necessary for the
* Mail driver.
*
- * @return mixed True on success, PEAR_Error on error.
+ * @throws Horde_Mime_Exception
*/
public function send($email, $headers, $driver, $params = array())
{
} else {
$userinfo = $result->toString();
}
- return PEAR::raiseError($error, null, null, null, $userinfo);
+ // TODO: userinfo
+ throw new Horde_Mime_Exception($error);
}
return $result;
<file name="zip.php" role="php" />
</dir> <!-- /lib/Horde/Mime/Viewer -->
<file name="Address.php" role="php" />
+ <file name="Exception.php" role="php" />
<file name="Headers.php" role="php" />
<file name="Magic.php" role="php" />
<file name="Mail.php" role="php" />
<min>1.5.0</min>
</pearinstaller>
<package>
+ <name>Horde_Framework</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
<name>Mail_mimeDecode</name>
<channel>pear.php.net</channel>
</package>
<channel>pear.horde.org</channel>
</package>
<package>
- <name>Horde_Framework</name>
- <channel>pear.horde.org</channel>
- </package>
- <package>
<name>iCalendar</name>
<channel>pear.horde.org</channel>
</package>
<install name="lib/Horde/Mime/Viewer/wordperfect.php" as="Horde/Mime/Viewer/wordperfect.php" />
<install name="lib/Horde/Mime/Viewer/zip.php" as="Horde/Mime/Viewer/zip.php" />
<install name="lib/Horde/Mime/Address.php" as="Horde/Mime/Address.php" />
+ <install name="lib/Horde/Mime/Exception.php" as="Horde/Mime/Exception.php" />
<install name="lib/Horde/Mime/Headers.php" as="Horde/Mime/Headers.php" />
<install name="lib/Horde/Mime/Mdn.php" as="Horde/Mime/Mdn.php" />
<install name="lib/Horde/Mime/Magic.php" as="Horde/Mime/Magic.php" />