5b3a09f3735834b45533162d0d179de3e4435844
3 * Message and Spam Filter Plugin
5 * Copyright (c) 1999-2004 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.
30 * Path for SquirrelMail required files.
33 define('SM_PATH','../../');
35 /* SquirrelMail required files. */
36 require_once(SM_PATH
. 'include/validate.php');
37 require_once(SM_PATH
. 'functions/page_header.php');
38 require_once(SM_PATH
. 'functions/imap.php');
39 require_once(SM_PATH
. 'include/load_prefs.php');
40 require_once(SM_PATH
. 'functions/html.php');
41 require_once(SM_PATH
. 'plugins/filters/filters.php');
42 global $AllowSpamFilters;
45 sqgetGlobalVar('username', $username, SQ_SESSION
);
46 sqgetGlobalVar('key', $key, SQ_COOKIE
);
47 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
48 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
50 sqgetGlobalVar('action', $action, SQ_GET
);
53 displayPageHeader($color, 'None');
55 if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST
)) {
56 $spam_filters = load_spam_filters();
58 // setting spam folder
59 sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST
);
60 if (isset($filters_spam_folder_set)) {
61 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
63 echo _("You must select spam folder.");
67 sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST
);
68 if (isset($filters_spam_scan_set)) {
69 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
71 echo _("You must select scan type.");
74 foreach ($spam_filters as $Key => $Value) {
75 $input = $spam_filters[$Key]['prefname'] . '_set';
76 if ( sqgetGlobalVar($input,$input_key,SQ_POST
) ) {
77 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
79 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
84 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
85 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
86 $filters = load_filters();
88 echo html_tag( 'table',
90 html_tag( 'th', _("Spam Filtering"), 'center' )
92 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
94 if ($SpamFilters_YourHop == ' ') {
96 html_tag( 'div', '<b>' .
97 sprintf(_("WARNING! Tell your admin to set the %s variable"),'SpamFilters_YourHop') .
104 if (isset($action) && $action == 'spam') {
105 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
106 $boxes = sqimap_mailbox_list($imapConnection);
107 sqimap_logout($imapConnection);
108 $numboxes = count($boxes);
110 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++
) {
111 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
112 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
113 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
114 $filters_spam_folder = $boxes[$i]['unformatted'];
118 echo '<form method="post" action="spamoptions.php">'.
120 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
122 html_tag( 'th', _("Move spam to:"), 'right', '', 'nowrap' ) .
123 html_tag( 'td', '', 'left' ) .
124 '<select name="filters_spam_folder_set">';
127 if ( isset($filters_spam_folder) )
128 $selected = array(strtolower($filters_spam_folder));
129 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
134 html_tag( 'td', ' ' ) .
136 _("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.") ,
140 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
142 '<select name="filters_spam_scan_set">'.
144 if ($filters_spam_scan == '') {
147 echo '>' . _("All messages") . '</option>'.
148 '<option value="new"';
149 if ($filters_spam_scan == 'new') {
152 echo '>' . _("Only unread messages") . '</option>' .
157 html_tag( 'td', ' ' ) .
159 _("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.") ,
163 $spam_filters = load_spam_filters();
165 foreach ($spam_filters as $Key => $Value) {
166 echo html_tag( 'tr' ) .
167 html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
169 '<input type="checkbox" name="' .
170 $spam_filters[$Key]['prefname'] .
172 if ($spam_filters[$Key]['enabled']) {
176 if ($spam_filters[$Key]['link']) {
178 $spam_filters[$Key]['link'] .
179 '" target="_blank">';
181 echo $spam_filters[$Key]['name'];
182 if ($spam_filters[$Key]['link']) {
187 html_tag( 'td', ' ' ) .
188 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
193 html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
199 // action is not set or action is not spam
200 echo html_tag( 'p', '', 'center' ) .
201 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
202 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br /><br />';
203 printf( _("Spam is sent to %s"), ($filters_spam_folder?
'<b>'.imap_utf7_decode_local($filters_spam_folder).'</b>':'[<i>'._("not set yet").'</i>]' ) );
205 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?
_("New Messages Only"):_("All Messages") ) );
207 '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
209 $spam_filters = load_spam_filters();
211 foreach ($spam_filters as $Key => $Value) {
212 echo html_tag( 'tr' ) .
213 html_tag( 'th', '', 'center' );
215 if ($spam_filters[$Key]['enabled']) {
222 html_tag( 'td', ' - ', 'left' ) .
223 html_tag( 'td', '', 'left' );
225 if ($spam_filters[$Key]['link']) {
227 $spam_filters[$Key]['link'] .
228 '" target="_blank">';
231 echo $spam_filters[$Key]['name'];
232 if ($spam_filters[$Key]['link']) {