/
Remote.php
158 lines (133 loc) · 4.82 KB
/
Remote.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* Copyright 2013-2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @category Horde
* @copyright 2013-2014 Horde LLC
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
/**
* Special prefs handling for the 'remotemanagement' preference.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2013-2014 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
class IMP_Prefs_Special_Remote implements Horde_Core_Prefs_Ui_Special
{
/**
*/
public function init(Horde_Core_Prefs_Ui $ui)
{
}
/**
*/
public function display(Horde_Core_Prefs_Ui $ui)
{
global $injector, $page_output;
$ui->nobuttons = true;
$page_output->addScriptFile('external/base64.js');
$page_output->addScriptFile('remoteprefs.js');
$page_output->addInlineJsVars(array(
'ImpRemotePrefs.confirm_delete' => _("Are you sure you want to delete this account?"),
'ImpRemotePrefs.empty_email' => _("The e-mail field cannot be empty."),
'ImpRemotePrefs.empty_password' => _("The password field cannot be empty."),
'ImpRemotePrefs.next' => _("Next"),
'ImpRemotePrefs.wait' => _("Please wait...")
));
$view = new Horde_View(array(
'templatePath' => IMP_TEMPLATES . '/prefs'
));
$view->addHelper('Horde_Core_View_Helper_Image');
$view->addHelper('Text');
switch ($ui->vars->remote_action) {
case 'new':
$view->new = true;
break;
default:
$view->accounts = iterator_to_array($injector->getInstance('IMP_Remote'));
break;
}
return $view->render('remote');
}
/**
*/
public function update(Horde_Core_Prefs_Ui $ui)
{
global $injector, $notification;
$remote = $injector->getInstance('IMP_Remote');
switch ($ui->vars->remote_action) {
case 'add':
try {
$ob = new IMP_Remote_Account();
$ob->hostspec = $ui->vars->remote_server;
$ob->username = $ui->vars->remote_user;
if (strlen($ui->vars->remote_label)) {
$ob->label = $ui->vars->remote_label;
}
if ($ui->vars->remote_port) {
$ob->port = $ui->vars->remote_port;
}
if ($ui->vars->get('remote_type') == 'pop3') {
$ob->type = $ob::POP3;
}
if (isset($ui->vars->remote_secure_autoconfig)) {
switch ($ui->vars->remote_secure_autoconfig) {
case 'starttls':
$ob->secure = 'tls';
break;
case 'tls':
$ob->secure = 'ssl';
break;
default:
$ob->secure = true;
break;
}
} else {
switch ($ui->vars->remote_secure) {
case 'auto':
$ob->secure = true;
break;
case 'yes':
switch ($ob->type) {
case $ob::IMAP:
$tmp = new Horde_Mail_Autoconfig_Server_Imap();
break;
case $ob::POP3:
$tmp = new Horde_Mail_Autoconfig_Server_Pop3();
break;
}
$tmp->host = $ob->hostspec;
$tmp->port = $ob->port;
$tmp->tls = 'tls';
$ob->secure = $tmp->valid()
? 'ssl'
: 'tls';
break;
}
}
$remote[strval($ob)] = $ob;
$notification->push(sprintf(_("Account \"%s\" added."), $ob->label), 'horde.success');
$injector->getInstance('IMP_Ftree')->insert($ob);
} catch (IMP_Exception $e) {
$notification->push($e, 'horde.error');
}
break;
case 'delete':
if (isset($remote[$ui->vars->remote_data])) {
$ob = $remote[$ui->vars->remote_data];
unset($remote[$ui->vars->remote_data]);
$notification->push(sprintf(_("Account \"%s\" deleted."), $ob->label), 'horde.success');
$injector->getInstance('IMP_Ftree')->delete($ob);
}
break;
}
return false;
}
}