b53ef1a137671c750df037f757f9fa6bed15e970
3 * Message and Spam Filter Plugin
4 * By Luke Ehresman <luke@squirrelmail.org>
7 * (c) 2000 (GNU GPL - see ../../COPYING)
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
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.
23 * Also view plugins/README.plugins for more information.
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");
32 global $AllowSpamFilters;
34 displayPageHeader($color, "None");
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("\"", """, $filter_what);
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)
53 $input = $spam_filters[$Key]['prefname'] . '_set';
54 setPref($data_dir, $username, $spam_filters[$Key]['prefname'],
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);
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');
69 $filters = load_filters();
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
>
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
>
79 for ($i=0; $i < count($filters); $i++
) {
80 if ($i %
2 == 0) $clr = $color[0];
81 else $clr = $color[9];
83 $fdr = ($folder_prefix)?
str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
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 ' | ';
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
>
107 <table width
=80% align
=center border
=0 cellpadding
=2 cellspacing
=0">
108 <tr><td> </td></tr>
111 <?PHP if ($AllowSpamFilters) { ?>
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>
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)
121 echo $filters_spam_folder;
125 echo '[<i>not set yet</i>]';
127 ?></b><br>Spam scan is limited to <b><?PHP
128 if ($filters_spam_scan == 'new')
130 echo 'New Messages Only';
138 <table border=0 cellpadding=3 cellspacing=0 align=center bgcolor="<?PHP
echo $color[0] ?
>">
141 $spam_filters = load_spam_filters();
143 foreach ($spam_filters as $Key => $Value)
145 echo '<tr><th align=center>';
147 if ($spam_filters[$Key]['enabled'])
156 echo '</th><td> - </td><td>';
158 if ($spam_filters[$Key]['link'])
161 echo $spam_filters[$Key]['link
'];
162 echo '" target="_blank
">';
165 echo $spam_filters[$Key]['name'];
166 if ($spam_filters[$Key]['link'])
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);
184 $theid = count($filters);
188 <form action="options
.php
" method=post>
189 <br><table cellpadding=2 cellspacing=0 border=0>
195 <select name=filter_where>
197 if (! isset($filters[$theid]['where'])) $L = false;
199 if ($L && $filters[$theid]["where
"] == "From
") echo "<option value
=\"From\" selected
> From\n
";
200 else echo "<option value
=\"From\"
> From\n
";
202 if ($L && $filters[$theid]["where
"] == "To
") echo "<option value
=\"To\" selected
> To\n
";
203 else echo "<option value
=\"To\"
> To\n
";
205 if ($L && $filters[$theid]["where
"] == "Cc
") echo "<option value
=\"Cc\" selected
> Cc\n
";
206 else echo "<option value
=\"Cc\"
> Cc\n
";
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
";
211 if ($L && $filters[$theid]["where
"] == "Subject
") echo "<option value
=\"Subject\" selected
> Subject\n
";
212 else echo "<option value
=\"Subject\"
> Subject\n
";
222 <input type=text size=32 name=filter_what value="<?php
223 if (isset($filters[$theid]['what'])) echo $filters[$theid]["what"]; ?
>">
232 <select name=filter_folder>
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(' ', ' ', $boxes[$i]["formatted
"]);
238 if (isset($filters[$theid]['folder']) &&
239 $filters[$theid]["folder
"] == $box)
240 echo " <OPTION VALUE
=\"$box\" SELECTED
>$box2\n";
242 echo " <OPTION VALUE
=\"$box\">$box2\n";
251 <input type=submit name=filter_submit value=Submit>
252 <input type=hidden name=theid value=<?php echo $theid ?>>
257 else if (isset($action) && $action == 'spam' && $AllowSpamFilters)
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'];
268 ?><form method=post action="options
.php
">
270 <table width=85% cellpadding=2 cellspacing=0 border=0>
272 <th align=right nowrap>Move spam to:</th>
273 <td><select name="filters_spam_folder_set
">
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(' ', ' ', $boxes[$i]["formatted
"]);
279 if ($filters_spam_folder == $box)
280 echo "<OPTION VALUE
=\"$box\" SELECTED
>$box2</OPTION
>\n";
282 echo "<OPTION VALUE
=\"$box\">$box2</OPTION
>\n";
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.
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>
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>
314 $spam_filters = load_spam_filters();
316 foreach ($spam_filters as $Key => $Value)
318 echo "<tr
><th align
=right nowrap
>$Key</th
>\n";
319 echo '<td><input type=checkbox name="';
320 echo $spam_filters[$Key]['prefname
'];
322 if ($spam_filters[$Key]['enabled'])
325 if ($spam_filters[$Key]['link'])
328 echo $spam_filters[$Key]['link
'];
329 echo '" target="_blank
">';
331 echo $spam_filters[$Key]['name'];
332 if ($spam_filters[$Key]['link'])
336 echo '</td></tr><tr><td></td><td>';
337 echo $spam_filters[$Key]['comment'];
341 <tr><td colspan=2 align=center><input type=submit name="spam_submit
" value="Save
"></td></tr>
347 sqimap_logout($imapConnection);