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