1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Ajax_Application_Handler_Remote extends Horde_Core_Ajax_Application_Handler
24: {
25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36:
37: public function remoteLogin()
38: {
39: global $injector, $notification, $prefs;
40:
41: $remote = $injector->getInstance('IMP_Remote');
42: $remoteid = IMP_Mailbox::formFrom($this->vars->remoteid);
43:
44: $res = new stdClass;
45: $res->success = false;
46:
47: if (!isset($remote[$remoteid])) {
48: $notification->push(_("Could not find remote server configuration."), 'horde.error');
49: return $res;
50: }
51:
52: $password = $this->vars->password;
53: if ($this->vars->password_base64) {
54: $password = base64_decode($password);
55: }
56:
57: $remote_ob = $remote[$remoteid];
58:
59: try {
60: $remote_ob->createImapObject($password);
61: $remote_ob->imp_imap->login();
62: $res->success = true;
63: $notification->push(sprintf(_("Successfully authenticated to %s."), $remote_ob->label), 'horde.success');
64:
65: $ftree = $injector->getInstance('IMP_Ftree');
66:
67: $ftree->delete($remote_ob);
68: $ftree->insert($remote_ob);
69:
70: $ftree[$remote_ob]->open = true;
71: $this->_base->queue->setMailboxOpt('expand', 1);
72:
73: $iterator = new IMP_Ftree_IteratorFilter(
74: new IMP_Ftree_Iterator($ftree[$remote_ob])
75: );
76: if ($this->vars->unsub) {
77: $ftree->loadUnsubscribed();
78: $iterator->remove($iterator::UNSUB);
79: }
80:
81: switch ($prefs->getValue('nav_expanded')) {
82: case IMP_Ftree_Prefs_Expanded::NO:
83: $iterator->add($iterator::CHILDREN);
84: break;
85:
86: case IMP_Ftree_Prefs_Expanded::LAST:
87: $iterator->add($iterator::EXPANDED);
88: break;
89: }
90:
91: array_map(
92: array($ftree->eltdiff, 'add'),
93: iterator_to_array($iterator, false)
94: );
95: } catch (Exception $e) {
96: $notification->push(sprintf(_("Could not authenticate to %s."), $remote_ob->label), 'horde.error');
97: }
98:
99: return $res;
100: }
101:
102: 103: 104: 105: 106: 107: 108: 109:
110: public function remoteLogout()
111: {
112: global $injector, $notification;
113:
114: $remote = $injector->getInstance('IMP_Remote');
115: $remoteid = IMP_Mailbox::formFrom($this->vars->remoteid);
116: $remote_ob = $remote[$remoteid];
117:
118: $injector->getInstance('IMP_Factory_Imap')->destroy($remoteid);
119:
120: $ftree = $injector->getInstance('IMP_Ftree');
121: $ftree->delete($remote_ob);
122: $ftree->insert($remote_ob);
123:
124: $notification->push(sprintf(_("Logged out of %s."), $remote_ob->label), 'horde.success');
125:
126: return true;
127: }
128:
129: }
130: