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