3 * Message and Spam Filter Plugin - Spam Options
5 * This plugin filters your inbox into different folders based upon given
6 * criteria. It is most useful for people who are subscibed to mailing lists
7 * to help organize their messages. The argument stands that filtering is
8 * not the place of the client, which is why this has been made a plugin for
9 * SquirrelMail. You may be better off using products such as Sieve or
10 * Procmail to do your filtering so it happens even when SquirrelMail isn't
13 * If you need help with this, or see improvements that can be made, please
14 * email me directly at the address above. I definately welcome suggestions
15 * and comments. This plugin, as is the case with all SquirrelMail plugins,
16 * is not directly supported by the developers. Please come to me off the
17 * mailing list if you have trouble with it.
19 * Also view plugins/README.plugins for more information.
22 * @copyright (c) 1999-2004 The SquirrelMail Project Team
23 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
29 * Path for SquirrelMail required files.
32 define('SM_PATH','../../');
34 /* SquirrelMail required files. */
35 require_once(SM_PATH
. 'include/validate.php');
36 require_once(SM_PATH
. 'functions/page_header.php');
37 require_once(SM_PATH
. 'functions/imap.php');
38 require_once(SM_PATH
. 'include/load_prefs.php');
39 require_once(SM_PATH
. 'functions/html.php');
40 require_once(SM_PATH
. 'plugins/filters/filters.php');
41 global $AllowSpamFilters;
44 sqgetGlobalVar('username', $username, SQ_SESSION
);
45 sqgetGlobalVar('key', $key, SQ_COOKIE
);
46 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
47 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
49 sqgetGlobalVar('action', $action, SQ_GET
);
52 displayPageHeader($color, 'None');
54 if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST
)) {
55 $spam_filters = load_spam_filters();
57 // setting spam folder
58 sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST
);
59 if (isset($filters_spam_folder_set)) {
60 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
62 echo _("You must select spam folder.");
66 sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST
);
67 if (isset($filters_spam_scan_set)) {
68 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
70 echo _("You must select scan type.");
73 foreach ($spam_filters as $Key => $Value) {
74 $input = $spam_filters[$Key]['prefname'] . '_set';
75 if ( sqgetGlobalVar($input,$input_key,SQ_POST
) ) {
76 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
78 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
83 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
84 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
85 $filters = load_filters();
87 echo html_tag( 'table',
89 html_tag( 'th', _("Spam Filtering"), 'center' )
91 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
93 if ($SpamFilters_YourHop == ' ') {
95 html_tag( 'div', '<b>' .
96 sprintf(_("WARNING! Tell your admin to set the %s variable"),'SpamFilters_YourHop') .
103 if (isset($action) && $action == 'spam') {
104 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
105 $boxes = sqimap_mailbox_list($imapConnection);
106 sqimap_logout($imapConnection);
107 $numboxes = count($boxes);
109 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++
) {
110 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
111 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
112 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
113 $filters_spam_folder = $boxes[$i]['unformatted'];
117 echo '<form method="post" action="spamoptions.php">'.
119 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
121 html_tag( 'th', _("Move spam to:"), 'right', '', 'nowrap' ) .
122 html_tag( 'td', '', 'left' ) .
123 '<select name="filters_spam_folder_set">';
126 if ( isset($filters_spam_folder) )
127 $selected = array(strtolower($filters_spam_folder));
128 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
133 html_tag( 'td', ' ' ) .
135 _("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.") ,
139 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
141 '<select name="filters_spam_scan_set">'.
143 if ($filters_spam_scan == '') {
146 echo '>' . _("All messages") . '</option>'.
147 '<option value="new"';
148 if ($filters_spam_scan == 'new') {
151 echo '>' . _("Only unread messages") . '</option>' .
156 html_tag( 'td', ' ' ) .
158 _("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.") ,
162 $spam_filters = load_spam_filters();
164 foreach ($spam_filters as $Key => $Value) {
165 echo html_tag( 'tr' ) .
166 html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
168 '<input type="checkbox" name="' .
169 $spam_filters[$Key]['prefname'] .
171 if ($spam_filters[$Key]['enabled']) {
175 if ($spam_filters[$Key]['link']) {
177 $spam_filters[$Key]['link'] .
178 '" target="_blank">';
180 echo $spam_filters[$Key]['name'];
181 if ($spam_filters[$Key]['link']) {
186 html_tag( 'td', ' ' ) .
187 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
192 html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
198 // action is not set or action is not spam
199 echo html_tag( 'p', '', 'center' ) .
200 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
201 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br /><br />';
202 printf( _("Spam is sent to %s"), ($filters_spam_folder?
'<b>'.imap_utf7_decode_local($filters_spam_folder).'</b>':'[<i>'._("not set yet").'</i>]' ) );
204 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?
_("New Messages Only"):_("All Messages") ) );
206 '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
208 $spam_filters = load_spam_filters();
210 foreach ($spam_filters as $Key => $Value) {
211 echo html_tag( 'tr' ) .
212 html_tag( 'th', '', 'center' );
214 if ($spam_filters[$Key]['enabled']) {
221 html_tag( 'td', ' - ', 'left' ) .
222 html_tag( 'td', '', 'left' );
224 if ($spam_filters[$Key]['link']) {
226 $spam_filters[$Key]['link'] .
227 '" target="_blank">';
230 echo $spam_filters[$Key]['name'];
231 if ($spam_filters[$Key]['link']) {