Add Null IMP_Sentmail driver
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 14 May 2010 20:04:26 +0000 (14:04 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 14 May 2010 20:09:51 +0000 (14:09 -0600)
imp/lib/Compose.php
imp/lib/Sentmail.php
imp/lib/Sentmail/Driver.php [new file with mode: 0644]
imp/lib/Sentmail/Null.php [new file with mode: 0644]
imp/lib/Sentmail/Sql.php

index 63fcbea..dbf1fd2 100644 (file)
@@ -752,7 +752,7 @@ class IMP_Compose
         $timelimit = $GLOBALS['injector']->getInstance('Horde_Perms')->hasAppPermission('max_timelimit');
         if ($timelimit !== true) {
             $sentmail = $GLOBALS['injector']->getInstance('IMP_Sentmail');
-            if (!is_subclass_of($sentmail, 'IMP_Sentmail')) {
+            if (!is_subclass_of($sentmail, 'IMP_Sentmail_Driver')) {
                 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."));
             }
index 7cae7d8..d7d8651 100644 (file)
 class IMP_Sentmail
 {
     /**
-     * Hash containing configuration parameters.
-     *
-     * @var array
-     */
-    protected $_params = array();
-
-    /**
      * Attempts to return a concrete instance based on $driver.
      *
      * @param string $driver  The type of the concrete subclass to return.
@@ -29,7 +22,7 @@ class IMP_Sentmail
      * @param array $params   A hash containing any additional configuration
      *                        or connection parameters a subclass might need.
      *
-     * @return IMP_Sentmail  The newly created concrete instance.
+     * @return IMP_Sentmail_Driver  The newly created concrete instance.
      * @throws IMP_Exception
      */
     static public function factory($driver, $params = array())
@@ -43,99 +36,4 @@ class IMP_Sentmail
         throw new IMP_Exception('Driver not found: ' . $driver);
     }
 
-    /**
-     * Constructor.
-     *
-     * @throws IMP_Exception
-     */
-    protected function __construct($params = array())
-    {
-        $this->_params = array_merge($this->_params, $params);
-    }
-
-    /**
-     * Logs an attempt to send a message.
-     *
-     * @param string $action            Why the message was sent, i.e. "new",
-     *                                  "reply", "forward", etc.
-     * @param string $message_id        The Message-ID.
-     * @param string|array $recipients  The list of message recipients.
-     * @param boolean $success          Whether the attempt was successful.
-     */
-    public function log($action, $message_id, $recipients, $success = true)
-    {
-        if (!is_array($recipients)) {
-            $recipients = array($recipients);
-        }
-
-        foreach ($recipients as $addresses) {
-            $addresses = Horde_Mime_Address::bareAddress($addresses, $_SESSION['imp']['maildomain'], true);
-            foreach ($addresses as $recipient) {
-                $this->_log($action, $message_id, $recipient, $success);
-            }
-        }
-    }
-
-    /**
-     * Logs an attempt to send a message per recipient.
-     *
-     * @param string $action      Why the message was sent, i.e. "new",
-     *                            "reply", "forward", etc.
-     * @param string $message_id  The Message-ID.
-     * @param string $recipients  A message recipient.
-     * @param boolean $success    Whether the attempt was successful.
-     */
-    protected function _log($action, $message_id, $recipient, $success)
-    {
-    }
-
-    /**
-     * Returns the favourite recipients.
-     *
-     * @param integer $limit  Return this number of recipients.
-     * @param array $filter   A list of messages types that should be returned.
-     *                        A value of null returns all message types.
-     *
-     * @return array  A list with the $limit most favourite recipients.
-     * @throws IMP_Exception
-     */
-    public function favouriteRecipients($limit,
-                                        $filter = array('new', 'forward', 'reply', 'redirect'))
-    {
-        return array();
-    }
-
-    /**
-     * Returns the number of recipients within a certain time period.
-     *
-     * @param integer $hours  Time period in hours.
-     * @param boolean $user   Return the number of recipients for the current
-     *                        user?
-     *
-     * @return integer  The number of recipients in the given time period.
-     * @throws IMP_Exception
-     */
-    public function numberOfRecipients($hours, $user = false)
-    {
-        return 0;
-    }
-
-    /**
-     * Garbage collect log entries.
-     */
-    public function gc()
-    {
-        $this->_deleteOldEntries(time() - ((isset($this->_params['threshold']) ? $this->_params['threshold'] : 0) * 86400));
-    }
-
-    /**
-     * Deletes all log entries older than a certain date.
-     *
-     * @param integer $before  Unix timestamp before that all log entries
-     *                         should be deleted.
-     */
-    protected function _deleteOldEntries($before)
-    {
-    }
-
 }
diff --git a/imp/lib/Sentmail/Driver.php b/imp/lib/Sentmail/Driver.php
new file mode 100644 (file)
index 0000000..d8c0bdf
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+/**
+ * The IMP_Sentmail_Driver:: class is the abstract class that all driver
+ * implementations inherit from.
+ *
+ * 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   Jan Schneider <jan@horde.org>
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @package  IMP
+ */
+abstract class IMP_Sentmail_Driver
+{
+    /**
+     * Hash containing configuration parameters.
+     *
+     * @var array
+     */
+    protected $_params = array();
+
+    /**
+     * Constructor.
+     *
+     * @throws IMP_Exception
+     */
+    public function __construct($params = array())
+    {
+        $this->_params = array_merge($this->_params, $params);
+    }
+
+    /**
+     * Logs an attempt to send a message.
+     *
+     * @param string $action            Why the message was sent, i.e. "new",
+     *                                  "reply", "forward", etc.
+     * @param string $message_id        The Message-ID.
+     * @param string|array $recipients  The list of message recipients.
+     * @param boolean $success          Whether the attempt was successful.
+     */
+    public function log($action, $message_id, $recipients, $success = true)
+    {
+        if (!is_array($recipients)) {
+            $recipients = array($recipients);
+        }
+
+        foreach ($recipients as $addresses) {
+            $addresses = Horde_Mime_Address::bareAddress($addresses, $_SESSION['imp']['maildomain'], true);
+            foreach ($addresses as $recipient) {
+                $this->_log($action, $message_id, $recipient, $success);
+            }
+        }
+    }
+
+    /**
+     * Garbage collect log entries.
+     */
+    public function gc()
+    {
+        $this->_deleteOldEntries(time() - ((isset($this->_params['threshold']) ? $this->_params['threshold'] : 0) * 86400));
+    }
+
+    /**
+     * Logs an attempt to send a message per recipient.
+     *
+     * @param string $action      Why the message was sent, i.e. "new",
+     *                            "reply", "forward", etc.
+     * @param string $message_id  The Message-ID.
+     * @param string $recipients  A message recipient.
+     * @param boolean $success    Whether the attempt was successful.
+     */
+    abstract protected function _log($action, $message_id, $recipient,
+                                     $success);
+
+    /**
+     * Returns the favourite recipients.
+     *
+     * @param integer $limit  Return this number of recipients.
+     * @param array $filter   A list of messages types that should be returned.
+     *                        A value of null returns all message types.
+     *
+     * @return array  A list with the $limit most favourite recipients.
+     * @throws IMP_Exception
+     */
+    abstract public function favouriteRecipients($limit,
+                                                 $filter = array('new', 'forward', 'reply', 'redirect'));
+
+    /**
+     * Returns the number of recipients within a certain time period.
+     *
+     * @param integer $hours  Time period in hours.
+     * @param boolean $user   Return the number of recipients for the current
+     *                        user?
+     *
+     * @return integer  The number of recipients in the given time period.
+     * @throws IMP_Exception
+     */
+    abstract public function numberOfRecipients($hours, $user = false);
+
+    /**
+     * Deletes all log entries older than a certain date.
+     *
+     * @param integer $before  Unix timestamp before that all log entries
+     *                         should be deleted.
+     */
+    abstract protected function _deleteOldEntries($before);
+
+}
diff --git a/imp/lib/Sentmail/Null.php b/imp/lib/Sentmail/Null.php
new file mode 100644 (file)
index 0000000..10c707e
--- /dev/null
@@ -0,0 +1,78 @@
+<?php
+/**
+ * The IMP_Sentmail_Null:: class is a null logging implementation.
+ *
+ * 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>
+ * @category Horde
+ * @package  IMP
+ */
+class IMP_Sentmail_Null extends IMP_Sentmail_Driver
+{
+    /**
+     * Garbage collect log entries.
+     */
+    public function gc()
+    {
+        $this->_deleteOldEntries(time() - ((isset($this->_params['threshold']) ? $this->_params['threshold'] : 0) * 86400));
+    }
+
+    /**
+     * Logs an attempt to send a message per recipient.
+     *
+     * @param string $action      Why the message was sent, i.e. "new",
+     *                            "reply", "forward", etc.
+     * @param string $message_id  The Message-ID.
+     * @param string $recipients  A message recipient.
+     * @param boolean $success    Whether the attempt was successful.
+     */
+    protected function _log($action, $message_id, $recipient, $success)
+    {
+    }
+
+    /**
+     * Returns the favourite recipients.
+     *
+     * @param integer $limit  Return this number of recipients.
+     * @param array $filter   A list of messages types that should be returned.
+     *                        A value of null returns all message types.
+     *
+     * @return array  A list with the $limit most favourite recipients.
+     * @throws IMP_Exception
+     */
+    public function favouriteRecipients($limit,
+                                        $filter = array('new', 'forward', 'reply', 'redirect'))
+    {
+        return array();
+    }
+
+    /**
+     * Returns the number of recipients within a certain time period.
+     *
+     * @param integer $hours  Time period in hours.
+     * @param boolean $user   Return the number of recipients for the current
+     *                        user?
+     *
+     * @return integer  The number of recipients in the given time period.
+     * @throws IMP_Exception
+     */
+    public function numberOfRecipients($hours, $user = false)
+    {
+        return 0;
+    }
+
+    /**
+     * Deletes all log entries older than a certain date.
+     *
+     * @param integer $before  Unix timestamp before that all log entries
+     *                         should be deleted.
+     */
+    protected function _deleteOldEntries($before)
+    {
+    }
+
+}
index fdca735..71e1850 100644 (file)
@@ -15,7 +15,7 @@
  * @category Horde
  * @package  IMP
  */
-class IMP_Sentmail_Sql extends IMP_Sentmail
+class IMP_Sentmail_Sql extends IMP_Sentmail_Driver
 {
     /**
      * Handle for the current database connection.