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