4 * mail_fetch/options.php
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Setup of the mailfetch plugin.
14 define('SM_PATH','../../');
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');
21 $username = $_SESSION['username'];
22 $key = $_COOKIE['key'];
23 $onetimepad = $_SESSION['onetimepad'];
24 $delimiter = $_SESSION['delimiter'];
26 if(isset($_POST['mf_cypher'])) {
27 $mf_cypher = $_POST['mf_cypher'];
29 if(isset($_POST['mf_sn'])) {
30 $mf_sn = $_POST['mf_sn'];
32 if(isset($_POST['mf_server'])) {
33 $mf_server = $_POST['mf_server'];
35 if(isset($_POST['mf_port'])) {
36 $mf_port = $_POST['mf_port'];
38 if(isset($_POST['mf_alias'])) {
39 $mf_alias = $_POST['mf_alias'];
41 if(isset($_POST['mf_user'])) {
42 $mf_user = $_POST['mf_user'];
44 if(isset($_POST['mf_pass'])) {
45 $mf_pass = $_POST['mf_pass'];
47 if(isset($_POST['mf_subfolder'])) {
48 $mf_subfolder = $_POST['mf_subfolder'];
50 if(isset($_POST['mf_login'])) {
51 $mf_login = $_POST['mf_login'];
53 if(isset($_POST['mf_fref'])) {
54 $mf_fref = $_POST['mf_fref'];
56 if(isset($_POST['submit_mailfetch'])) {
57 $submit_mailfetch = $_POST['submit_mailfetch'];
59 if(isset($_POST['mf_lmos'])) {
60 $mf_lmos = $_POST['mf_lmos'];
64 displayPageHeader( $color, 'None' );
66 //if dosen't select any option
67 if (!isset($_POST['mf_action'])) {
68 $mf_action = 'config';
70 $mf_action = $_POST['mf_action'];
73 switch( $mf_action ) {
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:""));
88 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
89 $mf_action = 'config';
91 case 'confirm_modify':
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';
106 case 'confirm_delete':
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);
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++
) {
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"));
130 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
132 $mf_action = 'config';
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;
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] );
156 echo '<BR><form method=post action="'.$PHP_SELF.'">' .
160 '<b>' . _("Remote POP server settings") . '</b>',
161 'center', $color[0] )
163 'center', '', 'width="95%" cols="1"' ) .
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." ) ,
172 _("If you leave password empty, it will be required when you fetch mail.") ,
177 '<input type=checkbox name=mf_cypher ' .
178 (($mailfetch_cypher=='on')?
'checked >':'>') .
179 _("Encrypt passwords (informative only)") ,
182 'center', '', 'width="95%" cols="1"' );
184 switch( $mf_action ) {
186 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
188 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
191 html_tag( 'td', '', 'center', $color[0] ) .
193 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
194 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
195 html_tag( 'table' ) .
197 html_tag( 'th', _("Server:"), 'right' ) .
198 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
201 html_tag( 'th', _("Port:"), 'right') .
202 html_tag( 'td', '<input type=text name=mf_port value="110" size=20', 'left')
205 html_tag( 'th', _("Alias:"), 'right' ) .
206 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
209 html_tag( 'th', _("Username:"), 'right' ) .
210 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
213 html_tag( 'th', _("Password:"), 'right' ) .
214 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
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">';
224 if ( isset($mf_subfolder) )
225 $selected = array(strtolower($mf_subfolder));
226 echo sqimap_mailbox_option_list($imapConnection, $selected);
227 echo '</select></td></tr>' .
229 html_tag( 'th', ' ', 'right' ) .
230 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
233 html_tag( 'th', ' ', 'right' ) .
234 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
237 html_tag( 'th', ' ', 'right' ) .
238 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
242 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
243 'center', '', 'colspan="2"' )
245 '</table></form></td></tr></table>';
248 echo '<font size=-5><BR></font>' .
249 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
251 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
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>>";
263 ' <INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
264 ' <INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
267 echo _("No-one server in use. Try to add.");
269 echo '</td></tr></table>';
271 case _("Delete"): //erase confirmation about a server
272 echo html_tag( 'table',
274 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
276 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
280 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
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") . '">' .
290 'center', $color[9] )
292 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' );
293 break; //modify a server
295 echo html_tag( 'table',
297 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
299 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
301 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
303 html_tag( 'td', '<b>' . _("Mofify a Server") . '</b>', 'center', $color[9] )
306 html_tag( 'td', '', 'center', $color[0] ) .
308 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
309 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
310 html_tag( 'table' ) .
312 html_tag( 'th', _("Server:"), 'right' ) .
313 html_tag( 'td', '<input type="text" name="mf_server" value="' . $mailfetch_server_[$mf_sn] . '" size="40">', 'left' )
316 html_tag( 'th', _("Port:"), 'right' ) .
317 html_tag( 'td', '<input type="text" name="mf_port" value="' . $mailfetch_port_[$mf_sn] . '" size="40">', 'left' )
320 html_tag( 'th', _("Alias:"), 'right' ) .
321 html_tag( 'td', '<input type="text" name="mf_alias" value="' . $mailfetch_alias_[$mf_sn] . '" size="40">', 'left' )
324 html_tag( 'th', _("Username:"), 'right' ) .
325 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
328 html_tag( 'th', _("Password:"), 'right' ) .
329 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
332 html_tag( 'th', _("Store in Folder:"), 'right' ) .
333 html_tag( 'td', '', 'left' );
335 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
336 $boxes = sqimap_mailbox_list($imapConnection);
337 echo '<select name="mf_subfolder">';
339 if ( isset($mf_subfolder) )
340 $selected = array(strtolower($mf_subfolder));
341 echo sqimap_mailbox_option_list($imapConnection, $selected);
342 echo '</select></td></tr>' .
345 html_tag( 'th', ' ', 'right' ) .
347 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?
'checked':'') .
348 '>' . _("Leave Mail on Server") ,
352 html_tag( 'th', ' ', 'right' ) .
354 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?
'checked':'') .
355 '>' . _("Check mail during login"),
359 html_tag( 'th', ' ', 'right' ) .
361 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?
'checked':'') .
362 '>' . _("Check mail during folder refresh") ,
367 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
368 'center', '', 'colspan="2"' )
371 '</table></form></td></tr></table>';
373 default: //unsupported action
377 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
379 'center', '', 'width="95%" cols="1"' ) .
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] )
386 'center', '', 'width="70%" cols="1"' );