1: <?php
2: /**
3: * Copyright 2013-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2013-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Dynamically generate the password needed for the mail server connection.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2013-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Imap_Password implements Horde_Imap_Client_Base_Password, Serializable
24: {
25: /* Password key. */
26: const PASSWORD_KEY = 'imap_ob_pass';
27:
28: /**
29: * Object storage ID.
30: *
31: * @var string
32: */
33: private $_id;
34:
35: /**
36: * Mail server password.
37: *
38: * @var string
39: */
40: private $_password;
41:
42: /**
43: * Constructor.
44: *
45: * @param string $password The mail server password.
46: */
47: public function __construct($password)
48: {
49: $this->_password = $password;
50: }
51:
52: /* Horde_Imap_Client_Base_Password methods. */
53:
54: /**
55: */
56: public function getPassword()
57: {
58: return $this->_password;
59: }
60:
61: /* Serializable methods. */
62:
63: /**
64: */
65: public function serialize()
66: {
67: global $session;
68:
69: if (!isset($this->_id)) {
70: $this->_id = strval(new Horde_Support_Randomid());
71: }
72:
73: $session->set('imp', self::PASSWORD_KEY . '/' . $this->_id, $this->_password, $session::ENCRYPT);
74:
75: return $this->_id;
76: }
77:
78: /**
79: */
80: public function unserialize($data)
81: {
82: $this->_id = $data;
83: $this->_password = $GLOBALS['session']->get('imp', self::PASSWORD_KEY . '/' . $this->_id);
84: }
85:
86: }
87: