Fix typo in var name and add two prefs which were left out when renumbering
[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
162cd2c6 33sqgetGlobalVar('mf_sn', $mf_sn, SQ_POST);
3c66c567 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;
162cd2c6 95 setPref($data_dir,$username,'mailfetch_server_'.$i,
96 getPref($data_dir,$username, 'mailfetch_server_'.$tmp));
97 setPref($data_dir,$username,'mailfetch_port_'.$i,
98 getPref($data_dir,$username, 'mailfetch_port_'.$tmp));
99 setPref($data_dir,$username,'mailfetch_alias_'.$i,
100 getPref($data_dir,$username, 'mailfetch_alias_'.$tmp));
101 setPref($data_dir,$username,'mailfetch_user_'.$i,
102 getPref($data_dir,$username, 'mailfetch_user_'.$tmp));
103 setPref($data_dir,$username,'mailfetch_pass_'.$i,
104 getPref($data_dir,$username, 'mailfetch_pass_'.$tmp));
105 setPref($data_dir,$username,'mailfetch_lmos_'.$i,
106 getPref($data_dir,$username, 'mailfetch_lmos_'.$tmp));
107 setPref($data_dir,$username,'mailfetch_login_'.$i,
108 getPref($data_dir,$username, 'mailfetch_login_'.$tmp));
109 setPref($data_dir,$username,'mailfetch_fref_'.$i,
110 getPref($data_dir,$username, 'mailfetch_fref_'.$tmp));
111 setPref($data_dir,$username,'mailfetch_subfolder_'.$i,
112 getPref($data_dir,$username, 'mailfetch_subfolder_'.$tmp));
113 setPref($data_dir,$username,'mailfetch_uidl_'.$i,
114 getPref($data_dir,$username, 'mailfetch_uidl_'.$tmp));
d3c89357 115 }
116 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
117 }
118 $mf_action = 'config';
119 break;
120 }
121
122 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
123 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
124 if ($mailfetch_server_number<1) {
125 $mailfetch_server_number=0;
126 }
d622d38a 127 for ($i=0;$i<$mailfetch_server_number;$i++) {
128 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
e42b0dd2 129 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
d622d38a 130 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
131 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
132 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
133 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
134 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
135 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
136 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
137 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
138 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
139 }
140
141
3c66c567 142 echo '<br><form method="post" action="'.$PHP_SELF.'">' .
4cf43843 143 html_tag( 'table',
144 html_tag( 'tr',
145 html_tag( 'td',
146 '<b>' . _("Remote POP server settings") . '</b>',
147 'center', $color[0] )
148 ),
149 'center', '', 'width="95%" cols="1"' ) .
150 html_tag( 'table',
151 html_tag( 'tr',
152 html_tag( 'td',
153 _("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." ) ,
154 'left' )
155 ) .
156 html_tag( 'tr',
157 html_tag( 'td',
158 _("If you leave password empty, it will be required when you fetch mail.") ,
159 'left' )
160 ) .
161 html_tag( 'tr',
162 html_tag( 'td',
163 '<input type=checkbox name=mf_cypher ' .
164 (($mailfetch_cypher=='on')?'checked >':'>') .
165 _("Encrypt passwords (informative only)") ,
166 'right' )
167 ) ,
168 'center', '', 'width="95%" cols="1"' );
d622d38a 169
d3c89357 170 switch( $mf_action ) {
171 case 'config':
4cf43843 172 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
173 html_tag( 'tr',
174 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
175 ) .
176 html_tag( 'tr' ) .
177 html_tag( 'td', '', 'center', $color[0] ) .
178
d3c89357 179 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
4cf43843 180 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
181 html_tag( 'table' ) .
182 html_tag( 'tr',
183 html_tag( 'th', _("Server:"), 'right' ) .
184 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
185 ) .
b33b71fc 186 html_tag( 'tr',
e42b0dd2 187 html_tag( 'th', _("Port:"), 'right') .
85756247 188 html_tag( 'td', '<input type=text name=mf_port value="110" size=20', 'left')
e42b0dd2 189 ) .
4cf43843 190 html_tag( 'tr',
191 html_tag( 'th', _("Alias:"), 'right' ) .
192 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
193 ) .
194 html_tag( 'tr',
195 html_tag( 'th', _("Username:"), 'right' ) .
196 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
197 ) .
198 html_tag( 'tr',
199 html_tag( 'th', _("Password:"), 'right' ) .
200 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
201 ) .
202 html_tag( 'tr' ) .
203 html_tag( 'th', _("Store in Folder:"), 'right' ) .
204 html_tag( 'td', '', 'left' );
d3c89357 205 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
206 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 207 echo '<select name="mf_subfolder">';
ae8a7931 208
209 $selected = 0;
210 if ( isset($mf_subfolder) )
211 $selected = array(strtolower($mf_subfolder));
212 echo sqimap_mailbox_option_list($imapConnection, $selected);
4cf43843 213 echo '</select></td></tr>' .
214 html_tag( 'tr',
215 html_tag( 'th', '&nbsp;', 'right' ) .
216 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
217 ) .
218 html_tag( 'tr',
219 html_tag( 'th', '&nbsp;', 'right' ) .
220 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
221 ) .
222 html_tag( 'tr',
223 html_tag( 'th', '&nbsp;', 'right' ) .
224 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
225 ) .
226 html_tag( 'tr',
227 html_tag( 'td',
228 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
229 'center', '', 'colspan="2"' )
230 ) .
231 '</table></form></td></tr></table>';
d622d38a 232
d3c89357 233 // Modify Server
234 echo '<font size=-5><BR></font>' .
4cf43843 235 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
236 html_tag( 'tr',
237 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
238 ) .
239 html_tag( 'tr' ) .
240 html_tag( 'td', '', 'center', $color[0] );
d3c89357 241 if ($mailfetch_server_number>0) {
4cf43843 242 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
243 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
d3c89357 244 for ($i=0;$i<$mailfetch_server_number;$i++) {
4cf43843 245 echo "<option value=\"$i\">" .
bcb9c674 246 htmlspecialchars( (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>>";
d3c89357 247 }
4cf43843 248 echo '</select>'.
d3c89357 249 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
250 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
251 '</form>';
252 } else {
253 echo _("No-one server in use. Try to add.");
254 }
4cf43843 255 echo '</td></tr></table>';
d3c89357 256 break;
257 case _("Delete"): //erase confirmation about a server
4cf43843 258 echo html_tag( 'table',
259 html_tag( 'tr',
260 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
261 ) ,
262 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
263 '<br>' .
264 html_tag( 'table',
265 html_tag( 'tr',
266 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
267 ) .
268 html_tag( 'tr',
269 html_tag( 'td',
270 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
271 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
617973c4 272 '<br>' . _("Selected Server:") . " <b>" . htmlentities($mailfetch_server_[$mf_sn]) . "</b><br>" .
4cf43843 273 _("Confirm delete of selected server?") . '<br><br>' .
274 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
275 '<br></form>' ,
276 'center', $color[9] )
277 ) ,
278 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' );
d3c89357 279 break; //modify a server
280 case _("Modify"):
4cf43843 281 echo html_tag( 'table',
282 html_tag( 'tr',
283 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
284 ) ,
285 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
286 '<br>' .
287 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
288 html_tag( 'tr',
289 html_tag( 'td', '<b>' . _("Mofify a Server") . '</b>', 'center', $color[9] )
290 ) .
291 html_tag( 'tr' ) .
292 html_tag( 'td', '', 'center', $color[0] ) .
293
d3c89357 294 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
295 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
4cf43843 296 html_tag( 'table' ) .
297 html_tag( 'tr',
298 html_tag( 'th', _("Server:"), 'right' ) .
617973c4 299 html_tag( 'td', '<input type="text" name="mf_server" value="' . htmlentities($mailfetch_server_[$mf_sn]) . '" size="40">', 'left' )
4cf43843 300 ) .
e42b0dd2 301 html_tag( 'tr',
302 html_tag( 'th', _("Port:"), 'right' ) .
303 html_tag( 'td', '<input type="text" name="mf_port" value="' . $mailfetch_port_[$mf_sn] . '" size="40">', 'left' )
304 ) .
4cf43843 305 html_tag( 'tr',
306 html_tag( 'th', _("Alias:"), 'right' ) .
617973c4 307 html_tag( 'td', '<input type="text" name="mf_alias" value="' . htmlentities($mailfetch_alias_[$mf_sn]) . '" size="40">', 'left' )
4cf43843 308 ) .
309 html_tag( 'tr',
310 html_tag( 'th', _("Username:"), 'right' ) .
311 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
312 ) .
313 html_tag( 'tr',
314 html_tag( 'th', _("Password:"), 'right' ) .
315 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
316 ) .
317 html_tag( 'tr' ) .
318 html_tag( 'th', _("Store in Folder:"), 'right' ) .
319 html_tag( 'td', '', 'left' );
320
d3c89357 321 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
322 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 323 echo '<select name="mf_subfolder">';
ae8a7931 324 $selected = 0;
956f0980 325 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
326 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
327 }
328 echo sqimap_mailbox_option_list($imapConnection, $selected) .
329 '</select></td></tr>' .
4cf43843 330
331 html_tag( 'tr',
332 html_tag( 'th', '&nbsp;', 'right' ) .
333 html_tag( 'td',
334 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
335 '>' . _("Leave Mail on Server") ,
336 'left' )
337 ) .
338 html_tag( 'tr',
339 html_tag( 'th', '&nbsp;', 'right' ) .
340 html_tag( 'td',
341 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
342 '>' . _("Check mail during login"),
343 'left' )
344 ) .
345 html_tag( 'tr',
346 html_tag( 'th', '&nbsp;', 'right' ) .
347 html_tag( 'td',
348 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
349 '>' . _("Check mail during folder refresh") ,
350 'left' )
351 ) .
352 html_tag( 'tr',
353 html_tag( 'td',
354 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
355 'center', '', 'colspan="2"' )
356 ) .
357
358 '</table></form></td></tr></table>';
d3c89357 359 break;
360 default: //unsupported action
4cf43843 361 echo '</form>' .
362 html_tag( 'table',
363 html_tag( 'tr',
364 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
365 ) ,
366 'center', '', 'width="95%" cols="1"' ) .
367 '<br>' .
368 html_tag( 'table',
369 html_tag( 'tr',
370 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
371 html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
372 ) ,
373 'center', '', 'width="70%" cols="1"' );
d3c89357 374 }
d622d38a 375
376 ?>
15e6162e 377</body></html>