mail_fetch adaptation
[squirrelmail.git] / plugins / mail_fetch / options.php
1 <?php
2
3 /**
4 ** mail_fetch/options.php
5 **
6 ** Copyright (c) 1999-2001 The Squirrelmail Development 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 **/
13
14 chdir('..');
15 require_once('../src/validate.php');
16 require_once('../functions/imap.php');
17 require_once('../src/load_prefs.php');
18
19 displayPageHeader( $color, 'None' );
20
21 //if dosen't select any option
22 if (!isset($mf_action))
23 $mf_action = 'config';
24
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;
69 setPref($data_dir,$username,"mailfetch_server_$mf_sn", getPref($data_dir, $username, "mailfetch_server_$tmp"));
70 setPref($data_dir,$username,"mailfetch_alias_$mf_sn", getPref($data_dir, $username, "mailfetch_alias_$tmp"));
71 setPref($data_dir,$username,"mailfetch_user_$mf_sn", getPref($data_dir, $username, "mailfetch_user_$tmp"));
72 setPref($data_dir,$username,"mailfetch_pass_$mf_sn",(isset($mf_pass)?encrypt( $mf_pass ) :""));
73 // if( $mf_cypher <> 'on' ) setPref($data_dir,$username,"mailfetch_cypher", 'on');
74 setPref($data_dir,$username,"mailfetch_lmos_$mf_sn", getPref($data_dir, $username, "mailfetch_lmos_$tmp"));
75 setPref($data_dir,$username,"mailfetch_login_$mf_sn", getPref($data_dir, $username, "mailfetch_login_$tmp"));
76 setPref($data_dir,$username,"mailfetch_fref_$mf_sn", getPref($data_dir, $username, "mailfetch_fref_$tmp"));
77 setPref($data_dir,$username,"mailfetch_subfolder_$mf_sn", getPref($data_dir, $username, "mailfetch_subfolder_$tmp"));
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 }
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
104 echo '<BR><form method=post action="'.$PHP_SELF.'">' .
105 "<TABLE WIDTH=95% COLS=1 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Remote POP server settings") . '</b></TD></TR></TABLE>' .
106 '<TABLE WIDTH=95% COLS=1 ALIGN=CENTER><TR><TD>' .
107 _("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." ) .
108 '</TD></TR><TR><TD>' .
109 _("If you leave password empty, it will be required when you fetch mail.") .
110 '</TD></TR>' .
111 '<tr><td align=right><input type=checkbox name=mf_cypher ' .
112 (($mailfetch_cypher=='on')?'checked >':'>') .
113 _("Encrypt passwords (informative only)") . ' </td><tr>' .
114 '</TABLE></td></tr>';
115
116 switch( $mf_action ) {
117 case 'config':
118 echo '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
119 " <TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Add Server") . '</b></TD></TR>' .
120 " <TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>" .
121 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mailfetch_server_number\">" .
122 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="add"><table>' .
123 '<tr><th align=right>' . _("Server:") . '</th><td><input type=text name=mf_server value="" size=40></td></tr>' .
124 '<tr><th align=right>' . _("Alias:") . '</th><td><input type=text name=mf_alias value="" size=20></td></tr>' .
125 '<tr><th align=right>' . _("Username:") . '</th><td><input type=text name=mf_user value="" size=20></td></tr>' .
126 '<tr><th align=right>' . _("Password:") . '</th><td><input type=password name=mf_pass value="" size=20></td></tr>' .
127 '<tr><th align=right>' . _("Store in Folder:") . '</th><td>';
128 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
129 $boxes = sqimap_mailbox_list($imapConnection);
130 echo '<SELECT NAME=mf_subfolder><OPTION SELECTED VALUE="">INBOX';
131 for ($i = 0; $i < count($boxes); $i++) {
132 if (in_array('noinferiors', $boxes[$i]['flags'])) {
133 if ((strtolower($boxes[$i]["unformatted"]) == 'inbox') &&
134 ($default_sub_of_inbox == true)) {
135 $box = $boxes[$i]['unformatted'];
136 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
137 echo "<OPTION VALUE=\"$box\">$box2";
138 } else {
139 $box = $boxes[$i]['unformatted'];
140 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
141 if (strtolower($imap_server_type) != 'courier' ||
142 strtolower($box) != 'inbox.trash')
143 echo "<OPTION VALUE=\"$box\">$box2";
144 }
145 }
146 }
147 echo '</SELECT></td></tr>' .
148 '<tr><th align=right>&nbsp;</th><td><input type=checkbox name=mf_lmos checked>' . _("Leave Mail on Server") . '</td></tr>' .
149 '<tr><th align=right>&nbsp;</th><td><input type=checkbox name=mf_login>' . _("Check mail during login") . '</td></tr>' .
150 '<tr><th align=right>&nbsp;</th><td><input type=checkbox name=mf_fref>' . _("Check mail during folder refresh") . '</td></tr>' .
151 '<tr><td align=center colspan=2><input type=submit name=submit_mailfetch value="' . _("Add Server") . '"></td></tr>' .
152 '</table></form></td></tr></TABLE>';
153
154 // Modify Server
155 echo '<font size=-5><BR></font>' .
156 '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
157 "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Modify Server") . '</b></TD></TR>' .
158 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
159 if ($mailfetch_server_number>0) {
160 echo "<form action=\"$PHP_SELF\" METHOD=\"POST\" TARGET=_self>";
161 echo '<b>' . _("Server Name:") . '</b> <SELECT NAME="mf_sn">';
162 for ($i=0;$i<$mailfetch_server_number;$i++) {
163 echo "<OPTION VALUE=\"$i\">" .
164 (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</OPTION>>";
165 }
166 echo '</SELECT>'.
167 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
168 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
169 '</form>';
170 } else {
171 echo _("No-one server in use. Try to add.");
172 }
173 echo '</TD></TR></TABLE>';
174 break;
175 case _("Delete"): //erase confirmation about a server
176 echo '<TABLE WIDTH=95% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
177 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Fetching Servers") . '</b></TD></TR>' .
178 '</TABLE>' .
179 '<BR>' .
180 '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
181 "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Confirm Deletion of a Server") . '</b></TD></TR>' .
182 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>" .
183 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
184 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
185 '<br>' . _("Selected Server:") . "<b>$mailfetch_server_[$mf_sn]</b><br>" .
186 _("Confirm delete of selected server?") . '<br><br>' .
187 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
188 '<br></form></TD></TR></TABLE>';
189 break; //modify a server
190 case _("Modify"):
191 echo '<TABLE WIDTH=95% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
192 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Fetching Servers") . '</b></TD></TR>' .
193 '</TABLE>' .
194 '<BR>' .
195 '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
196 "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Mofify a Server") . '</b></TD></TR>' .
197 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>" .
198 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
199 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
200 '<table>' .
201 '<tr><th align=right>' . _("Server:") . '</th>' .
202 "<td><input type=text name=mf_server value=\"$mailfetch_server_[$mf_sn]\" size=40></td></tr>" .
203 '<tr><th align=right>' . _("Alias:") . '</th>' .
204 "<td><input type=text name=mf_alias value=\"$mailfetch_alias_[$mf_sn]\" size=40></td></tr>" .
205 '<tr><th align=right>' . _("Username:") . '</th>' .
206 "<td><input type=text name=mf_user value=\"$mailfetch_user_[$mf_sn]\" size=20></td></tr>" .
207 '<tr><th align=right>' . _("Password:") . '</th>' .
208 "<td><input type=password name=mf_pass value=\"$mailfetch_pass_[$mf_sn]\" size=20></td></tr>" .
209 '<tr><th align=right>' . _("Store in Folder:") . '</th><td>';
210 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
211 $boxes = sqimap_mailbox_list($imapConnection);
212 echo "<SELECT NAME=mf_subfolder>";
213 echo "<OPTION " . ($mailfetch_subfolder_[$mf_sn]==""?"SELECTED":"") . ' VALUE="">INBOX';
214 for ($i = 0; $i < count($boxes); $i++) {
215 if (in_array('noinferiors', $boxes[$i]['flags'])) {
216 if ((strtolower($boxes[$i]['unformatted']) == 'inbox') &&
217 $default_sub_of_inbox) {
218 $box = $boxes[$i]['unformatted'];
219 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
220 echo "<OPTION " . (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?"SELECTED":"") . " VALUE=\"$box\">$box2";
221 } else {
222 $box = $boxes[$i]['unformatted'];
223 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
224 if (strtolower($imap_server_type) != 'courier' ||
225 strtolower($box) != 'inbox.trash')
226 echo "<OPTION " . (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?"SELECTED":"") . " VALUE=\"$box\">$box2";
227 }
228 }
229 }
230 echo '</SELECT></td></tr>' .
231 '<tr><th align=right>&nbsp;</th>' .
232 '<td><input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
233 '>' . _("Leave Mail on Server") . '</td></tr>' .
234 '<tr><th align=right>&nbsp;</TH><td><input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
235 '>' . _("Check mail during login") . '</td></tr>' .
236 '<tr><th align=right>&nbsp;</TH><td><input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
237 '>' . _("Check mail during folder refresh") . '</td></tr>' .
238 '<tr><td align=center colspan=2><input type=submit name=submit_mailfetch value="' . _("Modify Server") . '"></td></tr>' .
239 '</table></form></TD></TR></TABLE>';
240 break;
241 default: //unsupported action
242 echo '</form><TABLE WIDTH=95% COLS=1 ALIGN=CENTER>' .
243 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Fetching Servers") . '</b></TD></TR>' .
244 '</TABLE><BR>' .
245 '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>' .
246 "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Undefined Function") . '</b></TD></TR>' .
247 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" .
248 _("Hey! Wath do You are looking for?") . '</b></TD></TR></TABLE>';
249 }
250
251 ?>
252 </body></html>