Brent,
[squirrelmail.git] / plugins / filters / options.php
CommitLineData
849bdf42 1<?php
4eee5968 2 /**
3 ** Message and Spam Filter Plugin
4 **
5 ** Copyright (c) 1999-2001 The Squirrelmail Development 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 **/
25
26 chdir ('..');
849bdf42 27 require_once('../src/validate.php');
3fd1252d 28 require_once('../functions/page_header.php');
29 require_once('../functions/imap.php');
30 require_once('../src/load_prefs.php');
849bdf42 31
32 global $AllowSpamFilters;
33
3fd1252d 34 displayPageHeader($color, 'None');
849bdf42 35
36 if (isset($filter_submit)) {
37 if (!isset($theid)) $theid = 0;
4eee5968 38 $filter_what = ereg_replace(",", " ", $filter_what);
849bdf42 39 $filter_what = str_replace("\\\\", "\\", $filter_what);
40 $filter_what = str_replace("\\\"", "\"", $filter_what);
41 $filter_what = str_replace("\"", "&quot;", $filter_what);
42
4eee5968 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;
849bdf42 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);
4eee5968 51 foreach ($spam_filters as $Key => $Value) {
849bdf42 52 $input = $spam_filters[$Key]['prefname'] . '_set';
53 setPref($data_dir, $username, $spam_filters[$Key]['prefname'],
54 $$input);
55 }
3fd1252d 56 } elseif (isset($action) && $action == 'delete') {
849bdf42 57 remove_filter($theid);
3fd1252d 58 } elseif (isset($action) && $action == 'move_up') {
849bdf42 59 filter_swap($theid, $theid - 1);
3fd1252d 60 } elseif (isset($action) && $action == 'move_down') {
849bdf42 61 filter_swap($theid, $theid + 1);
62 }
63
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');
67 }
68 $filters = load_filters();
69
3fd1252d 70 echo '<br>' .
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>'.
74 '</td></tr></table>'.
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>';
849bdf42 78
4eee5968 79 for ($i=0; $i < count($filters); $i++) {
80
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>[';
88
89 if (isset($filters[$i + 1])) {
90 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
91 if ($i > 0) {
92 echo ' | ';
849bdf42 93 }
4eee5968 94 }
95 if ($i > 0) {
96 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
97 }
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 );
100 echo '</td></tr>';
101
102 }
103 echo '</table>'.
104 '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
105 '<tr><td>&nbsp</td></tr>'.
106 '</table>';
107
108
109 if ($AllowSpamFilters) {
3fd1252d 110
4eee5968 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>'.
113 '</table>';
114 if (! isset($action) || $action != 'spam') {
3fd1252d 115
4eee5968 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>]") ) );
118 echo '<br>';
119 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) );
120 echo '</p>'.
121 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
3fd1252d 122
4eee5968 123 $spam_filters = load_spam_filters();
124
125 foreach ($spam_filters as $Key => $Value) {
126 echo '<tr><th align=center>';
127
128 if ($spam_filters[$Key]['enabled']) {
129 echo _("ON");
130 } else {
131 echo _("OFF");
3fd1252d 132 }
3fd1252d 133
4eee5968 134 echo '</th><td>&nbsp;-&nbsp;</td><td>';
3fd1252d 135
4eee5968 136 if ($spam_filters[$Key]['link']) {
137 echo '<a href="' .
138 $spam_filters[$Key]['link'] .
139 '" target="_blank">';
3fd1252d 140 }
4eee5968 141
142 echo $spam_filters[$Key]['name'];
143 if ($spam_filters[$Key]['link']) {
144 echo '</a>';
145 }
146 echo "</td></tr>\n";
3fd1252d 147 }
4eee5968 148 echo '</table>';
149 }
3fd1252d 150 }
151
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) ) {
849bdf42 157 $theid = count($filters);
3fd1252d 158 }
159 echo '<center>'.
4eee5968 160 '<form action="options.php" method=post>'.
161 '<br><table cellpadding=2 cellspacing=0 border=0>'.
162 '<tr>'.
163 '<td>&nbsp;</td>'.
164 '<td>'.
165 '<select name=filter_where>';
849bdf42 166
3fd1252d 167 $L = isset($filters[$theid]['where']);
168
169 $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
170 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
4eee5968 171
3fd1252d 172 $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
173 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
174
175 $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
176 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
177
178 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
179 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
180
181 $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
182 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
183
184 echo '</select>'.
4eee5968 185 '</td>'.
186 '</tr>'.
187 '<tr>'.
188 '<td align=right>'.
189 _("Contains:").
190 '</td>'.
191 '<td>'.
192 '<input type=text size=32 name=filter_what value="';
3fd1252d 193 if (isset($filters[$theid]['what'])) {
4eee5968 194 echo $filters[$theid]["what"];
3fd1252d 195 }
196 echo '">'.
4eee5968 197 '</td>'.
198 '</tr>'.
199 '<tr>'.
200 '<td>'.
201 _("Move to:").
202 '</td>'.
203 '<td>'.
204 '<tt>'.
205 '<select name=filter_folder>';
3fd1252d 206
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(' ', '&nbsp;', $boxes[$i]['formatted']);
211 if (isset($filters[$theid]['folder']) &&
212 $filters[$theid]['folder'] == $box)
4eee5968 213 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
3fd1252d 214 else
4eee5968 215 echo "<OPTION VALUE=\"$box\">$box2</option>";
849bdf42 216 }
3fd1252d 217 }
218 echo '</tt>'.
4eee5968 219 '</select>'.
220 '</td>'.
221 '</tr>'.
3fd1252d 222 '</table>'.
223 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
224 "<input type=hidden name=theid value=$theid>".
225 '</form>'.
226 '</center>';
227
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++) {
4eee5968 233 if ($boxes[$i]['flags'][0] != 'noselect' &&
234 $boxes[$i]['flags'][1] != 'noselect' &&
3fd1252d 235 $boxes[$i]['flags'][2] != 'noselect') {
236 $filters_spam_folder = $boxes[$i]['unformatted'];
237 }
238 }
239
240 echo '<form method=post action="options.php">'.
4eee5968 241 '<center>'.
242 '<table width=85% cellpadding=2 cellspacing=0 border=0>'.
3fd1252d 243 '<tr>'.
4eee5968 244 '<th align=right nowrap>' . _("Move spam to:") . '</th>'.
245 '<td><select name="filters_spam_folder_set">';
246
3fd1252d 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(' ', '&nbsp;', $boxes[$i]['formatted']);
251 if ($filters_spam_folder == $box)
4eee5968 252 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
3fd1252d 253 else
4eee5968 254 echo "<OPTION VALUE=\"$box\">$box2</OPTION>\n";
3fd1252d 255 }
256 }
257 echo '</select>'.
4eee5968 258 '</td>'.
259 '</tr>'.
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.") .
262 '</td></tr>'.
263 '<tr>'.
3fd1252d 264 '<th align=right nowrap>' . _("What to Scan:") . '</th>'.
265 '<td><select name="filters_spam_scan_set">'.
4eee5968 266 '<option value=""';
267 if ($filters_spam_scan == '')
3fd1252d 268 echo ' SELECTED';
269 echo '>' . _("All messages") . '</option>'.
4eee5968 270 '<option value="new"';
271 if ($filters_spam_scan == 'new')
3fd1252d 272 echo ' SELECTED';
273 echo '>' . _("Only unread messages") . '</option>' .
274 '</select>'.
4eee5968 275 '</td>'.
276 '</tr>'.
277 '<tr>'.
278 '<td></td><td>'.
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.").
280 '</td></tr>';
3fd1252d 281
282 $spam_filters = load_spam_filters();
283
284 foreach ($spam_filters as $Key => $Value) {
285 echo "<tr><th align=right nowrap>$Key</th>\n" .
4eee5968 286 '<td><input type=checkbox name="' .
287 $spam_filters[$Key]['prefname'] .
288 '_set"';
3fd1252d 289 if ($spam_filters[$Key]['enabled'])
4eee5968 290 echo ' CHECKED';
3fd1252d 291 echo '> - ';
292 if ($spam_filters[$Key]['link']) {
4eee5968 293 echo '<a href="' .
3fd1252d 294 $spam_filters[$Key]['link'] .
295 '" target="_blank">';
296 }
297 echo $spam_filters[$Key]['name'];
298 if ($spam_filters[$Key]['link']) {
4eee5968 299 echo '</a>';
3fd1252d 300 }
301 echo '</td></tr><tr><td></td><td>' .
4eee5968 302 $spam_filters[$Key]['comment'] .
303 "</td></tr>\n";
3fd1252d 304 }
305 echo '<tr><td colspan=2 align=center><input type=submit name="spam_submit" value="' . _("Save") . '"></td></tr>'.
4eee5968 306 '</table>'.
307 '</center>'.
308 '</form>';
3fd1252d 309
310 sqimap_logout($imapConnection);
311 }
4eee5968 312?>