27715287038d6c7810ebe53355fcdbea084d98d1
[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_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
61 displayPageHeader( $color, 'None' );
62
63 //if dosen't select any option
64 if (!isset($_POST['mf_action'])) {
65 $mf_action = 'config';
66 } else {
67 $mf_action = $_POST['mf_action'];
68 }
69
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 ) :""));
78 if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on');
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;
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 ) :""));
118 // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
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"));
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 }
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
149 echo '<BR><form method=post action="'.$PHP_SELF.'">' .
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"' );
176
177 switch( $mf_action ) {
178 case 'config':
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
186 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
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' );
208 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
209 $boxes = sqimap_mailbox_list($imapConnection);
210 echo '<select name="mf_subfolder">';
211 $boxes = sqimap_mailbox_list($imapConnection);
212 for ($i = 0; $i < count($boxes); $i++) {
213 if (!in_array('noselect', $boxes[$i]['flags'])) {
214 $box = $boxes[$i]['unformatted'];
215 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
216 if ( strtolower( $box2 ) == 'inbox' ) {
217 $box2 = _("INBOX");
218 }
219 echo "<option value=\"$box\">$box2</option>\n";
220 }
221 }
222 echo '</select></td></tr>' .
223 html_tag( 'tr',
224 html_tag( 'th', '&nbsp;', 'right' ) .
225 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
226 ) .
227 html_tag( 'tr',
228 html_tag( 'th', '&nbsp;', 'right' ) .
229 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
230 ) .
231 html_tag( 'tr',
232 html_tag( 'th', '&nbsp;', 'right' ) .
233 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
234 ) .
235 html_tag( 'tr',
236 html_tag( 'td',
237 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
238 'center', '', 'colspan="2"' )
239 ) .
240 '</table></form></td></tr></table>';
241
242 // Modify Server
243 echo '<font size=-5><BR></font>' .
244 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
245 html_tag( 'tr',
246 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
247 ) .
248 html_tag( 'tr' ) .
249 html_tag( 'td', '', 'center', $color[0] );
250 if ($mailfetch_server_number>0) {
251 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
252 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
253 for ($i=0;$i<$mailfetch_server_number;$i++) {
254 echo "<option value=\"$i\">" .
255 (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</option>>";
256 }
257 echo '</select>'.
258 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
259 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
260 '</form>';
261 } else {
262 echo _("No-one server in use. Try to add.");
263 }
264 echo '</td></tr></table>';
265 break;
266 case _("Delete"): //erase confirmation about a server
267 echo html_tag( 'table',
268 html_tag( 'tr',
269 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
270 ) ,
271 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
272 '<br>' .
273 html_tag( 'table',
274 html_tag( 'tr',
275 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
276 ) .
277 html_tag( 'tr',
278 html_tag( 'td',
279 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
280 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
281 '<br>' . _("Selected Server:") . " <b>$mailfetch_server_[$mf_sn]</b><br>" .
282 _("Confirm delete of selected server?") . '<br><br>' .
283 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
284 '<br></form>' ,
285 'center', $color[9] )
286 ) ,
287 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' );
288 break; //modify a server
289 case _("Modify"):
290 echo html_tag( 'table',
291 html_tag( 'tr',
292 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
293 ) ,
294 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
295 '<br>' .
296 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
297 html_tag( 'tr',
298 html_tag( 'td', '<b>' . _("Mofify a Server") . '</b>', 'center', $color[9] )
299 ) .
300 html_tag( 'tr' ) .
301 html_tag( 'td', '', 'center', $color[0] ) .
302
303 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
304 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
305 html_tag( 'table' ) .
306 html_tag( 'tr',
307 html_tag( 'th', _("Server:"), 'right' ) .
308 html_tag( 'td', '<input type="text" name="mf_server" value="' . $mailfetch_server_[$mf_sn] . '" size="40">', 'left' )
309 ) .
310 html_tag( 'tr',
311 html_tag( 'th', _("Alias:"), 'right' ) .
312 html_tag( 'td', '<input type="text" name="mf_alias" value="' . $mailfetch_alias_[$mf_sn] . '" size="40">', 'left' )
313 ) .
314 html_tag( 'tr',
315 html_tag( 'th', _("Username:"), 'right' ) .
316 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
317 ) .
318 html_tag( 'tr',
319 html_tag( 'th', _("Password:"), 'right' ) .
320 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
321 ) .
322 html_tag( 'tr' ) .
323 html_tag( 'th', _("Store in Folder:"), 'right' ) .
324 html_tag( 'td', '', 'left' );
325
326 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
327 $boxes = sqimap_mailbox_list($imapConnection);
328 echo '<select name="mf_subfolder">';
329 $boxes = sqimap_mailbox_list($imapConnection);
330 for ($i = 0; $i < count($boxes); $i++) {
331 if (!in_array('noselect', $boxes[$i]['flags'])) {
332 $box = $boxes[$i]['unformatted'];
333 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
334 if ( strtolower( $box2 ) == 'inbox' ) {
335 $box2 = _("INBOX");
336 }
337 echo '<option ' .
338 (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?'selected':'') .
339 " value=\"$box\">$box2</option>\n";
340 }
341 }
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>