one more place affected by #1085377 bug
[squirrelmail.git] / plugins / filters / spamoptions.php
1 <?php
2 /**
3 * Message and Spam Filter Plugin - Spam Options
4 *
5 * This plugin filters your inbox into different folders based upon given
6 * criteria. It is most useful for people who are subscibed to mailing lists
7 * to help organize their messages. The argument stands that filtering is
8 * not the place of the client, which is why this has been made a plugin for
9 * SquirrelMail. You may be better off using products such as Sieve or
10 * Procmail to do your filtering so it happens even when SquirrelMail isn't
11 * running.
12 *
13 * If you need help with this, or see improvements that can be made, please
14 * email me directly at the address above. I definately welcome suggestions
15 * and comments. This plugin, as is the case with all SquirrelMail plugins,
16 * is not directly supported by the developers. Please come to me off the
17 * mailing list if you have trouble with it.
18 *
19 * Also view plugins/README.plugins for more information.
20 *
21 * @version $Id$
22 * @copyright (c) 1999-2005 The SquirrelMail Project Team
23 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
24 * @package plugins
25 * @subpackage filters
26 */
27
28 /**
29 * Path for SquirrelMail required files.
30 * @ignore
31 */
32 define('SM_PATH','../../');
33
34 /* SquirrelMail required files. */
35 require_once(SM_PATH . 'include/validate.php');
36 require_once(SM_PATH . 'functions/page_header.php');
37 require_once(SM_PATH . 'functions/imap.php');
38 require_once(SM_PATH . 'include/load_prefs.php');
39 require_once(SM_PATH . 'functions/html.php');
40 require_once(SM_PATH . 'plugins/filters/filters.php');
41 global $AllowSpamFilters;
42
43 /* get globals */
44 sqgetGlobalVar('username', $username, SQ_SESSION);
45 sqgetGlobalVar('key', $key, SQ_COOKIE);
46 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
47 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
48
49 sqgetGlobalVar('action', $action, SQ_GET);
50 /* end globals */
51
52 displayPageHeader($color, 'None');
53
54 if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) {
55 $spam_filters = load_spam_filters();
56
57 // setting spam folder
58 sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST);
59 if (isset($filters_spam_folder_set)) {
60 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
61 } else {
62 echo _("You must select a spam folder.");
63 }
64
65 // setting scan type
66 sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST);
67 if (isset($filters_spam_scan_set)) {
68 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
69 } else {
70 echo _("You must select a scan type.");
71 }
72
73 foreach ($spam_filters as $Key => $Value) {
74 $input = $spam_filters[$Key]['prefname'] . '_set';
75 if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) {
76 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
77 } else {
78 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
79 }
80 }
81 }
82
83 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
84 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
85 $filters = load_filters();
86
87 echo html_tag( 'table',
88 html_tag( 'tr',
89 html_tag( 'th', _("Spam Filtering"), 'center' )
90 ) ,
91 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
92
93 if ($SpamFilters_YourHop == ' ') {
94 echo '<br />' .
95 html_tag( 'div', '<b>' .
96 sprintf(_("WARNING! Tell the administrator to set the %s variable."), '&quot;SpamFilters_YourHop&quot;') .
97 '</b>' ,
98 'center' ) .
99 '<br />';
100 }
101
102
103 if (isset($action) && $action == 'spam') {
104 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
105 $boxes = sqimap_mailbox_list($imapConnection);
106 sqimap_logout($imapConnection);
107 $numboxes = count($boxes);
108
109 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
110 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
111 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
112 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
113 $filters_spam_folder = $boxes[$i]['unformatted'];
114 }
115 }
116
117 echo '<form method="post" action="spamoptions.php">'.
118 '<center>'.
119 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
120 html_tag( 'tr' ) .
121 html_tag( 'th', _("Move spam to:"), 'right', '', 'style="white-space: nowrap;"' ) .
122 html_tag( 'td', '', 'left' ) .
123 '<select name="filters_spam_folder_set">';
124
125 $selected = 0;
126 if ( isset($filters_spam_folder) )
127 $selected = array(strtolower($filters_spam_folder));
128 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
129 echo '</select>'.
130 '</td>'.
131 '</tr>'.
132 html_tag( 'tr',
133 html_tag( 'td', '&nbsp;' ) .
134 html_tag( 'td',
135 _("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.") ,
136 'left' )
137 ) .
138 html_tag( 'tr' ) .
139 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
140 html_tag( 'td' ) .
141 '<select name="filters_spam_scan_set">'.
142 '<option value=""';
143 if ($filters_spam_scan == '') {
144 echo ' selected="selected"';
145 }
146 echo '>' . _("All messages") . '</option>'.
147 '<option value="new"';
148 if ($filters_spam_scan == 'new') {
149 echo ' selected="selected"';
150 }
151 echo '>' . _("Unread messages only") . '</option>' .
152 '</select>'.
153 '</td>'.
154 '</tr>'.
155 html_tag( 'tr',
156 html_tag( 'td', '&nbsp;' ) .
157 html_tag( 'td',
158 _("The more messages scanned, the longer it takes. It's recommended to scan unread messages only. If a change to the filters is made, it's recommended to set it to scan all messages, then go view the INBOX, then come back and set it to scan unread messages only. That way, the new spam filters will be applied and even the spam you didn't catch with the old filters will be scanned.") ,
159 'left' )
160 );
161
162 $spam_filters = load_spam_filters();
163
164 foreach ($spam_filters as $Key => $Value) {
165 echo html_tag( 'tr' ) .
166 html_tag( 'th', $Key, 'right', '', 'style="white-space: nowrap;"' ) ."\n" .
167 html_tag( 'td' ) .
168 '<input type="checkbox" name="' .
169 $spam_filters[$Key]['prefname'] .
170 '_set"';
171 if ($spam_filters[$Key]['enabled']) {
172 echo ' checked="checked"';
173 }
174 echo ' /> - ';
175 if ($spam_filters[$Key]['link']) {
176 echo '<a href="' .
177 $spam_filters[$Key]['link'] .
178 '" target="_blank">';
179 }
180 echo $spam_filters[$Key]['name'];
181 if ($spam_filters[$Key]['link']) {
182 echo '</a>';
183 }
184 echo '</td></tr>' .
185 html_tag( 'tr',
186 html_tag( 'td', '&nbsp;' ) .
187 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
188 ) . "\n";
189
190 }
191 echo html_tag( 'tr',
192 html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
193 ) . "\n" .
194 '</table>'.
195 '</center>'.
196 '</form>';
197 } else {
198 // action is not set or action is not spam
199 echo html_tag( 'p', '', 'center' ) .
200 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
201 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br /><br />';
202 printf( _("Spam is sent to %s."), ($filters_spam_folder?'<b>'.imap_utf7_decode_local($filters_spam_folder).'</b>':'[<i>'._("not set yet").'</i>]' ) );
203 echo '<br />';
204 printf( _("Spam scan is limited to %s."), '<b>' . ( ($filters_spam_scan == 'new')?_("Unread messages only"):_("All messages") ) . '</b>' );
205 echo '</p>'.
206 '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
207
208 $spam_filters = load_spam_filters();
209
210 foreach ($spam_filters as $Key => $Value) {
211 echo html_tag( 'tr' ) .
212 html_tag( 'th', '', 'center' );
213
214 if ($spam_filters[$Key]['enabled']) {
215 echo _("ON");
216 } else {
217 echo _("OFF");
218 }
219
220 echo '</th>' .
221 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
222 html_tag( 'td', '', 'left' );
223
224 if ($spam_filters[$Key]['link']) {
225 echo '<a href="' .
226 $spam_filters[$Key]['link'] .
227 '" target="_blank">';
228 }
229
230 echo $spam_filters[$Key]['name'];
231 if ($spam_filters[$Key]['link']) {
232 echo '</a>';
233 }
234 echo "</td></tr>\n";
235 }
236 echo '</table>';
237 }
238 ?>
239 </body></html>