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