fsf changes, meant to be rebased on upstream
[squirrelmail.git] / plugins / filters / spamoptions.php
1 <?php
2
3 /**
4 * Message and Spam Filter Plugin - Spam Options
5 *
6 * @copyright 1999-2022 The SquirrelMail Project Team
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 * @version $Id$
9 * @package plugins
10 * @subpackage filters
11 */
12
13 /**
14 * Include the SquirrelMail initialization file.
15 */
16 require('../../include/init.php');
17
18 include_once(SM_PATH . 'functions/imap_general.php');
19 include_once(SM_PATH . 'functions/imap_messages.php');
20 include_once(SM_PATH . 'plugins/filters/filters.php');
21
22 /* get globals */
23 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
24
25 sqgetGlobalVar('action', $action, SQ_GET);
26 global $imap_stream_options; // in case not defined in config
27 /* end globals */
28
29 displayPageHeader($color);
30
31 if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) {
32 $spam_filters = load_spam_filters();
33
34 // setting spam folder
35 sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST);
36 if (isset($filters_spam_folder_set)) {
37 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
38 } else {
39 echo _("You must select a spam folder.");
40 }
41
42 // setting scan type
43 sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST);
44 if (isset($filters_spam_scan_set)) {
45 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
46 } else {
47 echo _("You must select a scan type.");
48 }
49
50 foreach ($spam_filters as $Key => $Value) {
51 $input = $spam_filters[$Key]['prefname'] . '_set';
52 if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) {
53 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
54 } else {
55 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
56 }
57 }
58 }
59
60 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
61 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
62 $filters = load_filters();
63
64 echo html_tag( 'table',
65 html_tag( 'tr',
66 html_tag( 'th', _("Spam Filtering"), 'center' )
67 ) ,
68 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
69
70 if ($SpamFilters_YourHop == ' ') {
71 echo '<br />' .
72 html_tag( 'div', '<b>' .
73 sprintf(_("WARNING! Tell the administrator to set the %s variable."), '&quot;SpamFilters_YourHop&quot;') .
74 '</b>' ,
75 'center' ) .
76 '<br />';
77 }
78
79
80 if (isset($action) && $action == 'spam') {
81 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
82 $boxes = sqimap_mailbox_list($imapConnection);
83 sqimap_logout($imapConnection);
84 $numboxes = count($boxes);
85
86 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
87 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
88 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
89 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
90 $filters_spam_folder = $boxes[$i]['unformatted'];
91 }
92 }
93
94 echo '<form method="post" action="spamoptions.php">'.
95 '<div style="text-align: center;">'.
96 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
97 html_tag( 'tr' ) .
98 html_tag( 'th', _("Move spam to:"), 'right', '', 'style="white-space: nowrap;"' ) .
99 html_tag( 'td', '', 'left' ) .
100 '<select name="filters_spam_folder_set">';
101
102 $selected = 0;
103 if ( isset($filters_spam_folder) )
104 $selected = array(strtolower($filters_spam_folder));
105 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
106 echo '</select>'.
107 '</td>'.
108 '</tr>'.
109 html_tag( 'tr',
110 html_tag( 'td', '&nbsp;' ) .
111 html_tag( 'td',
112 _("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.") ,
113 'left' )
114 ) .
115 html_tag( 'tr' ) .
116 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
117 html_tag( 'td' ) .
118 '<select name="filters_spam_scan_set">'.
119 '<option value=""';
120 if ($filters_spam_scan == '') {
121 echo ' selected="selected"';
122 }
123 echo '>' . _("All messages") . '</option>'.
124 '<option value="new"';
125 if ($filters_spam_scan == 'new') {
126 echo ' selected="selected"';
127 }
128 echo '>' . _("Unread messages only") . '</option>' .
129 '</select>'.
130 '</td>'.
131 '</tr>'.
132 html_tag( 'tr',
133 html_tag( 'td', '&nbsp;' ) .
134 html_tag( 'td',
135 _("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.") ,
136 'left' )
137 );
138
139 $spam_filters = load_spam_filters();
140
141 foreach ($spam_filters as $Key => $Value) {
142 echo html_tag( 'tr' ) .
143 html_tag( 'th', $Key, 'right', '', 'style="white-space: nowrap;"' ) ."\n" .
144 html_tag( 'td' ) .
145 '<input type="checkbox" name="' .
146 $spam_filters[$Key]['prefname'] .
147 '_set"';
148 if ($spam_filters[$Key]['enabled']) {
149 echo ' checked="checked"';
150 }
151 echo ' /> - ';
152 if ($spam_filters[$Key]['link']) {
153 echo '<a href="' .
154 $spam_filters[$Key]['link'] .
155 '" target="_blank">';
156 }
157 echo $spam_filters[$Key]['name'];
158 if ($spam_filters[$Key]['link']) {
159 echo '</a>';
160 }
161 echo '</td></tr>' .
162 html_tag( 'tr',
163 html_tag( 'td', '&nbsp;' ) .
164 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
165 ) . "\n";
166
167 }
168 echo html_tag( 'tr',
169 html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
170 ) . "\n" .
171 '</table>'.
172 '</div>'.
173 '</form>';
174 } else {
175 // action is not set or action is not spam
176 echo html_tag( 'p', '', 'center' ) .
177 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
178 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</div><br /><br />';
179 printf( _("Spam is sent to %s."), ($filters_spam_folder?'<b>'.sm_encode_html_special_chars(imap_utf7_decode_local($filters_spam_folder)).'</b>':'[<i>'._("not set yet").'</i>]' ) );
180 echo '<br />';
181 printf( _("Spam scan is limited to %s."), '<b>' . ( ($filters_spam_scan == 'new')?_("Unread messages only"):_("All messages") ) . '</b>' );
182 echo '</p>'.
183 '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
184
185 $spam_filters = load_spam_filters();
186
187 foreach ($spam_filters as $Key => $Value) {
188 echo html_tag( 'tr' ) .
189 html_tag( 'th', '', 'center' );
190
191 if ($spam_filters[$Key]['enabled']) {
192 echo _("ON");
193 } else {
194 echo _("OFF");
195 }
196
197 echo '</th>' .
198 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
199 html_tag( 'td', '', 'left' );
200
201 if ($spam_filters[$Key]['link']) {
202 echo '<a href="' .
203 $spam_filters[$Key]['link'] .
204 '" target="_blank">';
205 }
206
207 echo $spam_filters[$Key]['name'];
208 if ($spam_filters[$Key]['link']) {
209 echo '</a>';
210 }
211 echo "</td></tr>\n";
212 }
213 echo '</table>';
214 }
215 ?>
216 </body></html>