21582d9a9dbe1c6ee8ec043f6f6b310727f9abf1
3 * Message and Spam Filter Plugin
4 * Copyright (c) 1999-2001 The Squirrelmail Development Team
5 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 * This plugin filters your inbox into different folders based upon given
8 * criteria. It is most useful for people who are subscibed to mailing lists
9 * to help organize their messages. The argument stands that filtering is
10 * not the place of the client, which is why this has been made a plugin for
11 * SquirrelMail. You may be better off using products such as Sieve or
12 * Procmail to do your filtering so it happens even when SquirrelMail isn't
15 * If you need help with this, or see improvements that can be made, please
16 * email me directly at the address above. I definately welcome suggestions
17 * and comments. This plugin, as is the case with all SquirrelMail plugins,
18 * is not directly supported by the developers. Please come to me off the
19 * mailing list if you have trouble with it.
21 * Also view plugins/README.plugins for more information.
28 require_once('../src/validate.php');
29 require_once('../functions/page_header.php');
30 require_once('../functions/imap.php');
31 require_once('../src/load_prefs.php');
33 global $AllowSpamFilters;
35 displayPageHeader($color, 'None');
37 if (isset($filter_submit)) {
38 if (!isset($theid)) $theid = 0;
39 $filter_what = str_replace(',', ' ', $filter_what);
40 $filter_what = str_replace("\\\\", "\\", $filter_what);
41 $filter_what = str_replace("\\\"", "\"", $filter_what);
42 $filter_what = str_replace("\"", """, $filter_what);
44 setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
45 $filters[$theid]['where'] = $filter_where;
46 $filters[$theid]['what'] = $filter_what;
47 $filters[$theid]['folder'] = $filter_folder;
48 } elseif (isset($spam_submit) && $AllowSpamFilters) {
49 $spam_filters = load_spam_filters();
50 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
51 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
52 foreach ($spam_filters as $Key => $Value)
54 $input = $spam_filters[$Key]['prefname'] . '_set';
55 setPref($data_dir, $username, $spam_filters[$Key]['prefname'],
58 } elseif (isset($action) && $action == 'delete') {
59 remove_filter($theid);
60 } elseif (isset($action) && $action == 'move_up') {
61 filter_swap($theid, $theid - 1);
62 } elseif (isset($action) && $action == 'move_down') {
63 filter_swap($theid, $theid +
1);
66 if ($AllowSpamFilters) {
67 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
68 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
70 $filters = load_filters();
73 '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'.
74 "<tr><td bgcolor=\"$color[0]\">".
75 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'.
77 '<br><center>[<a href="options.php?action=add">' . _("New") .
78 '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br>' .
79 '<table border=0 cellpadding=3 cellspacing=0 align=center>';
81 for ($i=0; $i < count($filters); $i++
) {
88 $fdr = ($folder_prefix)?
str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
90 echo "<tr bgcolor=\"$clr\"><td><small>".
91 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
92 '</small></td><td><small>'.
93 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
94 '</small></td><td align=center><small>[';
96 if (isset($filters[$i +
1])) {
97 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
103 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
105 echo ']</small></td><td> - ';
106 printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
112 '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
113 '<tr><td> </td></tr>'.
116 if ($AllowSpamFilters) {
118 echo "<table width=95% align=center border=0 cellpadding=2 cellspacing=0 bgcolor=\"$color[0]\">".
119 '<tr><th align=center>' . _("Spam Filtering") . '</th></tr>'.
121 if (! isset($action) ||
$action != 'spam') {
123 echo '<p align=center>[<a href="options.php?action=spam">' . _("Edit") . '</a>]<br>';
124 printf( _("Spam is sent to <b>%s</b>"), ($filters_spam_folder?
$filters_spam_folder:_("[<i>not set yet</i>]") ) );
126 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?
_("New Messages Only"):_("All Messages") ) );
128 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
130 $spam_filters = load_spam_filters();
132 foreach ($spam_filters as $Key => $Value) {
133 echo '<tr><th align=center>';
135 if ($spam_filters[$Key]['enabled']) {
141 echo '</th><td> - </td><td>';
143 if ($spam_filters[$Key]['link']) {
145 $spam_filters[$Key]['link'] .
146 '" target="_blank">';
149 echo $spam_filters[$Key]['name'];
150 if ($spam_filters[$Key]['link']) {
159 if (isset($action) && ($action == 'add' ||
$action == 'edit')) {
160 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
161 $boxes = sqimap_mailbox_list($imapConnection);
162 sqimap_logout($imapConnection);
163 if ( !isset($theid) ) {
164 $theid = count($filters);
167 '<form action="options.php" method=post>'.
168 '<br><table cellpadding=2 cellspacing=0 border=0>'.
172 '<select name=filter_where>';
174 $L = isset($filters[$theid]['where']);
176 $sel = (($L && $filters[$theid]['where'] == 'From')?
'selected':'');
177 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
179 $sel = (($L && $filters[$theid]['where'] == 'To')?
'selected':'');
180 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
182 $sel = (($L && $filters[$theid]['where'] == 'Cc')?
'selected':'');
183 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
185 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?
'selected':'');
186 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
188 $sel = (($L && $filters[$theid]['where'] == 'Subject')?
'selected':'');
189 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
199 '<input type=text size=32 name=filter_what value="';
200 if (isset($filters[$theid]['what'])) {
201 echo $filters[$theid]["what"];
212 '<select name=filter_folder>';
214 for ($i = 0; $i < count($boxes); $i++
) {
215 if (! in_array('noselect', $boxes[$i]['flags'])) {
216 $box = $boxes[$i]['unformatted'];
217 $box2 = str_replace(' ', ' ', $boxes[$i]['formatted']);
218 if (isset($filters[$theid]['folder']) &&
219 $filters[$theid]['folder'] == $box)
220 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
222 echo "<OPTION VALUE=\"$box\">$box2</option>";
230 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
231 "<input type=hidden name=theid value=$theid>".
235 } else if (isset($action) && $action == 'spam' && $AllowSpamFilters) {
236 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
237 $boxes = sqimap_mailbox_list($imapConnection);
238 sqimap_logout($imapConnection);
239 for ($i = 0; $i < count($boxes) && $filters_spam_folder == ''; $i++
) {
240 if ($boxes[$i]['flags'][0] != 'noselect' &&
241 $boxes[$i]['flags'][1] != 'noselect' &&
242 $boxes[$i]['flags'][2] != 'noselect') {
243 $filters_spam_folder = $boxes[$i]['unformatted'];
247 echo '<form method=post action="options.php">'.
249 '<table width=85% cellpadding=2 cellspacing=0 border=0>'.
251 '<th align=right nowrap>' . _("Move spam to:") . '</th>'.
252 '<td><select name="filters_spam_folder_set">';
254 for ($i = 0; $i < count($boxes); $i++
) {
255 if (! in_array('noselect', $boxes[$i]['flags'])) {
256 $box = $boxes[$i]['unformatted'];
257 $box2 = str_replace(' ', ' ', $boxes[$i]['formatted']);
258 if ($filters_spam_folder == $box)
259 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
261 echo "<OPTION VALUE=\"$box\">$box2</OPTION>\n";
267 '<tr><td></td><td>' .
268 _("Moving spam directly to the trash may not be a good idea at first, since messages from friends and mailing lists might accidentally be marked as spam. Whatever folder you set this to, make sure that it gets cleaned out periodically, so that you don't have an excessively large mailbox hanging around.") .
271 '<th align=right nowrap>' . _("What to Scan:") . '</th>'.
272 '<td><select name="filters_spam_scan_set">'.
274 if ($filters_spam_scan == '')
276 echo '>' . _("All messages") . '</option>'.
277 '<option value="new"';
278 if ($filters_spam_scan == 'new')
280 echo '>' . _("Only unread messages") . '</option>' .
286 _("The more messages you scan, the longer it takes. I would suggest that you scan only new messages. If you make a change to your filters, I would set it to scan all messages, then go view my INBOX, then come back and set it to scan only new messages. That way, your new spam filters will be applied and you'll scan even the spam you read with the new filters.").
289 $spam_filters = load_spam_filters();
291 foreach ($spam_filters as $Key => $Value) {
292 echo "<tr><th align=right nowrap>$Key</th>\n" .
293 '<td><input type=checkbox name="' .
294 $spam_filters[$Key]['prefname'] .
296 if ($spam_filters[$Key]['enabled'])
299 if ($spam_filters[$Key]['link']) {
301 $spam_filters[$Key]['link'] .
302 '" target="_blank">';
304 echo $spam_filters[$Key]['name'];
305 if ($spam_filters[$Key]['link']) {
308 echo '</td></tr><tr><td></td><td>' .
309 $spam_filters[$Key]['comment'] .
312 echo '<tr><td colspan=2 align=center><input type=submit name="spam_submit" value="' . _("Save") . '"></td></tr>'.
317 sqimap_logout($imapConnection);