From 702c99f22fbd710031e66126426a4626d6f9f4ac Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 17 Mar 2010 17:55:45 -0600 Subject: [PATCH] Create IMP_Sentmail binder --- imp/lib/Api.php | 3 +- imp/lib/Application.php | 12 ++++++-- imp/lib/Compose.php | 16 ++++------ imp/lib/Injector/Binder/Sentmail.php | 34 ++++++++++++++++++++++ .../LoginTasks/SystemTask/GarbageCollection.php | 3 +- imp/lib/Sentmail.php | 26 ++++++----------- imp/lib/Ui/Compose.php | 5 +--- imp/lib/Ui/Message.php | 5 +--- 8 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 imp/lib/Injector/Binder/Sentmail.php diff --git a/imp/lib/Api.php b/imp/lib/Api.php index 9d0ec8eca..71b5a64dd 100644 --- a/imp/lib/Api.php +++ b/imp/lib/Api.php @@ -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); } /** diff --git a/imp/lib/Application.php b/imp/lib/Application.php index dd2910ae2..d189e4123 100644 --- a/imp/lib/Application.php +++ b/imp/lib/Application.php @@ -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(); diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 81f5adc34..67d29cbf7 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -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 index 000000000..5f4cceaad --- /dev/null +++ b/imp/lib/Injector/Binder/Sentmail.php @@ -0,0 +1,34 @@ + + * @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; + } + +} diff --git a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php index 45a81de0b..07ff01e62 100644 --- a/imp/lib/LoginTasks/SystemTask/GarbageCollection.php +++ b/imp/lib/LoginTasks/SystemTask/GarbageCollection.php @@ -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']) { diff --git a/imp/lib/Sentmail.php b/imp/lib/Sentmail.php index 8eab7df07..becf75f99 100644 --- a/imp/lib/Sentmail.php +++ b/imp/lib/Sentmail.php @@ -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); } /** diff --git a/imp/lib/Ui/Compose.php b/imp/lib/Ui/Compose.php index f3d6e38d3..bda3226da 100644 --- a/imp/lib/Ui/Compose.php +++ b/imp/lib/Ui/Compose.php @@ -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); } /** diff --git a/imp/lib/Ui/Message.php b/imp/lib/Ui/Message.php index 43bfad67f..8c61abd28 100644 --- a/imp/lib/Ui/Message.php +++ b/imp/lib/Ui/Message.php @@ -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; } -- 2.11.0