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');
20 displayPageHeader( $color, 'None' );
22 //if dosen't select any option
23 if (!isset($mf_action))
24 $mf_action = 'config';
26 switch( $mf_action ) {
28 if ($mf_sn<1) $mf_sn=0;
29 if (!isset($mf_server)) return;
30 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
31 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
32 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
33 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
34 if( $mf_cypher <> 'on' ) SetPref($data_dir,$username,"mailfetch_cypher", 'on');
35 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
36 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
37 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
38 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
40 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
41 $mf_action = 'config';
43 case 'confirm_modify':
45 if (!isset($mf_server)) return;
46 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
47 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
48 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
49 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
50 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
51 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
52 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
53 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
54 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
55 $mf_action = 'config';
57 case 'confirm_delete':
59 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
60 if ($mf_sn+
1==$mailfetch_server_number) {
61 //is the last server, whe can only decrase $mailfetch_server_number
62 $mailfetch_server_number--;
63 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
65 //if not the last, all the sequel server come up one step
66 //then whe decrase $mailfetch_server_number
67 $mailfetch_server_number--;
68 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++
) {
70 setPref($data_dir,$username,"mailfetch_server_$i", getPref($data_dir, $username, "mailfetch_server_$tmp"));
71 setPref($data_dir,$username,"mailfetch_alias_$i", getPref($data_dir, $username, "mailfetch_alias_$tmp"));
72 setPref($data_dir,$username,"mailfetch_user_$i", getPref($data_dir, $username, "mailfetch_user_$tmp"));
73 setPref($data_dir,$username,"mailfetch_pass_$i",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
74 // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
75 setPref($data_dir,$username,"mailfetch_lmos_$i", getPref($data_dir, $username, "mailfetch_lmos_$tmp"));
76 setPref($data_dir,$username,"mailfetch_login_$i", getPref($data_dir, $username, "mailfetch_login_$tmp"));
77 setPref($data_dir,$username,"mailfetch_fref_$i", getPref($data_dir, $username, "mailfetch_fref_$tmp"));
78 setPref($data_dir,$username,"mailfetch_subfolder_$i", getPref($data_dir, $username, "mailfetch_subfolder_$tmp"));
80 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
82 $mf_action = 'config';
86 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
87 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
88 if ($mailfetch_server_number<1) {
89 $mailfetch_server_number=0;
91 for ($i=0;$i<$mailfetch_server_number;$i++
) {
92 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
93 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
94 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
95 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
96 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
97 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
98 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
99 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
100 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
101 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
105 echo '<BR><form method=post action="'.$PHP_SELF.'">' .
109 '<b>' . _("Remote POP server settings") . '</b>',
110 'center', $color[0] )
112 'center', '', 'width="95%" cols="1"' ) .
116 _("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." ) ,
121 _("If you leave password empty, it will be required when you fetch mail.") ,
126 '<input type=checkbox name=mf_cypher ' .
127 (($mailfetch_cypher=='on')?
'checked >':'>') .
128 _("Encrypt passwords (informative only)") ,
131 'center', '', 'width="95%" cols="1"' );
133 switch( $mf_action ) {
135 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
137 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
140 html_tag( 'td', '', 'center', $color[0] ) .
142 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
143 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
144 html_tag( 'table' ) .
146 html_tag( 'th', _("Server:"), 'right' ) .
147 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
150 html_tag( 'th', _("Alias:"), 'right' ) .
151 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
154 html_tag( 'th', _("Username:"), 'right' ) .
155 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
158 html_tag( 'th', _("Password:"), 'right' ) .
159 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
162 html_tag( 'th', _("Store in Folder:"), 'right' ) .
163 html_tag( 'td', '', 'left' );
164 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
165 $boxes = sqimap_mailbox_list($imapConnection);
166 echo '<select name="mf_subfolder">';
167 $boxes = sqimap_mailbox_list($imapConnection);
168 for ($i = 0; $i < count($boxes); $i++
) {
169 if (!in_array('noselect', $boxes[$i]['flags'])) {
170 $box = $boxes[$i]['unformatted'];
171 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
172 if ( strtolower( $box2 ) == 'inbox' ) {
175 echo "<option value=\"$box\">$box2</option>\n";
178 echo '</select></td></tr>' .
180 html_tag( 'th', ' ', 'right' ) .
181 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
184 html_tag( 'th', ' ', 'right' ) .
185 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
188 html_tag( 'th', ' ', 'right' ) .
189 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
193 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
194 'center', '', 'colspan="2"' )
196 '</table></form></td></tr></table>';
199 echo '<font size=-5><BR></font>' .
200 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
202 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
205 html_tag( 'td', '', 'center', $color[0] );
206 if ($mailfetch_server_number>0) {
207 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
208 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
209 for ($i=0;$i<$mailfetch_server_number;$i++
) {
210 echo "<option value=\"$i\">" .
211 (($mailfetch_alias_[$i]=='')?
$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</option>>";
214 ' <INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
215 ' <INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
218 echo _("No-one server in use. Try to add.");
220 echo '</td></tr></table>';
222 case _("Delete"): //erase confirmation about a server
223 echo html_tag( 'table',
225 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
227 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
231 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
235 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
236 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
237 '<br>' . _("Selected Server:") . " <b>$mailfetch_server_[$mf_sn]</b><br>" .
238 _("Confirm delete of selected server?") . '<br><br>' .
239 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
241 'center', $color[9] )
243 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' );
244 break; //modify a server
246 echo html_tag( 'table',
248 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
250 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
252 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
254 html_tag( 'td', '<b>' . _("Mofify a Server") . '</b>', 'center', $color[9] )
257 html_tag( 'td', '', 'center', $color[0] ) .
259 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
260 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
261 html_tag( 'table' ) .
263 html_tag( 'th', _("Server:"), 'right' ) .
264 html_tag( 'td', '<input type="text" name="mf_server" value="' . $mailfetch_server_[$mf_sn] . '" size="40">', 'left' )
267 html_tag( 'th', _("Alias:"), 'right' ) .
268 html_tag( 'td', '<input type="text" name="mf_alias" value="' . $mailfetch_alias_[$mf_sn] . '" size="40">', 'left' )
271 html_tag( 'th', _("Username:"), 'right' ) .
272 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
275 html_tag( 'th', _("Password:"), 'right' ) .
276 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
279 html_tag( 'th', _("Store in Folder:"), 'right' ) .
280 html_tag( 'td', '', 'left' );
282 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
283 $boxes = sqimap_mailbox_list($imapConnection);
284 echo '<select name="mf_subfolder">';
285 $boxes = sqimap_mailbox_list($imapConnection);
286 for ($i = 0; $i < count($boxes); $i++
) {
287 if (!in_array('noselect', $boxes[$i]['flags'])) {
288 $box = $boxes[$i]['unformatted'];
289 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
290 if ( strtolower( $box2 ) == 'inbox' ) {
294 (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?
'selected':'') .
295 " value=\"$box\">$box2</option>\n";
298 echo '</select></td></tr>' .
301 html_tag( 'th', ' ', 'right' ) .
303 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?
'checked':'') .
304 '>' . _("Leave Mail on Server") ,
308 html_tag( 'th', ' ', 'right' ) .
310 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?
'checked':'') .
311 '>' . _("Check mail during login"),
315 html_tag( 'th', ' ', 'right' ) .
317 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?
'checked':'') .
318 '>' . _("Check mail during folder refresh") ,
323 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
324 'center', '', 'colspan="2"' )
327 '</table></form></td></tr></table>';
329 default: //unsupported action
333 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
335 'center', '', 'width="95%" cols="1"' ) .
339 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
340 html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
342 'center', '', 'width="70%" cols="1"' );