Add Mail binder.
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 24 Mar 2010 18:19:09 +0000 (12:19 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Mar 2010 04:47:46 +0000 (22:47 -0600)
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.

32 files changed:
agora/messages/abuse.php
ansel/img/ecard.php
ansel/lib/Report/mail.php
folks/lib/Folks.php
folks/lib/Notification/mail.php
framework/Alarm/lib/Horde/Alarm.php
framework/Auth/lib/Horde/Auth/Signup.php
framework/Core/lib/Horde.php
framework/Core/lib/Horde/Core/Binder/Mail.php [new file with mode: 0644]
framework/Core/lib/Horde/Registry.php
framework/Core/package.xml
framework/Mime/lib/Horde/Mime/Mail.php
framework/Mime/lib/Horde/Mime/Part.php
framework/Mime/test/Horde/Mime/mail_001.phpt
framework/Mime/test/Horde/Mime/mail_002.phpt
framework/Mime/test/Horde/Mime/mail_003.phpt
framework/Mime/test/Horde/Mime/mail_004.phpt
framework/Mime/test/Horde/Mime/mail_005.phpt
framework/Mime/test/Horde/Mime/mail_006.phpt
framework/Mime/test/Horde/Mime/mail_007.phpt
framework/Mime/test/Horde/Mime/mail_008.phpt
framework/Mime/test/Horde/Mime/mail_dummy.inc
framework/Release/lib/Horde/Release.php
horde/services/problem.php
horde/services/resetpassword.php
imp/lib/Compose.php
kronolith/lib/Kronolith.php
kronolith/scripts/agenda.php
nag/lib/Nag.php
news/mail.php
whups/lib/Driver.php
wicked/lib/Wicked.php

index 111527e..5c4bb76 100644 (file)
@@ -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);
index 14a62ef..f5f9efa 100644 (file)
@@ -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 {
index 853a916..0db2997 100644 (file)
@@ -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'));
     }
 }
index c19a5b9..6a84b06 100644 (file)
@@ -247,7 +247,7 @@ class Folks {
             }
         }
 
-        return $mail->send(Horde::getMailerConfig());
+        return $mail->send($GLOBALS['injector']->getInstance('Mail'));
     }
 
     /**
index c1f0c02..64ff854 100644 (file)
@@ -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;
index 4423b47..1c951ef 100644 (file)
@@ -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']);
index cd81cba..4b86754 100644 (file)
@@ -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'));
         }
     }
 
index 5ee01e5..3fe74d8 100644 (file)
@@ -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 (file)
index 0000000..cb0f92f
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+class Horde_Core_Binder_Mail implements Horde_Injector_Binder
+{
+    public function create(Horde_Injector $injector)
+    {
+        $driver = $GLOBALS['conf']['mailer']['type'];
+        $params = $GLOBALS['conf']['mailer']['params'];
+
+        if (($driver == 'smtp') &&
+            $params['auth'] &&
+            empty($params['username'])) {
+            $params['username'] = Horde_Auth::getAuth();
+            $params['password'] = Horde_Auth::getCredential('password');
+        }
+
+        $result = Mail::factory($driver, $params);
+        if ($result instanceof PEAR_Error) {
+            throw new Horde_Exception($result);
+        }
+
+        return $result;
+    }
+
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+}
index 481a408..5b339b5 100644 (file)
@@ -242,6 +242,7 @@ 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()
         );
 
index 48e5046..b8f9be4 100644 (file)
@@ -70,6 +70,7 @@ Application Framework.
        <file name="Dns.php" role="php" />
        <file name="Lock.php" role="php" />
        <file name="Logger.php" role="php" />
+       <file name="Mail.php" role="php" />
        <file name="Memcache.php" role="php" />
        <file name="Notification.php" role="php" />
        <file name="Perms.php" role="php" />
@@ -203,6 +204,7 @@ Application Framework.
    <install name="lib/Horde/Core/Binder/Dns.php" as="Horde/Core/Binder/Dns.php" />
    <install name="lib/Horde/Core/Binder/Lock.php" as="Horde/Core/Binder/Lock.php" />
    <install name="lib/Horde/Core/Binder/Logger.php" as="Horde/Core/Binder/Logger.php" />
+   <install name="lib/Horde/Core/Binder/Mail.php" as="Horde/Core/Binder/Mail.php" />
    <install name="lib/Horde/Core/Binder/Memcache.php" as="Horde/Core/Binder/Memcache.php" />
    <install name="lib/Horde/Core/Binder/Notification.php" as="Horde/Core/Binder/Notification.php" />
    <install name="lib/Horde/Core/Binder/Perms.php" as="Horde/Core/Binder/Perms.php" />
index 7a439e6..cb6d280 100644 (file)
@@ -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() . ')');
     }
+
 }
index dd3731e..68d164d 100644 (file)
@@ -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);
     }
 
     /**
index 37a4b16..25c21e2 100644 (file)
@@ -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--
index 4d4bca4..8df2e23 100644 (file)
@@ -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--
index d992ccd..dfd2c24 100644 (file)
@@ -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 <peter@example.com>', 'iso-8859-15');
-echo $mail->send(array('type' => 'dummy'));
+
+$dummy = Mail::factory('dummy');
+$mail->send($dummy);
+echo $dummy->send_output;
 
 ?>
 --EXPECTF--
index cbb6dfa..e4d340d 100644 (file)
@@ -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--
index 6f241b8..82f0f52 100644 (file)
@@ -30,7 +30,10 @@ $mail = new Horde_Mime_Mail(array('subject' => 'My Subject',
                                   'to' => 'recipient@example.com',
                                   'from' => 'sender@example.com'));
 $mail->setHTMLBody("<h1>Header Title</h1>\n<p>This is<br />the html text body.</p>");
-echo $mail->send(array('type' => 'dummy'));
+
+$dummy = Mail::factory('dummy');
+$mail->send($dummy);
+echo $dummy->send_output;
 
 ?>
 --EXPECTF--
index 380226f..20d86bd 100644 (file)
@@ -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--
index 68e0bcf..ac902e7 100644 (file)
@@ -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 <other@example.com>', '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";
index 2d7452b..ca21f70 100644 (file)
@@ -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--
index 92fb61f..0b0e822 100644 (file)
@@ -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;
     }
 }
index a52cb8e..75aa423 100644 (file)
@@ -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";
         }
     }
 
index 6526b10..833ece2 100644 (file)
@@ -112,7 +112,7 @@ case 'send_problem_report':
             }
 
             try {
-                $mail->send(Horde::getMailerConfig());
+                $mail->send($GLOBALS['injector']->getInstance('Mail'));
 
                 /* We succeeded. */
                 Horde::logMessage(
index 39e5b49..ee12a50 100644 (file)
@@ -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;
index 67d29cb..10f67a4 100644 (file)
@@ -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;
     }
 
     /**
index 0267f2c..937e2dd 100644 (file)
@@ -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);
                 }
             }
         }
index 2938dd9..9ab6db4 100755 (executable)
@@ -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) {}
     }
 }
index d24ce7c..66a698a 100644 (file)
@@ -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'));
                 }
             }
         }
index 7fed88d..f89486d 100644 (file)
@@ -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));
index 43b11a7..b590dc1 100644 (file)
@@ -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());
index ab043f4..63ce341 100644 (file)
@@ -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);
         }
     }