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.
13 * @subpackage mail_fetch
17 define('SM_PATH','../../');
19 require_once(SM_PATH
. 'include/validate.php');
20 require_once(SM_PATH
. 'functions/imap.php');
21 require_once(SM_PATH
. 'include/load_prefs.php');
24 sqgetGlobalVar('username', $username, SQ_SESSION
);
25 sqgetGlobalVar('key', $key, SQ_COOKIE
);
26 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
27 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
29 if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST
)) {
32 if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST
) ) {
33 if (sqgetGlobalVar('mf_action_mod', $mf_action_mod, SQ_POST
)) {
34 $mf_action = 'Modify';
36 elseif (sqgetGlobalVar('mf_action_del', $mf_action_del, SQ_POST
)) {
37 $mf_action = 'Delete';
40 $mf_action = 'config';
44 sqgetGlobalVar('mf_sn', $mf_sn, SQ_POST
);
45 sqgetGlobalVar('mf_server', $mf_server, SQ_POST
);
46 sqgetGlobalVar('mf_port', $mf_port, SQ_POST
);
47 sqgetGlobalVar('mf_alias', $mf_alias, SQ_POST
);
48 sqgetGlobalVar('mf_user', $mf_user, SQ_POST
);
49 sqgetGlobalVar('mf_pass', $mf_pass, SQ_POST
);
50 sqgetGlobalVar('mf_subfolder', $mf_subfolder, SQ_POST
);
51 sqgetGlobalVar('mf_login', $mf_login, SQ_POST
);
52 sqgetGlobalVar('mf_fref', $mf_fref, SQ_POST
);
53 sqgetGlobalVar('mf_lmos', $mf_lmos, SQ_POST
);
54 sqgetGlobalVar('submit_mailfetch', $submit_mailfetch, SQ_POST
);
59 displayPageHeader( $color, 'None' );
61 switch( $mf_action ) {
63 if ($mf_sn<1) $mf_sn=0;
64 if (!isset($mf_server)) return;
65 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
66 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?
$mf_port:110));
67 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
68 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
69 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
70 if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on');
71 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
72 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
73 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
74 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
76 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
77 $mf_action = 'config';
79 case 'confirm_modify':
81 if (!isset($mf_server)) return;
82 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?
$mf_server:""));
83 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?
$mf_port:110));
84 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?
$mf_alias:""));
85 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?
$mf_user:""));
86 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?
encrypt( $mf_pass ) :""));
87 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
88 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?
$mf_lmos:""));
89 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?
$mf_login:""));
90 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?
$mf_fref:""));
91 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?
$mf_subfolder:""));
92 $mf_action = 'config';
94 case 'confirm_delete':
96 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
97 if ($mf_sn+
1==$mailfetch_server_number) {
98 //is the last server, whe can only decrase $mailfetch_server_number
99 $mailfetch_server_number--;
100 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
102 //if not the last, all the sequel server come up one step
103 //then whe decrase $mailfetch_server_number
104 $mailfetch_server_number--;
105 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++
) {
107 setPref($data_dir,$username,'mailfetch_server_'.$i,
108 getPref($data_dir,$username, 'mailfetch_server_'.$tmp));
109 setPref($data_dir,$username,'mailfetch_port_'.$i,
110 getPref($data_dir,$username, 'mailfetch_port_'.$tmp));
111 setPref($data_dir,$username,'mailfetch_alias_'.$i,
112 getPref($data_dir,$username, 'mailfetch_alias_'.$tmp));
113 setPref($data_dir,$username,'mailfetch_user_'.$i,
114 getPref($data_dir,$username, 'mailfetch_user_'.$tmp));
115 setPref($data_dir,$username,'mailfetch_pass_'.$i,
116 getPref($data_dir,$username, 'mailfetch_pass_'.$tmp));
117 setPref($data_dir,$username,'mailfetch_lmos_'.$i,
118 getPref($data_dir,$username, 'mailfetch_lmos_'.$tmp));
119 setPref($data_dir,$username,'mailfetch_login_'.$i,
120 getPref($data_dir,$username, 'mailfetch_login_'.$tmp));
121 setPref($data_dir,$username,'mailfetch_fref_'.$i,
122 getPref($data_dir,$username, 'mailfetch_fref_'.$tmp));
123 setPref($data_dir,$username,'mailfetch_subfolder_'.$i,
124 getPref($data_dir,$username, 'mailfetch_subfolder_'.$tmp));
125 setPref($data_dir,$username,'mailfetch_uidl_'.$i,
126 getPref($data_dir,$username, 'mailfetch_uidl_'.$tmp));
128 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
130 $mf_action = 'config';
134 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
135 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
136 if ($mailfetch_server_number<1) {
137 $mailfetch_server_number=0;
139 for ($i=0;$i<$mailfetch_server_number;$i++
) {
140 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
141 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
142 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
143 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
144 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
145 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
146 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
147 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
148 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
149 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
150 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
154 echo '<br><form method="post" action="'.$PHP_SELF.'">' .
158 '<b>' . _("Remote POP server settings") . '</b>',
159 'center', $color[0] )
161 'center', '', 'width="95%"' ) .
165 _("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." ) ,
170 _("If you leave password empty, it will be required when you fetch mail.") ,
175 '<input type=checkbox name=mf_cypher ' .
176 (($mailfetch_cypher=='on')?
'checked>':'>') .
177 _("Encrypt passwords (informative only)") ,
180 'center', '', 'width="95%"' );
182 switch( $mf_action ) {
184 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
186 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
189 html_tag( 'td', '', 'center', $color[0] ) .
191 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
192 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
193 html_tag( 'table' ) .
195 html_tag( 'th', _("Server:"), 'right' ) .
196 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
199 html_tag( 'th', _("Port:"), 'right') .
200 html_tag( 'td', '<input type=text name=mf_port value="110" size=20>', 'left')
203 html_tag( 'th', _("Alias:"), 'right' ) .
204 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
207 html_tag( 'th', _("Username:"), 'right' ) .
208 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
211 html_tag( 'th', _("Password:"), 'right' ) .
212 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
215 html_tag( 'th', _("Store in Folder:"), 'right' ) .
216 html_tag( 'td', '', 'left' );
217 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
218 $boxes = sqimap_mailbox_list($imapConnection);
219 echo '<select name="mf_subfolder">';
222 if ( isset($mf_subfolder) )
223 $selected = array(strtolower($mf_subfolder));
224 echo sqimap_mailbox_option_list($imapConnection, $selected);
225 echo '</select></td></tr>' .
227 html_tag( 'th', ' ', 'right' ) .
228 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
231 html_tag( 'th', ' ', 'right' ) .
232 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
235 html_tag( 'th', ' ', 'right' ) .
236 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
240 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
241 'center', '', 'colspan="2"' )
243 '</table></td></tr></table></form>';
246 echo '<font size=-5><BR></font>' .
247 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
249 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
252 html_tag( 'td', '', 'center', $color[0] );
253 if ($mailfetch_server_number>0) {
254 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
255 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
256 for ($i=0;$i<$mailfetch_server_number;$i++
) {
257 echo "<option value=\"$i\">" .
258 htmlspecialchars( (($mailfetch_alias_[$i]=='')?
$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>";
261 ' <INPUT TYPE=submit name=mf_action_mod value="' . _("Modify") . '">'.
262 ' <INPUT TYPE=submit name=mf_action_del value="' . _("Delete") . '">'.
265 echo _("No-one server in use. Try to add.");
267 echo '</td></tr></table>';
269 case 'Delete': //erase confirmation about a server
270 echo html_tag( 'table',
272 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
274 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
278 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
282 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
283 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
284 '<br>' . _("Selected Server:") . " <b>" . htmlentities($mailfetch_server_[$mf_sn]) . "</b><br>" .
285 _("Confirm delete of selected server?") . '<br><br>' .
286 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
288 'center', $color[9] )
290 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' );
291 break; //modify a server
293 echo html_tag( 'table',
295 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
297 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
299 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
301 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
304 html_tag( 'td', '', 'center', $color[0] ) .
306 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
307 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
308 html_tag( 'table' ) .
310 html_tag( 'th', _("Server:"), 'right' ) .
311 html_tag( 'td', '<input type="text" name="mf_server" value="' . htmlentities($mailfetch_server_[$mf_sn]) . '" size="40">', 'left' )
314 html_tag( 'th', _("Port:"), 'right' ) .
315 html_tag( 'td', '<input type="text" name="mf_port" value="' . $mailfetch_port_[$mf_sn] . '" size="40">', 'left' )
318 html_tag( 'th', _("Alias:"), 'right' ) .
319 html_tag( 'td', '<input type="text" name="mf_alias" value="' . htmlentities($mailfetch_alias_[$mf_sn]) . '" size="40">', 'left' )
322 html_tag( 'th', _("Username:"), 'right' ) .
323 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
326 html_tag( 'th', _("Password:"), 'right' ) .
327 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
330 html_tag( 'th', _("Store in Folder:"), 'right' ) .
331 html_tag( 'td', '', 'left' );
333 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
334 $boxes = sqimap_mailbox_list($imapConnection);
335 echo '<select name="mf_subfolder">';
337 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
338 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
340 echo sqimap_mailbox_option_list($imapConnection, $selected) .
341 '</select></td></tr>' .
344 html_tag( 'th', ' ', 'right' ) .
346 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?
'checked':'') .
347 '>' . _("Leave Mail on Server") ,
351 html_tag( 'th', ' ', 'right' ) .
353 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?
'checked':'') .
354 '>' . _("Check mail during login"),
358 html_tag( 'th', ' ', 'right' ) .
360 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?
'checked':'') .
361 '>' . _("Check mail during folder refresh") ,
366 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
367 'center', '', 'colspan="2"' )
370 '</table></form></td></tr></table>';
372 default: //unsupported action
376 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
378 'center', '', 'width="95%"' ) .
382 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
383 html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
385 'center', '', 'width="70%"' );