Began rework of options page. Also added 3 plugins (filters, translate, and squirrels...
[squirrelmail.git] / plugins / filters / options.php
1 <?php
2 /*
3 * Message and Spam Filter Plugin
4 * By Luke Ehresman <luke@squirrelmail.org>
5 * Tyler Akins
6 * Brent Bice
7 * (c) 2000 (GNU GPL - see ../../COPYING)
8 *
9 * This plugin filters your inbox into different folders based upon given
10 * criteria. It is most useful for people who are subscibed to mailing lists
11 * to help organize their messages. The argument stands that filtering is
12 * not the place of the client, which is why this has been made a plugin for
13 * SquirrelMail. You may be better off using products such as Sieve or
14 * Procmail to do your filtering so it happens even when SquirrelMail isn't
15 * running.
16 *
17 * If you need help with this, or see improvements that can be made, please
18 * email me directly at the address above. I definately welcome suggestions
19 * and comments. This plugin, as is the case with all SquirrelMail plugins,
20 * is not directly supported by the developers. Please come to me off the
21 * mailing list if you have trouble with it.
22 *
23 * Also view plugins/README.plugins for more information.
24 *
25 */
26 chdir ("..");
27 require_once('../src/validate.php');
28 require_once ("../functions/page_header.php");
29 require_once ("../functions/imap.php");
30 require_once ("../src/load_prefs.php");
31
32 global $AllowSpamFilters;
33
34 displayPageHeader($color, "None");
35
36 if (isset($filter_submit)) {
37 if (!isset($theid)) $theid = 0;
38 $filter_what = ereg_replace(",", " ", $filter_what);
39 $filter_what = str_replace("\\\\", "\\", $filter_what);
40 $filter_what = str_replace("\\\"", "\"", $filter_what);
41 $filter_what = str_replace("\"", "&quot;", $filter_what);
42
43 setPref($data_dir, $username, "filter".$theid, $filter_where.",".$filter_what.",".$filter_folder);
44 $filters[$theid]["where"] = $filter_where;
45 $filters[$theid]["what"] = $filter_what;
46 $filters[$theid]["folder"] = $filter_folder;
47 } elseif (isset($spam_submit) && $AllowSpamFilters) {
48 $spam_filters = load_spam_filters();
49 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
50 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
51 foreach ($spam_filters as $Key => $Value)
52 {
53 $input = $spam_filters[$Key]['prefname'] . '_set';
54 setPref($data_dir, $username, $spam_filters[$Key]['prefname'],
55 $$input);
56 }
57 } elseif (isset($action) && $action == "delete") {
58 remove_filter($theid);
59 } elseif (isset($action) && $action == "move_up") {
60 filter_swap($theid, $theid - 1);
61 } elseif (isset($action) && $action == "move_down") {
62 filter_swap($theid, $theid + 1);
63 }
64
65 if ($AllowSpamFilters) {
66 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
67 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
68 }
69 $filters = load_filters();
70
71 ?>
72 <br>
73 <table width=95% align=center border=0 cellpadding=2 cellspacing=0><tr><td bgcolor="<?php echo $color[0] ?>">
74 <center><b><?php echo _("Options") ?> - Message Filtering</b></center>
75 </td></tr></table>
76 <br><center>[<a href="options.php?action=add">New</a>] - [<a href="../../src/options.php">Done</a>]</center><br>
77 <table border=0 cellpadding=3 cellspacing=0 align=center>
78 <?php
79 for ($i=0; $i < count($filters); $i++) {
80 if ($i % 2 == 0) $clr = $color[0];
81 else $clr = $color[9];
82
83 $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
84
85 ?>
86 <tr bgcolor="<?PHP echo $clr ?>"><td><small>
87 [<a href="options.php?theid=<?PHP echo $i ?>&action=edit">Edit</a>]
88 </small></td><td><small>
89 [<a href="options.php?theid=<?PHP echo $i ?>&action=delete">Delete</a>]
90 </small></td><td align=center><small>
91 [<?PHP if (isset($filters[$i + 1])) {
92 ?><a href="options.php?theid=<?PHP echo $i ?>&action=move_down">Down</a><?PHP
93 if ($i > 0) echo ' | ';
94 }
95 if ($i > 0) {
96 ?><a href="options.php?theid=<?PHP echo $i ?>&action=move_up">Up</a><?PHP
97 } ?>]</small></td><td>
98 - If <b><?PHP echo $filters[$i]['where'] ?></b> contains <b><?PHP
99 echo $filters[$i]['what'] ?></b> then move to <b><?PHP echo $fdr ?></b>
100 </td></tr>
101 <?PHP
102
103 }
104 ?>
105 </table>
106
107 <table width=80% align=center border=0 cellpadding=2 cellspacing=0">
108 <tr><td>&nbsp</td></tr>
109 </table>
110
111 <?PHP if ($AllowSpamFilters) { ?>
112
113 <table width=95% align=center border=0 cellpadding=2 cellspacing=0 bgcolor="<?php echo $color[0] ?>">
114 <tr><th align=center>Spam Filtering</th></tr>
115 </table>
116 <?PHP if (! isset($action) || $action != 'spam') { ?>
117 <p align=center>[<a href="options.php?action=spam">Edit</a>]<br>
118 Spam is sent to <b><?PHP
119 if ($filters_spam_folder)
120 {
121 echo $filters_spam_folder;
122 }
123 else
124 {
125 echo '[<i>not set yet</i>]';
126 }
127 ?></b><br>Spam scan is limited to <b><?PHP
128 if ($filters_spam_scan == 'new')
129 {
130 echo 'New Messages Only';
131 }
132 else
133 {
134 echo 'All Messages';
135 }
136 ?></b></p>
137
138 <table border=0 cellpadding=3 cellspacing=0 align=center bgcolor="<?PHP echo $color[0] ?>">
139 <?PHP
140
141 $spam_filters = load_spam_filters();
142
143 foreach ($spam_filters as $Key => $Value)
144 {
145 echo '<tr><th align=center>';
146
147 if ($spam_filters[$Key]['enabled'])
148 {
149 echo 'ON';
150 }
151 else
152 {
153 echo 'OFF';
154 }
155
156 echo '</th><td>&nbsp;-&nbsp;</td><td>';
157
158 if ($spam_filters[$Key]['link'])
159 {
160 echo '<a href="';
161 echo $spam_filters[$Key]['link'];
162 echo '" target="_blank">';
163 }
164
165 echo $spam_filters[$Key]['name'];
166 if ($spam_filters[$Key]['link'])
167 {
168 echo '</a>';
169 }
170 echo "</td></tr>\n";
171 }
172
173 ?>
174 </table>
175 <?php
176 }
177 }
178
179 if (isset($action) && ($action == "add" || $action == "edit")) {
180 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
181 $boxes = sqimap_mailbox_list($imapConnection);
182 sqimap_logout($imapConnection);
183 if (!isset($theid))
184 $theid = count($filters);
185
186 ?>
187 <center>
188 <form action="options.php" method=post>
189 <br><table cellpadding=2 cellspacing=0 border=0>
190 <tr>
191 <td>
192 &nbsp;
193 </td>
194 <td>
195 <select name=filter_where>
196 <?php
197 if (! isset($filters[$theid]['where'])) $L = false;
198 else $L = true;
199 if ($L && $filters[$theid]["where"] == "From") echo "<option value=\"From\" selected> From\n";
200 else echo "<option value=\"From\"> From\n";
201
202 if ($L && $filters[$theid]["where"] == "To") echo "<option value=\"To\" selected> To\n";
203 else echo "<option value=\"To\"> To\n";
204
205 if ($L && $filters[$theid]["where"] == "Cc") echo "<option value=\"Cc\" selected> Cc\n";
206 else echo "<option value=\"Cc\"> Cc\n";
207
208 if ($L && $filters[$theid]["where"] == "To or Cc") echo "<option value=\"To or Cc\" selected> To or Cc\n";
209 else echo "<option value=\"To or Cc\"> To or Cc\n";
210
211 if ($L && $filters[$theid]["where"] == "Subject") echo "<option value=\"Subject\" selected> Subject\n";
212 else echo "<option value=\"Subject\"> Subject\n";
213 ?>
214 </select>
215 </td>
216 </tr>
217 <tr>
218 <td align=right>
219 Contains:
220 </td>
221 <td>
222 <input type=text size=32 name=filter_what value="<?php
223 if (isset($filters[$theid]['what'])) echo $filters[$theid]["what"]; ?>">
224 </td>
225 </tr>
226 <tr>
227 <td>
228 Move to:
229 </td>
230 <td>
231 <tt>
232 <select name=filter_folder>
233 <?php
234 for ($i = 0; $i < count($boxes); $i++) {
235 if (! in_array('noselect', $boxes[$i]['flags'])) {
236 $box = $boxes[$i]["unformatted"];
237 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["formatted"]);
238 if (isset($filters[$theid]['folder']) &&
239 $filters[$theid]["folder"] == $box)
240 echo " <OPTION VALUE=\"$box\" SELECTED>$box2\n";
241 else
242 echo " <OPTION VALUE=\"$box\">$box2\n";
243 }
244 }
245 ?>
246 </tt>
247 </select>
248 </td>
249 </tr>
250 </table>
251 <input type=submit name=filter_submit value=Submit>
252 <input type=hidden name=theid value=<?php echo $theid ?>>
253 </form>
254 </center>
255 <?php
256 }
257 else if (isset($action) && $action == 'spam' && $AllowSpamFilters)
258 {
259 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
260 $boxes = sqimap_mailbox_list($imapConnection);
261 sqimap_logout($imapConnection);
262 for ($i = 0; $i < count($boxes) && $filters_spam_folder == ''; $i++) {
263 if ($boxes[$i]["flags"][0] != "noselect" && $boxes[$i]["flags"][1] != "noselect" && $boxes[$i]["flags"][2] != "noselect") {
264 $filters_spam_folder = $boxes[$i]['unformatted'];
265 }
266 }
267
268 ?><form method=post action="options.php">
269 <center>
270 <table width=85% cellpadding=2 cellspacing=0 border=0>
271 <tr>
272 <th align=right nowrap>Move spam to:</th>
273 <td><select name="filters_spam_folder_set">
274 <?PHP
275 for ($i = 0; $i < count($boxes); $i++) {
276 if (! in_array('noselect', $boxes[$i]['flags'])) {
277 $box = $boxes[$i]["unformatted"];
278 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]["formatted"]);
279 if ($filters_spam_folder == $box)
280 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
281 else
282 echo "<OPTION VALUE=\"$box\">$box2</OPTION>\n";
283 }
284 }
285 ?>
286 </select>
287 </td>
288 </tr>
289 <tr><td></td><td>Moving spam directly to the trash may not be a good idea at first,
290 since messages from friends and mailing lists might accidentally be marked as spam.
291 Whatever folder you set this to, make sure that it gets cleaned out periodically,
292 so that you don't have an excessively large mailbox hanging around.
293 </td></tr>
294 <tr>
295 <th align=right nowrap>What to Scan:</th>
296 <td><select name="filters_spam_scan_set">
297 <option value=''<?PHP
298 if ($filters_spam_scan == '') echo ' SELECTED';
299 ?>>All messages</option>
300 <option value='new'<?PHP
301 if ($filters_spam_scan == 'new') echo ' SELECTED';
302 ?>>Only unread messages</option>
303 </select>
304 </td>
305 </tr>
306 <tr>
307 <td></td><td>The more messages you scan, the longer it takes. I would suggest
308 that you scan only new messages. If you make a change to your filters, I
309 would set it to scan all messages, then go view my INBOX, then come back and
310 set it to scan only new messages. That way, your new spam filters will be
311 applied and you'll scan even the spam you read with the new filters.</td>
312 </tr>
313 <?PHP
314 $spam_filters = load_spam_filters();
315
316 foreach ($spam_filters as $Key => $Value)
317 {
318 echo "<tr><th align=right nowrap>$Key</th>\n";
319 echo '<td><input type=checkbox name="';
320 echo $spam_filters[$Key]['prefname'];
321 echo '_set"';
322 if ($spam_filters[$Key]['enabled'])
323 echo ' CHECKED';
324 echo '> - ';
325 if ($spam_filters[$Key]['link'])
326 {
327 echo '<a href="';
328 echo $spam_filters[$Key]['link'];
329 echo '" target="_blank">';
330 }
331 echo $spam_filters[$Key]['name'];
332 if ($spam_filters[$Key]['link'])
333 {
334 echo '</a>';
335 }
336 echo '</td></tr><tr><td></td><td>';
337 echo $spam_filters[$Key]['comment'];
338 echo "</td></tr>\n";
339 }
340 ?>
341 <tr><td colspan=2 align=center><input type=submit name="spam_submit" value="Save"></td></tr>
342 </table>
343 </center>
344 </form>
345 <?PHP
346
347 sqimap_logout($imapConnection);
348 }
349 ?>