$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."));
}
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.
* @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())
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)
- {
- }
-
}
--- /dev/null
+<?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);
+
+}
--- /dev/null
+<?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)
+ {
+ }
+
+}
* @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.