abb19cd21a90e74712e6703dfaa91f1e0754e728
[squirrelmail.git] / plugins / mail_fetch / options.php
1 <?php
2
3 /**
4 * mail_fetch/options.php
5 *
6 * Setup of the mailfetch plugin.
7 *
8 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package plugins
12 * @subpackage mail_fetch
13 */
14
15 /**
16 * Include the SquirrelMail initialization file.
17 */
18 require('../../include/init.php');
19 include_once(SM_PATH . 'plugins/mail_fetch/functions.php' );
20 include_once(SM_PATH . 'functions/imap_general.php');
21 include_once(SM_PATH . 'functions/forms.php');
22
23 /* globals */
24 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
25
26 if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST)) {
27 $mf_cypher = '';
28 }
29 if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST) ) {
30 if (sqgetGlobalVar('mf_action_mod', $mf_action_mod, SQ_POST)) {
31 $mf_action = 'Modify';
32 }
33 elseif (sqgetGlobalVar('mf_action_del', $mf_action_del, SQ_POST)) {
34 $mf_action = 'Delete';
35 }
36 else {
37 $mf_action = 'config';
38 }
39 }
40
41 sqgetGlobalVar('mf_sn', $mf_sn, SQ_POST);
42 sqgetGlobalVar('mf_server', $mf_server, SQ_POST);
43 sqgetGlobalVar('mf_port', $mf_port, SQ_POST);
44 sqgetGlobalVar('mf_alias', $mf_alias, SQ_POST);
45 sqgetGlobalVar('mf_user', $mf_user, SQ_POST);
46 sqgetGlobalVar('mf_pass', $mf_pass, SQ_POST);
47 sqgetGlobalVar('mf_subfolder', $mf_subfolder, SQ_POST);
48 sqgetGlobalVar('mf_login', $mf_login, SQ_POST);
49 sqgetGlobalVar('mf_fref', $mf_fref, SQ_POST);
50 sqgetGlobalVar('mf_lmos', $mf_lmos, SQ_POST);
51 sqgetGlobalVar('mf_auth', $mf_auth, SQ_POST);
52 sqgetGlobalVar('mf_type', $mf_type, SQ_POST);
53 sqgetGlobalVar('submit_mailfetch', $submit_mailfetch, SQ_POST);
54
55
56 /* end globals */
57
58 displayPageHeader( $color, 'None' );
59
60 switch( $mf_action ) {
61 case 'add':
62 if ($mf_sn<1) $mf_sn=0;
63 if (!isset($mf_server)) return;
64 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
65 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
66 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
67 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
68 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
69 if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on');
70 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
71 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
72 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
73 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
74 setPref($data_dir,$username,"mailfetch_auth_$mf_sn",(isset($mf_auth)?$mf_auth:MAIL_FETCH_AUTH_USER));
75 setPref($data_dir,$username,"mailfetch_type_$mf_sn",(isset($mf_type)?$mf_type:MAIL_FETCH_USE_PLAIN));
76 $mf_sn++;
77 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
78 $mf_action = 'config';
79 break;
80 case 'confirm_modify':
81 //modify a server
82 if (!isset($mf_server)) return;
83 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
84 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
85 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
86 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
87 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
88 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
89 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
90 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
91 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
92 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
93 setPref($data_dir,$username,"mailfetch_auth_$mf_sn",(isset($mf_auth)?$mf_auth:MAIL_FETCH_AUTH_USER));
94 setPref($data_dir,$username,"mailfetch_type_$mf_sn",(isset($mf_type)?$mf_type:MAIL_FETCH_USE_PLAIN));
95 $mf_action = 'config';
96 break;
97 case 'confirm_delete':
98 //delete a server
99 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
100 if ($mf_sn+1==$mailfetch_server_number) {
101 //is the last server, whe can only decrase $mailfetch_server_number
102 $mailfetch_server_number--;
103 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
104 } else {
105 //if not the last, all the sequel server come up one step
106 //then whe decrase $mailfetch_server_number
107 $mailfetch_server_number--;
108 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++) {
109 $tmp=$i+1;
110 setPref($data_dir,$username,'mailfetch_server_'.$i,
111 getPref($data_dir,$username, 'mailfetch_server_'.$tmp));
112 setPref($data_dir,$username,'mailfetch_port_'.$i,
113 getPref($data_dir,$username, 'mailfetch_port_'.$tmp));
114 setPref($data_dir,$username,'mailfetch_alias_'.$i,
115 getPref($data_dir,$username, 'mailfetch_alias_'.$tmp));
116 setPref($data_dir,$username,'mailfetch_user_'.$i,
117 getPref($data_dir,$username, 'mailfetch_user_'.$tmp));
118 setPref($data_dir,$username,'mailfetch_pass_'.$i,
119 getPref($data_dir,$username, 'mailfetch_pass_'.$tmp));
120 setPref($data_dir,$username,'mailfetch_lmos_'.$i,
121 getPref($data_dir,$username, 'mailfetch_lmos_'.$tmp));
122 setPref($data_dir,$username,'mailfetch_login_'.$i,
123 getPref($data_dir,$username, 'mailfetch_login_'.$tmp));
124 setPref($data_dir,$username,'mailfetch_fref_'.$i,
125 getPref($data_dir,$username, 'mailfetch_fref_'.$tmp));
126 setPref($data_dir,$username,'mailfetch_subfolder_'.$i,
127 getPref($data_dir,$username, 'mailfetch_subfolder_'.$tmp));
128 setPref($data_dir,$username,'mailfetch_auth_'.$i,
129 getPref($data_dir,$username, 'mailfetch_auth_'.$tmp,MAIL_FETCH_AUTH_USER));
130 setPref($data_dir,$username,'mailfetch_type_'.$i,
131 getPref($data_dir,$username, 'mailfetch_type_'.$tmp,MAIL_FETCH_USE_PLAIN));
132 setPref($data_dir,$username,'mailfetch_uidl_'.$i,
133 getPref($data_dir,$username, 'mailfetch_uidl_'.$tmp));
134 }
135 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
136 }
137 $mf_action = 'config';
138 break;
139 }
140
141 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
142 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
143 if ($mailfetch_server_number<1) {
144 $mailfetch_server_number=0;
145 }
146 for ($i=0;$i<$mailfetch_server_number;$i++) {
147 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
148 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
149 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
150 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
151 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
152 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
153 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
154 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
155 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
156 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
157 $mailfetch_auth_[$i] = getPref($data_dir, $username, "mailfetch_auth_$i",MAIL_FETCH_AUTH_USER);
158 $mailfetch_type_[$i] = getPref($data_dir, $username, "mailfetch_type_$i",MAIL_FETCH_USE_PLAIN);
159 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
160 }
161
162 echo '<br /><form method="post" action="'.$PHP_SELF.'">' .
163 html_tag( 'table',
164 html_tag( 'tr',
165 html_tag('td',
166 '<b>' . _("Remote POP server settings") . '</b>',
167 'center', $color[0] )
168 ),
169 'center', '', 'width="95%"' ) .
170 html_tag( 'table',
171 html_tag( 'tr',
172 html_tag( 'td',
173 _("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.") ,
174 'left' )
175 ) .
176 html_tag( 'tr',
177 html_tag( 'td',
178 _("If you leave password empty, it will be asked when you fetch mail.") ,
179 'left' )
180 ) .
181 html_tag( 'tr',
182 html_tag( 'td',
183 '<input type="checkbox" name="mf_cypher" ' .
184 (($mailfetch_cypher=='on')?'checked="checked" />':' />') .
185 _("Encrypt passwords (informative only)") ,
186 'right' )
187 ) ,
188 'center', '', 'width="95%"' );
189
190 switch( $mf_action ) {
191 case 'config':
192 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
193 html_tag( 'tr',
194 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
195 ) .
196 html_tag( 'tr' ) .
197 html_tag( 'td', '', 'center', $color[0] ) .
198
199 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mailfetch_server_number\" />" .
200 '<input type="hidden" name="mf_action" value="add" />' .
201 html_tag( 'table' ) .
202 html_tag( 'tr',
203 html_tag( 'th', _("Server:"), 'right' ) .
204 html_tag( 'td', '<input type="text" name="mf_server" value="" size="40" />', 'left' )
205 ) .
206 html_tag( 'tr',
207 html_tag( 'th', _("Port:"), 'right') .
208 html_tag( 'td', '<input type="text" name="mf_port" value="110" size="20" />', 'left')
209 ) .
210 html_tag( 'tr',
211 html_tag( 'th', _("Alias:"), 'right' ) .
212 html_tag( 'td', '<input type="text" name="mf_alias" value="" size="20" />', 'left' )
213 ) .
214 html_tag( 'tr',
215 html_tag( 'th', _("Username:"), 'right' ) .
216 html_tag( 'td', '<input type="text" name="mf_user" value="" size="20" />', 'left' )
217 ) .
218 html_tag( 'tr',
219 html_tag( 'th', _("Password:"), 'right' ) .
220 html_tag( 'td', '<input type="password" name="mf_pass" value="" size="20" />', 'left' )
221 ) .
222 html_tag( 'tr',
223 html_tag( 'th', _("Authentication type:"), 'right' ) .
224 html_tag( 'td', addSelect('mf_auth',
225 array(MAIL_FETCH_AUTH_USER => _("USER"),
226 MAIL_FETCH_AUTH_APOP => _("APOP"),
227 MAIL_FETCH_AUTH_RFC1939 => _("APOP or USER")),
228 MAIL_FETCH_AUTH_USER,true), 'left' )
229 ) .
230 html_tag( 'tr',
231 html_tag( 'th', _("Connection type:"), 'right' ) .
232 html_tag( 'td', addSelect('mf_type',
233 array(MAIL_FETCH_USE_PLAIN => _("Plain text"),
234 MAIL_FETCH_USE_TLS => _("Use TLS"),
235 MAIL_FETCH_USE_STLS => _("Use StartTLS")),
236 MAIL_FETCH_USE_PLAIN,true), 'left' )
237 ) .
238 html_tag( 'tr' ) .
239 html_tag( 'th', _("Store in Folder:"), 'right' ) .
240 html_tag( 'td', '', 'left' );
241 $imapConnection = sqimap_login ($username, false, $imapServerAddress, $imapPort, 0);
242 $boxes = sqimap_mailbox_list($imapConnection);
243 echo '<select name="mf_subfolder">';
244
245 $selected = 0;
246 if ( isset($mf_subfolder) )
247 $selected = array(strtolower($mf_subfolder));
248 echo sqimap_mailbox_option_list($imapConnection, $selected);
249 echo '</select></td></tr>' .
250 html_tag( 'tr',
251 html_tag( 'th', '&nbsp;', 'right' ) .
252 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked="checked" />' . _("Leave Mail on Server"), 'left' )
253 ) .
254 html_tag( 'tr',
255 html_tag( 'th', '&nbsp;', 'right' ) .
256 html_tag( 'td', '<input type="checkbox" name="mf_login" />' . _("Check mail at login"), 'left' )
257 ) .
258 html_tag( 'tr',
259 html_tag( 'th', '&nbsp;', 'right' ) .
260 html_tag( 'td', '<input type="checkbox" name="mf_fref" />' . _("Check mail at folder refresh"), 'left' )
261 ) .
262 html_tag( 'tr',
263 html_tag( 'td',
264 '<input type="submit" name="submit_mailfetch" value="' . _("Add Server") . '" />',
265 'center', '', 'colspan="2"' )
266 ) .
267 '</table></td></tr></table></form>';
268
269 // Modify Server
270 echo '<font size="-5"><br /></font>' .
271 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
272 html_tag( 'tr',
273 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
274 ) .
275 html_tag( 'tr' ) .
276 html_tag( 'td', '', 'center', $color[0] );
277 if ($mailfetch_server_number>0) {
278 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
279 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
280 for ($i=0;$i<$mailfetch_server_number;$i++) {
281 echo "<option value=\"$i\">" .
282 htmlspecialchars( (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>";
283 }
284 echo '</select>'.
285 '&nbsp;&nbsp;<input type="submit" name="mf_action_mod" value="' . _("Modify") . '" />'.
286 '&nbsp;&nbsp;<input type="submit" name="mf_action_del" value="' . _("Delete") . '" />'.
287 '</form>';
288 } else {
289 echo _("No servers known.");
290 }
291 echo '</td></tr></table>';
292 break;
293 case 'Delete': //erase confirmation about a server
294 echo html_tag( 'table',
295 html_tag( 'tr',
296 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
297 ) ,
298 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
299 '<br />' .
300 html_tag( 'table',
301 html_tag( 'tr',
302 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
303 ) .
304 html_tag( 'tr',
305 html_tag( 'td',
306 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mf_sn\" />" .
307 '<input type="hidden" name="mf_action" value="confirm_delete" />' .
308 '<br />' . _("Selected Server:") . " <b>" . htmlspecialchars($mailfetch_server_[$mf_sn]) . "</b><br />" .
309 _("Confirm delete of selected server?") . '<br /><br />' .
310 '<input type="submit" name="submit_mailfetch" value="' . _("Confirm Delete") . '" />' .
311 '<br /></form>' ,
312 'center', $color[9] )
313 ) ,
314 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' );
315 break; //modify a server
316 case 'Modify':
317 echo html_tag( 'table',
318 html_tag( 'tr',
319 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
320 ) ,
321 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
322 '<br />' .
323 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
324 html_tag( 'tr',
325 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
326 ) .
327 html_tag( 'tr' ) .
328 html_tag( 'td', '', 'center', $color[0] ) .
329
330 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mf_sn\" />" .
331 '<input type="hidden" name="mf_action" value="confirm_modify" />' .
332 html_tag( 'table' ) .
333 html_tag( 'tr',
334 html_tag( 'th', _("Server:"), 'right' ) .
335 html_tag( 'td', '<input type="text" name="mf_server" value="' .
336 htmlspecialchars($mailfetch_server_[$mf_sn]) . '" size="40" />', 'left' )
337 ) .
338 html_tag( 'tr',
339 html_tag( 'th', _("Port:"), 'right' ) .
340 html_tag( 'td', '<input type="text" name="mf_port" value="' .
341 htmlspecialchars($mailfetch_port_[$mf_sn]) . '" size="40" />', 'left' )
342 ) .
343 html_tag( 'tr',
344 html_tag( 'th', _("Alias:"), 'right' ) .
345 html_tag( 'td', '<input type="text" name="mf_alias" value="' .
346 htmlspecialchars($mailfetch_alias_[$mf_sn]) . '" size="40" />', 'left' )
347 ) .
348 html_tag( 'tr',
349 html_tag( 'th', _("Username:"), 'right' ) .
350 html_tag( 'td', '<input type="text" name="mf_user" value="' .
351 htmlspecialchars($mailfetch_user_[$mf_sn]) . '" size="20" />', 'left' )
352 ) .
353 html_tag( 'tr',
354 html_tag( 'th', _("Password:"), 'right' ) .
355 html_tag( 'td', '<input type="password" name="mf_pass" value="' .
356 htmlspecialchars($mailfetch_pass_[$mf_sn]) . '" size="20" />', 'left' )
357 ) .
358 html_tag( 'tr',
359 html_tag( 'th', _("Authentication type:"), 'right' ) .
360 html_tag( 'td', addSelect('mf_auth',array(MAIL_FETCH_AUTH_USER => _("USER"),
361 MAIL_FETCH_AUTH_APOP => _("APOP"),
362 MAIL_FETCH_AUTH_RFC1939 => _("APOP or USER")),
363 $mailfetch_auth_[$mf_sn],true), 'left' )
364 ) .
365 html_tag( 'tr',
366 html_tag( 'th', _("Connection type:"), 'right' ) .
367 html_tag( 'td', addSelect('mf_type',array(MAIL_FETCH_USE_PLAIN => _("Plain text"),
368 MAIL_FETCH_USE_TLS => _("Use TLS"),
369 MAIL_FETCH_USE_STLS => _("Use StartTLS")),
370 $mailfetch_type_[$mf_sn],true), 'left' )
371 ) .
372 html_tag( 'tr' ) .
373 html_tag( 'th', _("Store in Folder:"), 'right' ) .
374 html_tag( 'td', '', 'left' );
375
376 $imapConnection = sqimap_login ($username, false, $imapServerAddress, $imapPort, 0);
377 $boxes = sqimap_mailbox_list($imapConnection);
378 echo '<select name="mf_subfolder">';
379 $selected = 0;
380 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
381 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
382 }
383 echo sqimap_mailbox_option_list($imapConnection, $selected) .
384 '</select></td></tr>' .
385 html_tag( 'tr',
386 html_tag( 'th', '&nbsp;', 'right' ) .
387 html_tag( 'td',
388 '<input type="checkbox" name="mf_lmos" ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked="checked"':'') .
389 ' />' . _("Leave Mail on Server") ,
390 'left' )
391 ) .
392 html_tag( 'tr',
393 html_tag( 'th', '&nbsp;', 'right' ) .
394 html_tag( 'td',
395 '<input type="checkbox" name="mf_login" ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked="checked"':'') .
396 ' />' . _("Check mail at login"),
397 'left' )
398 ) .
399 html_tag( 'tr',
400 html_tag( 'th', '&nbsp;', 'right' ) .
401 html_tag( 'td',
402 '<input type="checkbox" name="mf_fref" ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked="checked"':'') .
403 ' />' . _("Check mail at folder refresh") ,
404 'left' )
405 ) .
406 html_tag( 'tr',
407 html_tag( 'td',
408 '<input type="submit" name="submit_mailfetch" value="' . _("Modify Server") . '" />',
409 'center', '', 'colspan="2"' )
410 ) .
411 '</table></form></td></tr></table>';
412 break;
413 default: //unsupported action
414 echo '</form>' .
415 html_tag( 'table',
416 html_tag( 'tr',
417 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
418 ) ,
419 'center', '', 'width="95%"' ) .
420 '<br />' .
421 html_tag( 'table',
422 html_tag( 'tr',
423 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
424 html_tag( 'td', '<b>' . _("The function you requested is unknown.") . '</b>', 'center', $color[0] )
425 ) ,
426 'center', '', 'width="70%"' );
427 }
428
429 $oTemplate->display('footer.tpl');