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