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