*** empty log message ***
[squirrelmail.git] / plugins / mail_fetch / options.php
CommitLineData
d622d38a 1<?php
d3c89357 2
3 /**
4 ** mail_fetch/options.php
5 **
15e6162e 6 ** Copyright (c) 1999-2002 The SquirrelMail Project Team
d3c89357 7 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 **
9 ** Setup of the mailfetch plugin.
10 **
11 ** $Id$
12 **/
d622d38a 13
14 chdir('..');
15 require_once('../src/validate.php');
16 require_once('../functions/imap.php');
17 require_once('../src/load_prefs.php');
d622d38a 18
d3c89357 19 displayPageHeader( $color, 'None' );
d622d38a 20
d3c89357 21 //if dosen't select any option
22 if (!isset($mf_action))
23 $mf_action = 'config';
d622d38a 24
d3c89357 25 switch( $mf_action ) {
26 case 'add':
27 if ($mf_sn<1) $mf_sn=0;
28 if (!isset($mf_server)) return;
29 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
30 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
31 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
32 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
33 if( $mf_cypher <> 'on' ) SetPref($data_dir,$username,"mailfetch_cypher", 'on');
34 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
35 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
36 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
37 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
38 $mf_sn++;
39 setPref($data_dir,$username,'mailfetch_server_number', $mf_sn);
40 $mf_action = 'config';
41 break;
42 case 'confirm_modify':
43 //modify a server
44 if (!isset($mf_server)) return;
45 setPref($data_dir,$username,"mailfetch_server_$mf_sn", (isset($mf_server)?$mf_server:""));
46 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", (isset($mf_alias)?$mf_alias:""));
47 setPref($data_dir,$username,"mailfetch_user_$mf_sn",(isset($mf_user)?$mf_user:""));
48 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
49 if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
50 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn",(isset($mf_lmos)?$mf_lmos:""));
51 setPref($data_dir,$username,"mailfetch_login_$mf_sn",(isset($mf_login)?$mf_login:""));
52 setPref($data_dir,$username,"mailfetch_fref_$mf_sn",(isset($mf_fref)?$mf_fref:""));
53 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn",(isset($mf_subfolder)?$mf_subfolder:""));
54 $mf_action = 'config';
55 break;
56 case 'confirm_delete':
57 //delete a server
58 $mailfetch_server_number = getPref($data_dir, $username, "mailfetch_server_number");
59 if ($mf_sn+1==$mailfetch_server_number) {
60 //is the last server, whe can only decrase $mailfetch_server_number
61 $mailfetch_server_number--;
62 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
63 } else {
64 //if not the last, all the sequel server come up one step
65 //then whe decrase $mailfetch_server_number
66 $mailfetch_server_number--;
67 for ($i=$mf_sn;$i<$mailfetch_server_number;$i++) {
68 $tmp=$i+1;
09e47788 69 setPref($data_dir,$username,"mailfetch_server_$i", getPref($data_dir, $username, "mailfetch_server_$tmp"));
70 setPref($data_dir,$username,"mailfetch_alias_$i", getPref($data_dir, $username, "mailfetch_alias_$tmp"));
71 setPref($data_dir,$username,"mailfetch_user_$i", getPref($data_dir, $username, "mailfetch_user_$tmp"));
72 setPref($data_dir,$username,"mailfetch_pass_$i",(isset($mf_pass)?encrypt( $mf_pass ) :""));
d3c89357 73 // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
09e47788 74 setPref($data_dir,$username,"mailfetch_lmos_$i", getPref($data_dir, $username, "mailfetch_lmos_$tmp"));
75 setPref($data_dir,$username,"mailfetch_login_$i", getPref($data_dir, $username, "mailfetch_login_$tmp"));
76 setPref($data_dir,$username,"mailfetch_fref_$i", getPref($data_dir, $username, "mailfetch_fref_$tmp"));
77 setPref($data_dir,$username,"mailfetch_subfolder_$i", getPref($data_dir, $username, "mailfetch_subfolder_$tmp"));
d3c89357 78 }
79 setPref($data_dir,$username,"mailfetch_server_number", $mailfetch_server_number);
80 }
81 $mf_action = 'config';
82 break;
83 }
84
85 $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
86 $mailfetch_cypher = getPref( $data_dir, $username, 'mailfetch_cypher' );
87 if ($mailfetch_server_number<1) {
88 $mailfetch_server_number=0;
89 }
d622d38a 90 for ($i=0;$i<$mailfetch_server_number;$i++) {
91 $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
92 $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
93 $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
94 $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
95 $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
96 $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
97 $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
98 $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
99 $mailfetch_subfolder_[$i] = getPref($data_dir, $username, "mailfetch_subfolder_$i");
100 if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
101 }
102
103
d3c89357 104 echo '<BR><form method=post action="'.$PHP_SELF.'">' .
4cf43843 105 html_tag( 'table',
106 html_tag( 'tr',
107 html_tag( 'td',
108 '<b>' . _("Remote POP server settings") . '</b>',
109 'center', $color[0] )
110 ),
111 'center', '', 'width="95%" cols="1"' ) .
112 html_tag( 'table',
113 html_tag( 'tr',
114 html_tag( 'td',
115 _("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." ) ,
116 'left' )
117 ) .
118 html_tag( 'tr',
119 html_tag( 'td',
120 _("If you leave password empty, it will be required when you fetch mail.") ,
121 'left' )
122 ) .
123 html_tag( 'tr',
124 html_tag( 'td',
125 '<input type=checkbox name=mf_cypher ' .
126 (($mailfetch_cypher=='on')?'checked >':'>') .
127 _("Encrypt passwords (informative only)") ,
128 'right' )
129 ) ,
130 'center', '', 'width="95%" cols="1"' );
d622d38a 131
d3c89357 132 switch( $mf_action ) {
133 case 'config':
4cf43843 134 echo html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
135 html_tag( 'tr',
136 html_tag( 'td', '<b>' . _("Add Server") . '</b>', 'center', $color[9] )
137 ) .
138 html_tag( 'tr' ) .
139 html_tag( 'td', '', 'center', $color[0] ) .
140
d3c89357 141 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
4cf43843 142 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add">' .
143 html_tag( 'table' ) .
144 html_tag( 'tr',
145 html_tag( 'th', _("Server:"), 'right' ) .
146 html_tag( 'td', '<input type=text name=mf_server value="" size=40>', 'left' )
147 ) .
148 html_tag( 'tr',
149 html_tag( 'th', _("Alias:"), 'right' ) .
150 html_tag( 'td', '<input type=text name=mf_alias value="" size=20>', 'left' )
151 ) .
152 html_tag( 'tr',
153 html_tag( 'th', _("Username:"), 'right' ) .
154 html_tag( 'td', '<input type=text name=mf_user value="" size=20>', 'left' )
155 ) .
156 html_tag( 'tr',
157 html_tag( 'th', _("Password:"), 'right' ) .
158 html_tag( 'td', '<input type=password name=mf_pass value="" size=20>', 'left' )
159 ) .
160 html_tag( 'tr' ) .
161 html_tag( 'th', _("Store in Folder:"), 'right' ) .
162 html_tag( 'td', '', 'left' );
d3c89357 163 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
164 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 165 echo '<select name="mf_subfolder">';
5e7f6ef6 166 $boxes = sqimap_mailbox_list($imapConnection);
d3c89357 167 for ($i = 0; $i < count($boxes); $i++) {
5e7f6ef6 168 if (!in_array('noselect', $boxes[$i]['flags'])) {
169 $box = $boxes[$i]['unformatted'];
170 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
171 if ( strtolower( $box2 ) == 'inbox' ) {
172 $box2 = _("INBOX");
d622d38a 173 }
4cf43843 174 echo "<option value=\"$box\">$box2</option>\n";
d622d38a 175 }
5e7f6ef6 176 }
4cf43843 177 echo '</select></td></tr>' .
178 html_tag( 'tr',
179 html_tag( 'th', '&nbsp;', 'right' ) .
180 html_tag( 'td', '<input type="checkbox" name="mf_lmos" checked>' . _("Leave Mail on Server"), 'left' )
181 ) .
182 html_tag( 'tr',
183 html_tag( 'th', '&nbsp;', 'right' ) .
184 html_tag( 'td', '<input type="checkbox" name="mf_login">' . _("Check mail during login"), 'left' )
185 ) .
186 html_tag( 'tr',
187 html_tag( 'th', '&nbsp;', 'right' ) .
188 html_tag( 'td', '<input type="checkbox" name="mf_fref">' . _("Check mail during folder refresh"), 'left' )
189 ) .
190 html_tag( 'tr',
191 html_tag( 'td',
192 '<input type=submit name="submit_mailfetch" value="' . _("Add Server") . '">',
193 'center', '', 'colspan="2"' )
194 ) .
195 '</table></form></td></tr></table>';
d622d38a 196
d3c89357 197 // Modify Server
198 echo '<font size=-5><BR></font>' .
4cf43843 199 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
200 html_tag( 'tr',
201 html_tag( 'td', '<b>' . _("Modify Server") . '</b>', 'center', $color[9] )
202 ) .
203 html_tag( 'tr' ) .
204 html_tag( 'td', '', 'center', $color[0] );
d3c89357 205 if ($mailfetch_server_number>0) {
4cf43843 206 echo "<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">";
207 echo '<b>' . _("Server Name:") . '</b> <select name="mf_sn">';
d3c89357 208 for ($i=0;$i<$mailfetch_server_number;$i++) {
4cf43843 209 echo "<option value=\"$i\">" .
210 (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</option>>";
d3c89357 211 }
4cf43843 212 echo '</select>'.
d3c89357 213 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
214 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
215 '</form>';
216 } else {
217 echo _("No-one server in use. Try to add.");
218 }
4cf43843 219 echo '</td></tr></table>';
d3c89357 220 break;
221 case _("Delete"): //erase confirmation about a server
4cf43843 222 echo html_tag( 'table',
223 html_tag( 'tr',
224 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
225 ) ,
226 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
227 '<br>' .
228 html_tag( 'table',
229 html_tag( 'tr',
230 html_tag( 'td', '<b>' . _("Confirm Deletion of a Server") . '</b>', 'center', $color[9] )
231 ) .
232 html_tag( 'tr',
233 html_tag( 'td',
234 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
235 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
236 '<br>' . _("Selected Server:") . " <b>$mailfetch_server_[$mf_sn]</b><br>" .
237 _("Confirm delete of selected server?") . '<br><br>' .
238 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
239 '<br></form>' ,
240 'center', $color[9] )
241 ) ,
242 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' );
d3c89357 243 break; //modify a server
244 case _("Modify"):
4cf43843 245 echo html_tag( 'table',
246 html_tag( 'tr',
247 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
248 ) ,
249 'center', '', 'width="95%" cols="1" cellpadding="5" cellspacing="1"' ) .
250 '<br>' .
251 html_tag( 'table', '', 'center', '', 'width="70%" cols="1" cellpadding="5" cellspacing="1"' ) .
252 html_tag( 'tr',
253 html_tag( 'td', '<b>' . _("Mofify a Server") . '</b>', 'center', $color[9] )
254 ) .
255 html_tag( 'tr' ) .
256 html_tag( 'td', '', 'center', $color[0] ) .
257
d3c89357 258 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
259 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
4cf43843 260 html_tag( 'table' ) .
261 html_tag( 'tr',
262 html_tag( 'th', _("Server:"), 'right' ) .
263 html_tag( 'td', '<input type="text" name="mf_server" value="' . $mailfetch_server_[$mf_sn] . '" size="40">', 'left' )
264 ) .
265 html_tag( 'tr',
266 html_tag( 'th', _("Alias:"), 'right' ) .
267 html_tag( 'td', '<input type="text" name="mf_alias" value="' . $mailfetch_alias_[$mf_sn] . '" size="40">', 'left' )
268 ) .
269 html_tag( 'tr',
270 html_tag( 'th', _("Username:"), 'right' ) .
271 html_tag( 'td', '<input type="text" name="mf_user" value="' . $mailfetch_user_[$mf_sn] . '" size="20">', 'left' )
272 ) .
273 html_tag( 'tr',
274 html_tag( 'th', _("Password:"), 'right' ) .
275 html_tag( 'td', '<input type="password" name="mf_pass" value="' . $mailfetch_pass_[$mf_sn] . '" size="20">', 'left' )
276 ) .
277 html_tag( 'tr' ) .
278 html_tag( 'th', _("Store in Folder:"), 'right' ) .
279 html_tag( 'td', '', 'left' );
280
d3c89357 281 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
282 $boxes = sqimap_mailbox_list($imapConnection);
4cf43843 283 echo '<select name="mf_subfolder">';
5e7f6ef6 284 $boxes = sqimap_mailbox_list($imapConnection);
d3c89357 285 for ($i = 0; $i < count($boxes); $i++) {
5e7f6ef6 286 if (!in_array('noselect', $boxes[$i]['flags'])) {
287 $box = $boxes[$i]['unformatted'];
288 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
289 if ( strtolower( $box2 ) == 'inbox' ) {
290 $box2 = _("INBOX");
d622d38a 291 }
4cf43843 292 echo '<option ' .
293 (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?'selected':'') .
294 " value=\"$box\">$box2</option>\n";
d622d38a 295 }
5e7f6ef6 296 }
4cf43843 297 echo '</select></td></tr>' .
298
299 html_tag( 'tr',
300 html_tag( 'th', '&nbsp;', 'right' ) .
301 html_tag( 'td',
302 '<input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
303 '>' . _("Leave Mail on Server") ,
304 'left' )
305 ) .
306 html_tag( 'tr',
307 html_tag( 'th', '&nbsp;', 'right' ) .
308 html_tag( 'td',
309 '<input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
310 '>' . _("Check mail during login"),
311 'left' )
312 ) .
313 html_tag( 'tr',
314 html_tag( 'th', '&nbsp;', 'right' ) .
315 html_tag( 'td',
316 '<input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
317 '>' . _("Check mail during folder refresh") ,
318 'left' )
319 ) .
320 html_tag( 'tr',
321 html_tag( 'td',
322 '<input type=submit name="submit_mailfetch" value="' . _("Modify Server") . '">',
323 'center', '', 'colspan="2"' )
324 ) .
325
326 '</table></form></td></tr></table>';
d3c89357 327 break;
328 default: //unsupported action
4cf43843 329 echo '</form>' .
330 html_tag( 'table',
331 html_tag( 'tr',
332 html_tag( 'td', '<b>' . _("Fetching Servers") . '</b>', 'center', $color[0] )
333 ) ,
334 'center', '', 'width="95%" cols="1"' ) .
335 '<br>' .
336 html_tag( 'table',
337 html_tag( 'tr',
338 html_tag( 'td', '<b>' . _("Undefined Function") . '</b>', 'center', $color[9] ) .
339 html_tag( 'td', '<b>' . _("Hey! Wath do You are looking for?") . '</b>', 'center', $color[0] )
340 ) ,
341 'center', '', 'width="70%" cols="1"' );
d3c89357 342 }
d622d38a 343
344 ?>
15e6162e 345</body></html>