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);
}
/**
*/
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();
}
} 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) {
} 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;
$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."));
}
--- /dev/null
+<?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;
+ }
+
+}
$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']) {
* 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);
*/
protected function __construct($params = array())
{
- $this->_params = $params;
+ $this->_params = array_merge($this->_params, $params);
}
/**
$_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);
}
/**
$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;
}