9d658a5c01d0577b6acc1e53201c1396aa306478
3 ** Message and Spam Filter Plugin
5 ** Copyright (c) 1999-2001 The Squirrelmail Development Team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** This plugin filters your inbox into different folders based upon given
9 ** criteria. It is most useful for people who are subscibed to mailing lists
10 ** to help organize their messages. The argument stands that filtering is
11 ** not the place of the client, which is why this has been made a plugin for
12 ** SquirrelMail. You may be better off using products such as Sieve or
13 ** Procmail to do your filtering so it happens even when SquirrelMail isn't
16 ** If you need help with this, or see improvements that can be made, please
17 ** email me directly at the address above. I definately welcome suggestions
18 ** and comments. This plugin, as is the case with all SquirrelMail plugins,
19 ** is not directly supported by the developers. Please come to me off the
20 ** mailing list if you have trouble with it.
22 ** 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) {
52 $input = $spam_filters[$Key]['prefname'] . '_set';
53 setPref($data_dir, $username, $spam_filters[$Key]['prefname'],
56 } elseif (isset($action) && $action == 'delete') {
57 remove_filter($theid);
58 } elseif (isset($action) && $action == 'move_up') {
59 filter_swap($theid, $theid - 1);
60 } elseif (isset($action) && $action == 'move_down') {
61 filter_swap($theid, $theid +
1);
64 if ($AllowSpamFilters) {
65 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
66 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
68 $filters = load_filters();
71 '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'.
72 "<tr><td bgcolor=\"$color[0]\">".
73 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'.
75 '<br><center>[<a href="options.php?action=add">' . _("New") .
76 '</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++
) {
81 $clr = (($i %
2)?
$color[0]:$color[9]);
82 $fdr = ($folder_prefix)?
str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
83 echo "<tr bgcolor=\"$clr\"><td><small>".
84 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
85 '</small></td><td><small>'.
86 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
87 '</small></td><td align=center><small>[';
89 if (isset($filters[$i +
1])) {
90 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
96 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
98 echo ']</small></td><td> - ';
99 printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
104 '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
105 '<tr><td> </td></tr>'.
109 if ($AllowSpamFilters) {
111 echo "<table width=95% align=center border=0 cellpadding=2 cellspacing=0 bgcolor=\"$color[0]\">".
112 '<tr><th align=center>' . _("Spam Filtering") . '</th></tr>'.
114 if (! isset($action) ||
$action != 'spam') {
116 echo '<p align=center>[<a href="options.php?action=spam">' . _("Edit") . '</a>]<br>';
117 printf( _("Spam is sent to <b>%s</b>"), ($filters_spam_folder?
$filters_spam_folder:_("[<i>not set yet</i>]") ) );
119 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?
_("New Messages Only"):_("All Messages") ) );
121 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
123 $spam_filters = load_spam_filters();
125 foreach ($spam_filters as $Key => $Value) {
126 echo '<tr><th align=center>';
128 if ($spam_filters[$Key]['enabled']) {
134 echo '</th><td> - </td><td>';
136 if ($spam_filters[$Key]['link']) {
138 $spam_filters[$Key]['link'] .
139 '" target="_blank">';
142 echo $spam_filters[$Key]['name'];
143 if ($spam_filters[$Key]['link']) {
152 if (isset($action) && ($action == 'add' ||
$action == 'edit')) {
153 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
154 $boxes = sqimap_mailbox_list($imapConnection);
155 sqimap_logout($imapConnection);
156 if ( !isset($theid) ) {
157 $theid = count($filters);
160 '<form action="options.php" method=post>'.
161 '<br><table cellpadding=2 cellspacing=0 border=0>'.
165 '<select name=filter_where>';
167 $L = isset($filters[$theid]['where']);
169 $sel = (($L && $filters[$theid]['where'] == 'From')?
'selected':'');
170 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
172 $sel = (($L && $filters[$theid]['where'] == 'To')?
'selected':'');
173 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
175 $sel = (($L && $filters[$theid]['where'] == 'Cc')?
'selected':'');
176 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
178 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?
'selected':'');
179 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
181 $sel = (($L && $filters[$theid]['where'] == 'Subject')?
'selected':'');
182 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
192 '<input type=text size=32 name=filter_what value="';
193 if (isset($filters[$theid]['what'])) {
194 echo $filters[$theid]["what"];
205 '<select name=filter_folder>';
207 for ($i = 0; $i < count($boxes); $i++
) {
208 if (! in_array('noselect', $boxes[$i]['flags'])) {
209 $box = $boxes[$i]['unformatted'];
210 $box2 = str_replace(' ', ' ', $boxes[$i]['formatted']);
211 if (isset($filters[$theid]['folder']) &&
212 $filters[$theid]['folder'] == $box)
213 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
215 echo "<OPTION VALUE=\"$box\">$box2</option>";
223 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
224 "<input type=hidden name=theid value=$theid>".
228 } else if (isset($action) && $action == 'spam' && $AllowSpamFilters) {
229 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
230 $boxes = sqimap_mailbox_list($imapConnection);
231 sqimap_logout($imapConnection);
232 for ($i = 0; $i < count($boxes) && $filters_spam_folder == ''; $i++
) {
233 if ($boxes[$i]['flags'][0] != 'noselect' &&
234 $boxes[$i]['flags'][1] != 'noselect' &&
235 $boxes[$i]['flags'][2] != 'noselect') {
236 $filters_spam_folder = $boxes[$i]['unformatted'];
240 echo '<form method=post action="options.php">'.
242 '<table width=85% cellpadding=2 cellspacing=0 border=0>'.
244 '<th align=right nowrap>' . _("Move spam to:") . '</th>'.
245 '<td><select name="filters_spam_folder_set">';
247 for ($i = 0; $i < count($boxes); $i++
) {
248 if (! in_array('noselect', $boxes[$i]['flags'])) {
249 $box = $boxes[$i]['unformatted'];
250 $box2 = str_replace(' ', ' ', $boxes[$i]['formatted']);
251 if ($filters_spam_folder == $box)
252 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
254 echo "<OPTION VALUE=\"$box\">$box2</OPTION>\n";
260 '<tr><td></td><td>' .
261 _("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.") .
264 '<th align=right nowrap>' . _("What to Scan:") . '</th>'.
265 '<td><select name="filters_spam_scan_set">'.
267 if ($filters_spam_scan == '')
269 echo '>' . _("All messages") . '</option>'.
270 '<option value="new"';
271 if ($filters_spam_scan == 'new')
273 echo '>' . _("Only unread messages") . '</option>' .
279 _("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.").
282 $spam_filters = load_spam_filters();
284 foreach ($spam_filters as $Key => $Value) {
285 echo "<tr><th align=right nowrap>$Key</th>\n" .
286 '<td><input type=checkbox name="' .
287 $spam_filters[$Key]['prefname'] .
289 if ($spam_filters[$Key]['enabled'])
292 if ($spam_filters[$Key]['link']) {
294 $spam_filters[$Key]['link'] .
295 '" target="_blank">';
297 echo $spam_filters[$Key]['name'];
298 if ($spam_filters[$Key]['link']) {
301 echo '</td></tr><tr><td></td><td>' .
302 $spam_filters[$Key]['comment'] .
305 echo '<tr><td colspan=2 align=center><input type=submit name="spam_submit" value="' . _("Save") . '"></td></tr>'.
310 sqimap_logout($imapConnection);