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.
15 define('SM_PATH','../');
17 require_once(SM_PATH
. 'include/validate.php');
18 require_once(SM_PATH
. 'functions/imap.php');
19 require_once(SM_PATH
. 'include/load_prefs.php');
21 displayPageHeader( $color, 'None' );
23 //if dosen't select any option
24 if (!isset($mf_action))
25 $mf_action = 'config';
27 switch( $mf_action ) {
29 if ($mf_sn<1) $mf_sn=0;
30 if (!isset($mf_server)) return;
31 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
32 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
33 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
34 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
35 if( $mf_cypher <> 'on' ) SetPref($data_dir,$username,"mailfetch_cypher", 'on');
36 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
37 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
38 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
39 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
41 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
42 $mf_action = 'config';
44 case 'confirm_modify':
46 if (!isset($mf_server)) return;
47 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
48 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
49 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
50 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
51 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
52 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
53 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
54 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
55 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
56 $mf_action = 'config';
58 case 'confirm_delete':
60 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
61 if ($mf_sn+
1==$mailfetch_server_number) {
62 //is the last server, whe can only decrase $mailfetch_server_number
63 $mailfetch_server_number--;
64 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
66 //if not the last, all the sequel server come up one step
67 //then whe decrase $mailfetch_server_number
68 $mailfetch_server_number--;
69 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++
) {
71 setPref($data_dir,$username,"mailfetch_server_$i", getPref($data_dir, $username, "mailfetch_server_$tmp"));
72 setPref($data_dir,$username,"mailfetch_alias_$i", getPref($data_dir, $username, "mailfetch_alias_$tmp"));
73 setPref($data_dir,$username,"mailfetch_user_$i", getPref($data_dir, $username, "mailfetch_user_$tmp"));
74 setPref($data_dir,$username,"mailfetch_pass_$i",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
75 // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
76 setPref($data_dir,$username,"mailfetch_lmos_$i", getPref($data_dir, $username, "mailfetch_lmos_$tmp"));
77 setPref($data_dir,$username,"mailfetch_login_$i", getPref($data_dir, $username, "mailfetch_login_$tmp"));
78 setPref($data_dir,$username,"mailfetch_fref_$i", getPref($data_dir, $username, "mailfetch_fref_$tmp"));
79 setPref($data_dir,$username,"mailfetch_subfolder_$i", getPref($data_dir, $username, "mailfetch_subfolder_$tmp"));
81 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
83 $mf_action = 'config';
87 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
88 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
89 if ($mailfetch_server_number<1) {
90 $mailfetch_server_number=0;
92 for ($i=0;$i<$mailfetch_server_number;$i++
) {
93 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
94 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
95 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
96 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
97 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
98 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
99 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
100 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
101 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
102 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
106 echo '<BR><form method=post action="'.$PHP_SELF.'">' .
110 '<b>' . _("Remote POP server settings") . '</b>',
111 'center', $color[0] )
113 'center', '', 'width="95%" cols="1"' ) .
117 _("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." ) ,
122 _("If you leave password empty, it will be required when you fetch mail.") ,
127 '<input type=checkbox name=mf_cypher ' .
128 (($mailfetch_cypher=='on')?
'checked >':'>') .
129 _("Encrypt passwords (informative only)") ,
132 'center', '', 'width="95%" cols="1"' );
134 switch( $mf_action ) {
136 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
138 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
141 html_tag( 'td', '', 'center', $color[0] ) .
143 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
144 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
145 html_tag( 'table' ) .
147 html_tag( 'th', _("Server:"), 'right' ) .
148 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
151 html_tag( 'th', _("Alias:"), 'right' ) .
152 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
155 html_tag( 'th', _("Username:"), 'right' ) .
156 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
159 html_tag( 'th', _("Password:"), 'right' ) .
160 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
163 html_tag( 'th', _("Store in Folder:"), 'right' ) .
164 html_tag( 'td', '', 'left' );
165 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
166 $boxes = sqimap_mailbox_list($imapConnection);
167 echo '<select name="mf_subfolder">';
168 $boxes = sqimap_mailbox_list($imapConnection);
169 for ($i = 0; $i < count($boxes); $i++
) {
170 if (!in_array('noselect', $boxes[$i]['flags'])) {
171 $box = $boxes[$i]['unformatted'];
172 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
173 if ( strtolower( $box2 ) == 'inbox' ) {
176 echo "<option value=\"$box\">$box2</option>\n";
179 echo '</select></td></tr>' .
181 html_tag( 'th', ' ', 'right' ) .
182 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
185 html_tag( 'th', ' ', 'right' ) .
186 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
189 html_tag( 'th', ' ', 'right' ) .
190 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
194 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
195 'center', '', 'colspan="2"' )
197 '</table></form></td></tr></table>';
200 echo '<font size=-5><BR></font>' .
201 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
203 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
206 html_tag( 'td', '', 'center', $color[0] );
207 if ($mailfetch_server_number>0) {
208 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
209 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
210 for ($i=0;$i<$mailfetch_server_number;$i++
) {
211 echo "<option value=\"$i\">" .
212 (($mailfetch_alias_[$i]=='')?
$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</option>>";
215 ' <INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
216 ' <INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
219 echo _("No-one server in use. Try to add.");
221 echo '</td></tr></table>';
223 case _("Delete"): //erase confirmation about a server
224 echo html_tag( 'table',
226 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
228 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
232 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
236 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
237 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
238 '<br>' . _("Selected Server:") . " <b>$mailfetch_server_[$mf_sn]</b><br>" .
239 _("Confirm delete of selected server?") . '<br><br>' .
240 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
242 'center', $color[9] )
244 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' );
245 break; //modify a server
247 echo html_tag( 'table',
249 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
251 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
253 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
255 html_tag( 'td', '<b>' . _("Mofify a Server") . '</b>', 'center', $color[9] )
258 html_tag( 'td', '', 'center', $color[0] ) .
260 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
261 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
262 html_tag( 'table' ) .
264 html_tag( 'th', _("Server:"), 'right' ) .
265 html_tag( 'td', '<input type="text" name="mf_server" value="' . $mailfetch_server_[$mf_sn] . '" size="40">', 'left' )
268 html_tag( 'th', _("Alias:"), 'right' ) .
269 html_tag( 'td', '<input type="text" name="mf_alias" value="' . $mailfetch_alias_[$mf_sn] . '" size="40">', 'left' )
272 html_tag( 'th', _("Username:"), 'right' ) .
273 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
276 html_tag( 'th', _("Password:"), 'right' ) .
277 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
280 html_tag( 'th', _("Store in Folder:"), 'right' ) .
281 html_tag( 'td', '', 'left' );
283 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
284 $boxes = sqimap_mailbox_list($imapConnection);
285 echo '<select name="mf_subfolder">';
286 $boxes = sqimap_mailbox_list($imapConnection);
287 for ($i = 0; $i < count($boxes); $i++
) {
288 if (!in_array('noselect', $boxes[$i]['flags'])) {
289 $box = $boxes[$i]['unformatted'];
290 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
291 if ( strtolower( $box2 ) == 'inbox' ) {
295 (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?
'selected':'') .
296 " value=\"$box\">$box2</option>\n";
299 echo '</select></td></tr>' .
302 html_tag( 'th', ' ', 'right' ) .
304 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?
'checked':'') .
305 '>' . _("Leave Mail on Server") ,
309 html_tag( 'th', ' ', 'right' ) .
311 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?
'checked':'') .
312 '>' . _("Check mail during login"),
316 html_tag( 'th', ' ', 'right' ) .
318 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?
'checked':'') .
319 '>' . _("Check mail during folder refresh") ,
324 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
325 'center', '', 'colspan="2"' )
328 '</table></form></td></tr></table>';
330 default: //unsupported action
334 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
336 'center', '', 'width="95%" cols="1"' ) .
340 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
341 html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
343 'center', '', 'width="70%" cols="1"' );