From d2fd48146c90e2d8b20065a6d1b4caf2723267e1 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 11 May 2010 21:58:26 -0600 Subject: [PATCH] Use new Horde_Mail:: package Resolves Request #8909 (pass stream to send()) --- agora/messages/abuse.php | 2 +- ansel/img/ecard.php | 2 +- ansel/lib/Report/mail.php | 2 +- babel/lib/Babel.php | 3 +- folks/lib/Folks.php | 2 +- folks/lib/Notification/mail.php | 2 +- framework/Alarm/lib/Horde/Alarm/Handler/Mail.php | 10 +- framework/Alarm/package.xml | 4 + framework/Alarm/test/Horde/Alarm/HandlerTest.php | 31 +++-- framework/Auth/lib/Horde/Auth/Signup.php | 2 +- framework/Core/lib/Horde/Core/Binder/Alarm.php | 2 +- framework/Core/lib/Horde/Core/Binder/Mail.php | 2 +- framework/Core/lib/Horde/Registry.php | 2 +- framework/Data/Data/tsv.php | 10 +- framework/Data/package.xml | 7 +- framework/Form/Form/Type.php | 8 +- framework/Mime/lib/Horde/Mime/Address.php | 27 +++-- framework/Mime/lib/Horde/Mime/Mail.php | 143 ----------------------- framework/Mime/lib/Horde/Mime/Mail/mail.php | 59 ---------- framework/Mime/lib/Horde/Mime/Mail/sendmail.php | 59 ---------- framework/Mime/lib/Horde/Mime/Mail/smtp.php | 59 ---------- framework/Mime/lib/Horde/Mime/Mail/smtpmx.php | 59 ---------- framework/Mime/lib/Horde/Mime/Part.php | 38 +++--- framework/Mime/package.xml | 16 +-- framework/Model/lib/Horde/Form.php | 6 +- framework/Model/lib/Horde/Form/Type/Email.php | 11 +- framework/Net_SMS/SMS/generic_smtp.php | 14 +-- framework/Net_SMS/SMS/vodafoneitaly_smtp.php | 9 +- framework/Net_SMS/package.xml | 3 +- framework/Prefs/lib/Horde/Prefs/Identity.php | 2 +- framework/iCalendar/iCalendar/vcard.php | 13 +-- framework/iCalendar/package.xml | 4 + horde/config/hooks.php.dist | 3 +- horde/docs/CHANGES | 1 + horde/docs/INSTALL | 9 +- horde/docs/UPGRADING | 1 - horde/lib/Test.php | 5 - horde/rpc.php | 2 +- horde/services/problem.php | 2 +- horde/services/resetpassword.php | 2 +- imp/docs/CHANGES | 2 + imp/lib/Application.php | 1 + imp/lib/Compose.php | 69 +---------- imp/lib/Injector/Binder/Mail.php | 52 +++++++++ imp/lib/Mime/Viewer/Itip.php | 6 +- imp/lib/Ui/Message.php | 3 +- kronolith/lib/FreeBusy.php | 18 +-- kronolith/lib/Kronolith.php | 30 +++-- kronolith/scripts/agenda.php | 2 +- nag/lib/Nag.php | 2 +- news/mail.php | 2 +- turba/data.php | 5 +- turba/scripts/upgrades/2.1_to_2.2_sql_schema.php | 6 +- whups/lib/Driver.php | 9 +- wicked/lib/Wicked.php | 2 +- 55 files changed, 228 insertions(+), 619 deletions(-) delete mode 100644 framework/Mime/lib/Horde/Mime/Mail/mail.php delete mode 100644 framework/Mime/lib/Horde/Mime/Mail/sendmail.php delete mode 100644 framework/Mime/lib/Horde/Mime/Mail/smtp.php delete mode 100644 framework/Mime/lib/Horde/Mime/Mail/smtpmx.php create mode 100644 imp/lib/Injector/Binder/Mail.php diff --git a/agora/messages/abuse.php b/agora/messages/abuse.php index 1774bd8e1..66571d2ea 100644 --- a/agora/messages/abuse.php +++ b/agora/messages/abuse.php @@ -77,7 +77,7 @@ if ($form->validate()) { 'from' => $emails[0], 'charset' => Horde_Nls::getCharset())); $mail->addHeader('User-Agent', 'Agora ' . $registry->getVersion()); - $mail->send($injector->getInstance('Mail')); + $mail->send($injector->getInstance('Horde_Mail')); $notification->push($subject, 'horde.success'); header('Location: ' . $url); diff --git a/ansel/img/ecard.php b/ansel/img/ecard.php index a4247a945..f91f3d84c 100644 --- a/ansel/img/ecard.php +++ b/ansel/img/ecard.php @@ -83,7 +83,7 @@ case 'send': $alt->setBasePart($alternative); /* Send. */ - $result = $alt->send($injector->getInstance('Mail')); + $result = $alt->send($injector->getInstance('Horde_Mail')); if (is_a($result, 'PEAR_Error')) { $notification->push(sprintf(_("There was an error sending your message: %s"), $result->getMessage()), 'horde.error'); } else { diff --git a/ansel/lib/Report/mail.php b/ansel/lib/Report/mail.php index 0db2997fa..cf37ba51a 100644 --- a/ansel/lib/Report/mail.php +++ b/ansel/lib/Report/mail.php @@ -37,6 +37,6 @@ class Ansel_Report_mail extends Ansel_Report { //FIXME: This address should be configurable $mail->addHeader('Sender', 'horde-problem@' . $conf['report_content']['maildomain']); - return $mail->send($GLOBALS['injector']->getInstance('Mail')); + return $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } } diff --git a/babel/lib/Babel.php b/babel/lib/Babel.php index bc76ceca7..c3b2c1f69 100644 --- a/babel/lib/Babel.php +++ b/babel/lib/Babel.php @@ -258,8 +258,7 @@ class Babel { $body = $mime->get(); $hdrs = $mime->headers($headers); - $mail_object = &Mail::factory("mail"); - return $mail_object->send($email['to'], $hdrs, $body); + return $GLOBALS['injector']->getInstance('Horde_Mail')->send($email['to'], $hdrs, $body); } diff --git a/folks/lib/Folks.php b/folks/lib/Folks.php index 6a84b061d..35b0795a7 100644 --- a/folks/lib/Folks.php +++ b/folks/lib/Folks.php @@ -247,7 +247,7 @@ class Folks { } } - return $mail->send($GLOBALS['injector']->getInstance('Mail')); + return $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } /** diff --git a/folks/lib/Notification/mail.php b/folks/lib/Notification/mail.php index 64ff85439..459d41444 100644 --- a/folks/lib/Notification/mail.php +++ b/folks/lib/Notification/mail.php @@ -79,7 +79,7 @@ class Folks_Notification_mail extends Folks_Notification { continue; } $mail->addHeader('To', $to, Horde_Nls::getCharset(), true); - $mail->send($GLOBALS['injector']->getInstance('Mail')); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } return true; diff --git a/framework/Alarm/lib/Horde/Alarm/Handler/Mail.php b/framework/Alarm/lib/Horde/Alarm/Handler/Mail.php index 30854b707..d751054a7 100644 --- a/framework/Alarm/lib/Horde/Alarm/Handler/Mail.php +++ b/framework/Alarm/lib/Horde/Alarm/Handler/Mail.php @@ -25,9 +25,9 @@ class Horde_Alarm_Handler_Mail extends Horde_Alarm_Handler protected $_identity; /** - * A Mail object. + * A Horde_Mail_Driver object. * - * @var Mail + * @var Horde_Mail_Driver */ protected $_mail; @@ -45,7 +45,7 @@ class Horde_Alarm_Handler_Mail extends Horde_Alarm_Handler * Required parameter: * - identity: An identity factory that implements * getIdentity(). - * - mail: A PEAR Mail instance. + * - mail: A Horde_Mail_Driver instance. * - charset: The charset of the messages. */ public function __construct(array $params = null) @@ -59,8 +59,8 @@ class Horde_Alarm_Handler_Mail extends Horde_Alarm_Handler throw new Horde_Alarm_Exception('Parameter \'identity\' does not implement getIdentity().'); } $r = new ReflectionObject($params['mail']); - if (!($params['mail'] instanceof Mail)) { - throw new Horde_Alarm_Exception('Parameter \'mail\' is not a Mail object.'); + if (!($params['mail'] instanceof Horde_Mail_Driver)) { + throw new Horde_Alarm_Exception('Parameter \'mail\' is not a Horde_Mail_Driver object.'); } $this->_identity = $params['identity']; $this->_mail = $params['mail']; diff --git a/framework/Alarm/package.xml b/framework/Alarm/package.xml index 1f5d5b4f3..1c5b52662 100644 --- a/framework/Alarm/package.xml +++ b/framework/Alarm/package.xml @@ -85,6 +85,10 @@ + Mail + pear.horde.org + + Mime pear.horde.org diff --git a/framework/Alarm/test/Horde/Alarm/HandlerTest.php b/framework/Alarm/test/Horde/Alarm/HandlerTest.php index 17df32907..d06472c0c 100644 --- a/framework/Alarm/test/Horde/Alarm/HandlerTest.php +++ b/framework/Alarm/test/Horde/Alarm/HandlerTest.php @@ -19,8 +19,8 @@ class Horde_Alarm_HandlerTest extends PHPUnit_Framework_TestCase $this->markTestSkipped('Horde_Notification not installed'); return; } - if (!class_exists('Mail')) { - $this->markTestSkipped('Mail not installed'); + if (!class_exists('Horde_Mail')) { + $this->markTestSkipped('Horde_Mail not installed'); return; } @@ -44,7 +44,7 @@ class Horde_Alarm_HandlerTest extends PHPUnit_Framework_TestCase $handler = new Horde_Alarm_Handler_Desktop(array('notification' => $notification, 'icon' => 'test.png')); self::$alarm->addHandler('desktop', $handler); - self::$mail = new Horde_Alarm_HandlerTest_Mail(); + self::$mail = Horde_Mail::factory('Mock'); $factory = new Horde_Alarm_HandlerTest_IdentityFactory(); $handler = new Horde_Alarm_Handler_Mail(array('mail' => self::$mail, 'identity' => $factory, 'charset' => 'us-ascii')); self::$alarm->addHandler('mail', $handler); @@ -85,15 +85,21 @@ Action is required\. EOR; $regexp = trim(str_replace("\r\n", "\n", $regexp)); - $this->assertRegExp('/' . $regexp . '/', trim(str_replace("\r\n", "\n", self::$mail->sentOutput))); - self::$mail->sentOutput = null; + $last_sent = end(self::$mail->sentMessages); + $sent_message = $last_sent['header_text'] . "\n\n" . $last_sent['body']; + $this->assertRegExp('/' . $regexp . '/', trim(str_replace("\r\n", "\n", $sent_message))); + + self::$mail->sentMessages = array(); self::$alarm->notify('john', false); - $this->assertNull(self::$mail->sentOutput); + $this->assertEquals(self::$mail->sentMessages, array()); /* Test re-sending mails after changing the alarm. */ self::$alarm->set(self::$alarm->get('personalalarm', 'john')); self::$alarm->notify('john', false); - $this->assertRegExp('/' . $regexp . '/', trim(str_replace("\r\n", "\n", self::$mail->sentOutput))); + + $last_sent = end(self::$mail->sentMessages); + $sent_message = $last_sent['header_text'] . "\n\n" . $last_sent['body']; + $this->assertRegExp('/' . $regexp . '/', trim(str_replace("\r\n", "\n", $sent_message))); } } @@ -112,14 +118,3 @@ class Horde_Alarm_HandlerTest_Identity return 'john@example.com'; } } - -class Horde_Alarm_HandlerTest_Mail extends Mail -{ - public $sentOutput; - - public function send($recipients, $headers, $body) - { - list(, $textHeaders) = Mail::prepareHeaders($headers); - $this->sentOutput = $textHeaders . "\n\n" . $body; - } -} diff --git a/framework/Auth/lib/Horde/Auth/Signup.php b/framework/Auth/lib/Horde/Auth/Signup.php index 4b8675490..34533b09a 100644 --- a/framework/Auth/lib/Horde/Auth/Signup.php +++ b/framework/Auth/lib/Horde/Auth/Signup.php @@ -134,7 +134,7 @@ class Horde_Auth_Signup 'to' => $conf['signup']['email'], 'from' => $conf['signup']['email'], 'subject' => Horde_Nls::getCharset())); - $mail->send($GLOBALS['injector']->getInstance('Mail')); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } } diff --git a/framework/Core/lib/Horde/Core/Binder/Alarm.php b/framework/Core/lib/Horde/Core/Binder/Alarm.php index 56b24b53a..21e07b43a 100644 --- a/framework/Core/lib/Horde/Core/Binder/Alarm.php +++ b/framework/Core/lib/Horde/Core/Binder/Alarm.php @@ -30,7 +30,7 @@ class Horde_Core_Binder_Alarm implements Horde_Injector_Binder */ $handler_params = array( 'identity' => $injector->getInstance('Horde_Prefs_Identity'), - 'mail' => $injector->getInstance('Mail'), + 'mail' => $injector->getInstance('Horde_Mail'), 'charset' => Horde_Nls::getCharset()); $alarm->addHandler('mail', new Horde_Alarm_Handler_Mail($handler_params)); diff --git a/framework/Core/lib/Horde/Core/Binder/Mail.php b/framework/Core/lib/Horde/Core/Binder/Mail.php index a8d7ea585..be04e6449 100644 --- a/framework/Core/lib/Horde/Core/Binder/Mail.php +++ b/framework/Core/lib/Horde/Core/Binder/Mail.php @@ -22,7 +22,7 @@ class Horde_Core_Binder_Mail implements Horde_Injector_Binder } try { - return Horde_Mime_Mail::getMailOb($driver, $params); + return Horde_Mail::factory($driver, $params); } catch (Horde_Mime_Exception $e) { throw new Horde_Exception($e); } diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 20a1e57bb..0c3be2d56 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -241,6 +241,7 @@ class Horde_Registry 'Horde_History' => new Horde_Core_Binder_History(), 'Horde_Lock' => new Horde_Core_Binder_Lock(), 'Horde_Log_Logger' => new Horde_Core_Binder_Logger(), + 'Horde_Mail' => new Horde_Core_Binder_Mail(), 'Horde_Memcache' => new Horde_Core_Binder_Memcache(), 'Horde_Notification' => new Horde_Core_Binder_Notification(), 'Horde_Perms' => new Horde_Core_Binder_Perms(), @@ -250,7 +251,6 @@ class Horde_Registry 'Horde_Template' => new Horde_Core_Binder_Template(), 'Horde_Token' => new Horde_Core_Binder_Token(), 'Horde_Vfs' => new Horde_Core_Binder_Vfs(), - 'Mail' => new Horde_Core_Binder_Mail(), 'Net_DNS_Resolver' => new Horde_Core_Binder_Dns() ); diff --git a/framework/Data/Data/tsv.php b/framework/Data/Data/tsv.php index 7779a54af..3b79404d4 100644 --- a/framework/Data/Data/tsv.php +++ b/framework/Data/Data/tsv.php @@ -157,10 +157,12 @@ class Horde_Data_tsv extends Horde_Data { } $row[1] = preg_replace('/^([^,"]+),\s*(.*)$/', '$2 $1', $row[1]); /* Address can be a full RFC822 address */ - require_once 'Horde/MIME.php'; - $addr_arr = MIME::parseAddressList($row[2]); - if (is_a($addr_arr, 'PEAR_Error') || - empty($addr_arr[0]->mailbox)) { + try { + $addr_arr = Horde_Mime_Address::parseAddressList($row[2]); + } catch (Horde_Mime_Exception $e) { + continue; + } + if (empty($addr_arr[0]->mailbox)) { continue; } $row[2] = $addr_arr[0]->mailbox . '@' . $addr_arr[0]->host; diff --git a/framework/Data/package.xml b/framework/Data/package.xml index 3601f63e5..fe19682ea 100644 --- a/framework/Data/package.xml +++ b/framework/Data/package.xml @@ -13,7 +13,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> * vCard * vNote * vTodo - Jan Schneider @@ -63,17 +62,17 @@ http://pear.php.net/dtd/package-2.0.xsd"> - 4.2.0 + 5.2.0 - 1.4.0b1 + 1.7.0 iCalendar pear.horde.org - Horde_MIME + Mime pear.horde.org diff --git a/framework/Form/Form/Type.php b/framework/Form/Form/Type.php index be70e40b5..713413c5f 100644 --- a/framework/Form/Form/Type.php +++ b/framework/Form/Form/Type.php @@ -2069,10 +2069,10 @@ class Horde_Form_Type_emailConfirm extends Horde_Form_Type { $message = _("Email addresses must match."); return false; } else { - $parsed_email = Horde_Mime_Address::parseAddressList($value['original'], - array('validate' => true)); - if (is_a($parsed_email, 'PEAR_Error')) { - $message = $parsed_email->getMessage(); + try { + $parsed_email = Horde_Mime_Address::parseAddressList($value['original'], array('validate' => true)); + } catch (Horde_Mime_Exception $e) { + $message = $e->getMessage(); return false; } if (count($parsed_email) > 1) { diff --git a/framework/Mime/lib/Horde/Mime/Address.php b/framework/Mime/lib/Horde/Mime/Address.php index 12621e4b2..17c056d6c 100644 --- a/framework/Mime/lib/Horde/Mime/Address.php +++ b/framework/Mime/lib/Horde/Mime/Address.php @@ -15,6 +15,13 @@ class Horde_Mime_Address { /** + * RFC 822 parser instance. + * + * @var Horde_Mail_Rfc822 + */ + static protected $_rfc822; + + /** * Builds an RFC compliant email address. * * @param string $mailbox Mailbox name. @@ -374,20 +381,24 @@ class Horde_Mime_Address return array(); } + if (!self::$_rfc822) { + self::$_rfc822 = new Horde_Mail_Rfc822(); + } + $options = array_merge(array( 'defserver' => null, 'nestgroups' => false, 'validate' => false ), $options); - static $parser; - if (!isset($parser)) { - $parser = new Mail_RFC822(); - } - - $ret = $parser->parseAddressList($address, $options['defserver'], $options['nestgroups'], $options['validate']); - if (is_a($ret, 'PEAR_Error')) { - throw new Horde_Mime_Exception($ret); + try { + $ret = self::$_rfc822->parseAddressList($address, array( + 'default_domain' => $options['defserver'], + 'nest_groups' => $options['nestgroups'], + 'validate' => $options['validate'] + )); + } catch (Horde_Mail_Exception $e) { + throw new Horde_Mime_Exception($e); } /* Convert objects to arrays. */ diff --git a/framework/Mime/lib/Horde/Mime/Mail.php b/framework/Mime/lib/Horde/Mime/Mail.php index 3504d8870..6eeb0ff4d 100644 --- a/framework/Mime/lib/Horde/Mime/Mail.php +++ b/framework/Mime/lib/Horde/Mime/Mail.php @@ -473,147 +473,4 @@ class Horde_Mime_Mail $this->_headers, $mailer); } - /** - * Utility function to create a Mail object. - * - * @param string $driver The mail driver. - * @param array $params The mail parameters. - * @param array $options Additional options: - *
-     * 'raw' - (array) If set, will use the value contained in 'headertext'
-     *         as the exact data to use for the message header. Additionally,
-     *         the 'from' key should contain the From address to use.
-     * 
- * - * @return Mail A Mail object. - * @throws Horde_Mime_Exception - */ - static public function getMailOb($driver, $params, $options = array()) - { - if (!empty($options['raw'])) { - switch ($driver) { - case 'mail': - case 'sendmail': - case 'smtp': - case 'smtpmx': - /* Can't autoload - Mail doesn't support it. */ - require_once dirname(__FILE__) . '/Mail/' . $driver . '.php'; - $driver = 'horde_mime_' . $driver; - $params['from'] = empty($options['raw']['from']) - ? '' - : $options['raw']['from']; - $params['headertext'] = empty($options['raw']['headertext']) - ? '' - : $options['raw']['headertext']; - break; - } - } - - $mailer = Mail::factory($driver, $params); - if ($mailer instanceof PEAR_Error) { - throw new Horde_Mime_Exception($mailer); - } - - return $mailer; - } - - /** - * Utility function to send a message using a PEAR Mail driver. Handles - * errors from this class. - * - * @param Mail $mailer A Mail object. - * @param string $email The address list to send to. - * @param array $headers An array of message headers. - * @param string $msg The message text. - * - * @throws Horde_Mime_Exception - */ - static public function sendPearMail($mailer, $email, $headers, $msg) - { - $result = $mailer->send($email, $headers, $msg); - - if (!$result instanceof PEAR_Error) { - return; - } - - if (!($mailer instanceof Mail_sendmail)) { - throw new Horde_Mime_Exception($result); - } - - switch ($result->getCode()) { - case 64: // EX_USAGE - $msg = 'command line usage error'; - break; - - case 65: // EX_DATAERR - $msg = 'data format error'; - break; - - case 66: // EX_NOINPUT - $msg = 'cannot open input'; - break; - - case 67: // EX_NOUSER - $msg = 'addressee unknown'; - break; - - case 68: // EX_NOHOST - $msg = 'host name unknown'; - break; - - case 69: // EX_UNAVAILABLE - $msg = 'service unavailable'; - break; - - case 70: // EX_SOFTWARE - $msg = 'internal software error'; - break; - - case 71: // EX_OSERR - $msg = 'system error'; - break; - - case 72: // EX_OSFILE - $msg = 'critical system file missing'; - break; - - case 73: // EX_CANTCREAT - $msg = 'cannot create output file'; - break; - - case 74: // EX_IOERR - $msg = 'input/output error'; - break; - - case 75: // EX_TEMPFAIL - $msg = 'temporary failure'; - break; - - case 76: // EX_PROTOCOL - $msg = 'remote error in protocol'; - break; - - case 77: // EX_NOPERM - $msg = 'permission denied'; - break; - - case 77: // EX_NOPERM - $msg = 'permission denied'; - break; - - case 78: // EX_CONFIG - $msg = 'configuration error'; - break; - - case 79: // EX_NOTFOUND - $msg = 'entry not found'; - break; - - default: - throw new Horde_Mime_Exception($result); - } - - throw new Horde_Mime_Exception('sendmail: ' . $msg . ' (' . $result->getCode() . ')'); - } - } diff --git a/framework/Mime/lib/Horde/Mime/Mail/mail.php b/framework/Mime/lib/Horde/Mime/Mail/mail.php deleted file mode 100644 index df4003c71..000000000 --- a/framework/Mime/lib/Horde/Mime/Mail/mail.php +++ /dev/null @@ -1,59 +0,0 @@ - - * @package Horde_Mime - */ -class Mail_horde_mime_mail extends Mail_mail -{ - /** - * The From address to use. - * - * @var string - */ - protected $_from; - - /** - * The raw headertext to use. - * - * @var string - */ - protected $_headertext; - - /** - * Constructor. - * - * @param array $params Configuration parameters: - *
-     * 'from' - (string) The From address to use.
-     * 'headertext' - (string) The raw headertext to use.
-     * 
- */ - public function __construct($params) - { - $this->_from = $params['from']; - $this->_headertext = $params['headertext']; - unset($params['from'], $params['headertext']); - - parent::__construct($params); - } - - /** - * Prepare headers for sending. - * - * @param array $headers The headers array (not used). - * - * @return array 2 elements: the from address and the header text. - */ - public function prepareHeaders($headers) - { - return array($this->_from, $this->_headertext); - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Mail/sendmail.php b/framework/Mime/lib/Horde/Mime/Mail/sendmail.php deleted file mode 100644 index 9e0b9ac32..000000000 --- a/framework/Mime/lib/Horde/Mime/Mail/sendmail.php +++ /dev/null @@ -1,59 +0,0 @@ - - * @package Horde_Mime - */ -class Mail_horde_mime_sendmail extends Mail_sendmail -{ - /** - * The From address to use. - * - * @var string - */ - protected $_from; - - /** - * The raw headertext to use. - * - * @var string - */ - protected $_headertext; - - /** - * Constructor. - * - * @param array $params Configuration parameters: - *
-     * 'from' - (string) The From address to use.
-     * 'headertext' - (string) The raw headertext to use.
-     * 
- */ - public function __construct($params) - { - $this->_from = $params['from']; - $this->_headertext = $params['headertext']; - unset($params['from'], $params['headertext']); - - parent::__construct($params); - } - - /** - * Prepare headers for sending. - * - * @param array $headers The headers array (not used). - * - * @return array 2 elements: the from address and the header text. - */ - public function prepareHeaders($headers) - { - return array($this->_from, $this->_headertext); - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Mail/smtp.php b/framework/Mime/lib/Horde/Mime/Mail/smtp.php deleted file mode 100644 index f6025dc94..000000000 --- a/framework/Mime/lib/Horde/Mime/Mail/smtp.php +++ /dev/null @@ -1,59 +0,0 @@ - - * @package Horde_Mime - */ -class Mail_horde_mime_smtp extends Mail_smtp -{ - /** - * The From address to use. - * - * @var string - */ - protected $_from; - - /** - * The raw headertext to use. - * - * @var string - */ - protected $_headertext; - - /** - * Constructor. - * - * @param array $params Configuration parameters: - *
-     * 'from' - (string) The From address to use.
-     * 'headertext' - (string) The raw headertext to use.
-     * 
- */ - public function __construct($params) - { - $this->_from = $params['from']; - $this->_headertext = $params['headertext']; - unset($params['from'], $params['headertext']); - - parent::__construct($params); - } - - /** - * Prepare headers for sending. - * - * @param array $headers The headers array (not used). - * - * @return array 2 elements: the from address and the header text. - */ - public function prepareHeaders($headers) - { - return array($this->_from, $this->_headertext); - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Mail/smtpmx.php b/framework/Mime/lib/Horde/Mime/Mail/smtpmx.php deleted file mode 100644 index 99bdef7f3..000000000 --- a/framework/Mime/lib/Horde/Mime/Mail/smtpmx.php +++ /dev/null @@ -1,59 +0,0 @@ - - * @package Horde_Mime - */ -class Mail_horde_mime_smtpmx extends Mail_smtpmx -{ - /** - * The From address to use. - * - * @var string - */ - protected $_from; - - /** - * The raw headertext to use. - * - * @var string - */ - protected $_headertext; - - /** - * Constructor. - * - * @param array $params Configuration parameters: - *
-     * 'from' - (string) The From address to use.
-     * 'headertext' - (string) The raw headertext to use.
-     * 
- */ - public function __construct($params) - { - $this->_from = $params['from']; - $this->_headertext = $params['headertext']; - unset($params['from'], $params['headertext']); - - parent::__construct($params); - } - - /** - * Prepare headers for sending. - * - * @param array $headers The headers array (not used). - * - * @return array 2 elements: the from address and the header text. - */ - public function prepareHeaders($headers) - { - return array($this->_from, $this->_headertext); - } - -} diff --git a/framework/Mime/lib/Horde/Mime/Part.php b/framework/Mime/lib/Horde/Mime/Part.php index 98ac9da71..3cf296fae 100644 --- a/framework/Mime/lib/Horde/Mime/Part.php +++ b/framework/Mime/lib/Horde/Mime/Part.php @@ -1471,42 +1471,48 @@ class Horde_Mime_Part * @param string $email The address list to send to. * @param Horde_Mime_Headers $headers The Horde_Mime_Headers object * holding this message's headers. - * @param Mail $mailer A Mail driver. + * @param Horde_Mail_Driver $mailer A Horde_Mail_Driver object. * * @throws Horde_Mime_Exception * @throws InvalidArgumentException */ public function send($email, $headers, $mailer) { - if (!($mailer instanceof Mail)) { - throw new InvalidArgumentException('Invalid Mail object passed to send().'); + if (!($mailer instanceof Horde_Mail_Driver)) { + throw new InvalidArgumentException('Invalid Horde_Mail_Driver object passed to send().'); } $old_basepart = $this->_basepart; $this->_basepart = true; /* Does the SMTP backend support 8BITMIME (RFC 1652) or - * BINARYMIME (RFC 3030) extensions? Requires PEAR's Mail package - * version 1.2+ and Net_SMTP version 1.3+. */ + * BINARYMIME (RFC 3030) extensions? Requires Net_SMTP version + * 1.3+. */ $encode = self::ENCODE_7BIT; - if ($mailer instanceof Mail_smtp) { - $net_smtp = $mailer->getSMTPObject(); - if (!($net_smtp instanceof PEAR_Error)) { - $smtp_ext = $net_smtp->getServiceExtensions(); + if ($mailer instanceof Horde_Mail_Smtp) { + try { + $smtp_ext = $mailer->getSMTPObject()->getServiceExtensions(); if (isset($smtp_ext['8BITMIME'])) { $encode |= self::ENCODE_8BIT; } if (isset($smtp_ext['BINARYMIME'])) { $encode |= self::ENCODE_BINARY; } - } + } catch (Horde_Mail_Exception $e) {} } + $msg = $this->toString(array( + 'encode' => $encode, + 'headers' => false, + 'stream' => true + )); + /* Make sure the message has a trailing newline. */ - $msg = $this->toString(array('encode' => $encode, 'headers' => false)); - if (substr($msg, -1) != "\n") { - $msg .= "\n"; + fseek($msg, -1, SEEK_END); + if (fgetc($msg) != "\n") { + fputs($msg, "\n"); } + rewind($msg); /* Add MIME Headers if they don't already exist. */ if (!$headers->getValue('MIME-Version')) { @@ -1528,7 +1534,11 @@ class Horde_Mime_Part $this->_basepart = $old_basepart; - Horde_Mime_Mail::sendPearMail($mailer, Horde_Mime::encodeAddress($email, $this->getCharset()), $headers->toArray(array('charset' => $this->getHeaderCharset())), $msg); + try { + $mailer->send(Horde_Mime::encodeAddress($email, $this->getCharset()), $headers->toArray(array('charset' => $this->getHeaderCharset())), $msg); + } catch (Horde_Mail_Exception $e) { + throw new Horde_Mime_Exception($e); + } } /** diff --git a/framework/Mime/package.xml b/framework/Mime/package.xml index 2f12530bb..a1ad7b145 100644 --- a/framework/Mime/package.xml +++ b/framework/Mime/package.xml @@ -31,8 +31,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> alpha LGPL - * Add Mail driver extensions (raw header output). - * No need to generate Content-Transfer-Encoding header if part data is 7bit. + * No need to generate Content-Transfer-Encoding header if part data is 7bit. * Default disposition should be empty by default, not inline (RFC 2183 [2]). * Request #8556: Allow specifying a header charset for a part. * Add 'raw' render view to Horde_Mime_Viewer. @@ -49,12 +48,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - - - @@ -173,8 +166,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> Mail - pear.php.net - 1.2.0 + pear.horde.org Stream_Filter @@ -222,10 +214,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - - - - diff --git a/framework/Model/lib/Horde/Form.php b/framework/Model/lib/Horde/Form.php index 4ba9b047e..6eec2319b 100644 --- a/framework/Model/lib/Horde/Form.php +++ b/framework/Model/lib/Horde/Form.php @@ -1661,8 +1661,10 @@ class Horde_Form_Type_emailConfirm extends Horde_Form_Type { $message = _("Email addresses must match."); return false; } else { - $parser = new Mail_RFC822(); - $parsed_email = $parser->parseAddressList($value['original'], false, true); + $parser = new Horde_Mail_Rfc822(); + $parsed_email = $parser->parseAddressList($value['original'], array( + 'default_domain' => false + )); if (count($parsed_email) > 1) { $message = _("Only one email address allowed."); diff --git a/framework/Model/lib/Horde/Form/Type/Email.php b/framework/Model/lib/Horde/Form/Type/Email.php index 96cf7567d..c39546834 100644 --- a/framework/Model/lib/Horde/Form/Type/Email.php +++ b/framework/Model/lib/Horde/Form/Type/Email.php @@ -429,11 +429,12 @@ class Horde_Form_Type_EmailConfirm extends Horde_Form_Type { $message = _("Email addresses must match."); return false; } else { - require_once 'Horde/MIME.php'; - $parsed_email = MIME::parseAddressList($value['original'], false, - true); - if (is_a($parsed_email, 'PEAR_Error')) { - $message = $parsed_email->getMessage(); + try { + $parsed_email = Horde_Mime_Address::parseAddressList($value['original'], array( + 'validate' => true + )); + } catch (Horde_Mime_Exception $e) { + $message = $e->getMessage(); return false; } if (count($parsed_email) > 1) { diff --git a/framework/Net_SMS/SMS/generic_smtp.php b/framework/Net_SMS/SMS/generic_smtp.php index c4580b21b..255cce210 100644 --- a/framework/Net_SMS/SMS/generic_smtp.php +++ b/framework/Net_SMS/SMS/generic_smtp.php @@ -99,7 +99,7 @@ class Net_SMS_generic_smtp extends Net_SMS { { return array( 'carrier' => array('label' => _("Carrier"), 'type' => 'text'), - 'mailBackend' => array('label' => _("PEAR::Mail backend"), 'type' => 'text') + 'mailBackend' => array('label' => _("Horde_Mail:: backend"), 'type' => 'text') ); } @@ -120,9 +120,7 @@ class Net_SMS_generic_smtp extends Net_SMS { */ function _send($message, $to) { - require_once 'Mail.php'; - $m = &Mail::factory($this->_params['mailBackend'], - $this->_params['mailParams']); + $m = Horde_Mail::factory($this->_params['mailBackend'], $this->_params['mailParams']); if (isset($message['carrier'])) { $dest = $this->_getDest($to, $message['carrier']); @@ -130,11 +128,11 @@ class Net_SMS_generic_smtp extends Net_SMS { $dest = $this->_getDest($to); } - $res = $m->send($dest, $this->_params['mailHeaders'], $message['text']); - if (PEAR::isError($res)) { - return array(0, $res->getMessage()); - } else { + try { + $m->send($dest, $this->_params['mailHeaders'], $message['text']); return array(1, null); + } catch (Horde_Mail_Exception $e) { + return array(0, $e->getMessage()); } } diff --git a/framework/Net_SMS/SMS/vodafoneitaly_smtp.php b/framework/Net_SMS/SMS/vodafoneitaly_smtp.php index a3c28e06e..ccd0f8342 100644 --- a/framework/Net_SMS/SMS/vodafoneitaly_smtp.php +++ b/framework/Net_SMS/SMS/vodafoneitaly_smtp.php @@ -57,12 +57,11 @@ class Net_SMS_vodafoneitaly_smtp extends Net_SMS { $headers['From'] = $this->_params['user']; $to = $matches[2] . '@sms.vodafone.it'; - $mailer = Mail::factory('mail'); - $result = $mailer->send($to, $headers, $message['text']); - if (is_a($result, 'PEAR_Error')) { - return array(0, $result->getMessage()); - } else { + try { + Horde_Mail::factory('Mail')->send($to, $headers, $message['text']); return array(1, null); + } catch (Horde_Mail_Exception $e) { + return array(0, $e->getMessage()); } } else { return array(0, _("You need to provide an Italian phone number")); diff --git a/framework/Net_SMS/package.xml b/framework/Net_SMS/package.xml index c2dd1ab1d..0ce91b7d4 100644 --- a/framework/Net_SMS/package.xml +++ b/framework/Net_SMS/package.xml @@ -7,7 +7,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> pear.php.net SMS functionality. This package provides SMS functionality and access to SMS gateways. - Marko Djukic @@ -74,7 +73,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> Mail - pear.php.net + pear.horde.org Net_SMPP_Client diff --git a/framework/Prefs/lib/Horde/Prefs/Identity.php b/framework/Prefs/lib/Horde/Prefs/Identity.php index 39f771da5..66cde77af 100644 --- a/framework/Prefs/lib/Horde/Prefs/Identity.php +++ b/framework/Prefs/lib/Horde/Prefs/Identity.php @@ -431,7 +431,7 @@ class Horde_Prefs_Identity $body->setContents(Horde_String::wrap($message, 76, "\n")); $body->setCharset(Horde_Nls::getCharset()); - $body->send($new_addr, $msg_headers, $GLOBALS['injector']->getInstance('Mail')); + $body->send($new_addr, $msg_headers, $GLOBALS['injector']->getInstance('Horde_Mail')); return new Horde_Notification_Event(sprintf(_("A message has been sent to \"%s\" to verify that this is really your address. The new email address is activated as soon as you confirm this message."), $new_addr)); } diff --git a/framework/iCalendar/iCalendar/vcard.php b/framework/iCalendar/iCalendar/vcard.php index ef7f284bd..bc4d3338f 100644 --- a/framework/iCalendar/iCalendar/vcard.php +++ b/framework/iCalendar/iCalendar/vcard.php @@ -132,15 +132,10 @@ class Horde_iCalendar_vcard extends Horde_iCalendar { return $address; } - static $rfc822; - if (is_null($rfc822)) { - $rfc822 = new Mail_RFC822(); - } - - if (!$rfc822->validateMailbox($address)) { - return $address; - } - return Horde_Mime_Address::writeAddress($address->mailbox, $address->host); + $rfc822 = new Horde_Mail_Rfc822(); + return $rfc822->validateMailbox($address) + ? Horde_Mime_Address::writeAddress($address->mailbox, $address->host) + : $address; } } diff --git a/framework/iCalendar/package.xml b/framework/iCalendar/package.xml index a90070e65..edda95d7e 100644 --- a/framework/iCalendar/package.xml +++ b/framework/iCalendar/package.xml @@ -105,6 +105,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> 1.5.4 + Mail + pear.horde.org + + Util pear.horde.org diff --git a/horde/config/hooks.php.dist b/horde/config/hooks.php.dist index ac3f0d2c7..f23be3aae 100644 --- a/horde/config/hooks.php.dist +++ b/horde/config/hooks.php.dist @@ -508,8 +508,7 @@ class Horde_Hooks // "\n" . // sprintf(_("You can approve this signup at %s"), Horde::applicationUrl('admin/user.php', true, -1)); // -// $mailer = Mail::factory($GLOBALS['conf']['mailer']['type'], $GLOBALS['conf']['mailer']['params']); -// $mailer->send($_SERVER['SERVER_ADMIN'], $headers, $msg); +// $GLOBALS['injector']->getInstance('Horde_Mail')->send($_SERVER['SERVER_ADMIN'], $headers, $msg); // } // // // Helper function for signup_queued Example #1 diff --git a/horde/docs/CHANGES b/horde/docs/CHANGES index 1ca6fa619..16a952f7b 100644 --- a/horde/docs/CHANGES +++ b/horde/docs/CHANGES @@ -2,6 +2,7 @@ v4.0-cvs -------- +[mms] Remove reliance on PEAR Mail library. [jan] Send alarm emails again if the alarm has changed (Bug #8717). [mms] Add advanced preferences options screen. [mms] Complete rewrite of options UI display. diff --git a/horde/docs/INSTALL b/horde/docs/INSTALL index 8642d0f03..30e57b3da 100644 --- a/horde/docs/INSTALL +++ b/horde/docs/INSTALL @@ -86,8 +86,7 @@ below at Prerequisites_. 3. Install PEAR/PECL packages:: - pear install -o Crypt_Blowfish Date DB File Mail Net_DNS \ - Services_Weather + pear install -o Crypt_Blowfish Date DB File Net_DNS Services_Weather pear -d preferred_state=beta install -a HTTP_WebDAV_Server pecl install -o fileinfo idn lzf [memcache] @@ -321,12 +320,6 @@ The following prerequisites are **REQUIRED** for Horde to function properly. pear install Crypt_Blowfish - b. Mail (>= 1.2.0) - - To install, enter the following at the command prompt:: - - pear install Mail - These PEAR modules are **RECOMMENDED** to be installed: a. Date diff --git a/horde/docs/UPGRADING b/horde/docs/UPGRADING index 854e0e55e..541da148a 100644 --- a/horde/docs/UPGRADING +++ b/horde/docs/UPGRADING @@ -41,7 +41,6 @@ The following hooks have changed: Horde_Alarm is using UTC dates now. -Mail 1.2.0 is minimum version. Crypt_Blowfish is required. diff --git a/horde/lib/Test.php b/horde/lib/Test.php index 1e265dc8a..207c448d2 100644 --- a/horde/lib/Test.php +++ b/horde/lib/Test.php @@ -291,11 +291,6 @@ class Horde_Test 'HTTP_WebDAV_Server' => array( 'error' => 'The HTTP_WebDAV_Server is required if you want to use the WebDAV interface of Horde, e.g. to access calendars or tasklists with external clients.' ), - 'Mail' => array( - 'path' => 'Mail/RFC822.php', - 'error' => 'You do not have the Mail package installed on your system. See the INSTALL file for instructions on how to install the package.', - 'required' => true - ), 'MDB2' => array( 'error' => 'You will need MDB2 if you are using the SQL driver for Shares.', ), diff --git a/horde/rpc.php b/horde/rpc.php index 709d76bd6..5068914c3 100644 --- a/horde/rpc.php +++ b/horde/rpc.php @@ -49,7 +49,7 @@ if ((!empty($_SERVER['CONTENT_TYPE']) && } else { $params['logger'] = $GLOBALS['injector']->getInstance('Horde_Log_Logger'); } - $mailer = $GLOBALS['injector']->getInstance('Mail'); + $mailer = $GLOBALS['injector']->getInstance('Horde_Mail'); /* TODO: Probably want to bind a factory to injector for this? */ $params['registry'] = $GLOBALS['registry']; diff --git a/horde/services/problem.php b/horde/services/problem.php index 85f7984dd..58eacd1fd 100644 --- a/horde/services/problem.php +++ b/horde/services/problem.php @@ -112,7 +112,7 @@ case 'send_problem_report': } try { - $mail->send($GLOBALS['injector']->getInstance('Mail')); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); /* We succeeded. */ Horde::logMessage( diff --git a/horde/services/resetpassword.php b/horde/services/resetpassword.php index ee12a5099..7dac226ce 100644 --- a/horde/services/resetpassword.php +++ b/horde/services/resetpassword.php @@ -77,7 +77,7 @@ if ($can_validate && $form->validate($vars)) { 'from' => $email, 'charset' => Horde_Nls::getCharset())); try { - $mail->send($GLOBALS['injector']->getInstance('Mail')); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); $notification->push(_("Your password has been reset, check your email and log in with your new password."), 'horde.success'); header('Location: ' . Horde::getServiceLink('login')->add('url', $info['url'])->setRaw(true)); exit; diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index d93f690b1..64e6a237d 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,8 @@ v5.0-git -------- +[mms] Pass compose message data to mailer backend via stream; much more + efficient, especially with larger messages (Request #8909). [mms] Add strip attachments support in DIMP. [mms] Add PGP & S/MIME compose support to DIMP. [mms] Check for incorrect identity on compose if a single recipient address diff --git a/imp/lib/Application.php b/imp/lib/Application.php index 96998b7af..820bd2ed7 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -95,6 +95,7 @@ class IMP_Application extends Horde_Registry_Application 'IMP_Identity' => new IMP_Injector_Binder_Identity(), 'IMP_Imap' => new IMP_Injector_Binder_Imap(), 'IMP_Imap_Tree' => new IMP_Injector_Binder_Imaptree(), + 'IMP_Mail' => new IMP_Injector_Binder_Mail(), 'IMP_Mailbox' => new IMP_Injector_Binder_Mailbox(), 'IMP_Quota' => new IMP_Injector_Binder_Quota(), 'IMP_Search' => new IMP_Injector_Binder_Search(), diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 8777b8e86..63fcbeafa 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -726,10 +726,9 @@ class IMP_Compose public function sendMessage($email, $headers, $message) { $email = $this->_prepSendMessage($email, $headers, $message); - $mailer = $this->getMailOb(); try { - $message->send($email, $headers, $mailer); + $message->send($email, $headers, $GLOBALS['injector']->getInstance('IMP_Mail')); } catch (Horde_Mime_Exception $e) { throw new IMP_Compose_Exception($e); } @@ -1626,15 +1625,13 @@ class IMP_Compose $header_text = trim($resent_headers->toString(array('encode' => Horde_Nls::getCharset()))) . "\n" . trim($contents->getHeaderOb(false)); - $mailer = $this->getMailOb(array( - 'raw' => array('from' => $headers->getValue('from'), 'headertext' => $header_text) - )); - $to = $this->_prepSendMessage($recipients); + $hdr_array = $headers->toArray(array('charset' => Horde_Nls::getCharset())); + $hdr_array['_raw'] = $header_text; try { - Horde_Mime_Mail::sendPearMail($mailer, $to, $headers->toArray(array('charset' => Horde_Nls::getCharset())), $contents->getBody()); - } catch (Horde_Mime_Exception $e) { + $GLOBALS['injector']->getInstance('IMP_Mail')->send($to, $hdr_array, $contents->getBody()); + } catch (Horde_Mail_Exception $e) { throw new IMP_Compose_Exception($e); } @@ -2701,62 +2698,6 @@ class IMP_Compose /* Static utility functions. */ /** - * Return mail driver/params necessary to send a message. - * - * @return array 'driver' => mail driver; 'params' => list of params. - */ - static public function getMailDriver() - { - /* We don't actually want to alter the contents of the $conf['mailer'] - * array, so we make a copy of the current settings. We will apply our - * modifications (if any) to the copy, instead. */ - $params = $GLOBALS['conf']['mailer']['params']; - - /* Force the SMTP host and port value to the current SMTP server if - * one has been selected for this connection. */ - if (!empty($_SESSION['imp']['smtp'])) { - $params = array_merge($params, $_SESSION['imp']['smtp']); - } - - /* If SMTP authentication has been requested, use either the username - * and password provided in the configuration or populate the username - * and password fields based on the current values for the user. Note - * that we assume that the username and password values from the - * current IMAP / POP3 connection are valid for SMTP authentication as - * well. */ - if (!empty($params['auth']) && empty($params['username'])) { - $imap_ob = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb(); - $params['username'] = $imap_ob->getParam('username'); - $params['password'] = $imap_ob->getParam('password'); - } - - return array( - 'driver' => $GLOBALS['conf']['mailer']['type'], - 'params' => $params - ); - } - - /** - * Return a Mail object with the current driver parameters. - * - * @param array $options Additional options to pass to - * Horde_Mime_Mail::getMailOb(). - * - * @return Mail A Mail object. - * @throws IMP_Compose_Exception - */ - static public function getMailOb($options = array()) - { - $mail_driver = self::getMailDriver(); - - try { - return Horde_Mime_Mail::getMailOb($mail_driver['driver'], $mail_driver['params'], $options); - } catch (Horde_Mime_Exception $e) { - throw new IMP_Compose_Exception($e); - } - } - - /** * Formats the address properly. * * @param string $addr The address to format. diff --git a/imp/lib/Injector/Binder/Mail.php b/imp/lib/Injector/Binder/Mail.php new file mode 100644 index 000000000..592f0fd53 --- /dev/null +++ b/imp/lib/Injector/Binder/Mail.php @@ -0,0 +1,52 @@ + + * @package IMP + */ +class IMP_Injector_Binder_Mail implements Horde_Injector_Binder +{ + /** + */ + public function create(Horde_Injector $injector) + { + /* We don't actually want to alter the contents of the $conf['mailer'] + * array, so we make a copy of the current settings. We will apply our + * modifications (if any) to the copy, instead. */ + $params = $GLOBALS['conf']['mailer']['params']; + + /* Force the SMTP host and port value to the current SMTP server if + * one has been selected for this connection. */ + if (!empty($_SESSION['imp']['smtp'])) { + $params = array_merge($params, $_SESSION['imp']['smtp']); + } + + /* If SMTP authentication has been requested, use either the username + * and password provided in the configuration or populate the username + * and password fields based on the current values for the user. Note + * that we assume that the username and password values from the + * current IMAP / POP3 connection are valid for SMTP authentication as + * well. */ + if (!empty($params['auth']) && empty($params['username'])) { + $imap_ob = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb(); + $params['username'] = $imap_ob->getParam('username'); + $params['password'] = $imap_ob->getParam('password'); + } + + return Horde_Mail::factory($GLOBALS['conf']['mailer']['type'], $params); + } + + /** + */ + public function equals(Horde_Injector_Binder $binder) + { + return false; + } + +} diff --git a/imp/lib/Mime/Viewer/Itip.php b/imp/lib/Mime/Viewer/Itip.php index d45172ebc..ade038c29 100644 --- a/imp/lib/Mime/Viewer/Itip.php +++ b/imp/lib/Mime/Viewer/Itip.php @@ -343,8 +343,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver // Send the reply. try { - $mailer = IMP_Compose::getMailOb(); - $mime->send($organizerEmail, $msg_headers, $mailer); + $mime->send($organizerEmail, $msg_headers, $GLOBALS['injector']->getInstance('IMP_Mail')); $msgs[] = array('success', _("Reply Sent.")); } catch (Exception $e) { $msgs[] = array('error', sprintf(_("Error sending reply: %s."), $e->getMessage())); @@ -444,8 +443,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver // Send the reply. try { - $mailer = IMP_Compose::getMailOb(); - $mime->send($organizerEmail, $msg_headers, $mailer); + $mime->send($organizerEmail, $msg_headers, $GLOBALS['injector']->getInstance('IMP_Mail')); $msgs[] = array('success', _("Reply Sent.")); } catch (Exception $e) { $msgs[] = array('error', sprintf(_("Error sending reply: %s."), $e->getMessage())); diff --git a/imp/lib/Ui/Message.php b/imp/lib/Ui/Message.php index acb304449..6120f2c25 100644 --- a/imp/lib/Ui/Message.php +++ b/imp/lib/Ui/Message.php @@ -117,8 +117,7 @@ class IMP_Ui_Message /* Send out the MDN now. */ try { - $mailer = IMP_Compose::getMailOb(); - $mdn->generate(false, $confirmed, 'displayed', $GLOBALS['conf']['server']['name'], $mailer); + $mdn->generate(false, $confirmed, 'displayed', $GLOBALS['conf']['server']['name'], $GLOBALS['injector']->getInstance('IMP_Mail')); IMP_Maillog::log('mdn', $msg_id, 'displayed'); $success = true; diff --git a/kronolith/lib/FreeBusy.php b/kronolith/lib/FreeBusy.php index 073c4afd9..3425f0daf 100644 --- a/kronolith/lib/FreeBusy.php +++ b/kronolith/lib/FreeBusy.php @@ -135,17 +135,17 @@ class Kronolith_FreeBusy */ public static function get($email, $json = false) { - /* Properly handle RFC822-compliant email addresses. */ - static $rfc822; - if (is_null($rfc822)) { - $rfc822 = new Mail_RFC822(); - } - $default_domain = empty($GLOBALS['conf']['storage']['default_domain']) ? null : $GLOBALS['conf']['storage']['default_domain']; - $res = $rfc822->parseAddressList($email, $default_domain); - if ($res instanceof PEAR_Error) { - throw new Kronolith_Exception($res); + $rfc822 = new Horde_Mail_Rfc822(); + + try { + $res = $rfc822->parseAddressList($email, array( + 'default_domain' => $default_domain + )); + } catch (Horde_Mail_Exception $e) { + throw new Kronolith_Exception($e); } + if (!count($res)) { throw new Kronolith_Exception(_("No valid email address found")); } diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 28db1dfc1..1417d44a9 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -1901,24 +1901,30 @@ class Kronolith return; } - $parser = new Mail_RFC822; + $parser = new Horde_Mail_Rfc822(); $attendees = array(); + foreach (Horde_Mime_Address::explode($newAttendees) as $newAttendee) { // Parse the address without validation to see what we can get out // of it. We allow email addresses (john@example.com), email // address with user information (John Doe ), // and plain names (John Doe). - $newAttendeeParsed = $parser->parseAddressList($newAttendee, '', - false, false); + try { + $newAttendeeParsed = $parser->parseAddressList($newAttendee, array( + 'default_domain' => null, + 'nest_groups' => false, + 'validate' => false + )); + $error = (!isset($newAttendeeParsed[0]) || !isset($newAttendeeParsed[0]->mailbox)); + } catch (Horde_Mail_Exception $e) { + $error = true; + } // If we can't even get a mailbox out of the address, then it is // likely unuseable. Reject it entirely. - if ($newAttendeeParsed instanceof PEAR_Error || - !isset($newAttendeeParsed[0]) || - !isset($newAttendeeParsed[0]->mailbox)) { + if ($error) { $notification->push( - sprintf(_("Unable to recognize \"%s\" as an email address."), - $newAttendee), + sprintf(_("Unable to recognize \"%s\" as an email address."), $newAttendee), 'horde.error'); continue; } @@ -1943,7 +1949,9 @@ class Kronolith try { $newAttendeeParsedPartNew = Horde_Mime::encodeAddress(Horde_Mime_Address::writeAddress($newAttendeeParsedPart->mailbox, $newAttendeeParsedPart->host, $name)); - $newAttendeeParsedPartValidated = $parser->parseAddressList($newAttendeeParsedPartNew, '', null, true); + $newAttendeeParsedPartValidated = $parser->parseAddressList($newAttendeeParsedPartNew, array( + 'default_domain' => null + )); $email = $newAttendeeParsedPart->mailbox . '@' . $newAttendeeParsedPart->host; @@ -2129,7 +2137,7 @@ class Kronolith $mail->setBasePart($multipart); try { - $mail->send($GLOBALS['injector']->getInstance('Mail')); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); $notification->push( sprintf(_("The event notification to %s was successfully sent."), $recipient), 'horde.success' @@ -2261,7 +2269,7 @@ class Kronolith $mime_mail->addHeader('User-Agent', 'Kronolith ' . $GLOBALS['registry']->getVersion()); $mime_mail->setBody($message, Horde_Nls::getCharset(), true); Horde::logMessage(sprintf('Sending event notifications for %s to %s', $event->title, implode(', ', $df_recipients)), 'DEBUG'); - $mime_mail->send($GLOBALS['injector']->getInstance('Mail'), false, false); + $mime_mail->send($GLOBALS['injector']->getInstance('Horde_Mail'), false, false); } } } diff --git a/kronolith/scripts/agenda.php b/kronolith/scripts/agenda.php index d3f7c6eb1..d260db56a 100755 --- a/kronolith/scripts/agenda.php +++ b/kronolith/scripts/agenda.php @@ -157,7 +157,7 @@ function send_agendas() } catch (Horde_Mime_Exception $e) {} Horde::logMessage(sprintf('Sending daily agenda to %s', $email), 'DEBUG'); try { - $mime_mail->send($GLOBALS['injector']->getInstance('Mail'), false, false); + $mime_mail->send($GLOBALS['injector']->getInstance('Horde_Mail'), false, false); } catch (Horde_Mime_Exception $e) {} } } diff --git a/nag/lib/Nag.php b/nag/lib/Nag.php index f13491dac..473d323dc 100644 --- a/nag/lib/Nag.php +++ b/nag/lib/Nag.php @@ -1036,7 +1036,7 @@ class Nag Horde::logMessage(sprintf('Sending event notifications for %s to %s', $task->name, implode(', ', $df_recipients)), 'INFO'); - $mail->send($GLOBALS['injector']->getInstance('Mail')); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } } } diff --git a/news/mail.php b/news/mail.php index f89486d01..19a9eae4c 100644 --- a/news/mail.php +++ b/news/mail.php @@ -55,7 +55,7 @@ $body = sprintf(_("%s would you like to invite you to read the news\n Title: %s\ $mail = new Horde_Mime_Mail(array('subject' => $row['title'], 'body' => $body, 'to' => $to, 'from' => $from, 'charset' => Horde_Nls::getCharset())); try { - $mail->send($GLOBALS['injector']->getInstance('Mail')); + $mail->send($injector->getInstance('Horde_Mail')); $notification->push(sprintf(_("News succesfully send to %s"), $to), 'horde.success'); } catch (Horde_Mime_Exception $e) { $notification->push($e); diff --git a/turba/data.php b/turba/data.php index 1c88379f3..42e493087 100644 --- a/turba/data.php +++ b/turba/data.php @@ -54,10 +54,7 @@ function _getBareEmail($address, $allow_multi = false) return $address; } - static $rfc822; - if (is_null($rfc822)) { - $rfc822 = new Mail_RFC822(); - } + $rfc822 = new Horde_Mail_Rfc822(); // Split multiple email addresses if ($allow_multi) { diff --git a/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php b/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php index e4f040e28..e00b02136 100755 --- a/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php +++ b/turba/scripts/upgrades/2.1_to_2.2_sql_schema.php @@ -291,11 +291,7 @@ function getBareEmail($address) return $address; } - static $rfc822; - if (is_null($rfc822)) { - $rfc822 = new Mail_RFC822(); - } - + $rfc822 = new Horde_Mail_Rfc822(); $rfc822->validateMailbox($address); return Horde_Mime_Address::writeAddress($address->mailbox, $address->host); } diff --git a/whups/lib/Driver.php b/whups/lib/Driver.php index b590dc1c3..9b9827038 100644 --- a/whups/lib/Driver.php +++ b/whups/lib/Driver.php @@ -450,8 +450,9 @@ class Whups_Driver { continue; } - $addr_arr = Horde_Mime_Address::parseAddressList($to); - if (!is_a($addr_arr, 'PEAR_Error') && isset($addr_arr[0])) { + try { + $addr_arr = Horde_Mime_Address::parseAddressList($to); + if (isset($addr_arr[0])) { $bare_address = strtolower($addr_arr[0]['mailbox'] . '@' . $addr_arr[0]['host']); if (!empty($seen_email_addresses[$bare_address])) { continue; @@ -461,7 +462,7 @@ class Whups_Driver { if (empty($full_name) && isset($addr_arr[0]['personal'])) { $full_name = $addr_arr[0]['personal']; } - } + } catch (Horde_Mime_Exception $e) {} // use email address as fallback if (empty($full_name)) { @@ -489,7 +490,7 @@ class Whups_Driver { $mail->addHeader('To', $to, Horde_Nls::getCharset()); try { - $mail->send($GLOBALS['injector']->getInstance('Mail'), true); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'), true); $entry = sprintf('%s Message sent to %s from "%s"', $_SERVER['REMOTE_ADDR'], $to, Horde_Auth::getAuth()); diff --git a/wicked/lib/Wicked.php b/wicked/lib/Wicked.php index 8c0b86506..76972f3ff 100644 --- a/wicked/lib/Wicked.php +++ b/wicked/lib/Wicked.php @@ -187,7 +187,7 @@ class Wicked { $mail->addHeader($hkey, $headers[$hkey]); } try { - $mail->send($GLOBALS['injector']->getInstance('Mail')); + $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } catch (Horde_Mime_Exception $e) { $GLOBALS['notification']->push($e); } -- 2.11.0