Clean up spamcop plugin wrt globals.
[squirrelmail.git] / plugins / mail_fetch / options.php
CommitLineData
d622d38a 1<?php
d3c89357 2
8d6a115b 3/**
4 * mail_fetch/options.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
8d6a115b 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Setup of the mailfetch plugin.
10 *
11 * $Id$
12 */
d622d38a 13
8d6a115b 14define('SM_PATH','../../');
aa7fb30c 15
8d6a115b 16require_once(SM_PATH . 'include/validate.php');
17require_once(SM_PATH . 'functions/imap.php');
18require_once(SM_PATH . 'include/load_prefs.php');
d622d38a 19
86bb8549 20 /* globals */
21 $username = $_SESSION['username'];
22 $key = $_COOKIE['key'];
23 $onetimepad = $_SESSION['onetimepad'];
24 $delimiter = $_SESSION['delimiter'];
25
26 if(isset($_POST['mf_cypher'])) {
27 $mf_cypher = $_POST['mf_cypher'];
28 }
9d43e2db 29 else {
30 $mf_cyper = '';
31 }
86bb8549 32 if(isset($_POST['mf_sn'])) {
33 $mf_sn = $_POST['mf_sn'];
34 }
35 if(isset($_POST['mf_server'])) {
36 $mf_server = $_POST['mf_server'];
37 }
e42b0dd2 38 if(isset($_POST['mf_port'])) {
39 $mf_port = $_POST['mf_port'];
40 }
86bb8549 41 if(isset($_POST['mf_alias'])) {
42 $mf_alias = $_POST['mf_alias'];
43 }
44 if(isset($_POST['mf_user'])) {
45 $mf_user = $_POST['mf_user'];
46 }
47 if(isset($_POST['mf_pass'])) {
48 $mf_pass = $_POST['mf_pass'];
49 }
50 if(isset($_POST['mf_subfolder'])) {
51 $mf_subfolder = $_POST['mf_subfolder'];
52 }
53 if(isset($_POST['mf_login'])) {
54 $mf_login = $_POST['mf_login'];
55 }
56 if(isset($_POST['mf_fref'])) {
57 $mf_fref = $_POST['mf_fref'];
58 }
59 if(isset($_POST['submit_mailfetch'])) {
60 $submit_mailfetch = $_POST['submit_mailfetch'];
61 }
62 if(isset($_POST['mf_lmos'])) {
63 $mf_lmos = $_POST['mf_lmos'];
64 }
65 /* end globals */
66
d3c89357 67 displayPageHeader( $color, 'None' );
d622d38a 68
d3c89357 69 //if dosen't select any option
86bb8549 70 if (!isset($_POST['mf_action'])) {
d3c89357 71 $mf_action = 'config';
86bb8549 72 } else {
73 $mf_action = $_POST['mf_action'];
74 }
d622d38a 75
d3c89357 76 switch( $mf_action ) {
77 case 'add':
78 if ($mf_sn<1) $mf_sn=0;
79 if (!isset($mf_server)) return;
80 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
85756247 81 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
d3c89357 82 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
83 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
84 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
86bb8549 85 if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on');
d3c89357 86 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
87 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
88 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
89 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
90 $mf_sn++;
91 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
92 $mf_action = 'config';
93 break;
94 case 'confirm_modify':
95 //modify a server
96 if (!isset($mf_server)) return;
97 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
85756247 98 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
d3c89357 99 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
100 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
101 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
102 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
103 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
104 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
105 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
106 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
107 $mf_action = 'config';
108 break;
109 case 'confirm_delete':
110 //delete a server
111 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
112 if ($mf_sn+1==$mailfetch_server_number) {
113 //is the last server, whe can only decrase $mailfetch_server_number
114 $mailfetch_server_number--;
115 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
116 } else {
117 //if not the last, all the sequel server come up one step
118 //then whe decrase $mailfetch_server_number
119 $mailfetch_server_number--;
120 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++) {
121 $tmp=$i+1;
09e47788 122 setPref($data_dir,$username,"mailfetch_server_$i", getPref($data_dir, $username, "mailfetch_server_$tmp"));
b33b71fc 123 setPref($data_dir,$username,"mailfetch_port_$i", getPref($data_dir,$username, "mailfetch_port_$tmp"));
09e47788 124 setPref($data_dir,$username,"mailfetch_alias_$i", getPref($data_dir, $username, "mailfetch_alias_$tmp"));
125 setPref($data_dir,$username,"mailfetch_user_$i", getPref($data_dir, $username, "mailfetch_user_$tmp"));
126 setPref($data_dir,$username,"mailfetch_pass_$i",(isset($mf_pass)?encrypt( $mf_pass ) :""));
d3c89357 127 // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
09e47788 128 setPref($data_dir,$username,"mailfetch_lmos_$i", getPref($data_dir, $username, "mailfetch_lmos_$tmp"));
129 setPref($data_dir,$username,"mailfetch_login_$i", getPref($data_dir, $username, "mailfetch_login_$tmp"));
130 setPref($data_dir,$username,"mailfetch_fref_$i", getPref($data_dir, $username, "mailfetch_fref_$tmp"));
131 setPref($data_dir,$username,"mailfetch_subfolder_$i", getPref($data_dir, $username, "mailfetch_subfolder_$tmp"));
d3c89357 132 }
133 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
134 }
135 $mf_action = 'config';
136 break;
137 }
138
139 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
140 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
141 if ($mailfetch_server_number<1) {
142 $mailfetch_server_number=0;
143 }
d622d38a 144 for ($i=0;$i<$mailfetch_server_number;$i++) {
145 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
e42b0dd2 146 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
d622d38a 147 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
148 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
149 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
150 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
151 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
152 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
153 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
154 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
155 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
156 }
157
158
d3c89357 159 echo '<BR><form method=post action="'.$PHP_SELF.'">' .
4cf43843 160 html_tag( 'table',
161 html_tag( 'tr',
162 html_tag( 'td',
163 '<b>' . _("Remote POP server settings") . '</b>',
164 'center', $color[0] )
165 ),
166 'center', '', 'width="95%" cols="1"' ) .
167 html_tag( 'table',
168 html_tag( 'tr',
169 html_tag( 'td',
170 _("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." ) ,
171 'left' )
172 ) .
173 html_tag( 'tr',
174 html_tag( 'td',
175 _("If you leave password empty, it will be required when you fetch mail.") ,
176 'left' )
177 ) .
178 html_tag( 'tr',
179 html_tag( 'td',
180 '<input type=checkbox name=mf_cypher ' .
181 (($mailfetch_cypher=='on')?'checked >':'>') .
182 _("Encrypt passwords (informative only)") ,
183 'right' )
184 ) ,
185 'center', '', 'width="95%" cols="1"' );
d622d38a 186
d3c89357 187 switch( $mf_action ) {
188 case 'config':
4cf43843 189 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
190 html_tag( 'tr',
191 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
192 ) .
193 html_tag( 'tr' ) .
194 html_tag( 'td', '', 'center', $color[0] ) .
195
d3c89357 196 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
4cf43843 197 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
198 html_tag( 'table' ) .
199 html_tag( 'tr',
200 html_tag( 'th', _("Server:"), 'right' ) .
201 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
202 ) .
b33b71fc 203 html_tag( 'tr',
e42b0dd2 204 html_tag( 'th', _("Port:"), 'right') .
85756247 205 html_tag( 'td', '<input type=text name=mf_port value="110" size=20', 'left')
e42b0dd2 206 ) .
4cf43843 207 html_tag( 'tr',
208 html_tag( 'th', _("Alias:"), 'right' ) .
209 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
210 ) .
211 html_tag( 'tr',
212 html_tag( 'th', _("Username:"), 'right' ) .
213 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
214 ) .
215 html_tag( 'tr',
216 html_tag( 'th', _("Password:"), 'right' ) .
217 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
218 ) .
219 html_tag( 'tr' ) .
220 html_tag( 'th', _("Store in Folder:"), 'right' ) .
221 html_tag( 'td', '', 'left' );
d3c89357 222 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
223 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 224 echo '<select name="mf_subfolder">';
ae8a7931 225
226 $selected = 0;
227 if ( isset($mf_subfolder) )
228 $selected = array(strtolower($mf_subfolder));
229 echo sqimap_mailbox_option_list($imapConnection, $selected);
4cf43843 230 echo '</select></td></tr>' .
231 html_tag( 'tr',
232 html_tag( 'th', '&nbsp;', 'right' ) .
233 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
234 ) .
235 html_tag( 'tr',
236 html_tag( 'th', '&nbsp;', 'right' ) .
237 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
238 ) .
239 html_tag( 'tr',
240 html_tag( 'th', '&nbsp;', 'right' ) .
241 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
242 ) .
243 html_tag( 'tr',
244 html_tag( 'td',
245 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
246 'center', '', 'colspan="2"' )
247 ) .
248 '</table></form></td></tr></table>';
d622d38a 249
d3c89357 250 // Modify Server
251 echo '<font size=-5><BR></font>' .
4cf43843 252 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
253 html_tag( 'tr',
254 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
255 ) .
256 html_tag( 'tr' ) .
257 html_tag( 'td', '', 'center', $color[0] );
d3c89357 258 if ($mailfetch_server_number>0) {
4cf43843 259 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
260 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
d3c89357 261 for ($i=0;$i<$mailfetch_server_number;$i++) {
4cf43843 262 echo "<option value=\"$i\">" .
bcb9c674 263 htmlspecialchars( (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>>";
d3c89357 264 }
4cf43843 265 echo '</select>'.
d3c89357 266 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
267 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
268 '</form>';
269 } else {
270 echo _("No-one server in use. Try to add.");
271 }
4cf43843 272 echo '</td></tr></table>';
d3c89357 273 break;
274 case _("Delete"): //erase confirmation about a server
4cf43843 275 echo html_tag( 'table',
276 html_tag( 'tr',
277 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
278 ) ,
279 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
280 '<br>' .
281 html_tag( 'table',
282 html_tag( 'tr',
283 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
284 ) .
285 html_tag( 'tr',
286 html_tag( 'td',
287 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
288 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
617973c4 289 '<br>' . _("Selected Server:") . " <b>" . htmlentities($mailfetch_server_[$mf_sn]) . "</b><br>" .
4cf43843 290 _("Confirm delete of selected server?") . '<br><br>' .
291 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
292 '<br></form>' ,
293 'center', $color[9] )
294 ) ,
295 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' );
d3c89357 296 break; //modify a server
297 case _("Modify"):
4cf43843 298 echo html_tag( 'table',
299 html_tag( 'tr',
300 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
301 ) ,
302 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
303 '<br>' .
304 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
305 html_tag( 'tr',
306 html_tag( 'td', '<b>' . _("Mofify a Server") . '</b>', 'center', $color[9] )
307 ) .
308 html_tag( 'tr' ) .
309 html_tag( 'td', '', 'center', $color[0] ) .
310
d3c89357 311 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
312 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
4cf43843 313 html_tag( 'table' ) .
314 html_tag( 'tr',
315 html_tag( 'th', _("Server:"), 'right' ) .
617973c4 316 html_tag( 'td', '<input type="text" name="mf_server" value="' . htmlentities($mailfetch_server_[$mf_sn]) . '" size="40">', 'left' )
4cf43843 317 ) .
e42b0dd2 318 html_tag( 'tr',
319 html_tag( 'th', _("Port:"), 'right' ) .
320 html_tag( 'td', '<input type="text" name="mf_port" value="' . $mailfetch_port_[$mf_sn] . '" size="40">', 'left' )
321 ) .
4cf43843 322 html_tag( 'tr',
323 html_tag( 'th', _("Alias:"), 'right' ) .
617973c4 324 html_tag( 'td', '<input type="text" name="mf_alias" value="' . htmlentities($mailfetch_alias_[$mf_sn]) . '" size="40">', 'left' )
4cf43843 325 ) .
326 html_tag( 'tr',
327 html_tag( 'th', _("Username:"), 'right' ) .
328 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
329 ) .
330 html_tag( 'tr',
331 html_tag( 'th', _("Password:"), 'right' ) .
332 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
333 ) .
334 html_tag( 'tr' ) .
335 html_tag( 'th', _("Store in Folder:"), 'right' ) .
336 html_tag( 'td', '', 'left' );
337
d3c89357 338 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
339 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 340 echo '<select name="mf_subfolder">';
ae8a7931 341 $selected = 0;
956f0980 342 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
343 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
344 }
345 echo sqimap_mailbox_option_list($imapConnection, $selected) .
346 '</select></td></tr>' .
4cf43843 347
348 html_tag( 'tr',
349 html_tag( 'th', '&nbsp;', 'right' ) .
350 html_tag( 'td',
351 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
352 '>' . _("Leave Mail on Server") ,
353 'left' )
354 ) .
355 html_tag( 'tr',
356 html_tag( 'th', '&nbsp;', 'right' ) .
357 html_tag( 'td',
358 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
359 '>' . _("Check mail during login"),
360 'left' )
361 ) .
362 html_tag( 'tr',
363 html_tag( 'th', '&nbsp;', 'right' ) .
364 html_tag( 'td',
365 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
366 '>' . _("Check mail during folder refresh") ,
367 'left' )
368 ) .
369 html_tag( 'tr',
370 html_tag( 'td',
371 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
372 'center', '', 'colspan="2"' )
373 ) .
374
375 '</table></form></td></tr></table>';
d3c89357 376 break;
377 default: //unsupported action
4cf43843 378 echo '</form>' .
379 html_tag( 'table',
380 html_tag( 'tr',
381 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
382 ) ,
383 'center', '', 'width="95%" cols="1"' ) .
384 '<br>' .
385 html_tag( 'table',
386 html_tag( 'tr',
387 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
388 html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
389 ) ,
390 'center', '', 'width="70%" cols="1"' );
d3c89357 391 }
d622d38a 392
393 ?>
15e6162e 394</body></html>