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_alias'])) {
36 $mf_alias = $_POST['mf_alias'];
38 if(isset($_POST['mf_user'])) {
39 $mf_user = $_POST['mf_user'];
41 if(isset($_POST['mf_pass'])) {
42 $mf_pass = $_POST['mf_pass'];
44 if(isset($_POST['mf_subfolder'])) {
45 $mf_subfolder = $_POST['mf_subfolder'];
47 if(isset($_POST['mf_login'])) {
48 $mf_login = $_POST['mf_login'];
50 if(isset($_POST['mf_fref'])) {
51 $mf_fref = $_POST['mf_fref'];
53 if(isset($_POST['submit_mailfetch'])) {
54 $submit_mailfetch = $_POST['submit_mailfetch'];
56 if(isset($_POST['mf_lmos'])) {
57 $mf_lmos = $_POST['mf_lmos'];
61 displayPageHeader( $color, 'None' );
63 //if dosen't select any option
64 if (!isset($_POST['mf_action'])) {
65 $mf_action = 'config';
67 $mf_action = $_POST['mf_action'];
70 switch( $mf_action ) {
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:""));
84 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
85 $mf_action = 'config';
87 case 'confirm_modify':
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';
101 case 'confirm_delete':
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);
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++
) {
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"));
124 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
126 $mf_action = 'config';
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;
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] );
149 echo '<BR><form method=post action="'.$PHP_SELF.'">' .
153 '<b>' . _("Remote POP server settings") . '</b>',
154 'center', $color[0] )
156 'center', '', 'width="95%" cols="1"' ) .
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." ) ,
165 _("If you leave password empty, it will be required when you fetch mail.") ,
170 '<input type=checkbox name=mf_cypher ' .
171 (($mailfetch_cypher=='on')?
'checked >':'>') .
172 _("Encrypt passwords (informative only)") ,
175 'center', '', 'width="95%" cols="1"' );
177 switch( $mf_action ) {
179 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
181 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
184 html_tag( 'td', '', 'center', $color[0] ) .
186 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
187 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
188 html_tag( 'table' ) .
190 html_tag( 'th', _("Server:"), 'right' ) .
191 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
194 html_tag( 'th', _("Alias:"), 'right' ) .
195 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
198 html_tag( 'th', _("Username:"), 'right' ) .
199 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
202 html_tag( 'th', _("Password:"), 'right' ) .
203 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
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(' ', ' ', $boxes[$i]['unformatted-disp']);
216 if ( strtolower( $box2 ) == 'inbox' ) {
219 echo "<option value=\"$box\">$box2</option>\n";
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></form></td></tr></table>';
243 echo '<font size=-5><BR></font>' .
244 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" 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 (($mailfetch_alias_[$i]=='')?
$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</option>>";
258 ' <INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
259 ' <INPUT TYPE=submit name=mf_action 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%" cols="1" 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>$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%" cols="1" 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%" cols="1" cellpadding="5" cellspacing="1"' ) .
296 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
298 html_tag( 'td', '<b>' . _("Mofify 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="' . $mailfetch_server_[$mf_sn] . '" size="40">', 'left' )
311 html_tag( 'th', _("Alias:"), 'right' ) .
312 html_tag( 'td', '<input type="text" name="mf_alias" value="' . $mailfetch_alias_[$mf_sn] . '" size="40">', 'left' )
315 html_tag( 'th', _("Username:"), 'right' ) .
316 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
319 html_tag( 'th', _("Password:"), 'right' ) .
320 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
323 html_tag( 'th', _("Store in Folder:"), 'right' ) .
324 html_tag( 'td', '', 'left' );
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(' ', ' ', $boxes[$i]['unformatted-disp']);
334 if ( strtolower( $box2 ) == 'inbox' ) {
338 (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?
'selected':'') .
339 " value=\"$box\">$box2</option>\n";
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"' );