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