4 * mail_fetch/options.php
6 * Copyright (c) 1999-2003 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 sqgetGlobalVar('username', $username, SQ_SESSION
);
22 sqgetGlobalVar('key', $key, SQ_COOKIE
);
23 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
24 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
26 if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST
)) {
29 if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST
) ) {
30 if (sqgetGlobalVar('mf_action_mod', $mf_action_mod, SQ_POST
)) {
31 $mf_action = 'Modify';
33 elseif (sqgetGlobalVar('mf_action_del', $mf_action_del, SQ_POST
)) {
34 $mf_action = 'Delete';
37 $mf_action = 'config';
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('submit_mailfetch', $submit_mailfetch, SQ_POST
);
56 displayPageHeader( $color, 'None' );
58 switch( $mf_action ) {
60 if ($mf_sn<1) $mf_sn=0;
61 if (!isset($mf_server)) return;
62 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
63 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?
$mf_port:110));
64 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
65 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
66 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
67 if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on');
68 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
69 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
70 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
71 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
73 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
74 $mf_action = 'config';
76 case 'confirm_modify':
78 if (!isset($mf_server)) return;
79 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
80 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?
$mf_port:110));
81 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
82 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
83 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
84 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
85 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
86 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
87 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
88 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
89 $mf_action = 'config';
91 case 'confirm_delete':
93 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
94 if ($mf_sn+
1==$mailfetch_server_number) {
95 //is the last server, whe can only decrase $mailfetch_server_number
96 $mailfetch_server_number--;
97 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
99 //if not the last, all the sequel server come up one step
100 //then whe decrase $mailfetch_server_number
101 $mailfetch_server_number--;
102 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++
) {
104 setPref($data_dir,$username,'mailfetch_server_'.$i,
105 getPref($data_dir,$username, 'mailfetch_server_'.$tmp));
106 setPref($data_dir,$username,'mailfetch_port_'.$i,
107 getPref($data_dir,$username, 'mailfetch_port_'.$tmp));
108 setPref($data_dir,$username,'mailfetch_alias_'.$i,
109 getPref($data_dir,$username, 'mailfetch_alias_'.$tmp));
110 setPref($data_dir,$username,'mailfetch_user_'.$i,
111 getPref($data_dir,$username, 'mailfetch_user_'.$tmp));
112 setPref($data_dir,$username,'mailfetch_pass_'.$i,
113 getPref($data_dir,$username, 'mailfetch_pass_'.$tmp));
114 setPref($data_dir,$username,'mailfetch_lmos_'.$i,
115 getPref($data_dir,$username, 'mailfetch_lmos_'.$tmp));
116 setPref($data_dir,$username,'mailfetch_login_'.$i,
117 getPref($data_dir,$username, 'mailfetch_login_'.$tmp));
118 setPref($data_dir,$username,'mailfetch_fref_'.$i,
119 getPref($data_dir,$username, 'mailfetch_fref_'.$tmp));
120 setPref($data_dir,$username,'mailfetch_subfolder_'.$i,
121 getPref($data_dir,$username, 'mailfetch_subfolder_'.$tmp));
122 setPref($data_dir,$username,'mailfetch_uidl_'.$i,
123 getPref($data_dir,$username, 'mailfetch_uidl_'.$tmp));
125 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
127 $mf_action = 'config';
131 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
132 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
133 if ($mailfetch_server_number<1) {
134 $mailfetch_server_number=0;
136 for ($i=0;$i<$mailfetch_server_number;$i++
) {
137 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
138 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
139 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
140 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
141 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
142 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
143 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
144 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
145 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
146 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
147 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
151 echo '<br><form method="post" action="'.$PHP_SELF.'">' .
155 '<b>' . _("Remote POP server settings") . '</b>',
156 'center', $color[0] )
158 'center', '', 'width="95%"' ) .
162 _("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." ) ,
167 _("If you leave password empty, it will be required when you fetch mail.") ,
172 '<input type=checkbox name=mf_cypher ' .
173 (($mailfetch_cypher=='on')?
'checked>':'>') .
174 _("Encrypt passwords (informative only)") ,
177 'center', '', 'width="95%"' );
179 switch( $mf_action ) {
181 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
183 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
186 html_tag( 'td', '', 'center', $color[0] ) .
188 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
189 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
190 html_tag( 'table' ) .
192 html_tag( 'th', _("Server:"), 'right' ) .
193 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
196 html_tag( 'th', _("Port:"), 'right') .
197 html_tag( 'td', '<input type=text name=mf_port value="110" size=20>', 'left')
200 html_tag( 'th', _("Alias:"), 'right' ) .
201 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
204 html_tag( 'th', _("Username:"), 'right' ) .
205 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
208 html_tag( 'th', _("Password:"), 'right' ) .
209 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
212 html_tag( 'th', _("Store in Folder:"), 'right' ) .
213 html_tag( 'td', '', 'left' );
214 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
215 $boxes = sqimap_mailbox_list($imapConnection);
216 echo '<select name="mf_subfolder">';
219 if ( isset($mf_subfolder) )
220 $selected = array(strtolower($mf_subfolder));
221 echo sqimap_mailbox_option_list($imapConnection, $selected);
222 echo '</select></td></tr>' .
224 html_tag( 'th', ' ', 'right' ) .
225 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
228 html_tag( 'th', ' ', 'right' ) .
229 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
232 html_tag( 'th', ' ', 'right' ) .
233 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
237 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
238 'center', '', 'colspan="2"' )
240 '</table></td></tr></table></form>';
243 echo '<font size=-5><BR></font>' .
244 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
246 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
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 htmlspecialchars( (($mailfetch_alias_[$i]=='')?
$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>";
258 ' <INPUT TYPE=submit name=mf_action_mod value="' . _("Modify") . '">'.
259 ' <INPUT TYPE=submit name=mf_action_del value="' . _("Delete") . '">'.
262 echo _("No-one server in use. Try to add.");
264 echo '</td></tr></table>';
266 case 'Delete': //erase confirmation about a server
267 echo html_tag( 'table',
269 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
271 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
275 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
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>" . htmlentities($mailfetch_server_[$mf_sn]) . "</b><br>" .
282 _("Confirm delete of selected server?") . '<br><br>' .
283 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
285 'center', $color[9] )
287 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' );
288 break; //modify a server
290 echo html_tag( 'table',
292 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
294 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
296 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
298 html_tag( 'td', '<b>' . _("Modify a Server") . '</b>', 'center', $color[9] )
301 html_tag( 'td', '', 'center', $color[0] ) .
303 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
304 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
305 html_tag( 'table' ) .
307 html_tag( 'th', _("Server:"), 'right' ) .
308 html_tag( 'td', '<input type="text" name="mf_server" value="' . htmlentities($mailfetch_server_[$mf_sn]) . '" size="40">', 'left' )
311 html_tag( 'th', _("Port:"), 'right' ) .
312 html_tag( 'td', '<input type="text" name="mf_port" value="' . $mailfetch_port_[$mf_sn] . '" size="40">', 'left' )
315 html_tag( 'th', _("Alias:"), 'right' ) .
316 html_tag( 'td', '<input type="text" name="mf_alias" value="' . htmlentities($mailfetch_alias_[$mf_sn]) . '" size="40">', 'left' )
319 html_tag( 'th', _("Username:"), 'right' ) .
320 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
323 html_tag( 'th', _("Password:"), 'right' ) .
324 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
327 html_tag( 'th', _("Store in Folder:"), 'right' ) .
328 html_tag( 'td', '', 'left' );
330 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
331 $boxes = sqimap_mailbox_list($imapConnection);
332 echo '<select name="mf_subfolder">';
334 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
335 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
337 echo sqimap_mailbox_option_list($imapConnection, $selected) .
338 '</select></td></tr>' .
341 html_tag( 'th', ' ', 'right' ) .
343 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?
'checked':'') .
344 '>' . _("Leave Mail on Server") ,
348 html_tag( 'th', ' ', 'right' ) .
350 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?
'checked':'') .
351 '>' . _("Check mail during login"),
355 html_tag( 'th', ' ', 'right' ) .
357 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?
'checked':'') .
358 '>' . _("Check mail during folder refresh") ,
363 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
364 'center', '', 'colspan="2"' )
367 '</table></form></td></tr></table>';
369 default: //unsupported action
373 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
375 'center', '', 'width="95%"' ) .
379 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
380 html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
382 'center', '', 'width="70%"' );