From: Michael M Slusarz Date: Fri, 14 May 2010 20:04:26 +0000 (-0600) Subject: Add Null IMP_Sentmail driver X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=8763512795317061d4cef961637aeb2df6bcd6f4;p=horde.git Add Null IMP_Sentmail driver --- diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 63fcbeafa..dbf1fd26c 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -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.")); } diff --git a/imp/lib/Sentmail.php b/imp/lib/Sentmail.php index 7cae7d8d3..d7d8651fd 100644 --- a/imp/lib/Sentmail.php +++ b/imp/lib/Sentmail.php @@ -14,13 +14,6 @@ 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 index 000000000..d8c0bdf89 --- /dev/null +++ b/imp/lib/Sentmail/Driver.php @@ -0,0 +1,111 @@ + + * @author Michael Slusarz + * @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 index 000000000..10c707e03 --- /dev/null +++ b/imp/lib/Sentmail/Null.php @@ -0,0 +1,78 @@ + + * @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) + { + } + +} diff --git a/imp/lib/Sentmail/Sql.php b/imp/lib/Sentmail/Sql.php index fdca735a5..71e185023 100644 --- a/imp/lib/Sentmail/Sql.php +++ b/imp/lib/Sentmail/Sql.php @@ -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.