Patch to fix several problems in MagicHTML.
[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 chdir ('..');
28 require_once('../src/validate.php');
29 require_once('../functions/page_header.php');
30 require_once('../functions/imap.php');
31 require_once('../src/load_prefs.php');
32
33 global $AllowSpamFilters;
34
35 displayPageHeader($color, 'None');
36
37 if (isset($spam_submit)) {
38 $spam_filters = load_spam_filters();
39 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
40 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
41 foreach ($spam_filters as $Key => $Value) {
42 $input = $spam_filters[$Key]['prefname'] . '_set';
43 if ( isset( $$input ) ) {
44 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],
45 $$input);
46 }
47 }
48 }
49
50 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
51 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
52 $filters = load_filters();
53
54 echo "<table width=95% align=center border=0 cellpadding=2 cellspacing=0 bgcolor=\"$color[0]\">".
55 '<tr><th align=center>' . _("Spam Filtering") . '</th></tr>'.
56 '</table>';
57
58 if ($SpamFilters_YourHop == ' ') {
59 echo '<BR><center><b>' .
60 _("WARNING! Tell your admin to set the SpamFilters_YourHop variable") .
61 '</b></center><BR>';
62 }
63
64
65 if (isset($action) && $action == 'spam') {
66 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
67 $boxes = sqimap_mailbox_list($imapConnection);
68 sqimap_logout($imapConnection);
69 for ($i = 0; $i < count($boxes) && $filters_spam_folder == ''; $i++) {
70
71 if ($boxes[$i]['flags'][0] != 'noselect' &&
72 $boxes[$i]['flags'][1] != 'noselect' &&
73 $boxes[$i]['flags'][2] != 'noselect') {
74 $filters_spam_folder = $boxes[$i]['unformatted'];
75 }
76 }
77
78 echo '<form method=post action="spamoptions.php">'.
79 '<center>'.
80 '<table width=85% cellpadding=2 cellspacing=0 border=0>'.
81 '<tr>'.
82 '<th align=right nowrap>' . _("Move spam to:") . '</th>'.
83 '<td><select name="filters_spam_folder_set">';
84
85 for ($i = 0; $i < count($boxes); $i++) {
86 if (! in_array('noselect', $boxes[$i]['flags'])) {
87 $box = $boxes[$i]['unformatted'];
88 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
89 if ($filters_spam_folder == $box) {
90 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
91 } else {
92 echo "<OPTION VALUE=\"$box\">$box2</OPTION>\n";
93 }
94 }
95 }
96 echo '</select>'.
97 '</td>'.
98 '</tr>'.
99 '<tr><td></td><td>' .
100 _("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.") .
101 '</td></tr>'.
102 '<tr>'.
103 '<th align=right nowrap>' . _("What to Scan:") . '</th>'.
104 '<td><select name="filters_spam_scan_set">'.
105 '<option value=""';
106 if ($filters_spam_scan == '') {
107 echo ' SELECTED';
108 }
109 echo '>' . _("All messages") . '</option>'.
110 '<option value="new"';
111 if ($filters_spam_scan == 'new') {
112 echo ' SELECTED';
113 }
114 echo '>' . _("Only unread messages") . '</option>' .
115 '</select>'.
116 '</td>'.
117 '</tr>'.
118 '<tr>'.
119 '<td></td><td>'.
120 _("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.").
121 '</td></tr>';
122
123 $spam_filters = load_spam_filters();
124
125 foreach ($spam_filters as $Key => $Value) {
126 echo "<tr><th align=right nowrap>$Key</th>\n" .
127 '<td><input type=checkbox name="' .
128 $spam_filters[$Key]['prefname'] .
129 '_set"';
130 if ($spam_filters[$Key]['enabled']) {
131 echo ' CHECKED';
132 }
133 echo '> - ';
134 if ($spam_filters[$Key]['link']) {
135 echo '<a href="' .
136 $spam_filters[$Key]['link'] .
137 '" target="_blank">';
138 }
139 echo $spam_filters[$Key]['name'];
140 if ($spam_filters[$Key]['link']) {
141 echo '</a>';
142 }
143 echo '</td></tr><tr><td></td><td>' .
144 $spam_filters[$Key]['comment'] .
145 "</td></tr>\n";
146 }
147 echo '<tr><td colspan=2 align=center><input type=submit name="spam_submit" value="' . _("Save") . '"></td></tr>'.
148 '</table>'.
149 '</center>'.
150 '</form>';
151
152 }
153
154 if (! isset($action) || $action != 'spam') {
155
156 echo '<p align=center>[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
157 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br><br>';
158 printf( _("Spam is sent to <b>%s</b>"), ($filters_spam_folder?$filters_spam_folder:_("[<i>not set yet</i>]") ) );
159 echo '<br>';
160 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) );
161 echo '</p>'.
162 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
163
164 $spam_filters = load_spam_filters();
165
166 foreach ($spam_filters as $Key => $Value) {
167 echo '<tr><th align=center>';
168
169 if ($spam_filters[$Key]['enabled']) {
170 echo _("ON");
171 } else {
172 echo _("OFF");
173 }
174
175 echo '</th><td>&nbsp;-&nbsp;</td><td>';
176
177 if ($spam_filters[$Key]['link']) {
178 echo '<a href="' .
179 $spam_filters[$Key]['link'] .
180 '" target="_blank">';
181 }
182
183 echo $spam_filters[$Key]['name'];
184 if ($spam_filters[$Key]['link']) {
185 echo '</a>';
186 }
187 echo "</td></tr>\n";
188 }
189 echo '</table>';
190 }
191
192 ?>