Centralized init
[squirrelmail.git] / plugins / mail_fetch / options.php
CommitLineData
d622d38a 1<?php
4b4abf93 2
8d6a115b 3/**
4 * mail_fetch/options.php
5 *
8d6a115b 6 * Setup of the mailfetch plugin.
7 *
47ccfad4 8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
4f51df66 10 * @version $Id$
ea5f4b8e 11 * @package plugins
12 * @subpackage mail_fetch
8d6a115b 13 */
d622d38a 14
202bcbcc 15/**
16 * Include the SquirrelMail initialization file.
17 */
18require('../../include/init.php');
aa7fb30c 19
202bcbcc 20include_once(SM_PATH . 'functions/imap_general.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
60683821 58displayPageHeader( $color, 'None' );
d622d38a 59
60683821 60switch( $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:""));
65 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
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 ) :""));
69 if( isset($mf_cypher) && $mf_cypher <> 'on' ) SetPref($data_dir,$username,'mailfetch_cypher', 'on');
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:""));
82 setPref($data_dir,$username,"mailfetch_port_$mf_sn", (isset($mf_port)?$mf_port:110));
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;
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));
124 setPref($data_dir,$username,'mailfetch_uidl_'.$i,
125 getPref($data_dir,$username, 'mailfetch_uidl_'.$tmp));
126 }
127 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
128 }
129 $mf_action = 'config';
130 break;
131}
4cf43843 132
60683821 133$mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
134$mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
135if ($mailfetch_server_number<1) {
136 $mailfetch_server_number=0;
137}
138for ($i=0;$i<$mailfetch_server_number;$i++) {
139 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
140 $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
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}
ae8a7931 151
60683821 152echo '<br /><form method="post" action="'.$PHP_SELF.'">' .
153 html_tag( 'table',
154 html_tag( 'tr',
155 html_tag('td',
156 '<b>' . _("Remote POP server settings") . '</b>',
157 'center', $color[0] )
158 ),
159 'center', '', 'width="95%"' ) .
160 html_tag( 'table',
161 html_tag( 'tr',
162 html_tag( 'td',
163 _("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.") ,
164 'left' )
165 ) .
166 html_tag( 'tr',
167 html_tag( 'td',
168 _("If you leave password empty, it will be asked when you fetch mail.") ,
169 'left' )
170 ) .
171 html_tag( 'tr',
172 html_tag( 'td',
173 '<input type="checkbox" name="mf_cypher" ' .
174 (($mailfetch_cypher=='on')?'checked="checked" />':' />') .
175 _("Encrypt passwords (informative only)") ,
176 'right' )
177 ) ,
178 'center', '', 'width="95%"' );
d622d38a 179
60683821 180switch( $mf_action ) {
181 case 'config':
182 echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
183 html_tag( 'tr',
184 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
185 ) .
186 html_tag( 'tr' ) .
187 html_tag( 'td', '', 'center', $color[0] ) .
4cf43843 188
60683821 189 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mailfetch_server_number\" />" .
190 '<input type="hidden" name="mf_action" value="add" />' .
191 html_tag( 'table' ) .
192 html_tag( 'tr',
193 html_tag( 'th', _("Server:"), 'right' ) .
194 html_tag( 'td', '<input type="text" name="mf_server" value="" size="40" />', 'left' )
195 ) .
196 html_tag( 'tr',
197 html_tag( 'th', _("Port:"), 'right') .
198 html_tag( 'td', '<input type="text" name="mf_port" value="110" size="20" />', 'left')
199 ) .
200 html_tag( 'tr',
201 html_tag( 'th', _("Alias:"), 'right' ) .
202 html_tag( 'td', '<input type="text" name="mf_alias" value="" size="20" />', 'left' )
203 ) .
204 html_tag( 'tr',
205 html_tag( 'th', _("Username:"), 'right' ) .
206 html_tag( 'td', '<input type="text" name="mf_user" value="" size="20" />', 'left' )
207 ) .
208 html_tag( 'tr',
209 html_tag( 'th', _("Password:"), 'right' ) .
210 html_tag( 'td', '<input type="password" name="mf_pass" value="" size="20" />', 'left' )
211 ) .
212 html_tag( 'tr' ) .
213 html_tag( 'th', _("Store in Folder:"), 'right' ) .
214 html_tag( 'td', '', 'left' );
215 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
216 $boxes = sqimap_mailbox_list($imapConnection);
217 echo '<select name="mf_subfolder">';
4cf43843 218
60683821 219 $selected = 0;
220 if ( isset($mf_subfolder) )
221 $selected = array(strtolower($mf_subfolder));
222 echo sqimap_mailbox_option_list($imapConnection, $selected);
223 echo '</select></td></tr>' .
224 html_tag( 'tr',
225 html_tag( 'th', '&nbsp;', 'right' ) .
226 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked="checked" />' . _("Leave Mail on Server"), 'left' )
227 ) .
228 html_tag( 'tr',
229 html_tag( 'th', '&nbsp;', 'right' ) .
230 html_tag( 'td', '<input type="checkbox" name="mf_login" />' . _("Check mail at login"), 'left' )
231 ) .
232 html_tag( 'tr',
233 html_tag( 'th', '&nbsp;', 'right' ) .
234 html_tag( 'td', '<input type="checkbox" name="mf_fref" />' . _("Check mail at folder refresh"), 'left' )
235 ) .
236 html_tag( 'tr',
237 html_tag( 'td',
238 '<input type="submit" name="submit_mailfetch" value="' . _("Add Server") . '" />',
239 'center', '', 'colspan="2"' )
240 ) .
241 '</table></td></tr></table></form>';
4cf43843 242
60683821 243 // Modify Server
244 echo '<font size="-5"><br /></font>' .
245 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
246 html_tag( 'tr',
247 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
248 ) .
249 html_tag( 'tr' ) .
250 html_tag( 'td', '', 'center', $color[0] );
251 if ($mailfetch_server_number>0) {
252 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
253 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
254 for ($i=0;$i<$mailfetch_server_number;$i++) {
255 echo "<option value=\"$i\">" .
256 htmlspecialchars( (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i])) . "</option>";
257 }
258 echo '</select>'.
259 '&nbsp;&nbsp;<input type="submit" name="mf_action_mod" value="' . _("Modify") . '" />'.
260 '&nbsp;&nbsp;<input type="submit" name="mf_action_del" value="' . _("Delete") . '" />'.
261 '</form>';
262 } else {
263 echo _("No servers known.");
264 }
265 echo '</td></tr></table>';
266 break;
267 case 'Delete': //erase confirmation about a server
268 echo html_tag( 'table',
269 html_tag( 'tr',
270 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
271 ) ,
272 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
273 '<br />' .
274 html_tag( 'table',
275 html_tag( 'tr',
276 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
277 ) .
278 html_tag( 'tr',
279 html_tag( 'td',
280 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mf_sn\" />" .
281 '<input type="hidden" name="mf_action" value="confirm_delete" />' .
282 '<br />' . _("Selected Server:") . " <b>" . htmlspecialchars($mailfetch_server_[$mf_sn]) . "</b><br />" .
283 _("Confirm delete of selected server?") . '<br /><br />' .
284 '<input type="submit" name="submit_mailfetch" value="' . _("Confirm Delete") . '" />' .
285 '<br /></form>' ,
286 'center', $color[9] )
287 ) ,
288 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' );
289 break; //modify a server
290 case 'Modify':
291 echo html_tag( 'table',
292 html_tag( 'tr',
293 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
294 ) ,
295 'center', '', 'width="95%" cellpadding="5" cellspacing="1"' ) .
296 '<br />' .
297 html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="5" cellspacing="1"' ) .
298 html_tag( 'tr',
299 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
300 ) .
301 html_tag( 'tr' ) .
302 html_tag( 'td', '', 'center', $color[0] ) .
4cf43843 303
60683821 304 "<input type=\"hidden\" name=\"mf_sn\" value=\"$mf_sn\" />" .
305 '<input type="hidden" name="mf_action" value="confirm_modify" />' .
306 html_tag( 'table' ) .
307 html_tag( 'tr',
308 html_tag( 'th', _("Server:"), 'right' ) .
309 html_tag( 'td', '<input type="text" name="mf_server" value="' .
310 htmlspecialchars($mailfetch_server_[$mf_sn]) . '" size="40" />', 'left' )
311 ) .
312 html_tag( 'tr',
313 html_tag( 'th', _("Port:"), 'right' ) .
314 html_tag( 'td', '<input type="text" name="mf_port" value="' .
315 htmlspecialchars($mailfetch_port_[$mf_sn]) . '" size="40" />', 'left' )
316 ) .
317 html_tag( 'tr',
318 html_tag( 'th', _("Alias:"), 'right' ) .
319 html_tag( 'td', '<input type="text" name="mf_alias" value="' .
320 htmlspecialchars($mailfetch_alias_[$mf_sn]) . '" size="40" />', 'left' )
321 ) .
322 html_tag( 'tr',
323 html_tag( 'th', _("Username:"), 'right' ) .
324 html_tag( 'td', '<input type="text" name="mf_user" value="' .
325 htmlspecialchars($mailfetch_user_[$mf_sn]) . '" size="20" />', 'left' )
326 ) .
327 html_tag( 'tr',
328 html_tag( 'th', _("Password:"), 'right' ) .
329 html_tag( 'td', '<input type="password" name="mf_pass" value="' .
330 htmlspecialchars($mailfetch_pass_[$mf_sn]) . '" size="20" />', 'left' )
331 ) .
332 html_tag( 'tr' ) .
333 html_tag( 'th', _("Store in Folder:"), 'right' ) .
334 html_tag( 'td', '', 'left' );
dcc1cc82 335
60683821 336 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
337 $boxes = sqimap_mailbox_list($imapConnection);
338 echo '<select name="mf_subfolder">';
339 $selected = 0;
340 if ( isset($mailfetch_subfolder_[$mf_sn]) ) {
341 $selected = array(strtolower($mailfetch_subfolder_[$mf_sn]));
342 }
343 echo sqimap_mailbox_option_list($imapConnection, $selected) .
344 '</select></td></tr>' .
345 html_tag( 'tr',
346 html_tag( 'th', '&nbsp;', 'right' ) .
347 html_tag( 'td',
348 '<input type="checkbox" name="mf_lmos" ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked="checked"':'') .
349 ' />' . _("Leave Mail on Server") ,
350 'left' )
351 ) .
352 html_tag( 'tr',
353 html_tag( 'th', '&nbsp;', 'right' ) .
354 html_tag( 'td',
355 '<input type="checkbox" name="mf_login" ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked="checked"':'') .
356 ' />' . _("Check mail at login"),
357 'left' )
358 ) .
359 html_tag( 'tr',
360 html_tag( 'th', '&nbsp;', 'right' ) .
361 html_tag( 'td',
362 '<input type="checkbox" name="mf_fref" ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked="checked"':'') .
363 ' />' . _("Check mail at folder refresh") ,
364 'left' )
365 ) .
366 html_tag( 'tr',
367 html_tag( 'td',
368 '<input type="submit" name="submit_mailfetch" value="' . _("Modify Server") . '" />',
369 'center', '', 'colspan="2"' )
370 ) .
371 '</table></form></td></tr></table>';
372 break;
373 default: //unsupported action
374 echo '</form>' .
375 html_tag( 'table',
376 html_tag( 'tr',
377 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
378 ) ,
379 'center', '', 'width="95%"' ) .
380 '<br />' .
381 html_tag( 'table',
382 html_tag( 'tr',
383 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
384 html_tag( 'td', '<b>' . _("The function you requested is unknown.") . '</b>', 'center', $color[0] )
385 ) ,
386 'center', '', 'width="70%"' );
387}
5c89bd63 388?>
4f51df66 389</body></html>