do not special case a folder named 'None'. There's no reason
[squirrelmail.git] / plugins / mail_fetch / options.php
1 <?php
2
3 /**
4 * mail_fetch/options.php
5 *
6 * Setup of the mailfetch plugin.
7 *
8 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package plugins
12 * @subpackage mail_fetch
13 */
14
15 /**
16 * Include the SquirrelMail initialization file.
17 */
18 require('../../include/init.php');
19 include_once(SM_PATH . 'plugins/mail_fetch/functions.php' );
20 include_once(SM_PATH . 'functions/imap_general.php');
21 include_once(SM_PATH . 'functions/forms.php');
22
23 /* globals */
24 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
25
26 if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST)) {
27 $mf_cypher = '';
28 }
29 if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST) ) {
30 if (sqgetGlobalVar('mf_action_mod', $mf_action_mod, SQ_POST)) {
31 $mf_action = 'Modify';
32 }
33 elseif (sqgetGlobalVar('mf_action_del', $mf_action_del, SQ_POST)) {
34 $mf_action = 'Delete';
35 }
36 else {
37 $mf_action = 'config';
38 }
39 }
40
41 sqgetGlobalVar('mf_sn', $mf_sn, SQ_POST);
42 sqgetGlobalVar('mf_server', $mf_server, SQ_POST);
43 sqgetGlobalVar('mf_port', $mf_port, SQ_POST);
44 sqgetGlobalVar('mf_alias', $mf_alias, SQ_POST);
45 sqgetGlobalVar('mf_user', $mf_user, SQ_POST);
46 sqgetGlobalVar('mf_pass', $mf_pass, SQ_POST);
47 sqgetGlobalVar('mf_subfolder', $mf_subfolder, SQ_POST);
48 sqgetGlobalVar('mf_login', $mf_login, SQ_POST);
49 sqgetGlobalVar('mf_fref', $mf_fref, SQ_POST);
50 sqgetGlobalVar('mf_lmos', $mf_lmos, SQ_POST);
51 sqgetGlobalVar('mf_auth', $mf_auth, SQ_POST);
52 sqgetGlobalVar('mf_type', $mf_type, SQ_POST);
53 sqgetGlobalVar('submit_mailfetch', $submit_mailfetch, SQ_POST);
54
55
56 /* end globals */
57
58 displayPageHeader( $color );
59
60 switch( $mf_action ) {
61 case 'add':
62 if ($mf_sn<1) $mf_sn=0;
63 if (!isset($mf_server)) return;
64 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
65 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
66 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
67 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
68 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
69 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
70 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
71 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
72 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
73 setPref($data_dir,$username,"mailfetch_auth_$mf_sn",(isset($mf_auth)?$mf_auth:MAIL_FETCH_AUTH_USER));
74 setPref($data_dir,$username,"mailfetch_type_$mf_sn",(isset($mf_type)?$mf_type:MAIL_FETCH_USE_PLAIN));
75 $mf_sn++;
76 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
77 $mf_action = 'config';
78 break;
79 case 'confirm_modify':
80 //modify a server
81 if (!isset($mf_server)) return;
82 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
83 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
84 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
85 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
86 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
87 setPref($data_dir,$username,"mailfetch_cypher", ($mf_cypher == 'on' ? 'on' : ''));
88 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
89 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
90 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
91 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
92 setPref($data_dir,$username,"mailfetch_auth_$mf_sn",(isset($mf_auth)?$mf_auth:MAIL_FETCH_AUTH_USER));
93 setPref($data_dir,$username,"mailfetch_type_$mf_sn",(isset($mf_type)?$mf_type:MAIL_FETCH_USE_PLAIN));
94 $mf_action = 'config';
95 break;
96 case 'confirm_delete':
97 //delete a server
98 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
99 if ($mf_sn+1==$mailfetch_server_number) {
100 //is the last server, whe can only decrase $mailfetch_server_number
101 $mailfetch_server_number--;
102 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
103 } else {
104 //if not the last, all the sequel server come up one step
105 //then whe decrase $mailfetch_server_number
106 $mailfetch_server_number--;
107 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++) {
108 $tmp=$i+1;
109 setPref($data_dir,$username,'mailfetch_server_'.$i,
110 getPref($data_dir,$username, 'mailfetch_server_'.$tmp));
111 setPref($data_dir,$username,'mailfetch_port_'.$i,
112 getPref($data_dir,$username, 'mailfetch_port_'.$tmp));
113 setPref($data_dir,$username,'mailfetch_alias_'.$i,
114 getPref($data_dir,$username, 'mailfetch_alias_'.$tmp));
115 setPref($data_dir,$username,'mailfetch_user_'.$i,
116 getPref($data_dir,$username, 'mailfetch_user_'.$tmp));
117 setPref($data_dir,$username,'mailfetch_pass_'.$i,
118 getPref($data_dir,$username, 'mailfetch_pass_'.$tmp));
119 setPref($data_dir,$username,'mailfetch_lmos_'.$i,
120 getPref($data_dir,$username, 'mailfetch_lmos_'.$tmp));
121 setPref($data_dir,$username,'mailfetch_login_'.$i,
122 getPref($data_dir,$username, 'mailfetch_login_'.$tmp));
123 setPref($data_dir,$username,'mailfetch_fref_'.$i,
124 getPref($data_dir,$username, 'mailfetch_fref_'.$tmp));
125 setPref($data_dir,$username,'mailfetch_subfolder_'.$i,
126 getPref($data_dir,$username, 'mailfetch_subfolder_'.$tmp));
127 setPref($data_dir,$username,'mailfetch_auth_'.$i,
128 getPref($data_dir,$username, 'mailfetch_auth_'.$tmp,MAIL_FETCH_AUTH_USER));
129 setPref($data_dir,$username,'mailfetch_type_'.$i,
130 getPref($data_dir,$username, 'mailfetch_type_'.$tmp,MAIL_FETCH_USE_PLAIN));
131 setPref($data_dir,$username,'mailfetch_uidl_'.$i,
132 getPref($data_dir,$username, 'mailfetch_uidl_'.$tmp));
133 }
134 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
135 }
136 $mf_action = 'config';
137 break;
138 }
139
140 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
141 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
142 if ($mailfetch_server_number<1) {
143 $mailfetch_server_number=0;
144 }
145 for ($i=0;$i<$mailfetch_server_number;$i++) {
146 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
147 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
148 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
149 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
150 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
151 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
152 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
153 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
154 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
155 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
156 $mailfetch_auth_[$i] = getPref($data_dir, $username, "mailfetch_auth_$i",MAIL_FETCH_AUTH_USER);
157 $mailfetch_type_[$i] = getPref($data_dir, $username, "mailfetch_type_$i",MAIL_FETCH_USE_PLAIN);
158 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
159 }
160
161 echo '<br /><form method="post" action="'.$PHP_SELF.'">' .
162 html_tag( 'table',
163 html_tag( 'tr',
164 html_tag('td',
165 '<b>' . _("Remote POP server settings") . '</b>',
166 'center', $color[0] )
167 ),
168 'center', '', 'width="95%"' ) .
169 html_tag( 'table',
170 html_tag( 'tr',
171 html_tag( 'td',
172 _("You should be aware that the encryption used to store your password is not perfectly secure. However, if you are using pop, there is inherently no encryption anyway. Additionally, the encryption that we do to save it on the server can be undone by a hacker reading the source to this file.") ,
173 'left' )
174 ) .
175 html_tag( 'tr',
176 html_tag( 'td',
177 _("If you leave password empty, it will be asked when you fetch mail.") ,
178 'left' )
179 ) .
180 html_tag( 'tr',
181 html_tag( 'td',
182 '<input type="checkbox" name="mf_cypher" ' .
183 (($mailfetch_cypher=='on')?'checked="checked" />':' />') .
184 _("Encrypt passwords (informative only)") ,
185 'right' )
186 ) ,
187 'center', '', 'width="95%"' );
188
189 switch( $mf_action ) {
190 case 'config':
191 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
192 html_tag( 'tr',
193 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
194 ) .
195 html_tag( 'tr' ) .
196 html_tag( 'td', '', 'center', $color[0] ) .
197
198 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mailfetch_server_number\" />" .
199 '<input type="hidden" name="mf_action" value="add" />' .
200 html_tag( 'table' ) .
201 html_tag( 'tr',
202 html_tag( 'th', _("Server:"), 'right' ) .
203 html_tag( 'td', '<input type="text" name="mf_server" value="" size="40" />', 'left' )
204 ) .
205 html_tag( 'tr',
206 html_tag( 'th', _("Port:"), 'right') .
207 html_tag( 'td', '<input type="text" name="mf_port" value="110" size="20" />', 'left')
208 ) .
209 html_tag( 'tr',
210 html_tag( 'th', _("Alias:"), 'right' ) .
211 html_tag( 'td', '<input type="text" name="mf_alias" value="" size="20" />', 'left' )
212 ) .
213 html_tag( 'tr',
214 html_tag( 'th', _("Username:"), 'right' ) .
215 html_tag( 'td', '<input type="text" name="mf_user" value="" size="20" />', 'left' )
216 ) .
217 html_tag( 'tr',
218 html_tag( 'th', _("Password:"), 'right' ) .
219 html_tag( 'td', '<input type="password" name="mf_pass" value="" size="20" />', 'left' )
220 ) .
221 html_tag( 'tr',
222 html_tag( 'th', _("Authentication type:"), 'right' ) .
223 html_tag( 'td', addSelect('mf_auth',
224 array(MAIL_FETCH_AUTH_USER => _("USER"),
225 MAIL_FETCH_AUTH_APOP => _("APOP"),
226 MAIL_FETCH_AUTH_RFC1939 => _("APOP or USER")),
227 MAIL_FETCH_AUTH_USER,true), 'left' )
228 ) .
229 html_tag( 'tr',
230 html_tag( 'th', _("Connection type:"), 'right' ) .
231 html_tag( 'td', addSelect('mf_type',
232 array(MAIL_FETCH_USE_PLAIN => _("Plain text"),
233 MAIL_FETCH_USE_TLS => _("Use TLS"),
234 MAIL_FETCH_USE_STLS => _("Use StartTLS")),
235 MAIL_FETCH_USE_PLAIN,true), 'left' )
236 ) .
237 html_tag( 'tr' ) .
238 html_tag( 'th', _("Store in Folder:"), 'right' ) .
239 html_tag( 'td', '', 'left' );
240 $imapConnection = sqimap_login ($username, false, $imapServerAddress, $imapPort, 0);
241 $boxes = sqimap_mailbox_list($imapConnection);
242 echo '<select name="mf_subfolder">';
243
244 $selected = 0;
245 if ( isset($mf_subfolder) )
246 $selected = array(strtolower($mf_subfolder));
247 echo sqimap_mailbox_option_list($imapConnection, $selected);
248 echo '</select></td></tr>' .
249 html_tag( 'tr',
250 html_tag( 'th', '&nbsp;', 'right' ) .
251 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked="checked" />' . _("Leave Mail on Server"), 'left' )
252 ) .
253 html_tag( 'tr',
254 html_tag( 'th', '&nbsp;', 'right' ) .
255 html_tag( 'td', '<input type="checkbox" name="mf_login" />' . _("Check mail at login"), 'left' )
256 ) .
257 html_tag( 'tr',
258 html_tag( 'th', '&nbsp;', 'right' ) .
259 html_tag( 'td', '<input type="checkbox" name="mf_fref" />' . _("Check mail at folder refresh"), 'left' )
260 ) .
261 html_tag( 'tr',
262 html_tag( 'td',
263 '<input type="submit" name="submit_mailfetch" value="' . _("Add Server") . '" />',
264 'center', '', 'colspan="2"' )
265 ) .
266 '</table></td></tr></table></form>';
267
268 // Modify Server
269 echo '<font size="-5"><br /></font>' .
270 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
271 html_tag( 'tr',
272 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
273 ) .
274 html_tag( 'tr' ) .
275 html_tag( 'td', '', 'center', $color[0] );
276 if ($mailfetch_server_number>0) {
277 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
278 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
279 for ($i=0;$i<$mailfetch_server_number;$i++) {
280 echo "<option value=\"$i\">" .
281 htmlspecialchars( (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>";
282 }
283 echo '</select>'.
284 '&nbsp;&nbsp;<input type="submit" name="mf_action_mod" value="' . _("Modify") . '" />'.
285 '&nbsp;&nbsp;<input type="submit" name="mf_action_del" value="' . _("Delete") . '" />'.
286 '</form>';
287 } else {
288 echo _("No servers known.");
289 }
290 echo '</td></tr></table>';
291 break;
292 case 'Delete': //erase confirmation about a server
293 echo html_tag( 'table',
294 html_tag( 'tr',
295 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
296 ) ,
297 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
298 '<br />' .
299 html_tag( 'table',
300 html_tag( 'tr',
301 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
302 ) .
303 html_tag( 'tr',
304 html_tag( 'td',
305 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mf_sn\" />" .
306 '<input type="hidden" name="mf_action" value="confirm_delete" />' .
307 '<br />' . _("Selected Server:") . " <b>" . htmlspecialchars($mailfetch_server_[$mf_sn]) . "</b><br />" .
308 _("Confirm delete of selected server?") . '<br /><br />' .
309 '<input type="submit" name="submit_mailfetch" value="' . _("Confirm Delete") . '" />' .
310 '<br /></form>' ,
311 'center', $color[9] )
312 ) ,
313 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' );
314 break; //modify a server
315 case 'Modify':
316 echo html_tag( 'table',
317 html_tag( 'tr',
318 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
319 ) ,
320 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
321 '<br />' .
322 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
323 html_tag( 'tr',
324 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
325 ) .
326 html_tag( 'tr' ) .
327 html_tag( 'td', '', 'center', $color[0] ) .
328
329 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mf_sn\" />" .
330 '<input type="hidden" name="mf_action" value="confirm_modify" />' .
331 html_tag( 'table' ) .
332 html_tag( 'tr',
333 html_tag( 'th', _("Server:"), 'right' ) .
334 html_tag( 'td', '<input type="text" name="mf_server" value="' .
335 htmlspecialchars($mailfetch_server_[$mf_sn]) . '" size="40" />', 'left' )
336 ) .
337 html_tag( 'tr',
338 html_tag( 'th', _("Port:"), 'right' ) .
339 html_tag( 'td', '<input type="text" name="mf_port" value="' .
340 htmlspecialchars($mailfetch_port_[$mf_sn]) . '" size="40" />', 'left' )
341 ) .
342 html_tag( 'tr',
343 html_tag( 'th', _("Alias:"), 'right' ) .
344 html_tag( 'td', '<input type="text" name="mf_alias" value="' .
345 htmlspecialchars($mailfetch_alias_[$mf_sn]) . '" size="40" />', 'left' )
346 ) .
347 html_tag( 'tr',
348 html_tag( 'th', _("Username:"), 'right' ) .
349 html_tag( 'td', '<input type="text" name="mf_user" value="' .
350 htmlspecialchars($mailfetch_user_[$mf_sn]) . '" size="20" />', 'left' )
351 ) .
352 html_tag( 'tr',
353 html_tag( 'th', _("Password:"), 'right' ) .
354 html_tag( 'td', '<input type="password" name="mf_pass" value="' .
355 htmlspecialchars($mailfetch_pass_[$mf_sn]) . '" size="20" />', 'left' )
356 ) .
357 html_tag( 'tr',
358 html_tag( 'th', _("Authentication type:"), 'right' ) .
359 html_tag( 'td', addSelect('mf_auth',array(MAIL_FETCH_AUTH_USER => _("USER"),
360 MAIL_FETCH_AUTH_APOP => _("APOP"),
361 MAIL_FETCH_AUTH_RFC1939 => _("APOP or USER")),
362 $mailfetch_auth_[$mf_sn],true), 'left' )
363 ) .
364 html_tag( 'tr',
365 html_tag( 'th', _("Connection type:"), 'right' ) .
366 html_tag( 'td', addSelect('mf_type',array(MAIL_FETCH_USE_PLAIN => _("Plain text"),
367 MAIL_FETCH_USE_TLS => _("Use TLS"),
368 MAIL_FETCH_USE_STLS => _("Use StartTLS")),
369 $mailfetch_type_[$mf_sn],true), 'left' )
370 ) .
371 html_tag( 'tr' ) .
372 html_tag( 'th', _("Store in Folder:"), 'right' ) .
373 html_tag( 'td', '', 'left' );
374
375 $imapConnection = sqimap_login ($username, false, $imapServerAddress, $imapPort, 0);
376 $boxes = sqimap_mailbox_list($imapConnection);
377 echo '<select name="mf_subfolder">';
378 $selected = 0;
379 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
380 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
381 }
382 echo sqimap_mailbox_option_list($imapConnection, $selected) .
383 '</select></td></tr>' .
384 html_tag( 'tr',
385 html_tag( 'th', '&nbsp;', 'right' ) .
386 html_tag( 'td',
387 '<input type="checkbox" name="mf_lmos" ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked="checked"':'') .
388 ' />' . _("Leave Mail on Server") ,
389 'left' )
390 ) .
391 html_tag( 'tr',
392 html_tag( 'th', '&nbsp;', 'right' ) .
393 html_tag( 'td',
394 '<input type="checkbox" name="mf_login" ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked="checked"':'') .
395 ' />' . _("Check mail at login"),
396 'left' )
397 ) .
398 html_tag( 'tr',
399 html_tag( 'th', '&nbsp;', 'right' ) .
400 html_tag( 'td',
401 '<input type="checkbox" name="mf_fref" ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked="checked"':'') .
402 ' />' . _("Check mail at folder refresh") ,
403 'left' )
404 ) .
405 html_tag( 'tr',
406 html_tag( 'td',
407 '<input type="submit" name="submit_mailfetch" value="' . _("Modify Server") . '" />',
408 'center', '', 'colspan="2"' )
409 ) .
410 '</table></form></td></tr></table>';
411 break;
412 default: //unsupported action
413 echo '</form>' .
414 html_tag( 'table',
415 html_tag( 'tr',
416 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
417 ) ,
418 'center', '', 'width="95%"' ) .
419 '<br />' .
420 html_tag( 'table',
421 html_tag( 'tr',
422 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
423 html_tag( 'td', '<b>' . _("The function you requested is unknown.") . '</b>', 'center', $color[0] )
424 ) ,
425 'center', '', 'width="70%"' );
426 }
427
428 $oTemplate->display('footer.tpl');