Back out support for using SM without Frames
[squirrelmail.git] / plugins / mail_fetch / options.php
CommitLineData
d622d38a 1<?php
d3c89357 2
8d6a115b 3/**
4 * mail_fetch/options.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
8d6a115b 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Setup of the mailfetch plugin.
10 *
11 * $Id$
ea5f4b8e 12 * @package plugins
13 * @subpackage mail_fetch
8d6a115b 14 */
d622d38a 15
ea5f4b8e 16/** @ignore */
8d6a115b 17define('SM_PATH','../../');
aa7fb30c 18
8d6a115b 19require_once(SM_PATH . 'include/validate.php');
20require_once(SM_PATH . 'functions/imap.php');
21require_once(SM_PATH . 'include/load_prefs.php');
d622d38a 22
3c66c567 23/* globals */
24sqgetGlobalVar('username', $username, SQ_SESSION);
25sqgetGlobalVar('key', $key, SQ_COOKIE);
26sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
27sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
86bb8549 28
3c66c567 29if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST)) {
30 $mf_cypher = '';
31}
32if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST) ) {
a747d971 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 }
3c66c567 42}
86bb8549 43
162cd2c6 44sqgetGlobalVar('mf_sn', $mf_sn, SQ_POST);
3c66c567 45sqgetGlobalVar('mf_server', $mf_server, SQ_POST);
46sqgetGlobalVar('mf_port', $mf_port, SQ_POST);
47sqgetGlobalVar('mf_alias', $mf_alias, SQ_POST);
48sqgetGlobalVar('mf_user', $mf_user, SQ_POST);
49sqgetGlobalVar('mf_pass', $mf_pass, SQ_POST);
50sqgetGlobalVar('mf_subfolder', $mf_subfolder, SQ_POST);
51sqgetGlobalVar('mf_login', $mf_login, SQ_POST);
52sqgetGlobalVar('mf_fref', $mf_fref, SQ_POST);
53sqgetGlobalVar('mf_lmos', $mf_lmos, SQ_POST);
54sqgetGlobalVar('submit_mailfetch', $submit_mailfetch, SQ_POST);
d622d38a 55
a747d971 56
3c66c567 57/* end globals */
58
59 displayPageHeader( $color, 'None' );
d622d38a 60
d3c89357 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:""));
85756247 66 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
d3c89357 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 ) :""));
86bb8549 70 if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on');
d3c89357 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:""));
85756247 83 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
d3c89357 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;
162cd2c6 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));
d3c89357 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 }
d622d38a 139 for ($i=0;$i<$mailfetch_server_number;$i++) {
140 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
e42b0dd2 141 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
d622d38a 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
3c66c567 154 echo '<br><form method="post" action="'.$PHP_SELF.'">' .
4cf43843 155 html_tag( 'table',
156 html_tag( 'tr',
157 html_tag( 'td',
158 '<b>' . _("Remote POP server settings") . '</b>',
159 'center', $color[0] )
160 ),
658b4c55 161 'center', '', 'width="95%"' ) .
4cf43843 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 ' .
658b4c55 176 (($mailfetch_cypher=='on')?'checked>':'>') .
4cf43843 177 _("Encrypt passwords (informative only)") ,
178 'right' )
179 ) ,
658b4c55 180 'center', '', 'width="95%"' );
d622d38a 181
d3c89357 182 switch( $mf_action ) {
183 case 'config':
658b4c55 184 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
4cf43843 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
d3c89357 191 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
4cf43843 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 ) .
b33b71fc 198 html_tag( 'tr',
e42b0dd2 199 html_tag( 'th', _("Port:"), 'right') .
658b4c55 200 html_tag( 'td', '<input type=text name=mf_port value="110" size=20>', 'left')
e42b0dd2 201 ) .
4cf43843 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' );
d3c89357 217 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
218 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 219 echo '<select name="mf_subfolder">';
ae8a7931 220
221 $selected = 0;
222 if ( isset($mf_subfolder) )
223 $selected = array(strtolower($mf_subfolder));
224 echo sqimap_mailbox_option_list($imapConnection, $selected);
4cf43843 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 ) .
658b4c55 243 '</table></td></tr></table></form>';
d622d38a 244
d3c89357 245 // Modify Server
246 echo '<font size=-5><BR></font>' .
658b4c55 247 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
4cf43843 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] );
d3c89357 253 if ($mailfetch_server_number>0) {
4cf43843 254 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
255 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
d3c89357 256 for ($i=0;$i<$mailfetch_server_number;$i++) {
4cf43843 257 echo "<option value=\"$i\">" .
658b4c55 258 htmlspecialchars( (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>";
d3c89357 259 }
4cf43843 260 echo '</select>'.
a747d971 261 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action_mod value="' . _("Modify") . '">'.
262 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action_del value="' . _("Delete") . '">'.
d3c89357 263 '</form>';
264 } else {
265 echo _("No-one server in use. Try to add.");
266 }
4cf43843 267 echo '</td></tr></table>';
d3c89357 268 break;
a747d971 269 case 'Delete': //erase confirmation about a server
4cf43843 270 echo html_tag( 'table',
271 html_tag( 'tr',
272 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
273 ) ,
658b4c55 274 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
4cf43843 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">' .
617973c4 284 '<br>' . _("Selected Server:") . " <b>" . htmlentities($mailfetch_server_[$mf_sn]) . "</b><br>" .
4cf43843 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 ) ,
658b4c55 290 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' );
d3c89357 291 break; //modify a server
a747d971 292 case 'Modify':
4cf43843 293 echo html_tag( 'table',
294 html_tag( 'tr',
295 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
296 ) ,
658b4c55 297 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
4cf43843 298 '<br>' .
658b4c55 299 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
4cf43843 300 html_tag( 'tr',
09c5aef1 301 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
4cf43843 302 ) .
303 html_tag( 'tr' ) .
304 html_tag( 'td', '', 'center', $color[0] ) .
305
d3c89357 306 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
307 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
4cf43843 308 html_tag( 'table' ) .
309 html_tag( 'tr',
310 html_tag( 'th', _("Server:"), 'right' ) .
617973c4 311 html_tag( 'td', '<input type="text" name="mf_server" value="' . htmlentities($mailfetch_server_[$mf_sn]) . '" size="40">', 'left' )
4cf43843 312 ) .
e42b0dd2 313 html_tag( 'tr',
314 html_tag( 'th', _("Port:"), 'right' ) .
315 html_tag( 'td', '<input type="text" name="mf_port" value="' . $mailfetch_port_[$mf_sn] . '" size="40">', 'left' )
316 ) .
4cf43843 317 html_tag( 'tr',
318 html_tag( 'th', _("Alias:"), 'right' ) .
617973c4 319 html_tag( 'td', '<input type="text" name="mf_alias" value="' . htmlentities($mailfetch_alias_[$mf_sn]) . '" size="40">', 'left' )
4cf43843 320 ) .
321 html_tag( 'tr',
322 html_tag( 'th', _("Username:"), 'right' ) .
323 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
324 ) .
325 html_tag( 'tr',
326 html_tag( 'th', _("Password:"), 'right' ) .
327 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
328 ) .
329 html_tag( 'tr' ) .
330 html_tag( 'th', _("Store in Folder:"), 'right' ) .
331 html_tag( 'td', '', 'left' );
332
d3c89357 333 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
334 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 335 echo '<select name="mf_subfolder">';
ae8a7931 336 $selected = 0;
956f0980 337 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
338 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
339 }
340 echo sqimap_mailbox_option_list($imapConnection, $selected) .
341 '</select></td></tr>' .
4cf43843 342
343 html_tag( 'tr',
344 html_tag( 'th', '&nbsp;', 'right' ) .
345 html_tag( 'td',
346 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
347 '>' . _("Leave Mail on Server") ,
348 'left' )
349 ) .
350 html_tag( 'tr',
351 html_tag( 'th', '&nbsp;', 'right' ) .
352 html_tag( 'td',
353 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
354 '>' . _("Check mail during login"),
355 'left' )
356 ) .
357 html_tag( 'tr',
358 html_tag( 'th', '&nbsp;', 'right' ) .
359 html_tag( 'td',
360 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
361 '>' . _("Check mail during folder refresh") ,
362 'left' )
363 ) .
364 html_tag( 'tr',
365 html_tag( 'td',
366 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
367 'center', '', 'colspan="2"' )
368 ) .
369
370 '</table></form></td></tr></table>';
d3c89357 371 break;
372 default: //unsupported action
4cf43843 373 echo '</form>' .
374 html_tag( 'table',
375 html_tag( 'tr',
376 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
377 ) ,
658b4c55 378 'center', '', 'width="95%"' ) .
4cf43843 379 '<br>' .
380 html_tag( 'table',
381 html_tag( 'tr',
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] )
384 ) ,
658b4c55 385 'center', '', 'width="70%"' );
d3c89357 386 }
dcc1cc82 387
388 ?>
389</body></html>