3 * Message and Spam Filter Plugin
5 * Copyright (c) 1999-2002 The SquirrelMail Project 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 /* Path for SquirrelMail required files. */
28 define('SM_PATH','../../');
30 /* SquirrelMail required files. */
31 require_once(SM_PATH
. 'include/validate.php');
32 require_once(SM_PATH
. 'functions/page_header.php');
33 require_once(SM_PATH
. 'functions/imap.php');
34 require_once(SM_PATH
. 'include/load_prefs.php');
35 require_once(SM_PATH
. 'functions/html.php');
36 require_once(SM_PATH
. 'plugins/filters/filters.php');
37 global $AllowSpamFilters;
39 displayPageHeader($color, 'None');
41 if (isset($spam_submit)) {
42 $spam_filters = load_spam_filters();
43 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
44 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
45 foreach ($spam_filters as $Key => $Value) {
46 $input = $spam_filters[$Key]['prefname'] . '_set';
47 if ( isset( $
$input ) ) {
48 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],
51 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
56 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
57 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
58 $filters = load_filters();
60 echo html_tag( 'table',
62 html_tag( 'th', _("Spam Filtering"), 'center' )
64 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
66 if ($SpamFilters_YourHop == ' ') {
68 html_tag( 'div', '<b>' .
69 _("WARNING! Tell your admin to set the SpamFilters_YourHop variable") .
76 if (isset($action) && $action == 'spam') {
77 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
78 $boxes = sqimap_mailbox_list($imapConnection);
79 sqimap_logout($imapConnection);
80 for ($i = 0; $i < count($boxes) && $filters_spam_folder == ''; $i++
) {
82 if ($boxes[$i]['flags'][0] != 'noselect' &&
83 $boxes[$i]['flags'][1] != 'noselect' &&
84 $boxes[$i]['flags'][2] != 'noselect') {
85 $filters_spam_folder = $boxes[$i]['unformatted'];
89 echo '<form method=post action="spamoptions.php">'.
91 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
93 html_tag( 'th', _("Move spam to:"), 'right', '', 'nowrap' ) .
94 html_tag( 'td', '', 'left' ) .
95 '<select name="filters_spam_folder_set">';
97 for ($i = 0; $i < count($boxes); $i++
) {
98 if (! in_array('noselect', $boxes[$i]['flags'])) {
99 $box = $boxes[$i]['unformatted'];
100 $box2 = str_replace(' ', ' ', $boxes[$i]['formatted']);
101 if ($filters_spam_folder == $box) {
102 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
104 echo "<OPTION VALUE=\"$box\">$box2</OPTION>\n";
112 html_tag( 'td', ' ' ) .
114 _("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.") ,
118 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
120 '<select name="filters_spam_scan_set">'.
122 if ($filters_spam_scan == '') {
125 echo '>' . _("All messages") . '</option>'.
126 '<option value="new"';
127 if ($filters_spam_scan == 'new') {
130 echo '>' . _("Only unread messages") . '</option>' .
135 html_tag( 'td', ' ' ) .
137 _("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.") ,
141 $spam_filters = load_spam_filters();
143 foreach ($spam_filters as $Key => $Value) {
144 echo html_tag( 'tr' ) .
145 html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
147 '<input type=checkbox name="' .
148 $spam_filters[$Key]['prefname'] .
150 if ($spam_filters[$Key]['enabled']) {
154 if ($spam_filters[$Key]['link']) {
156 $spam_filters[$Key]['link'] .
157 '" target="_blank">';
159 echo $spam_filters[$Key]['name'];
160 if ($spam_filters[$Key]['link']) {
165 html_tag( 'td', ' ' ) .
166 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
171 html_tag( 'td', '<input type=submit name="spam_submit" value="' . _("Save") . '">', 'center', '', 'colspan="2"' )
179 if (! isset($action) ||
$action != 'spam') {
181 echo html_tag( 'p', '', 'center' ) .
182 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
183 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br><br>';
184 printf( _("Spam is sent to <b>%s</b>"), ($filters_spam_folder?
$filters_spam_folder:_("[<i>not set yet</i>]") ) );
186 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?
_("New Messages Only"):_("All Messages") ) );
188 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
190 $spam_filters = load_spam_filters();
192 foreach ($spam_filters as $Key => $Value) {
193 echo html_tag( 'tr' ) .
194 html_tag( 'th', '', 'center' );
196 if ($spam_filters[$Key]['enabled']) {
203 html_tag( 'td', ' - ', 'left' ) .
204 html_tag( 'td', '', 'left' );
206 if ($spam_filters[$Key]['link']) {
208 $spam_filters[$Key]['link'] .
209 '" target="_blank">';
212 echo $spam_filters[$Key]['name'];
213 if ($spam_filters[$Key]['link']) {