From 4e8e3e4474fc5ea4363ff940e0ee96f84767b343 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 24 Mar 2010 12:19:09 -0600 Subject: [PATCH] Add Mail binder. Concurrently, require a Mail object to be passed into Horde_Mime functions. Reorganize code a bit in there and provide a helper function (Horde_Mime_Mail::sendPearMail) that will parse PEAR_Error information as needed. --- agora/messages/abuse.php | 2 +- ansel/img/ecard.php | 2 +- ansel/lib/Report/mail.php | 2 +- folks/lib/Folks.php | 2 +- folks/lib/Notification/mail.php | 4 +- framework/Alarm/lib/Horde/Alarm.php | 2 +- framework/Auth/lib/Horde/Auth/Signup.php | 2 +- framework/Core/lib/Horde.php | 18 ----- framework/Core/lib/Horde/Core/Binder/Mail.php | 28 +++++++ framework/Core/lib/Horde/Registry.php | 1 + framework/Core/package.xml | 2 + framework/Mime/lib/Horde/Mime/Mail.php | 102 ++++++++++++++++---------- framework/Mime/lib/Horde/Mime/Part.php | 26 ++----- framework/Mime/test/Horde/Mime/mail_001.phpt | 4 +- framework/Mime/test/Horde/Mime/mail_002.phpt | 4 +- framework/Mime/test/Horde/Mime/mail_003.phpt | 5 +- framework/Mime/test/Horde/Mime/mail_004.phpt | 4 +- framework/Mime/test/Horde/Mime/mail_005.phpt | 5 +- framework/Mime/test/Horde/Mime/mail_006.phpt | 4 +- framework/Mime/test/Horde/Mime/mail_007.phpt | 12 ++- framework/Mime/test/Horde/Mime/mail_008.phpt | 4 +- framework/Mime/test/Horde/Mime/mail_dummy.inc | 7 +- framework/Release/lib/Horde/Release.php | 7 +- horde/services/problem.php | 2 +- horde/services/resetpassword.php | 2 +- imp/lib/Compose.php | 55 ++++++++++---- kronolith/lib/Kronolith.php | 4 +- kronolith/scripts/agenda.php | 2 +- nag/lib/Nag.php | 5 +- news/mail.php | 8 +- whups/lib/Driver.php | 2 +- wicked/lib/Wicked.php | 6 +- 32 files changed, 202 insertions(+), 133 deletions(-) create mode 100644 framework/Core/lib/Horde/Core/Binder/Mail.php diff --git a/agora/messages/abuse.php b/agora/messages/abuse.php index 111527e96..5c4bb7691 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(Horde::getMailerConfig()); + $mail->send($injector->getInstance('Mail')); $notification->push($subject, 'horde.success'); header('Location: ' . $url); diff --git a/ansel/img/ecard.php b/ansel/img/ecard.php index 14a62efaf..f5f9efaa0 100644 --- a/ansel/img/ecard.php +++ b/ansel/img/ecard.php @@ -83,7 +83,7 @@ case 'send': $alt->setBasePart($alternative); /* Send. */ - $result = $alt->send(Horde::getMailerConfig()); + $result = $alt->send($injector->getInstance('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 853a91617..0db2997fa 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(Horde::getMailerConfig()); + return $mail->send($GLOBALS['injector']->getInstance('Mail')); } } diff --git a/folks/lib/Folks.php b/folks/lib/Folks.php index c19a5b9f3..6a84b061d 100644 --- a/folks/lib/Folks.php +++ b/folks/lib/Folks.php @@ -247,7 +247,7 @@ class Folks { } } - return $mail->send(Horde::getMailerConfig()); + return $mail->send($GLOBALS['injector']->getInstance('Mail')); } /** diff --git a/folks/lib/Notification/mail.php b/folks/lib/Notification/mail.php index c1f0c0243..64ff85439 100644 --- a/folks/lib/Notification/mail.php +++ b/folks/lib/Notification/mail.php @@ -54,8 +54,6 @@ class Folks_Notification_mail extends Folks_Notification { return true; } - list($mail_driver, $mail_params) = Horde::getMailerConfig(); - $mail = new Horde_Mime_Mail(array('subject' => $subject, 'body' => $body, 'from' => $this->_params['from_addr'], @@ -81,7 +79,7 @@ class Folks_Notification_mail extends Folks_Notification { continue; } $mail->addHeader('To', $to, Horde_Nls::getCharset(), true); - $mail->send($mail_driver, $mail_params); + $mail->send($GLOBALS['injector']->getInstance('Mail')); } return true; diff --git a/framework/Alarm/lib/Horde/Alarm.php b/framework/Alarm/lib/Horde/Alarm.php index 4423b47e0..1c951ef60 100644 --- a/framework/Alarm/lib/Horde/Alarm.php +++ b/framework/Alarm/lib/Horde/Alarm.php @@ -464,7 +464,7 @@ class Horde_Alarm )); $mail->addHeader('Auto-Submitted', 'auto-generated'); $mail->addHeader('X-Horde-Alarm', $alarm['title'], Horde_Nls::getCharset()); - $sent = $mail->send(Horde::getMailerConfig()); + $mail->send($GLOBALS['injector']->getInstance('Mail')); $alarm['internal']['mail']['sent'] = true; $this->_internal($alarm['id'], $alarm['user'], $alarm['internal']); diff --git a/framework/Auth/lib/Horde/Auth/Signup.php b/framework/Auth/lib/Horde/Auth/Signup.php index cd81cba84..4b8675490 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(Horde::getMailerConfig()); + $mail->send($GLOBALS['injector']->getInstance('Mail')); } } diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 5ee01e541..3fe74d85f 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -843,24 +843,6 @@ HTML; } /** - * Return the driver and parameters for the current mailer configuration. - * - * @return array Array with driver name and parameter hash. - */ - static public function getMailerConfig() - { - $mail_driver = $GLOBALS['conf']['mailer']['type']; - $mail_params = $GLOBALS['conf']['mailer']['params']; - if ($mail_driver == 'smtp' && $mail_params['auth'] && - empty($mail_params['username'])) { - $mail_params['username'] = Horde_Auth::getAuth(); - $mail_params['password'] = Horde_Auth::getCredential('password'); - } - - return array('type' => $mail_driver, 'params' => $mail_params); - } - - /** * Checks if all necessary parameters for a driver configuration * are set and throws a fatal error with a detailed explanation * how to fix this, if something is missing. diff --git a/framework/Core/lib/Horde/Core/Binder/Mail.php b/framework/Core/lib/Horde/Core/Binder/Mail.php new file mode 100644 index 000000000..cb0f92f11 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Binder/Mail.php @@ -0,0 +1,28 @@ + 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/Core/package.xml b/framework/Core/package.xml index 48e504638..b8f9be488 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -70,6 +70,7 @@ Application Framework. + @@ -203,6 +204,7 @@ Application Framework. + diff --git a/framework/Mime/lib/Horde/Mime/Mail.php b/framework/Mime/lib/Horde/Mime/Mail.php index 7a439e6d1..cb6d2801d 100644 --- a/framework/Mime/lib/Horde/Mime/Mail.php +++ b/framework/Mime/lib/Horde/Mime/Mail.php @@ -401,20 +401,14 @@ class Horde_Mime_Mail /** * Sends this message. * - * For the possible Mail drivers and parameters see the PEAR Mail - * documentation. - * @link http://pear.php.net/Mail - * - * @param array $config A hash with the Mail driver to use in 'type' and - * any parameters necessary for the Mail driver in - * 'params'. + * @param Mail $mailer A Mail object. * @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. * * @throws Horde_Mime_Exception */ - public function send($config, $resend = false, $flowed = true) + public function send($mailer, $resend = false, $flowed = true) { /* Add mandatory headers if missing. */ $has_header = $this->_headers->getValue('Message-ID'); @@ -475,80 +469,108 @@ class Horde_Mime_Mail } } - /* Check mailer configuration. */ - if (!empty($config['type'])) { - $this->_mailer_driver = $config['type']; - } - if (!empty($config['params'])) { - $this->_mailer_params = $config['params']; - } - /* Send message. */ return $basepart->send(implode(', ', $this->_recipients), - $this->_headers, $this->_mailer_driver, - $this->_mailer_params); + $this->_headers, $mailer); } /** - * Return error string corresponding to a sendmail error code. + * Utility function to send a message using a PEAR Mail driver. Handles + * errors from this class. * - * @param integer $code The error code. + * @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. * - * @return string The error string, or null if the code is unknown. + * @throws Horde_Mime_Exception */ - static public function sendmailError($code) + static public function sendPearMail($mailer, $email, $headers, $msg) { - switch ($code) { + $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 - return 'sendmail: ' . _("command line usage error") . ' (64)'; + $msg = 'command line usage error'; + break; case 65: // EX_DATAERR - return 'sendmail: ' . _("data format error") . ' (65)'; + $msg = 'data format error'; + break; case 66: // EX_NOINPUT - return 'sendmail: ' . _("cannot open input") . ' (66)'; + $msg = 'cannot open input'; + break; case 67: // EX_NOUSER - return 'sendmail: ' . _("addressee unknown") . ' (67)'; + $msg = 'addressee unknown'; + break; case 68: // EX_NOHOST - return 'sendmail: ' . _("host name unknown") . ' (68)'; + $msg = 'host name unknown'; + break; case 69: // EX_UNAVAILABLE - return 'sendmail: ' . _("service unavailable") . ' (69)'; + $msg = 'service unavailable'; + break; case 70: // EX_SOFTWARE - return 'sendmail: ' . _("internal software error") . ' (70)'; + $msg = 'internal software error'; + break; case 71: // EX_OSERR - return 'sendmail: ' . _("system error") . ' (71)'; + $msg = 'system error'; + break; case 72: // EX_OSFILE - return 'sendmail: ' . _("critical system file missing") . ' (72)'; + $msg = 'critical system file missing'; + break; case 73: // EX_CANTCREAT - return 'sendmail: ' . _("cannot create output file") . ' (73)'; + $msg = 'cannot create output file'; + break; case 74: // EX_IOERR - return 'sendmail: ' . _("input/output error") . ' (74)'; + $msg = 'input/output error'; + break; case 75: // EX_TEMPFAIL - return 'sendmail: ' . _("temporary failure") . ' (75)'; + $msg = 'temporary failure'; + break; case 76: // EX_PROTOCOL - return 'sendmail: ' . _("remote error in protocol") . ' (76)'; + $msg = 'remote error in protocol'; + break; case 77: // EX_NOPERM - return 'sendmail: ' . _("permission denied") . ' (77)'; + $msg = 'permission denied'; + break; + + case 77: // EX_NOPERM + $msg = 'permission denied'; + break; case 78: // EX_CONFIG - return 'sendmail: ' . _("configuration error") . ' (78)'; + $msg = 'configuration error'; + break; case 79: // EX_NOTFOUND - return 'sendmail: ' . _("entry not found") . ' (79)'; + $msg = 'entry not found'; + break; default: - return null; + throw new Horde_Mime_Exception($result); } + + throw new Horde_Mime_Exception('sendmail: ' . $msg . ' (' . $result->getCode() . ')'); } + } diff --git a/framework/Mime/lib/Horde/Mime/Part.php b/framework/Mime/lib/Horde/Mime/Part.php index dd3731e78..68d164d4f 100644 --- a/framework/Mime/lib/Horde/Mime/Part.php +++ b/framework/Mime/lib/Horde/Mime/Part.php @@ -1440,17 +1440,15 @@ 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 string $driver The Mail:: driver to use. - * @param array $params Any parameters necessary for the - * Mail driver. + * @param Mail $mailer A Mail driver. * * @throws Horde_Mime_Exception + * @throws InvalidArgumentException */ - public function send($email, $headers, $driver, $params = array()) + public function send($email, $headers, $mailer) { - $mailer = Mail::factory($driver, $params); - if ($mailer instanceof PEAR_Error) { - throw new Horde_Mime_Exception($mailer); + if (!($mailer instanceof Mail)) { + throw new InvalidArgumentException('Invalid Mail object passed to send().'); } $old_basepart = $this->_basepart; @@ -1460,7 +1458,7 @@ class Horde_Mime_Part * BINARYMIME (RFC 3030) extensions? Requires PEAR's Mail package * version 1.2+ and Net_SMTP version 1.3+. */ $encode = self::ENCODE_7BIT; - if ($driver == 'smtp') { + if ($mailer instanceof Mail_smtp) { $net_smtp = $mailer->getSMTPObject(); if (!($net_smtp instanceof PEAR_Error)) { $smtp_ext = $net_smtp->getServiceExtensions(); @@ -1497,19 +1495,9 @@ class Horde_Mime_Part } } - $result = $mailer->send(Horde_Mime::encodeAddress($email, $this->getCharset()), $headers->toArray(array('charset' => $this->getHeaderCharset())), $msg); - $this->_basepart = $old_basepart; - if (($result instanceof PEAR_Error) && ($driver == 'sendmail')) { - $error = Horde_Mime_Mail::sendmailError($result->getCode()); - if (is_null($error)) { - $error = $result; - } - throw new Horde_Mime_Exception($error); - } - - return $result; + Horde_Mime_Mail::sendPearMail($mailer, Horde_Mime::encodeAddress($email, $this->getCharset()), $headers->toArray(array('charset' => $this->getHeaderCharset())), $msg); } /** diff --git a/framework/Mime/test/Horde/Mime/mail_001.phpt b/framework/Mime/test/Horde/Mime/mail_001.phpt index 37a4b16e0..25c21e2e5 100644 --- a/framework/Mime/test/Horde/Mime/mail_001.phpt +++ b/framework/Mime/test/Horde/Mime/mail_001.phpt @@ -12,7 +12,9 @@ $mail = new Horde_Mime_Mail(array('subject' => 'My Subject', 'to' => 'recipient@example.com', 'from' => 'sender@example.com', 'charset' => 'iso-8859-15')); -echo $mail->send(array('type' => 'dummy')); +$dummy = Mail::factory('dummy'); +$mail->send($dummy); +echo $dummy->send_output; ?> --EXPECTF-- diff --git a/framework/Mime/test/Horde/Mime/mail_002.phpt b/framework/Mime/test/Horde/Mime/mail_002.phpt index 4d4bca4db..8df2e23d8 100644 --- a/framework/Mime/test/Horde/Mime/mail_002.phpt +++ b/framework/Mime/test/Horde/Mime/mail_002.phpt @@ -16,7 +16,9 @@ $mail->addHeader('Bcc', 'invisible@example.com'); $mail->addHeader('From', 'sender@example.com'); $mail->removeHeader('Cc'); -echo $mail->send(array('type' => 'dummy')); +$dummy = Mail::factory('dummy'); +$mail->send($dummy); +echo $dummy->send_output; ?> --EXPECTF-- diff --git a/framework/Mime/test/Horde/Mime/mail_003.phpt b/framework/Mime/test/Horde/Mime/mail_003.phpt index d992ccdfa..dfd2c24b4 100644 --- a/framework/Mime/test/Horde/Mime/mail_003.phpt +++ b/framework/Mime/test/Horde/Mime/mail_003.phpt @@ -14,7 +14,10 @@ $mail = new Horde_Mime_Mail(array('subject' => 'Sch 'from' => 'sender@example.com', 'charset' => 'iso-8859-1')); $mail->addHeader('Cc', 'Der schöne Peter ', 'iso-8859-15'); -echo $mail->send(array('type' => 'dummy')); + +$dummy = Mail::factory('dummy'); +$mail->send($dummy); +echo $dummy->send_output; ?> --EXPECTF-- diff --git a/framework/Mime/test/Horde/Mime/mail_004.phpt b/framework/Mime/test/Horde/Mime/mail_004.phpt index cbb6dfa7c..e4d340dd8 100644 --- a/framework/Mime/test/Horde/Mime/mail_004.phpt +++ b/framework/Mime/test/Horde/Mime/mail_004.phpt @@ -17,7 +17,9 @@ $mail->addPart('application/octet-stream', file_get_contents(dirname(__FILE__) . '/fixtures/attachment.bin'), null, 'attachment'); -echo $mail->send(array('type' => 'dummy')); +$dummy = Mail::factory('dummy'); +$mail->send($dummy); +echo $dummy->send_output; ?> --EXPECTF-- diff --git a/framework/Mime/test/Horde/Mime/mail_005.phpt b/framework/Mime/test/Horde/Mime/mail_005.phpt index 6f241b822..82f0f52dc 100644 --- a/framework/Mime/test/Horde/Mime/mail_005.phpt +++ b/framework/Mime/test/Horde/Mime/mail_005.phpt @@ -30,7 +30,10 @@ $mail = new Horde_Mime_Mail(array('subject' => 'My Subject', 'to' => 'recipient@example.com', 'from' => 'sender@example.com')); $mail->setHTMLBody("

Header Title

\n

This is
the html text body.

"); -echo $mail->send(array('type' => 'dummy')); + +$dummy = Mail::factory('dummy'); +$mail->send($dummy); +echo $dummy->send_output; ?> --EXPECTF-- diff --git a/framework/Mime/test/Horde/Mime/mail_006.phpt b/framework/Mime/test/Horde/Mime/mail_006.phpt index 380226f8a..20d86bd8b 100644 --- a/framework/Mime/test/Horde/Mime/mail_006.phpt +++ b/framework/Mime/test/Horde/Mime/mail_006.phpt @@ -15,7 +15,9 @@ $mail = new Horde_Mime_Mail(array('subject' => 'My Subject', $mail->addAttachment(dirname(__FILE__) . '/fixtures/attachment.bin'); $mail->addAttachment(dirname(__FILE__) . '/mail_dummy.inc', 'my_name.html', 'text/html', 'iso-8859-15'); -echo $mail->send(array('type' => 'dummy')); +$dummy = Mail::factory('dummy'); +$mail->send($dummy); +echo $dummy->send_output; ?> --EXPECTF-- diff --git a/framework/Mime/test/Horde/Mime/mail_007.phpt b/framework/Mime/test/Horde/Mime/mail_007.phpt index 68e0bcf84..ac902e753 100644 --- a/framework/Mime/test/Horde/Mime/mail_007.phpt +++ b/framework/Mime/test/Horde/Mime/mail_007.phpt @@ -7,12 +7,17 @@ require dirname(__FILE__) . '/mail_dummy.inc'; require_once 'Horde/String.php'; require_once 'Horde/Util.php'; +$dummy = Mail::factory('dummy'); + $mail = new Horde_Mime_Mail(array('subject' => 'My Subject', 'body' => "This is\nthe body", 'to' => 'recipient@example.com', 'from' => 'sender@example.com', 'charset' => 'iso-8859-15')); -$raw = $mail->send(array('type' => 'dummy')); + +$mail->send($dummy); +$raw = $dummy->send_output; + echo $raw; preg_match('/^Message-ID: (.*)$/m', $raw, $id1); @@ -20,7 +25,10 @@ echo "====================================================================\n"; $mail->addHeader('To', 'Änderung ', 'utf-8'); $raw = $mail->send(array('type' => 'dummy')); -echo $raw; + +$mail->send($dummy); +$raw = $dummy->send_output; + preg_match('/^Message-ID: (.*)$/m', $raw, $id2); echo "====================================================================\n"; diff --git a/framework/Mime/test/Horde/Mime/mail_008.phpt b/framework/Mime/test/Horde/Mime/mail_008.phpt index 2d7452b06..ca21f70a1 100644 --- a/framework/Mime/test/Horde/Mime/mail_008.phpt +++ b/framework/Mime/test/Horde/Mime/mail_008.phpt @@ -14,7 +14,9 @@ $mail->setBody('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'); -echo $mail->send(array('type' => 'dummy')); +$dummy = Mail::factory('dummy'); +$mail->send($dummy); +echo $dummy->send_output; ?> --EXPECTF-- diff --git a/framework/Mime/test/Horde/Mime/mail_dummy.inc b/framework/Mime/test/Horde/Mime/mail_dummy.inc index 92fb61f1b..0b0e82203 100644 --- a/framework/Mime/test/Horde/Mime/mail_dummy.inc +++ b/framework/Mime/test/Horde/Mime/mail_dummy.inc @@ -15,10 +15,13 @@ require dirname(__FILE__) . '/../../../lib/Horde/Mime/Mail.php'; require dirname(__FILE__) . '/../../../lib/Horde/Mime/Part.php'; $_SERVER['SERVER_NAME'] = 'mail.example.com'; -class Mail_dummy extends Mail { +class Mail_dummy extends Mail +{ + var $send_output; + function send($recipients, $headers, $body) { list(,$text_headers) = Mail::prepareHeaders($headers); - return $text_headers . "\n\n" . $body; + $this->send_output = $text_headers . "\n\n" . $body; } } diff --git a/framework/Release/lib/Horde/Release.php b/framework/Release/lib/Horde/Release.php index a52cb8e83..75aa42338 100644 --- a/framework/Release/lib/Horde/Release.php +++ b/framework/Release/lib/Horde/Release.php @@ -649,9 +649,10 @@ class Horde_Release $mail = new Horde_Mime_Mail(); $mail->setBody($body, 'utf-8', false); $mail->addHeaders($headers); - $result = $mail->send(array('type' => $this->_options['mailer']['type'], 'params' => $this->_options['mailer']['params'])); - if (is_a($result, 'PEAR_Error')) { - print $result->getMessage() . "\n"; + try { + $mail->send(Mail::factory($this->_options['mailer']['type'], $this->_options['mailer']['params'])); + } catch (Horde_Mime_Exception $e) { + print $e->getMessage() . "\n"; } } diff --git a/horde/services/problem.php b/horde/services/problem.php index 6526b1084..833ece2d1 100644 --- a/horde/services/problem.php +++ b/horde/services/problem.php @@ -112,7 +112,7 @@ case 'send_problem_report': } try { - $mail->send(Horde::getMailerConfig()); + $mail->send($GLOBALS['injector']->getInstance('Mail')); /* We succeeded. */ Horde::logMessage( diff --git a/horde/services/resetpassword.php b/horde/services/resetpassword.php index 39e5b4944..ee12a5099 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(Horde::getMailerConfig()); + $mail->send($GLOBALS['injector']->getInstance('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/lib/Compose.php b/imp/lib/Compose.php index 67d29cbf7..10f67a4bf 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -741,13 +741,40 @@ class IMP_Compose * @param Horde_Mime_Part $message The Horde_Mime_Part object that * contains the text to send. * - * @throws Horde_Exception * @throws IMP_Compose_Exception */ public function sendMessage($email, $headers, $message) { - global $conf; + $email = $this->_prepSendMessage($email, $headers, $message); + + $mail_driver = $this->getMailDriver(); + $mailer = Mail::factory($mail_driver['driver'], $mail_driver['params']); + if ($mailer instanceof PEAR_Error) { + throw new IMP_Compose_Exception($mailer); + } + try { + $message->send($email, $headers, $mailer); + } catch (Horde_Mime_Exception $e) { + throw new IMP_Compose_Exception($e); + } + } + + /** + * Sanity checking/MIME formatting before sending a message. + * + * @param string $email The e-mail list to send to. + * @param Horde_Mime_Headers $headers The object holding this message's + * headers. + * @param Horde_Mime_Part $message The Horde_Mime_Part object that + * contains the text to send. + * + * @return string The encoded $email list. + * @throws IMP_Compose_Exception + */ + protected function _prepSendMessage($email, $headers = null, + $message = null) + { $timelimit = $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_timelimit'); if ($timelimit !== true) { $sentmail = $GLOBALS['injector']->getInstance('IMP_Sentmail'); @@ -756,7 +783,7 @@ class IMP_Compose throw new IMP_Compose_Exception(_("The system is not properly configured. A detailed error description has been logged for the administrator.")); } $sentmail = IMP_Sentmail::factory(); - $recipients = $sentmail->numberOfRecipients($conf['sentmail']['params']['limit_period'], true); + $recipients = $sentmail->numberOfRecipients($GLOBALS['conf']['sentmail']['params']['limit_period'], true); foreach ($result as $address) { $recipients += isset($address['grounpname']) ? count($address['addresses']) : 1; } @@ -764,16 +791,18 @@ class IMP_Compose try { $error = Horde::callHook('perms_denied', array('imp:max_timelimit')); } catch (Horde_Exception_HookNotSet $e) { - $error = @htmlspecialchars(sprintf(_("You are not allowed to send messages to more than %d recipients within %d hours."), $timelimit, $conf['sentmail']['params']['limit_period']), ENT_COMPAT, Horde_Nls::getCharset()); + $error = @htmlspecialchars(sprintf(_("You are not allowed to send messages to more than %d recipients within %d hours."), $timelimit, $GLOBALS['conf']['sentmail']['params']['limit_period']), ENT_COMPAT, Horde_Nls::getCharset()); } throw new IMP_Compose_Exception($error); } } /* Pass to hook to allow alteration of message details. */ - try { - Horde::callHook('pre_sent', array($message, $headers), 'imp'); - } catch (Horde_Exception_HookNotSet $e) {} + if (!is_null($message)) { + try { + Horde::callHook('pre_sent', array($message, $headers), 'imp'); + } catch (Horde_Exception_HookNotSet $e) {} + } /* Properly encode the addresses we're sending to. */ try { @@ -784,18 +813,12 @@ class IMP_Compose /* Validate the recipient addresses. */ try { - $result = Horde_Mime_Address::parseAddressList($email, array('defserver' => $_SESSION['imp']['maildomain'], 'validate' => true)); - } catch (Horde_Mime_Exception $e) { - return; - } - - $mail_driver = $this->getMailDriver(); - - try { - $message->send($email, $headers, $mail_driver['driver'], $mail_driver['params']); + Horde_Mime_Address::parseAddressList($email, array('defserver' => $_SESSION['imp']['maildomain'], 'validate' => true)); } catch (Horde_Mime_Exception $e) { throw new IMP_Compose_Exception($e); } + + return $email; } /** diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 0267f2cf7..937e2dd24 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -2048,7 +2048,7 @@ class Kronolith $mail->setBasePart($multipart); try { - $mail->send(Horde::getMailerConfig()); + $mail->send($GLOBALS['injector']->getInstance('Mail')); $notification->push( sprintf(_("The event notification to %s was successfully sent."), $recipient), 'horde.success' @@ -2180,7 +2180,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(Horde::getMailerConfig(), false, false); + $mime_mail->send($GLOBALS['injector']->getInstance('Mail'), false, false); } } } diff --git a/kronolith/scripts/agenda.php b/kronolith/scripts/agenda.php index 2938dd979..9ab6db40a 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(Horde::getMailerConfig(), false, false); + $mime_mail->send($GLOBALS['injector']->getInstance('Mail'), false, false); } catch (Horde_Mime_Exception $e) {} } } diff --git a/nag/lib/Nag.php b/nag/lib/Nag.php index d24ce7cdd..66a698ab6 100644 --- a/nag/lib/Nag.php +++ b/nag/lib/Nag.php @@ -1036,10 +1036,7 @@ class Nag Horde::logMessage(sprintf('Sending event notifications for %s to %s', $task->name, implode(', ', $df_recipients)), 'INFO'); - $sent = $mail->send(Horde::getMailerConfig()); - if (is_a($sent, 'PEAR_Error')) { - return $sent; - } + $mail->send($GLOBALS['injector']->getInstance('Mail')); } } } diff --git a/news/mail.php b/news/mail.php index 7fed88d81..f89486d01 100644 --- a/news/mail.php +++ b/news/mail.php @@ -54,11 +54,11 @@ $body = sprintf(_("%s would you like to invite you to read the news\n Title: %s\ News::getUrlFor('news', $id, true, -1)); $mail = new Horde_Mime_Mail(array('subject' => $row['title'], 'body' => $body, 'to' => $to, 'from' => $from, 'charset' => Horde_Nls::getCharset())); -$result = $mail->send($conf['mailer']['type'], $conf['mailer']['params']); -if ($result instanceof PEAR_Error) { - $notification->push($result); -} else { +try { + $mail->send($GLOBALS['injector']->getInstance('Mail')); $notification->push(sprintf(_("News succesfully send to %s"), $to), 'horde.success'); +} catch (Horde_Mime_Exception $e) { + $notification->push($e); } header('Location: ' . News::getUrlFor('news', $id)); diff --git a/whups/lib/Driver.php b/whups/lib/Driver.php index 43b11a7e8..b590dc1c3 100644 --- a/whups/lib/Driver.php +++ b/whups/lib/Driver.php @@ -489,7 +489,7 @@ class Whups_Driver { $mail->addHeader('To', $to, Horde_Nls::getCharset()); try { - $mail->send(Horde::getMailerConfig(), true); + $mail->send($GLOBALS['injector']->getInstance('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 ab043f466..63ce341a5 100644 --- a/wicked/lib/Wicked.php +++ b/wicked/lib/Wicked.php @@ -187,9 +187,9 @@ class Wicked { $mail->addHeader($hkey, $headers[$hkey]); } try { - $mail->send(Horde::getMailerConfig()); - } catch (Exception $e) { - $GLOBALS['notification']->push($e->getMessage()); + $mail->send($GLOBALS['injector']->getInstance('Mail')); + } catch (Horde_Mime_Exception $e) { + $GLOBALS['notification']->push($e); } } -- 2.11.0