Create IMP_Sentmail binder
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 17 Mar 2010 23:55:45 +0000 (17:55 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 18 Mar 2010 03:24:03 +0000 (21:24 -0600)
imp/lib/Api.php
imp/lib/Application.php
imp/lib/Compose.php
imp/lib/Injector/Binder/Sentmail.php [new file with mode: 0644]
imp/lib/LoginTasks/SystemTask/GarbageCollection.php
imp/lib/Sentmail.php
imp/lib/Ui/Compose.php
imp/lib/Ui/Message.php

index 9d0ec8e..71b5a64 100644 (file)
@@ -193,8 +193,7 @@ class IMP_Api extends Horde_Registry_Api
     public function favouriteRecipients($limit,
                                         $filter = array('new', 'forward', 'reply', 'redirect'))
     {
-        $sentmail = IMP_Sentmail::factory();
-        return $sentmail->favouriteRecipients($limit, $filter);
+        return $GLOBALS['injector']->getInstance('IMP_Sentmail')->favouriteRecipients($limit, $filter);
     }
 
     /**
index dd2910a..d189e41 100644 (file)
@@ -98,8 +98,16 @@ class IMP_Application extends Horde_Registry_Application
      */
     protected function _init()
     {
-        $GLOBALS['injector']->addBinder('IMP_Folder', new IMP_Injector_Binder_Folder());
-        $GLOBALS['injector']->addBinder('IMP_Imap_Tree', new IMP_Injector_Binder_Imaptree());
+        /* Add IMP-specific binders. */
+        $binders = array(
+            'IMP_Folder' => new IMP_Injector_Binder_Folder(),
+            'IMP_Imap_Tree' => new IMP_Injector_Binder_Imaptree(),
+            'IMP_Sentmail' => new IMP_Injector_Binder_Imaptree()
+        );
+
+        foreach ($binders as $key => $val) {
+            $GLOBALS['injector']->addBinder($key, $val);
+        }
 
         // Initialize global $imp_imap object.
         $GLOBALS['imp_imap'] = new IMP_Imap();
index 81f5adc..67d29cb 100644 (file)
@@ -594,9 +594,7 @@ class IMP_Compose
             }
         } catch (Horde_Exception $e) {}
 
-        if ($conf['sentmail']['driver'] != 'none') {
-            $sentmail = IMP_Sentmail::factory();
-        }
+        $sentmail = $GLOBALS['injector']->getInstance('IMP_Sentmail');
 
         /* Send the messages out now. */
         foreach ($send_msgs as $val) {
@@ -605,17 +603,12 @@ class IMP_Compose
             } catch (IMP_Compose_Exception $e) {
                 /* Unsuccessful send. */
                 Horde::logMessage($e, 'ERR');
-                if (isset($sentmail)) {
-                    $sentmail->log($this->getMetadata('reply_type') || 'new', $headers->getValue('message-id'), $val['recipients'], false);
-                }
-
+                $sentmail->log($this->getMetadata('reply_type') || 'new', $headers->getValue('message-id'), $val['recipients'], false);
                 throw new IMP_Compose_Exception(sprintf(_("There was an error sending your message: %s"), $e->getMessage()));
             }
 
             /* Store history information. */
-            if (isset($sentmail)) {
-                $sentmail->log($this->getMetadata('reply_type') || 'new', $headers->getValue('message-id'), $val['recipients'], true);
-            }
+            $sentmail->log($this->getMetadata('reply_type') || 'new', $headers->getValue('message-id'), $val['recipients'], true);
         }
 
         $sent_saved = true;
@@ -757,7 +750,8 @@ class IMP_Compose
 
         $timelimit = $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_timelimit');
         if ($timelimit !== true) {
-            if ($conf['sentmail']['driver'] == 'none') {
+            $sentmail = $GLOBALS['injector']->getInstance('IMP_Sentmail');
+            if (!is_subclass_of($sentmail, 'IMP_Sentmail')) {
                 Horde::logMessage('The permission for the maximum number of recipients per time period has been enabled, but no backend for the sent-mail logging has been configured for IMP.', 'ERR');
                 throw new IMP_Compose_Exception(_("The system is not properly configured. A detailed error description has been logged for the administrator."));
             }
diff --git a/imp/lib/Injector/Binder/Sentmail.php b/imp/lib/Injector/Binder/Sentmail.php
new file mode 100644 (file)
index 0000000..5f4ccea
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+/**
+ * Binder for IMP_Sentmail::.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Injector_Binder_Sentmail implements Horde_Injector_Binder
+{
+    /**
+     */
+    public function create(Horde_Injector $injector)
+    {
+        if (empty($GLOBALS['conf']['sentmail']['driver'])) {
+            return IMP_Sentmail::factory();
+        }
+
+        $driver = $GLOBALS['conf']['sentmail']['driver'];
+        return IMP_Sentmail::factory($driver, Horde::getDriverConfig('sentmail', $driver));
+    }
+
+    /**
+     */
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+
+}
index 45a81de..07ff01e 100644 (file)
@@ -28,8 +28,7 @@ class IMP_LoginTasks_SystemTask_GarbageCollection extends Horde_LoginTasks_Syste
         $GLOBALS['injector']->getInstance('IMP_Imap_Tree')->getPollList(true, true);
 
         /* Do garbage collection on sentmail entries. */
-        $sentmail = IMP_Sentmail::factory();
-        $sentmail->gc();
+        $GLOBALS['injector']->getInstance('IMP_Sentmail')->gc();
 
         /* Do garbage collection on compose VFS data. */
         if ($GLOBALS['conf']['compose']['use_vfs']) {
index 8eab7df..becf75f 100644 (file)
@@ -27,28 +27,20 @@ class IMP_Sentmail
      *                        to return.  The class name is based on the
      *                        storage driver ($driver).  The code is
      *                        dynamically included.
-     *
      * @param array $params   A hash containing any additional configuration
      *                        or connection parameters a subclass might need.
      *
      * @return IMP_Sentmail  The newly created concrete IMP_Sentmail instance.
      */
-    static public function factory($driver = null, $params = null)
+    static public function factory($driver = null, $params = array())
     {
-        if (is_null($driver)) {
-            $driver = $GLOBALS['conf']['sentmail']['driver'];
-        }
-
-        if (is_null($params)) {
-            $params = Horde::getDriverConfig('sentmail', $driver);
-        }
-
-        $class = 'IMP_Sentmail_' . ucfirst(basename($driver));
-
-        if (class_exists($class)) {
-            try {
-                return new $class($params);
-            } catch (Horde_Exception $e) {}
+        if ($driver && ($driver != 'none')) {
+            $class = 'IMP_Sentmail_' . ucfirst(basename($driver));
+            if (class_exists($class)) {
+                try {
+                    return new $class($params);
+                } catch (Horde_Exception $e) {}
+            }
         }
 
         return new IMP_Sentmail($params);
@@ -61,7 +53,7 @@ class IMP_Sentmail
      */
     protected function __construct($params = array())
     {
-        $this->_params = $params;
+        $this->_params = array_merge($this->_params, $params);
     }
 
     /**
index f3d6e38..bda3226 100644 (file)
@@ -108,10 +108,7 @@ class IMP_Ui_Compose
                          $_SERVER['REMOTE_ADDR'], $recipients, Horde_Auth::getAuth());
         Horde::logMessage($entry, 'INFO');
 
-        if ($GLOBALS['conf']['sentmail']['driver'] != 'none') {
-            $sentmail = IMP_Sentmail::factory();
-            $sentmail->log('redirect', $headers->getValue('message-id'), $recipients);
-        }
+        $GLOBALS['injector']->getInstance('IMP_Sentmail')>log('redirect', $headers->getValue('message-id'), $recipients);
     }
 
     /**
index 43bfad6..8c61abd 100644 (file)
@@ -125,10 +125,7 @@ class IMP_Ui_Message
             $success = false;
         }
 
-        if ($GLOBALS['conf']['sentmail']['driver'] != 'none') {
-            $sentmail = IMP_Sentmail::factory();
-            $sentmail->log('mdn', '', $return_addr, $success);
-        }
+        $GLOBALS['injector']->getInstance('IMP_Sentmail')->log('mdn', '', $return_addr, $success);
 
         return false;
     }