Removing random double spaces in strings
[squirrelmail.git] / plugins / mail_fetch / options.php
1 <?php
2
3 /**
4 * mail_fetch/options.php
5 *
6 * Copyright (c) 1999-2004 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 * @package plugins
13 * @subpackage mail_fetch
14 */
15
16 /** @ignore */
17 define('SM_PATH','../../');
18
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');
22
23 /* globals */
24 sqgetGlobalVar('username', $username, SQ_SESSION);
25 sqgetGlobalVar('key', $key, SQ_COOKIE);
26 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
27 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
28
29 if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST)) {
30 $mf_cypher = '';
31 }
32 if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST) ) {
33 if (sqgetGlobalVar('mf_action_mod', $mf_action_mod, SQ_POST)) {
34 $mf_action = 'Modify';
35 }
36 elseif (sqgetGlobalVar('mf_action_del', $mf_action_del, SQ_POST)) {
37 $mf_action = 'Delete';
38 }
39 else {
40 $mf_action = 'config';
41 }
42 }
43
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);
55
56
57 /* end globals */
58
59 displayPageHeader( $color, 'None' );
60
61 switch( $mf_action ) {
62 case 'add':
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:""));
75 $mf_sn++;
76 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
77 $mf_action = 'config';
78 break;
79 case 'confirm_modify':
80 //modify a server
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';
93 break;
94 case 'confirm_delete':
95 //delete a server
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);
101 } else {
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++) {
106 $tmp=$i+1;
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));
127 }
128 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
129 }
130 $mf_action = 'config';
131 break;
132 }
133
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;
138 }
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] );
151 }
152
153
154 echo '<br><form method="post" action="'.$PHP_SELF.'">' .
155 html_tag( 'table',
156 html_tag( 'tr',
157 html_tag( 'td',
158 '<b>' . _("Remote POP server settings") . '</b>',
159 'center', $color[0] )
160 ),
161 'center', '', 'width="95%"' ) .
162 html_tag( 'table',
163 html_tag( 'tr',
164 html_tag( 'td',
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." ) ,
166 'left' )
167 ) .
168 html_tag( 'tr',
169 html_tag( 'td',
170 _("If you leave password empty, it will be required when you fetch mail.") ,
171 'left' )
172 ) .
173 html_tag( 'tr',
174 html_tag( 'td',
175 '<input type=checkbox name=mf_cypher ' .
176 (($mailfetch_cypher=='on')?'checked>':'>') .
177 _("Encrypt passwords (informative only)") ,
178 'right' )
179 ) ,
180 'center', '', 'width="95%"' );
181
182 switch( $mf_action ) {
183 case 'config':
184 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
185 html_tag( 'tr',
186 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
187 ) .
188 html_tag( 'tr' ) .
189 html_tag( 'td', '', 'center', $color[0] ) .
190
191 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
192 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
193 html_tag( 'table' ) .
194 html_tag( 'tr',
195 html_tag( 'th', _("Server:"), 'right' ) .
196 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
197 ) .
198 html_tag( 'tr',
199 html_tag( 'th', _("Port:"), 'right') .
200 html_tag( 'td', '<input type=text name=mf_port value="110" size=20>', 'left')
201 ) .
202 html_tag( 'tr',
203 html_tag( 'th', _("Alias:"), 'right' ) .
204 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
205 ) .
206 html_tag( 'tr',
207 html_tag( 'th', _("Username:"), 'right' ) .
208 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
209 ) .
210 html_tag( 'tr',
211 html_tag( 'th', _("Password:"), 'right' ) .
212 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
213 ) .
214 html_tag( 'tr' ) .
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">';
220
221 $selected = 0;
222 if ( isset($mf_subfolder) )
223 $selected = array(strtolower($mf_subfolder));
224 echo sqimap_mailbox_option_list($imapConnection, $selected);
225 echo '</select></td></tr>' .
226 html_tag( 'tr',
227 html_tag( 'th', '&nbsp;', 'right' ) .
228 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
229 ) .
230 html_tag( 'tr',
231 html_tag( 'th', '&nbsp;', 'right' ) .
232 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
233 ) .
234 html_tag( 'tr',
235 html_tag( 'th', '&nbsp;', 'right' ) .
236 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
237 ) .
238 html_tag( 'tr',
239 html_tag( 'td',
240 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
241 'center', '', 'colspan="2"' )
242 ) .
243 '</table></td></tr></table></form>';
244
245 // Modify Server
246 echo '<font size=-5><BR></font>' .
247 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
248 html_tag( 'tr',
249 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
250 ) .
251 html_tag( 'tr' ) .
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>";
259 }
260 echo '</select>'.
261 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action_mod value="' . _("Modify") . '">'.
262 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action_del value="' . _("Delete") . '">'.
263 '</form>';
264 } else {
265 echo _("No-one server in use. Try to add.");
266 }
267 echo '</td></tr></table>';
268 break;
269 case 'Delete': //erase confirmation about a server
270 echo html_tag( 'table',
271 html_tag( 'tr',
272 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
273 ) ,
274 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
275 '<br>' .
276 html_tag( 'table',
277 html_tag( 'tr',
278 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
279 ) .
280 html_tag( 'tr',
281 html_tag( 'td',
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>" . htmlspecialchars($mailfetch_server_[$mf_sn]) . "</b><br>" .
285 _("Confirm delete of selected server?") . '<br><br>' .
286 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
287 '<br></form>' ,
288 'center', $color[9] )
289 ) ,
290 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' );
291 break; //modify a server
292 case 'Modify':
293 echo html_tag( 'table',
294 html_tag( 'tr',
295 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
296 ) ,
297 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
298 '<br>' .
299 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
300 html_tag( 'tr',
301 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
302 ) .
303 html_tag( 'tr' ) .
304 html_tag( 'td', '', 'center', $color[0] ) .
305
306 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
307 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
308 html_tag( 'table' ) .
309 html_tag( 'tr',
310 html_tag( 'th', _("Server:"), 'right' ) .
311 html_tag( 'td', '<input type="text" name="mf_server" value="' .
312 htmlspecialchars($mailfetch_server_[$mf_sn]) . '" size="40">', 'left' )
313 ) .
314 html_tag( 'tr',
315 html_tag( 'th', _("Port:"), 'right' ) .
316 html_tag( 'td', '<input type="text" name="mf_port" value="' .
317 htmlspecialchars($mailfetch_port_[$mf_sn]) . '" size="40">', 'left' )
318 ) .
319 html_tag( 'tr',
320 html_tag( 'th', _("Alias:"), 'right' ) .
321 html_tag( 'td', '<input type="text" name="mf_alias" value="' .
322 htmlspecialchars($mailfetch_alias_[$mf_sn]) . '" size="40">', 'left' )
323 ) .
324 html_tag( 'tr',
325 html_tag( 'th', _("Username:"), 'right' ) .
326 html_tag( 'td', '<input type="text" name="mf_user" value="' .
327 htmlspecialchars($mailfetch_user_[$mf_sn]) . '" size="20">', 'left' )
328 ) .
329 html_tag( 'tr',
330 html_tag( 'th', _("Password:"), 'right' ) .
331 html_tag( 'td', '<input type="password" name="mf_pass" value="' .
332 htmlspecialchars($mailfetch_pass_[$mf_sn]) . '" size="20">', 'left' )
333 ) .
334 html_tag( 'tr' ) .
335 html_tag( 'th', _("Store in Folder:"), 'right' ) .
336 html_tag( 'td', '', 'left' );
337
338 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
339 $boxes = sqimap_mailbox_list($imapConnection);
340 echo '<select name="mf_subfolder">';
341 $selected = 0;
342 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
343 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
344 }
345 echo sqimap_mailbox_option_list($imapConnection, $selected) .
346 '</select></td></tr>' .
347
348 html_tag( 'tr',
349 html_tag( 'th', '&nbsp;', 'right' ) .
350 html_tag( 'td',
351 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
352 '>' . _("Leave Mail on Server") ,
353 'left' )
354 ) .
355 html_tag( 'tr',
356 html_tag( 'th', '&nbsp;', 'right' ) .
357 html_tag( 'td',
358 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
359 '>' . _("Check mail during login"),
360 'left' )
361 ) .
362 html_tag( 'tr',
363 html_tag( 'th', '&nbsp;', 'right' ) .
364 html_tag( 'td',
365 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
366 '>' . _("Check mail during folder refresh") ,
367 'left' )
368 ) .
369 html_tag( 'tr',
370 html_tag( 'td',
371 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
372 'center', '', 'colspan="2"' )
373 ) .
374
375 '</table></form></td></tr></table>';
376 break;
377 default: //unsupported action
378 echo '</form>' .
379 html_tag( 'table',
380 html_tag( 'tr',
381 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
382 ) ,
383 'center', '', 'width="95%"' ) .
384 '<br>' .
385 html_tag( 'table',
386 html_tag( 'tr',
387 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
388 html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
389 ) ,
390 'center', '', 'width="70%"' );
391 }
392
393 ?>
394 </body></html>