Marcos Tadeu <marcos@v2r.com.br>
[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;
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 }
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.'">' .
d622d38a 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
d3c89357 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);
5e7f6ef6 130 echo '<SELECT NAME=mf_subfolder>';
131 $boxes = sqimap_mailbox_list($imapConnection);
d3c89357 132 for ($i = 0; $i < count($boxes); $i++) {
5e7f6ef6 133 if (!in_array('noselect', $boxes[$i]['flags'])) {
134 $box = $boxes[$i]['unformatted'];
135 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
136 if ( strtolower( $box2 ) == 'inbox' ) {
137 $box2 = _("INBOX");
d622d38a 138 }
5e7f6ef6 139 echo "<OPTION VALUE=\"$box\">$box2</option>\n";
d622d38a 140 }
5e7f6ef6 141 }
d3c89357 142 echo '</SELECT></td></tr>' .
143 '<tr><th align=right>&nbsp;</th><td><input type=checkbox name=mf_lmos checked>' . _("Leave Mail on Server") . '</td></tr>' .
144 '<tr><th align=right>&nbsp;</th><td><input type=checkbox name=mf_login>' . _("Check mail during login") . '</td></tr>' .
145 '<tr><th align=right>&nbsp;</th><td><input type=checkbox name=mf_fref>' . _("Check mail during folder refresh") . '</td></tr>' .
146 '<tr><td align=center colspan=2><input type=submit name=submit_mailfetch value="' . _("Add Server") . '"></td></tr>' .
147 '</table></form></td></tr></TABLE>';
d622d38a 148
d3c89357 149 // Modify Server
150 echo '<font size=-5><BR></font>' .
151 '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
152 "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Modify Server") . '</b></TD></TR>' .
153 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>";
154 if ($mailfetch_server_number>0) {
155 echo "<form action=\"$PHP_SELF\" METHOD=\"POST\" TARGET=_self>";
156 echo '<b>' . _("Server Name:") . '</b> <SELECT NAME="mf_sn">';
157 for ($i=0;$i<$mailfetch_server_number;$i++) {
158 echo "<OPTION VALUE=\"$i\">" .
159 (($mailfetch_alias_[$i]=='')?$mailfetch_server_[$i]:$mailfetch_alias_[$i]) . "</OPTION>>";
160 }
161 echo '</SELECT>'.
162 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Modify") . '">'.
163 '&nbsp;&nbsp;<INPUT TYPE=submit name=mf_action value="' . _("Delete") . '">'.
164 '</form>';
165 } else {
166 echo _("No-one server in use. Try to add.");
167 }
168 echo '</TD></TR></TABLE>';
169 break;
170 case _("Delete"): //erase confirmation about a server
171 echo '<TABLE WIDTH=95% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
172 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Fetching Servers") . '</b></TD></TR>' .
173 '</TABLE>' .
174 '<BR>' .
175 '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
176 "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Confirm Deletion of a Server") . '</b></TD></TR>' .
177 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>" .
178 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
179 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_delete">' .
180 '<br>' . _("Selected Server:") . "<b>$mailfetch_server_[$mf_sn]</b><br>" .
181 _("Confirm delete of selected server?") . '<br><br>' .
182 '<input type=submit name=submit_mailfetch value="' . _("Confirm Delete") . '">' .
183 '<br></form></TD></TR></TABLE>';
184 break; //modify a server
185 case _("Modify"):
186 echo '<TABLE WIDTH=95% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
187 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Fetching Servers") . '</b></TD></TR>' .
188 '</TABLE>' .
189 '<BR>' .
190 '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER cellpadding=5 cellspacing=1>' .
191 "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Mofify a Server") . '</b></TD></TR>' .
192 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>" .
193 "<INPUT TYPE=\"hidden\" NAME=\"mf_sn\" VALUE=\"$mf_sn\">" .
194 '<INPUT TYPE="hidden" NAME="mf_action" VALUE="confirm_modify">' .
195 '<table>' .
196 '<tr><th align=right>' . _("Server:") . '</th>' .
197 "<td><input type=text name=mf_server value=\"$mailfetch_server_[$mf_sn]\" size=40></td></tr>" .
198 '<tr><th align=right>' . _("Alias:") . '</th>' .
199 "<td><input type=text name=mf_alias value=\"$mailfetch_alias_[$mf_sn]\" size=40></td></tr>" .
200 '<tr><th align=right>' . _("Username:") . '</th>' .
201 "<td><input type=text name=mf_user value=\"$mailfetch_user_[$mf_sn]\" size=20></td></tr>" .
202 '<tr><th align=right>' . _("Password:") . '</th>' .
203 "<td><input type=password name=mf_pass value=\"$mailfetch_pass_[$mf_sn]\" size=20></td></tr>" .
204 '<tr><th align=right>' . _("Store in Folder:") . '</th><td>';
205 $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0);
206 $boxes = sqimap_mailbox_list($imapConnection);
207 echo "<SELECT NAME=mf_subfolder>";
5e7f6ef6 208 $boxes = sqimap_mailbox_list($imapConnection);
d3c89357 209 for ($i = 0; $i < count($boxes); $i++) {
5e7f6ef6 210 if (!in_array('noselect', $boxes[$i]['flags'])) {
211 $box = $boxes[$i]['unformatted'];
212 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
213 if ( strtolower( $box2 ) == 'inbox' ) {
214 $box2 = _("INBOX");
d622d38a 215 }
5e7f6ef6 216 echo '<OPTION ' .
217 (strcmp($mailfetch_subfolder_[$mf_sn],$box)==0?'SELECTED':'') .
218 " VALUE=\"$box\">$box2</option>\n";
d622d38a 219 }
5e7f6ef6 220 }
d3c89357 221 echo '</SELECT></td></tr>' .
222 '<tr><th align=right>&nbsp;</th>' .
223 '<td><input type=checkbox name=mf_lmos ' . (($mailfetch_lmos_[$mf_sn] == 'on')?'checked':'') .
224 '>' . _("Leave Mail on Server") . '</td></tr>' .
225 '<tr><th align=right>&nbsp;</TH><td><input type=checkbox name=mf_login ' . ( ($mailfetch_login_[$mf_sn] == 'on')?'checked':'') .
226 '>' . _("Check mail during login") . '</td></tr>' .
227 '<tr><th align=right>&nbsp;</TH><td><input type=checkbox name=mf_fref ' . ( ($mailfetch_fref_[$mf_sn] == 'on')?'checked':'') .
228 '>' . _("Check mail during folder refresh") . '</td></tr>' .
229 '<tr><td align=center colspan=2><input type=submit name=submit_mailfetch value="' . _("Modify Server") . '"></td></tr>' .
230 '</table></form></TD></TR></TABLE>';
231 break;
232 default: //unsupported action
233 echo '</form><TABLE WIDTH=95% COLS=1 ALIGN=CENTER>' .
234 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" . _("Fetching Servers") . '</b></TD></TR>' .
235 '</TABLE><BR>' .
236 '<TABLE WIDTH=70% COLS=1 ALIGN=CENTER>' .
237 "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><b>" . _("Undefined Function") . '</b></TD></TR>' .
238 "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><b>" .
239 _("Hey! Wath do You are looking for?") . '</b></TD></TR></TABLE>';
240 }
d622d38a 241
242 ?>
15e6162e 243</body></html>