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