PHP 4.3.x prefs fix for db based prefs.
[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
3c66c567 20/* globals */
21sqgetGlobalVar('username', $username, SQ_SESSION);
22sqgetGlobalVar('key', $key, SQ_COOKIE);
23sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
24sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
86bb8549 25
3c66c567 26if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST)) {
27 $mf_cypher = '';
28}
29if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST) ) {
30 $mf_action = 'config';
31}
86bb8549 32
3c66c567 33sqgetGlobalVar('mf_sn', $mf_an, SQ_POST);
34sqgetGlobalVar('mf_server', $mf_server, SQ_POST);
35sqgetGlobalVar('mf_port', $mf_port, SQ_POST);
36sqgetGlobalVar('mf_alias', $mf_alias, SQ_POST);
37sqgetGlobalVar('mf_user', $mf_user, SQ_POST);
38sqgetGlobalVar('mf_pass', $mf_pass, SQ_POST);
39sqgetGlobalVar('mf_subfolder', $mf_subfolder, SQ_POST);
40sqgetGlobalVar('mf_login', $mf_login, SQ_POST);
41sqgetGlobalVar('mf_fref', $mf_fref, SQ_POST);
42sqgetGlobalVar('mf_lmos', $mf_lmos, SQ_POST);
43sqgetGlobalVar('submit_mailfetch', $submit_mailfetch, SQ_POST);
d622d38a 44
3c66c567 45/* end globals */
46
47 displayPageHeader( $color, 'None' );
d622d38a 48
d3c89357 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:""));
85756247 54 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
d3c89357 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 ) :""));
86bb8549 58 if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on');
d3c89357 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:""));
85756247 71 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
d3c89357 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;
09e47788 95 setPref($data_dir,$username,"mailfetch_server_$i", getPref($data_dir, $username, "mailfetch_server_$tmp"));
b33b71fc 96 setPref($data_dir,$username,"mailfetch_port_$i", getPref($data_dir,$username, "mailfetch_port_$tmp"));
09e47788 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 ) :""));
d3c89357 100 // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
09e47788 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"));
d3c89357 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 }
d622d38a 117 for ($i=0;$i<$mailfetch_server_number;$i++) {
118 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
e42b0dd2 119 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
d622d38a 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
3c66c567 132 echo '<br><form method="post" action="'.$PHP_SELF.'">' .
4cf43843 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"' );
d622d38a 159
d3c89357 160 switch( $mf_action ) {
161 case 'config':
4cf43843 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
d3c89357 169 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
4cf43843 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 ) .
b33b71fc 176 html_tag( 'tr',
e42b0dd2 177 html_tag( 'th', _("Port:"), 'right') .
85756247 178 html_tag( 'td', '<input type=text name=mf_port value="110" size=20', 'left')
e42b0dd2 179 ) .
4cf43843 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' );
d3c89357 195 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
196 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 197 echo '<select name="mf_subfolder">';
ae8a7931 198
199 $selected = 0;
200 if ( isset($mf_subfolder) )
201 $selected = array(strtolower($mf_subfolder));
202 echo sqimap_mailbox_option_list($imapConnection, $selected);
4cf43843 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>';
d622d38a 222
d3c89357 223 // Modify Server
224 echo '<font size=-5><BR></font>' .
4cf43843 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] );
d3c89357 231 if ($mailfetch_server_number>0) {
4cf43843 232 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
233 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
d3c89357 234 for ($i=0;$i<$mailfetch_server_number;$i++) {
4cf43843 235 echo "<option value=\"$i\">" .
bcb9c674 236 htmlspecialchars( (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>>";
d3c89357 237 }
4cf43843 238 echo '</select>'.
d3c89357 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 }
4cf43843 245 echo '</td></tr></table>';
d3c89357 246 break;
247 case _("Delete"): //erase confirmation about a server
4cf43843 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">' .
617973c4 262 '<br>' . _("Selected Server:") . " <b>" . htmlentities($mailfetch_server_[$mf_sn]) . "</b><br>" .
4cf43843 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"' );
d3c89357 269 break; //modify a server
270 case _("Modify"):
4cf43843 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
d3c89357 284 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
285 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
4cf43843 286 html_tag( 'table' ) .
287 html_tag( 'tr',
288 html_tag( 'th', _("Server:"), 'right' ) .
617973c4 289 html_tag( 'td', '<input type="text" name="mf_server" value="' . htmlentities($mailfetch_server_[$mf_sn]) . '" size="40">', 'left' )
4cf43843 290 ) .
291 html_tag( 'tr',
e42b0dd2 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',
4cf43843 296 html_tag( 'th', _("Alias:"), 'right' ) .
617973c4 297 html_tag( 'td', '<input type="text" name="mf_alias" value="' . htmlentities($mailfetch_alias_[$mf_sn]) . '" size="40">', 'left' )
4cf43843 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
d3c89357 311 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
312 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 313 echo '<select name="mf_subfolder">';
ae8a7931 314 $selected = 0;
956f0980 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>' .
4cf43843 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>';
d3c89357 349 break;
350 default: //unsupported action
4cf43843 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"' );
d3c89357 364 }
d622d38a 365
366 ?>
15e6162e 367</body></html>