Time to stop coding for tonight. Making this kind of terrible bugs is bad.
[squirrelmail.git] / plugins / mail_fetch / options.php
1 <?php
2
3 /**
4 * mail_fetch/options.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Setup of the mailfetch plugin.
10 *
11 * $Id$
12 */
13
14 define('SM_PATH','../../');
15
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');
19
20 displayPageHeader( $color, 'None' );
21
22 //if dosen't select any option
23 if (!isset($mf_action))
24 $mf_action = 'config';
25
26 switch( $mf_action ) {
27 case 'add':
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:""));
39 $mf_sn++;
40 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
41 $mf_action = 'config';
42 break;
43 case 'confirm_modify':
44 //modify a server
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';
56 break;
57 case 'confirm_delete':
58 //delete a server
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);
64 } else {
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++) {
69 $tmp=$i+1;
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"));
79 }
80 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
81 }
82 $mf_action = 'config';
83 break;
84 }
85
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;
90 }
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] );
102 }
103
104
105 echo '<BR><form method=post action="'.$PHP_SELF.'">' .
106 html_tag( 'table',
107 html_tag( 'tr',
108 html_tag( 'td',
109 '<b>' . _("Remote POP server settings") . '</b>',
110 'center', $color[0] )
111 ),
112 'center', '', 'width="95%" cols="1"' ) .
113 html_tag( 'table',
114 html_tag( 'tr',
115 html_tag( 'td',
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." ) ,
117 'left' )
118 ) .
119 html_tag( 'tr',
120 html_tag( 'td',
121 _("If you leave password empty, it will be required when you fetch mail.") ,
122 'left' )
123 ) .
124 html_tag( 'tr',
125 html_tag( 'td',
126 '<input type=checkbox name=mf_cypher ' .
127 (($mailfetch_cypher=='on')?'checked >':'>') .
128 _("Encrypt passwords (informative only)") ,
129 'right' )
130 ) ,
131 'center', '', 'width="95%" cols="1"' );
132
133 switch( $mf_action ) {
134 case 'config':
135 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
136 html_tag( 'tr',
137 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
138 ) .
139 html_tag( 'tr' ) .
140 html_tag( 'td', '', 'center', $color[0] ) .
141
142 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
143 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
144 html_tag( 'table' ) .
145 html_tag( 'tr',
146 html_tag( 'th', _("Server:"), 'right' ) .
147 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
148 ) .
149 html_tag( 'tr',
150 html_tag( 'th', _("Alias:"), 'right' ) .
151 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
152 ) .
153 html_tag( 'tr',
154 html_tag( 'th', _("Username:"), 'right' ) .
155 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
156 ) .
157 html_tag( 'tr',
158 html_tag( 'th', _("Password:"), 'right' ) .
159 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
160 ) .
161 html_tag( 'tr' ) .
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(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
172 if ( strtolower( $box2 ) == 'inbox' ) {
173 $box2 = _("INBOX");
174 }
175 echo "<option value=\"$box\">$box2</option>\n";
176 }
177 }
178 echo '</select></td></tr>' .
179 html_tag( 'tr',
180 html_tag( 'th', '&nbsp;', 'right' ) .
181 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
182 ) .
183 html_tag( 'tr',
184 html_tag( 'th', '&nbsp;', 'right' ) .
185 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
186 ) .
187 html_tag( 'tr',
188 html_tag( 'th', '&nbsp;', 'right' ) .
189 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
190 ) .
191 html_tag( 'tr',
192 html_tag( 'td',
193 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
194 'center', '', 'colspan="2"' )
195 ) .
196 '</table></form></td></tr></table>';
197
198 // Modify Server
199 echo '<font size=-5><BR></font>' .
200 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
201 html_tag( 'tr',
202 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
203 ) .
204 html_tag( 'tr' ) .
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>>";
212 }
213 echo '</select>'.
214 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
215 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
216 '</form>';
217 } else {
218 echo _("No-one server in use. Try to add.");
219 }
220 echo '</td></tr></table>';
221 break;
222 case _("Delete"): //erase confirmation about a server
223 echo html_tag( 'table',
224 html_tag( 'tr',
225 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
226 ) ,
227 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
228 '<br>' .
229 html_tag( 'table',
230 html_tag( 'tr',
231 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
232 ) .
233 html_tag( 'tr',
234 html_tag( 'td',
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") . '">' .
240 '<br></form>' ,
241 'center', $color[9] )
242 ) ,
243 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' );
244 break; //modify a server
245 case _("Modify"):
246 echo html_tag( 'table',
247 html_tag( 'tr',
248 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
249 ) ,
250 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
251 '<br>' .
252 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
253 html_tag( 'tr',
254 html_tag( 'td', '<b>' . _("Mofify a Server") . '</b>', 'center', $color[9] )
255 ) .
256 html_tag( 'tr' ) .
257 html_tag( 'td', '', 'center', $color[0] ) .
258
259 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
260 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
261 html_tag( 'table' ) .
262 html_tag( 'tr',
263 html_tag( 'th', _("Server:"), 'right' ) .
264 html_tag( 'td', '<input type="text" name="mf_server" value="' . $mailfetch_server_[$mf_sn] . '" size="40">', 'left' )
265 ) .
266 html_tag( 'tr',
267 html_tag( 'th', _("Alias:"), 'right' ) .
268 html_tag( 'td', '<input type="text" name="mf_alias" value="' . $mailfetch_alias_[$mf_sn] . '" size="40">', 'left' )
269 ) .
270 html_tag( 'tr',
271 html_tag( 'th', _("Username:"), 'right' ) .
272 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
273 ) .
274 html_tag( 'tr',
275 html_tag( 'th', _("Password:"), 'right' ) .
276 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
277 ) .
278 html_tag( 'tr' ) .
279 html_tag( 'th', _("Store in Folder:"), 'right' ) .
280 html_tag( 'td', '', 'left' );
281
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(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
290 if ( strtolower( $box2 ) == 'inbox' ) {
291 $box2 = _("INBOX");
292 }
293 echo '<option ' .
294 (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?'selected':'') .
295 " value=\"$box\">$box2</option>\n";
296 }
297 }
298 echo '</select></td></tr>' .
299
300 html_tag( 'tr',
301 html_tag( 'th', '&nbsp;', 'right' ) .
302 html_tag( 'td',
303 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
304 '>' . _("Leave Mail on Server") ,
305 'left' )
306 ) .
307 html_tag( 'tr',
308 html_tag( 'th', '&nbsp;', 'right' ) .
309 html_tag( 'td',
310 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
311 '>' . _("Check mail during login"),
312 'left' )
313 ) .
314 html_tag( 'tr',
315 html_tag( 'th', '&nbsp;', 'right' ) .
316 html_tag( 'td',
317 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
318 '>' . _("Check mail during folder refresh") ,
319 'left' )
320 ) .
321 html_tag( 'tr',
322 html_tag( 'td',
323 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
324 'center', '', 'colspan="2"' )
325 ) .
326
327 '</table></form></td></tr></table>';
328 break;
329 default: //unsupported action
330 echo '</form>' .
331 html_tag( 'table',
332 html_tag( 'tr',
333 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
334 ) ,
335 'center', '', 'width="95%" cols="1"' ) .
336 '<br>' .
337 html_tag( 'table',
338 html_tag( 'tr',
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] )
341 ) ,
342 'center', '', 'width="70%" cols="1"' );
343 }
344
345 ?>
346 </body></html>