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 require_once('../src/validate.php');
16 require_once('../functions/imap.php');
17 require_once('../src/load_prefs.php');
19 displayPageHeader( $color, 'None' );
21 //if dosen't select any option
22 if (!isset($mf_action))
23 $mf_action = 'config';
25 switch( $mf_action ) {
27 if ($mf_sn<1) $mf_sn=0;
28 if (!isset($mf_server)) return;
29 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
30 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
31 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
32 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
33 if( $mf_cypher <> 'on' ) SetPref($data_dir,$username,"mailfetch_cypher", 'on');
34 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
35 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
36 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
37 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
39 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
40 $mf_action = 'config';
42 case 'confirm_modify':
44 if (!isset($mf_server)) return;
45 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
46 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
47 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
48 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
49 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
50 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
51 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
52 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
53 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
54 $mf_action = 'config';
56 case 'confirm_delete':
58 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
59 if ($mf_sn+
1==$mailfetch_server_number) {
60 //is the last server, whe can only decrase $mailfetch_server_number
61 $mailfetch_server_number--;
62 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
64 //if not the last, all the sequel server come up one step
65 //then whe decrase $mailfetch_server_number
66 $mailfetch_server_number--;
67 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++
) {
69 setPref($data_dir,$username,"mailfetch_server_$i", getPref($data_dir, $username, "mailfetch_server_$tmp"));
70 setPref($data_dir,$username,"mailfetch_alias_$i", getPref($data_dir, $username, "mailfetch_alias_$tmp"));
71 setPref($data_dir,$username,"mailfetch_user_$i", getPref($data_dir, $username, "mailfetch_user_$tmp"));
72 setPref($data_dir,$username,"mailfetch_pass_$i",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
73 // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
74 setPref($data_dir,$username,"mailfetch_lmos_$i", getPref($data_dir, $username, "mailfetch_lmos_$tmp"));
75 setPref($data_dir,$username,"mailfetch_login_$i", getPref($data_dir, $username, "mailfetch_login_$tmp"));
76 setPref($data_dir,$username,"mailfetch_fref_$i", getPref($data_dir, $username, "mailfetch_fref_$tmp"));
77 setPref($data_dir,$username,"mailfetch_subfolder_$i", getPref($data_dir, $username, "mailfetch_subfolder_$tmp"));
79 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
81 $mf_action = 'config';
85 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
86 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
87 if ($mailfetch_server_number<1) {
88 $mailfetch_server_number=0;
90 for ($i=0;$i<$mailfetch_server_number;$i++
) {
91 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
92 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
93 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
94 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
95 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
96 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
97 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
98 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
99 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
100 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
104 echo '<BR><form method=post action="'.$PHP_SELF.'">' .
108 '<b>' . _("Remote POP server settings") . '</b>',
109 'center', $color[0] )
111 'center', '', 'width="95%" cols="1"' ) .
115 _("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." ) ,
120 _("If you leave password empty, it will be required when you fetch mail.") ,
125 '<input type=checkbox name=mf_cypher ' .
126 (($mailfetch_cypher=='on')?
'checked >':'>') .
127 _("Encrypt passwords (informative only)") ,
130 'center', '', 'width="95%" cols="1"' );
132 switch( $mf_action ) {
134 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
136 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
139 html_tag( 'td', '', 'center', $color[0] ) .
141 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
142 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
143 html_tag( 'table' ) .
145 html_tag( 'th', _("Server:"), 'right' ) .
146 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
149 html_tag( 'th', _("Alias:"), 'right' ) .
150 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
153 html_tag( 'th', _("Username:"), 'right' ) .
154 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
157 html_tag( 'th', _("Password:"), 'right' ) .
158 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
161 html_tag( 'th', _("Store in Folder:"), 'right' ) .
162 html_tag( 'td', '', 'left' );
163 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
164 $boxes = sqimap_mailbox_list($imapConnection);
165 echo '<select name="mf_subfolder">';
166 $boxes = sqimap_mailbox_list($imapConnection);
167 for ($i = 0; $i < count($boxes); $i++
) {
168 if (!in_array('noselect', $boxes[$i]['flags'])) {
169 $box = $boxes[$i]['unformatted'];
170 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
171 if ( strtolower( $box2 ) == 'inbox' ) {
174 echo "<option value=\"$box\">$box2</option>\n";
177 echo '</select></td></tr>' .
179 html_tag( 'th', ' ', 'right' ) .
180 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
183 html_tag( 'th', ' ', 'right' ) .
184 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
187 html_tag( 'th', ' ', 'right' ) .
188 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
192 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
193 'center', '', 'colspan="2"' )
195 '</table></form></td></tr></table>';
198 echo '<font size=-5><BR></font>' .
199 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
201 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
204 html_tag( 'td', '', 'center', $color[0] );
205 if ($mailfetch_server_number>0) {
206 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
207 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
208 for ($i=0;$i<$mailfetch_server_number;$i++
) {
209 echo "<option value=\"$i\">" .
210 (($mailfetch_alias_[$i]=='')?
$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</option>>";
213 ' <INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
214 ' <INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
217 echo _("No-one server in use. Try to add.");
219 echo '</td></tr></table>';
221 case _("Delete"): //erase confirmation about a server
222 echo html_tag( 'table',
224 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
226 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
230 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
234 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
235 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
236 '<br>' . _("Selected Server:") . " <b>$mailfetch_server_[$mf_sn]</b><br>" .
237 _("Confirm delete of selected server?") . '<br><br>' .
238 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
240 'center', $color[9] )
242 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' );
243 break; //modify a server
245 echo html_tag( 'table',
247 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
249 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
251 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
253 html_tag( 'td', '<b>' . _("Mofify a Server") . '</b>', 'center', $color[9] )
256 html_tag( 'td', '', 'center', $color[0] ) .
258 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
259 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
260 html_tag( 'table' ) .
262 html_tag( 'th', _("Server:"), 'right' ) .
263 html_tag( 'td', '<input type="text" name="mf_server" value="' . $mailfetch_server_[$mf_sn] . '" size="40">', 'left' )
266 html_tag( 'th', _("Alias:"), 'right' ) .
267 html_tag( 'td', '<input type="text" name="mf_alias" value="' . $mailfetch_alias_[$mf_sn] . '" size="40">', 'left' )
270 html_tag( 'th', _("Username:"), 'right' ) .
271 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
274 html_tag( 'th', _("Password:"), 'right' ) .
275 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
278 html_tag( 'th', _("Store in Folder:"), 'right' ) .
279 html_tag( 'td', '', 'left' );
281 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
282 $boxes = sqimap_mailbox_list($imapConnection);
283 echo '<select name="mf_subfolder">';
284 $boxes = sqimap_mailbox_list($imapConnection);
285 for ($i = 0; $i < count($boxes); $i++
) {
286 if (!in_array('noselect', $boxes[$i]['flags'])) {
287 $box = $boxes[$i]['unformatted'];
288 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
289 if ( strtolower( $box2 ) == 'inbox' ) {
293 (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?
'selected':'') .
294 " value=\"$box\">$box2</option>\n";
297 echo '</select></td></tr>' .
300 html_tag( 'th', ' ', 'right' ) .
302 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?
'checked':'') .
303 '>' . _("Leave Mail on Server") ,
307 html_tag( 'th', ' ', 'right' ) .
309 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?
'checked':'') .
310 '>' . _("Check mail during login"),
314 html_tag( 'th', ' ', 'right' ) .
316 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?
'checked':'') .
317 '>' . _("Check mail during folder refresh") ,
322 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
323 'center', '', 'colspan="2"' )
326 '</table></form></td></tr></table>';
328 default: //unsupported action
332 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
334 'center', '', 'width="95%" cols="1"' ) .
338 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
339 html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
341 'center', '', 'width="70%" cols="1"' );