Added require_once for filters.php
[squirrelmail.git] / plugins / filters / spamoptions.php
1 <?php
2 /**
3 * Message and Spam Filter Plugin
4 *
5 * Copyright (c) 1999-2002 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
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
14 * running.
15 *
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.
21 *
22 * Also view plugins/README.plugins for more information.
23 *
24 * $Id$
25 */
26
27 /* Path for SquirrelMail required files. */
28 define('SM_PATH','../../');
29
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;
38
39 displayPageHeader($color, 'None');
40
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'],
49 $$input);
50 } else {
51 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
52 }
53 }
54 }
55
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();
59
60 echo html_tag( 'table',
61 html_tag( 'tr',
62 html_tag( 'th', _("Spam Filtering"), 'center' )
63 ) ,
64 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
65
66 if ($SpamFilters_YourHop == ' ') {
67 echo '<br>' .
68 html_tag( 'div', '<b>' .
69 _("WARNING! Tell your admin to set the SpamFilters_YourHop variable") .
70 '</b>' ,
71 'center' ) .
72 '<br>';
73 }
74
75
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++) {
81
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'];
86 }
87 }
88
89 echo '<form method=post action="spamoptions.php">'.
90 '<center>'.
91 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
92 html_tag( 'tr' ) .
93 html_tag( 'th', _("Move spam to:"), 'right', '', 'nowrap' ) .
94 html_tag( 'td', '', 'left' ) .
95 '<select name="filters_spam_folder_set">';
96
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(' ', '&nbsp;', $boxes[$i]['formatted']);
101 if ($filters_spam_folder == $box) {
102 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
103 } else {
104 echo "<OPTION VALUE=\"$box\">$box2</OPTION>\n";
105 }
106 }
107 }
108 echo '</select>'.
109 '</td>'.
110 '</tr>'.
111 html_tag( 'tr',
112 html_tag( 'td', '&nbsp;' ) .
113 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.") ,
115 'left' )
116 ) .
117 html_tag( 'tr' ) .
118 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
119 html_tag( 'td' ) .
120 '<select name="filters_spam_scan_set">'.
121 '<option value=""';
122 if ($filters_spam_scan == '') {
123 echo ' SELECTED';
124 }
125 echo '>' . _("All messages") . '</option>'.
126 '<option value="new"';
127 if ($filters_spam_scan == 'new') {
128 echo ' SELECTED';
129 }
130 echo '>' . _("Only unread messages") . '</option>' .
131 '</select>'.
132 '</td>'.
133 '</tr>'.
134 html_tag( 'tr',
135 html_tag( 'td', '&nbsp;' ) .
136 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.") ,
138 'left' )
139 );
140
141 $spam_filters = load_spam_filters();
142
143 foreach ($spam_filters as $Key => $Value) {
144 echo html_tag( 'tr' ) .
145 html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
146 html_tag( 'td' ) .
147 '<input type=checkbox name="' .
148 $spam_filters[$Key]['prefname'] .
149 '_set"';
150 if ($spam_filters[$Key]['enabled']) {
151 echo ' CHECKED';
152 }
153 echo '> - ';
154 if ($spam_filters[$Key]['link']) {
155 echo '<a href="' .
156 $spam_filters[$Key]['link'] .
157 '" target="_blank">';
158 }
159 echo $spam_filters[$Key]['name'];
160 if ($spam_filters[$Key]['link']) {
161 echo '</a>';
162 }
163 echo '</td></tr>' .
164 html_tag( 'tr',
165 html_tag( 'td', '&nbsp;' ) .
166 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
167 ) . "\n";
168
169 }
170 echo html_tag( 'tr',
171 html_tag( 'td', '<input type=submit name="spam_submit" value="' . _("Save") . '">', 'center', '', 'colspan="2"' )
172 ) . "\n" .
173 '</table>'.
174 '</center>'.
175 '</form>';
176
177 }
178
179 if (! isset($action) || $action != 'spam') {
180
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>]") ) );
185 echo '<br>';
186 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) );
187 echo '</p>'.
188 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
189
190 $spam_filters = load_spam_filters();
191
192 foreach ($spam_filters as $Key => $Value) {
193 echo html_tag( 'tr' ) .
194 html_tag( 'th', '', 'center' );
195
196 if ($spam_filters[$Key]['enabled']) {
197 echo _("ON");
198 } else {
199 echo _("OFF");
200 }
201
202 echo '</th>' .
203 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
204 html_tag( 'td', '', 'left' );
205
206 if ($spam_filters[$Key]['link']) {
207 echo '<a href="' .
208 $spam_filters[$Key]['link'] .
209 '" target="_blank">';
210 }
211
212 echo $spam_filters[$Key]['name'];
213 if ($spam_filters[$Key]['link']) {
214 echo '</a>';
215 }
216 echo "</td></tr>\n";
217 }
218 echo '</table>';
219 }
220
221 ?>