1: <?php
2: /**
3: * A Horde_Injector based factory for IMP's configuration of Horde_Mail::
4: *
5: * PHP version 5
6: *
7: * @author Michael Slusarz <slusarz@horde.org>
8: * @category Horde
9: * @license http://www.horde.org/licenses/gpl GPL
10: * @link http://pear.horde.org/index.php?package=IMP
11: * @package IMP
12: */
13:
14: /**
15: * A Horde_Injector based factory for IMP's configuration of Horde_Mail::
16: *
17: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (GPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/gpl.
21: *
22: * @author Michael Slusarz <slusarz@horde.org>
23: * @category Horde
24: * @license http://www.horde.org/licenses/gpl GPL
25: * @link http://pear.horde.org/index.php?package=IMP
26: * @package IMP
27: */
28: class IMP_Factory_Mail extends Horde_Core_Factory_Injector
29: {
30: /**
31: * Return the Horde_Mail instance.
32: *
33: * @return Horde_Mail The singleton instance.
34: * @throws Horde_Exception
35: */
36: public function create(Horde_Injector $injector)
37: {
38: /* We don't actually want to alter the contents of the $conf['mailer']
39: * array, so we make a copy of the current settings. We will apply our
40: * modifications (if any) to the copy, instead. */
41: $params = $GLOBALS['conf']['mailer']['params'];
42:
43: /* Force the SMTP host and port value to the current SMTP server if
44: * one has been selected for this connection. */
45: $params = array_merge($params, $GLOBALS['session']->get('imp', 'smtp', Horde_Session::TYPE_ARRAY));
46:
47: /* If SMTP authentication has been requested, use either the username
48: * and password provided in the configuration or populate the username
49: * and password fields based on the current values for the user. Note
50: * that we assume that the username and password values from the
51: * current IMAP / POP3 connection are valid for SMTP authentication as
52: * well. */
53: if (!empty($params['auth']) && empty($params['username'])) {
54: $imap_ob = $injector->getInstance('IMP_Factory_Imap')->create();
55: $params['username'] = $imap_ob->getParam('username');
56: $params['password'] = $imap_ob->getParam('password');
57: }
58:
59: $transport = $GLOBALS['conf']['mailer']['type'];
60: $class = 'Horde_Mail_Transport_' . ucfirst($transport);
61: if (class_exists($class)) {
62: return new $class($params);
63: }
64:
65: throw new Horde_Exception('Unable to find class for transport ' . $transport);
66: }
67:
68: }
69: