4 * mail_fetch/options.php
6 * Setup of the mailfetch plugin.
8 * @copyright 1999-2015 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @subpackage mail_fetch
16 * Include the SquirrelMail initialization file.
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');
23 // don't load this page if this plugin is not enabled
26 if (!in_array('mail_fetch', $plugins)) exit;
29 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
31 if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST
)) {
34 if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST
) ) {
35 if (sqgetGlobalVar('mf_action_mod', $mf_action_mod, SQ_POST
)) {
36 $mf_action = 'Modify';
38 elseif (sqgetGlobalVar('mf_action_del', $mf_action_del, SQ_POST
)) {
39 $mf_action = 'Delete';
42 $mf_action = 'config';
46 sqgetGlobalVar('mf_sn', $mf_sn, SQ_POST
);
47 sqgetGlobalVar('mf_server', $mf_server, SQ_POST
);
48 sqgetGlobalVar('mf_port', $mf_port, SQ_POST
);
49 sqgetGlobalVar('mf_alias', $mf_alias, SQ_POST
);
50 sqgetGlobalVar('mf_user', $mf_user, SQ_POST
);
51 sqgetGlobalVar('mf_pass', $mf_pass, SQ_POST
);
52 sqgetGlobalVar('mf_subfolder', $mf_subfolder, SQ_POST
);
53 sqgetGlobalVar('mf_login', $mf_login, SQ_POST
);
54 sqgetGlobalVar('mf_fref', $mf_fref, SQ_POST
);
55 sqgetGlobalVar('mf_lmos', $mf_lmos, SQ_POST
);
56 sqgetGlobalVar('mf_auth', $mf_auth, SQ_POST
);
57 sqgetGlobalVar('mf_type', $mf_type, SQ_POST
);
58 sqgetGlobalVar('submit_mailfetch', $submit_mailfetch, SQ_POST
);
59 $mf_port = trim($mf_port);
60 $mf_server = trim($mf_server);
62 global $imap_stream_options; // in case not defined in config
66 displayPageHeader( $color );
68 switch( $mf_action ) {
71 $mf_action = 'config';
73 // restrict port number if necessary
75 $message = validate_mail_fetch_port_number($mf_port);
76 if (!empty($message)) break;
78 // restrict server address if necessary
80 $message = validate_mail_fetch_server_address($mf_server);
81 if (!empty($message)) break;
83 if ($mf_sn<1) $mf_sn=0;
84 if (!isset($mf_server)) return;
85 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
86 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?
$mf_port:110));
87 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
88 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
90 if ( isset($mf_pass) ) {
91 if ( isset($mf_cypher) && $mf_cypher == 'on' ) {
92 setPref($data_dir,$username,"mailfetch_cypher", ($mf_cypher == 'on' ?
'on' : ''));
93 $pass = encrypt($mf_pass);
98 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",$pass);
99 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
100 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
101 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
102 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
103 setPref($data_dir,$username,"mailfetch_auth_$mf_sn",(isset($mf_auth)?
$mf_auth:MAIL_FETCH_AUTH_USER
));
104 setPref($data_dir,$username,"mailfetch_type_$mf_sn",(isset($mf_type)?
$mf_type:MAIL_FETCH_USE_PLAIN
));
106 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
111 case 'confirm_modify':
113 // restrict port number if necessary
115 $message = validate_mail_fetch_port_number($mf_port);
116 if (!empty($message)) {
117 $mf_action = 'Modify';
121 // restrict server address if necessary
123 $message = validate_mail_fetch_server_address($mf_server);
124 if (!empty($message)) {
125 $mf_action = 'Modify';
129 if (!isset($mf_server)) return;
130 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
131 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?
$mf_port:110));
132 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
133 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
135 if ( isset($mf_pass) ) {
136 if ( isset($mf_cypher) && $mf_cypher == 'on' ) {
137 setPref($data_dir,$username,"mailfetch_cypher", 'on');
138 $pass = encrypt($mf_pass);
140 setPref($data_dir,$username,"mailfetch_cypher", '');
144 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",$pass);
145 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
146 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
147 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
148 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
149 setPref($data_dir,$username,"mailfetch_auth_$mf_sn",(isset($mf_auth)?
$mf_auth:MAIL_FETCH_AUTH_USER
));
150 setPref($data_dir,$username,"mailfetch_type_$mf_sn",(isset($mf_type)?
$mf_type:MAIL_FETCH_USE_PLAIN
));
151 $mf_action = 'config';
153 case 'confirm_delete':
155 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
156 if ($mf_sn+
1==$mailfetch_server_number) {
157 //is the last server, whe can only decrase $mailfetch_server_number
158 $mailfetch_server_number--;
159 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
161 //if not the last, all the sequel server come up one step
162 //then whe decrase $mailfetch_server_number
163 $mailfetch_server_number--;
164 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++
) {
166 setPref($data_dir,$username,'mailfetch_server_'.$i,
167 getPref($data_dir,$username, 'mailfetch_server_'.$tmp));
168 setPref($data_dir,$username,'mailfetch_port_'.$i,
169 getPref($data_dir,$username, 'mailfetch_port_'.$tmp));
170 setPref($data_dir,$username,'mailfetch_alias_'.$i,
171 getPref($data_dir,$username, 'mailfetch_alias_'.$tmp));
172 setPref($data_dir,$username,'mailfetch_user_'.$i,
173 getPref($data_dir,$username, 'mailfetch_user_'.$tmp));
174 setPref($data_dir,$username,'mailfetch_pass_'.$i,
175 getPref($data_dir,$username, 'mailfetch_pass_'.$tmp));
176 setPref($data_dir,$username,'mailfetch_lmos_'.$i,
177 getPref($data_dir,$username, 'mailfetch_lmos_'.$tmp));
178 setPref($data_dir,$username,'mailfetch_login_'.$i,
179 getPref($data_dir,$username, 'mailfetch_login_'.$tmp));
180 setPref($data_dir,$username,'mailfetch_fref_'.$i,
181 getPref($data_dir,$username, 'mailfetch_fref_'.$tmp));
182 setPref($data_dir,$username,'mailfetch_subfolder_'.$i,
183 getPref($data_dir,$username, 'mailfetch_subfolder_'.$tmp));
184 setPref($data_dir,$username,'mailfetch_auth_'.$i,
185 getPref($data_dir,$username, 'mailfetch_auth_'.$tmp,MAIL_FETCH_AUTH_USER
));
186 setPref($data_dir,$username,'mailfetch_type_'.$i,
187 getPref($data_dir,$username, 'mailfetch_type_'.$tmp,MAIL_FETCH_USE_PLAIN
));
188 setPref($data_dir,$username,'mailfetch_uidl_'.$i,
189 getPref($data_dir,$username, 'mailfetch_uidl_'.$tmp));
191 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
193 $mf_action = 'config';
197 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
198 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
199 if ($mailfetch_server_number<1) {
200 $mailfetch_server_number=0;
202 for ($i=0;$i<$mailfetch_server_number;$i++
) {
203 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
204 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
205 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
206 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
207 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
208 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
209 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
210 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
211 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
212 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
213 $mailfetch_auth_[$i] = getPref($data_dir, $username, "mailfetch_auth_$i",MAIL_FETCH_AUTH_USER
);
214 $mailfetch_type_[$i] = getPref($data_dir, $username, "mailfetch_type_$i",MAIL_FETCH_USE_PLAIN
);
215 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
218 echo '<br /><form method="post" action="'.$PHP_SELF.'">' .
222 '<b>' . _("Remote POP server settings") . '</b>',
223 'center', $color[0] )
225 'center', '', 'width="95%"' ) .
229 _("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.") ,
234 _("If you leave password empty, it will be asked when you fetch mail.") ,
239 '<input type="checkbox" name="mf_cypher" ' .
240 (($mailfetch_cypher=='on')?
'checked="checked" />':' />') .
241 _("Encrypt passwords (informative only)") ,
244 'center', '', 'width="95%"' );
246 // display error or other messages if necessary
248 if (!empty($message)) {
249 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
251 html_tag( 'td', '<b>' . $message . '</b>', 'center', $color[2] ));
254 switch( $mf_action ) {
256 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
258 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
261 html_tag( 'td', '', 'center', $color[0] ) .
263 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mailfetch_server_number\" />" .
264 '<input type="hidden" name="mf_action" value="add" />' .
265 html_tag( 'table' ) .
267 html_tag( 'th', _("Server:"), 'right' ) .
268 html_tag( 'td', '<input type="text" name="mf_server" value="" size="40" />', 'left' )
271 html_tag( 'th', _("Port:"), 'right') .
272 html_tag( 'td', '<input type="text" name="mf_port" value="110" size="20" />', 'left')
275 html_tag( 'th', _("Alias:"), 'right' ) .
276 html_tag( 'td', '<input type="text" name="mf_alias" value="" size="20" />', 'left' )
279 html_tag( 'th', _("Username:"), 'right' ) .
280 html_tag( 'td', '<input type="text" name="mf_user" value="" size="20" />', 'left' )
283 html_tag( 'th', _("Password:"), 'right' ) .
284 html_tag( 'td', '<input type="password" name="mf_pass" value="" size="20" />', 'left' )
287 html_tag( 'th', _("Authentication type:"), 'right' ) .
288 html_tag( 'td', addSelect('mf_auth',
289 array(MAIL_FETCH_AUTH_USER
=> _("USER"),
290 MAIL_FETCH_AUTH_APOP
=> _("APOP"),
291 MAIL_FETCH_AUTH_RFC1939
=> _("APOP or USER")),
292 MAIL_FETCH_AUTH_USER
,true), 'left' )
295 html_tag( 'th', _("Connection type:"), 'right' ) .
296 html_tag( 'td', addSelect('mf_type',
297 array(MAIL_FETCH_USE_PLAIN
=> _("Plain text"),
298 MAIL_FETCH_USE_TLS
=> _("Use TLS"),
299 MAIL_FETCH_USE_STLS
=> _("Use StartTLS")),
300 MAIL_FETCH_USE_PLAIN
,true), 'left' )
303 html_tag( 'th', _("Store in Folder:"), 'right' ) .
304 html_tag( 'td', '', 'left' );
305 $imapConnection = sqimap_login ($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
306 $boxes = sqimap_mailbox_list($imapConnection);
307 echo '<select name="mf_subfolder">';
310 if ( isset($mf_subfolder) )
311 $selected = array(strtolower($mf_subfolder));
312 echo sqimap_mailbox_option_list($imapConnection, $selected);
313 echo '</select></td></tr>' .
315 html_tag( 'th', ' ', 'right' ) .
316 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked="checked" />' . _("Leave Mail on Server"), 'left' )
319 html_tag( 'th', ' ', 'right' ) .
320 html_tag( 'td', '<input type="checkbox" name="mf_login" />' . _("Check mail at login"), 'left' )
323 html_tag( 'th', ' ', 'right' ) .
324 html_tag( 'td', '<input type="checkbox" name="mf_fref" />' . _("Check mail at folder refresh"), 'left' )
328 '<input type="submit" name="submit_mailfetch" value="' . _("Add Server") . '" />',
329 'center', '', 'colspan="2"' )
331 '</table></td></tr></table></form>';
334 echo '<font size="-5"><br /></font>' .
335 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
337 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
340 html_tag( 'td', '', 'center', $color[0] );
341 if ($mailfetch_server_number>0) {
342 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
343 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
344 for ($i=0;$i<$mailfetch_server_number;$i++
) {
345 echo "<option value=\"$i\">" .
346 sm_encode_html_special_chars( (($mailfetch_alias_[$i]=='')?
$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>";
349 ' <input type="submit" name="mf_action_mod" value="' . _("Modify") . '" />'.
350 ' <input type="submit" name="mf_action_del" value="' . _("Delete") . '" />'.
353 echo _("No servers known.");
355 echo '</td></tr></table>';
357 case 'Delete': //erase confirmation about a server
358 echo html_tag( 'table',
360 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
362 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
366 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
370 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mf_sn\" />" .
371 '<input type="hidden" name="mf_action" value="confirm_delete" />' .
372 '<br />' . _("Selected Server:") . " <b>" . sm_encode_html_special_chars($mailfetch_server_[$mf_sn]) . "</b><br />" .
373 _("Confirm delete of selected server?") . '<br /><br />' .
374 '<input type="submit" name="submit_mailfetch" value="' . _("Confirm Delete") . '" />' .
376 'center', $color[9] )
378 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' );
379 break; //modify a server
381 echo html_tag( 'table',
383 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
385 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
387 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
389 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
392 html_tag( 'td', '', 'center', $color[0] ) .
394 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mf_sn\" />" .
395 '<input type="hidden" name="mf_action" value="confirm_modify" />' .
396 html_tag( 'table' ) .
398 html_tag( 'th', _("Server:"), 'right' ) .
399 html_tag( 'td', '<input type="text" name="mf_server" value="' .
400 sm_encode_html_special_chars($mailfetch_server_[$mf_sn]) . '" size="40" />', 'left' )
403 html_tag( 'th', _("Port:"), 'right' ) .
404 html_tag( 'td', '<input type="text" name="mf_port" value="' .
405 sm_encode_html_special_chars($mailfetch_port_[$mf_sn]) . '" size="40" />', 'left' )
408 html_tag( 'th', _("Alias:"), 'right' ) .
409 html_tag( 'td', '<input type="text" name="mf_alias" value="' .
410 sm_encode_html_special_chars($mailfetch_alias_[$mf_sn]) . '" size="40" />', 'left' )
413 html_tag( 'th', _("Username:"), 'right' ) .
414 html_tag( 'td', '<input type="text" name="mf_user" value="' .
415 sm_encode_html_special_chars($mailfetch_user_[$mf_sn]) . '" size="20" />', 'left' )
418 html_tag( 'th', _("Password:"), 'right' ) .
419 html_tag( 'td', '<input type="password" name="mf_pass" value="' .
420 sm_encode_html_special_chars($mailfetch_pass_[$mf_sn]) . '" size="20" />', 'left' )
423 html_tag( 'th', _("Authentication type:"), 'right' ) .
424 html_tag( 'td', addSelect('mf_auth',array(MAIL_FETCH_AUTH_USER
=> _("USER"),
425 MAIL_FETCH_AUTH_APOP
=> _("APOP"),
426 MAIL_FETCH_AUTH_RFC1939
=> _("APOP or USER")),
427 $mailfetch_auth_[$mf_sn],true), 'left' )
430 html_tag( 'th', _("Connection type:"), 'right' ) .
431 html_tag( 'td', addSelect('mf_type',array(MAIL_FETCH_USE_PLAIN
=> _("Plain text"),
432 MAIL_FETCH_USE_TLS
=> _("Use TLS"),
433 MAIL_FETCH_USE_STLS
=> _("Use StartTLS")),
434 $mailfetch_type_[$mf_sn],true), 'left' )
437 html_tag( 'th', _("Store in Folder:"), 'right' ) .
438 html_tag( 'td', '', 'left' );
440 $imapConnection = sqimap_login ($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
441 $boxes = sqimap_mailbox_list($imapConnection);
442 echo '<select name="mf_subfolder">';
444 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
445 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
447 echo sqimap_mailbox_option_list($imapConnection, $selected) .
448 '</select></td></tr>' .
450 html_tag( 'th', ' ', 'right' ) .
452 '<input type="checkbox" name="mf_lmos" ' . (($mailfetch_lmos_[$mf_sn] == 'on')?
'checked="checked"':'') .
453 ' />' . _("Leave Mail on Server") ,
457 html_tag( 'th', ' ', 'right' ) .
459 '<input type="checkbox" name="mf_login" ' . ( ($mailfetch_login_[$mf_sn] == 'on')?
'checked="checked"':'') .
460 ' />' . _("Check mail at login"),
464 html_tag( 'th', ' ', 'right' ) .
466 '<input type="checkbox" name="mf_fref" ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?
'checked="checked"':'') .
467 ' />' . _("Check mail at folder refresh") ,
472 '<input type="submit" name="submit_mailfetch" value="' . _("Modify Server") . '" />',
473 'center', '', 'colspan="2"' )
475 '</table></form></td></tr></table>';
477 default: //unsupported action
481 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
483 'center', '', 'width="95%"' ) .
487 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
488 html_tag( 'td', '<b>' . _("The function you requested is unknown.") . '</b>', 'center', $color[0] )
490 'center', '', 'width="70%"' );
493 $oTemplate->display('footer.tpl');