Removal of unused commented code blocks
[squirrelmail.git] / plugins / mail_fetch / options.php
CommitLineData
d622d38a 1<?php
d3c89357 2
8d6a115b 3/**
4 * mail_fetch/options.php
5 *
6c84ba1e 6 * Copyright (c) 1999-2005 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 *
4f51df66 11 * @version $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');
5c89bd63 20include_once(SM_PATH . 'functions/imap.php');
d622d38a 21
3c66c567 22/* globals */
23sqgetGlobalVar('username', $username, SQ_SESSION);
24sqgetGlobalVar('key', $key, SQ_COOKIE);
25sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
26sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
91e0dccc 27
3c66c567 28if(!sqgetGlobalVar('mf_cypher', $mf_cypher, SQ_POST)) {
29 $mf_cypher = '';
30}
31if(! sqgetGlobalVar('mf_action', $mf_action, SQ_POST) ) {
a747d971 32 if (sqgetGlobalVar('mf_action_mod', $mf_action_mod, SQ_POST)) {
33 $mf_action = 'Modify';
34 }
35 elseif (sqgetGlobalVar('mf_action_del', $mf_action_del, SQ_POST)) {
36 $mf_action = 'Delete';
37 }
38 else {
39 $mf_action = 'config';
40 }
3c66c567 41}
86bb8549 42
162cd2c6 43sqgetGlobalVar('mf_sn', $mf_sn, SQ_POST);
3c66c567 44sqgetGlobalVar('mf_server', $mf_server, SQ_POST);
45sqgetGlobalVar('mf_port', $mf_port, SQ_POST);
46sqgetGlobalVar('mf_alias', $mf_alias, SQ_POST);
47sqgetGlobalVar('mf_user', $mf_user, SQ_POST);
48sqgetGlobalVar('mf_pass', $mf_pass, SQ_POST);
49sqgetGlobalVar('mf_subfolder', $mf_subfolder, SQ_POST);
50sqgetGlobalVar('mf_login', $mf_login, SQ_POST);
51sqgetGlobalVar('mf_fref', $mf_fref, SQ_POST);
52sqgetGlobalVar('mf_lmos', $mf_lmos, SQ_POST);
53sqgetGlobalVar('submit_mailfetch', $submit_mailfetch, SQ_POST);
d622d38a 54
a747d971 55
3c66c567 56/* end globals */
57
58 displayPageHeader( $color, 'None' );
d622d38a 59
d3c89357 60 switch( $mf_action ) {
61 case 'add':
62 if ($mf_sn<1) $mf_sn=0;
63 if (!isset($mf_server)) return;
64 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
85756247 65 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
d3c89357 66 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
67 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
68 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
86bb8549 69 if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on');
d3c89357 70 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
71 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
72 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
73 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
74 $mf_sn++;
75 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
76 $mf_action = 'config';
77 break;
78 case 'confirm_modify':
79 //modify a server
80 if (!isset($mf_server)) return;
81 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
85756247 82 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
d3c89357 83 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
84 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
85 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
86 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
87 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
88 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
89 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
90 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
91 $mf_action = 'config';
92 break;
93 case 'confirm_delete':
94 //delete a server
95 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
96 if ($mf_sn+1==$mailfetch_server_number) {
97 //is the last server, whe can only decrase $mailfetch_server_number
98 $mailfetch_server_number--;
99 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
100 } else {
101 //if not the last, all the sequel server come up one step
102 //then whe decrase $mailfetch_server_number
103 $mailfetch_server_number--;
104 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++) {
105 $tmp=$i+1;
162cd2c6 106 setPref($data_dir,$username,'mailfetch_server_'.$i,
107 getPref($data_dir,$username, 'mailfetch_server_'.$tmp));
108 setPref($data_dir,$username,'mailfetch_port_'.$i,
109 getPref($data_dir,$username, 'mailfetch_port_'.$tmp));
110 setPref($data_dir,$username,'mailfetch_alias_'.$i,
111 getPref($data_dir,$username, 'mailfetch_alias_'.$tmp));
112 setPref($data_dir,$username,'mailfetch_user_'.$i,
113 getPref($data_dir,$username, 'mailfetch_user_'.$tmp));
114 setPref($data_dir,$username,'mailfetch_pass_'.$i,
115 getPref($data_dir,$username, 'mailfetch_pass_'.$tmp));
116 setPref($data_dir,$username,'mailfetch_lmos_'.$i,
117 getPref($data_dir,$username, 'mailfetch_lmos_'.$tmp));
118 setPref($data_dir,$username,'mailfetch_login_'.$i,
119 getPref($data_dir,$username, 'mailfetch_login_'.$tmp));
120 setPref($data_dir,$username,'mailfetch_fref_'.$i,
121 getPref($data_dir,$username, 'mailfetch_fref_'.$tmp));
122 setPref($data_dir,$username,'mailfetch_subfolder_'.$i,
123 getPref($data_dir,$username, 'mailfetch_subfolder_'.$tmp));
91e0dccc 124 setPref($data_dir,$username,'mailfetch_uidl_'.$i,
162cd2c6 125 getPref($data_dir,$username, 'mailfetch_uidl_'.$tmp));
d3c89357 126 }
127 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
128 }
129 $mf_action = 'config';
130 break;
131 }
132
133 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
134 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
135 if ($mailfetch_server_number<1) {
136 $mailfetch_server_number=0;
137 }
d622d38a 138 for ($i=0;$i<$mailfetch_server_number;$i++) {
139 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
e42b0dd2 140 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
d622d38a 141 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
142 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
143 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
144 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
145 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
146 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
147 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
148 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
149 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
150 }
151
152
6fd95361 153 echo '<br /><form method="post" action="'.$PHP_SELF.'">' .
4cf43843 154 html_tag( 'table',
155 html_tag( 'tr',
156 html_tag( 'td',
157 '<b>' . _("Remote POP server settings") . '</b>',
158 'center', $color[0] )
159 ),
658b4c55 160 'center', '', 'width="95%"' ) .
4cf43843 161 html_tag( 'table',
162 html_tag( 'tr',
163 html_tag( 'td',
6fd95361 164 _("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.") ,
4cf43843 165 'left' )
166 ) .
167 html_tag( 'tr',
168 html_tag( 'td',
333daac7 169 _("If you leave password empty, it will be asked when you fetch mail.") ,
4cf43843 170 'left' )
171 ) .
172 html_tag( 'tr',
173 html_tag( 'td',
6fd95361 174 '<input type="checkbox" name="mf_cypher" ' .
175 (($mailfetch_cypher=='on')?'checked="checked" />':' />') .
4cf43843 176 _("Encrypt passwords (informative only)") ,
177 'right' )
178 ) ,
658b4c55 179 'center', '', 'width="95%"' );
d622d38a 180
d3c89357 181 switch( $mf_action ) {
182 case 'config':
658b4c55 183 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
4cf43843 184 html_tag( 'tr',
185 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
186 ) .
187 html_tag( 'tr' ) .
188 html_tag( 'td', '', 'center', $color[0] ) .
189
6fd95361 190 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mailfetch_server_number\" />" .
191 '<input type="hidden" name="mf_action" value="add" />' .
4cf43843 192 html_tag( 'table' ) .
193 html_tag( 'tr',
194 html_tag( 'th', _("Server:"), 'right' ) .
6fd95361 195 html_tag( 'td', '<input type="text" name="mf_server" value="" size="40" />', 'left' )
4cf43843 196 ) .
b33b71fc 197 html_tag( 'tr',
e42b0dd2 198 html_tag( 'th', _("Port:"), 'right') .
6fd95361 199 html_tag( 'td', '<input type="text" name="mf_port" value="110" size="20" />', 'left')
e42b0dd2 200 ) .
4cf43843 201 html_tag( 'tr',
202 html_tag( 'th', _("Alias:"), 'right' ) .
6fd95361 203 html_tag( 'td', '<input type="text" name="mf_alias" value="" size="20" />', 'left' )
4cf43843 204 ) .
205 html_tag( 'tr',
206 html_tag( 'th', _("Username:"), 'right' ) .
6fd95361 207 html_tag( 'td', '<input type="text" name="mf_user" value="" size="20" />', 'left' )
4cf43843 208 ) .
209 html_tag( 'tr',
210 html_tag( 'th', _("Password:"), 'right' ) .
6fd95361 211 html_tag( 'td', '<input type="password" name="mf_pass" value="" size="20" />', 'left' )
4cf43843 212 ) .
213 html_tag( 'tr' ) .
214 html_tag( 'th', _("Store in Folder:"), 'right' ) .
215 html_tag( 'td', '', 'left' );
d3c89357 216 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
217 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 218 echo '<select name="mf_subfolder">';
ae8a7931 219
220 $selected = 0;
221 if ( isset($mf_subfolder) )
222 $selected = array(strtolower($mf_subfolder));
223 echo sqimap_mailbox_option_list($imapConnection, $selected);
4cf43843 224 echo '</select></td></tr>' .
225 html_tag( 'tr',
226 html_tag( 'th', '&nbsp;', 'right' ) .
6fd95361 227 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked="checked" />' . _("Leave Mail on Server"), 'left' )
4cf43843 228 ) .
229 html_tag( 'tr',
230 html_tag( 'th', '&nbsp;', 'right' ) .
333daac7 231 html_tag( 'td', '<input type="checkbox" name="mf_login" />' . _("Check mail at login"), 'left' )
4cf43843 232 ) .
233 html_tag( 'tr',
234 html_tag( 'th', '&nbsp;', 'right' ) .
333daac7 235 html_tag( 'td', '<input type="checkbox" name="mf_fref" />' . _("Check mail at folder refresh"), 'left' )
4cf43843 236 ) .
237 html_tag( 'tr',
238 html_tag( 'td',
6fd95361 239 '<input type="submit" name="submit_mailfetch" value="' . _("Add Server") . '" />',
4cf43843 240 'center', '', 'colspan="2"' )
241 ) .
658b4c55 242 '</table></td></tr></table></form>';
d622d38a 243
d3c89357 244 // Modify Server
6fd95361 245 echo '<font size="-5"><br /></font>' .
658b4c55 246 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
4cf43843 247 html_tag( 'tr',
248 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
249 ) .
250 html_tag( 'tr' ) .
251 html_tag( 'td', '', 'center', $color[0] );
d3c89357 252 if ($mailfetch_server_number>0) {
4cf43843 253 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
254 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
d3c89357 255 for ($i=0;$i<$mailfetch_server_number;$i++) {
4cf43843 256 echo "<option value=\"$i\">" .
658b4c55 257 htmlspecialchars( (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>";
d3c89357 258 }
4cf43843 259 echo '</select>'.
6fd95361 260 '&nbsp;&nbsp;<input type="submit" name="mf_action_mod" value="' . _("Modify") . '" />'.
261 '&nbsp;&nbsp;<input type="submit" name="mf_action_del" value="' . _("Delete") . '" />'.
d3c89357 262 '</form>';
263 } else {
333daac7 264 echo _("No servers known.");
d3c89357 265 }
4cf43843 266 echo '</td></tr></table>';
d3c89357 267 break;
a747d971 268 case 'Delete': //erase confirmation about a server
4cf43843 269 echo html_tag( 'table',
270 html_tag( 'tr',
271 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
272 ) ,
658b4c55 273 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
6fd95361 274 '<br />' .
4cf43843 275 html_tag( 'table',
276 html_tag( 'tr',
277 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
278 ) .
279 html_tag( 'tr',
280 html_tag( 'td',
6fd95361 281 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mf_sn\" />" .
282 '<input type="hidden" name="mf_action" value="confirm_delete" />' .
283 '<br />' . _("Selected Server:") . " <b>" . htmlspecialchars($mailfetch_server_[$mf_sn]) . "</b><br />" .
284 _("Confirm delete of selected server?") . '<br /><br />' .
285 '<input type="submit" name="submit_mailfetch" value="' . _("Confirm Delete") . '" />' .
286 '<br /></form>' ,
4cf43843 287 'center', $color[9] )
288 ) ,
658b4c55 289 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' );
d3c89357 290 break; //modify a server
a747d971 291 case 'Modify':
4cf43843 292 echo html_tag( 'table',
293 html_tag( 'tr',
294 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
295 ) ,
658b4c55 296 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
6fd95361 297 '<br />' .
658b4c55 298 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
4cf43843 299 html_tag( 'tr',
09c5aef1 300 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
4cf43843 301 ) .
302 html_tag( 'tr' ) .
303 html_tag( 'td', '', 'center', $color[0] ) .
304
6fd95361 305 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mf_sn\" />" .
306 '<input type="hidden" name="mf_action" value="confirm_modify" />' .
4cf43843 307 html_tag( 'table' ) .
308 html_tag( 'tr',
309 html_tag( 'th', _("Server:"), 'right' ) .
a9e1e670 310 html_tag( 'td', '<input type="text" name="mf_server" value="' .
6fd95361 311 htmlspecialchars($mailfetch_server_[$mf_sn]) . '" size="40" />', 'left' )
4cf43843 312 ) .
e42b0dd2 313 html_tag( 'tr',
314 html_tag( 'th', _("Port:"), 'right' ) .
a9e1e670 315 html_tag( 'td', '<input type="text" name="mf_port" value="' .
6fd95361 316 htmlspecialchars($mailfetch_port_[$mf_sn]) . '" size="40" />', 'left' )
e42b0dd2 317 ) .
4cf43843 318 html_tag( 'tr',
319 html_tag( 'th', _("Alias:"), 'right' ) .
a9e1e670 320 html_tag( 'td', '<input type="text" name="mf_alias" value="' .
6fd95361 321 htmlspecialchars($mailfetch_alias_[$mf_sn]) . '" size="40" />', 'left' )
4cf43843 322 ) .
323 html_tag( 'tr',
324 html_tag( 'th', _("Username:"), 'right' ) .
91e0dccc 325 html_tag( 'td', '<input type="text" name="mf_user" value="' .
6fd95361 326 htmlspecialchars($mailfetch_user_[$mf_sn]) . '" size="20" />', 'left' )
4cf43843 327 ) .
328 html_tag( 'tr',
329 html_tag( 'th', _("Password:"), 'right' ) .
a9e1e670 330 html_tag( 'td', '<input type="password" name="mf_pass" value="' .
6fd95361 331 htmlspecialchars($mailfetch_pass_[$mf_sn]) . '" size="20" />', 'left' )
4cf43843 332 ) .
333 html_tag( 'tr' ) .
334 html_tag( 'th', _("Store in Folder:"), 'right' ) .
335 html_tag( 'td', '', 'left' );
336
d3c89357 337 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
338 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 339 echo '<select name="mf_subfolder">';
ae8a7931 340 $selected = 0;
956f0980 341 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
342 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
91e0dccc 343 }
956f0980 344 echo sqimap_mailbox_option_list($imapConnection, $selected) .
345 '</select></td></tr>' .
4cf43843 346
347 html_tag( 'tr',
348 html_tag( 'th', '&nbsp;', 'right' ) .
349 html_tag( 'td',
6fd95361 350 '<input type="checkbox" name="mf_lmos" ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked="checked"':'') .
351 ' />' . _("Leave Mail on Server") ,
4cf43843 352 'left' )
353 ) .
354 html_tag( 'tr',
355 html_tag( 'th', '&nbsp;', 'right' ) .
356 html_tag( 'td',
6fd95361 357 '<input type="checkbox" name="mf_login" ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked="checked"':'') .
333daac7 358 ' />' . _("Check mail at login"),
4cf43843 359 'left' )
360 ) .
361 html_tag( 'tr',
362 html_tag( 'th', '&nbsp;', 'right' ) .
363 html_tag( 'td',
6fd95361 364 '<input type="checkbox" name="mf_fref" ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked="checked"':'') .
333daac7 365 ' />' . _("Check mail at folder refresh") ,
4cf43843 366 'left' )
367 ) .
368 html_tag( 'tr',
369 html_tag( 'td',
6fd95361 370 '<input type="submit" name="submit_mailfetch" value="' . _("Modify Server") . '" />',
4cf43843 371 'center', '', 'colspan="2"' )
372 ) .
373
374 '</table></form></td></tr></table>';
d3c89357 375 break;
376 default: //unsupported action
4cf43843 377 echo '</form>' .
378 html_tag( 'table',
379 html_tag( 'tr',
380 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
381 ) ,
658b4c55 382 'center', '', 'width="95%"' ) .
6fd95361 383 '<br />' .
4cf43843 384 html_tag( 'table',
385 html_tag( 'tr',
386 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
333daac7 387 html_tag( 'td', '<b>' . _("The function you requested is unknown.") . '</b>', 'center', $color[0] )
4cf43843 388 ) ,
658b4c55 389 'center', '', 'width="70%"' );
d3c89357 390 }
dcc1cc82 391
5c89bd63 392?>
4f51df66 393</body></html>