1460638 fix info
[squirrelmail.git] / plugins / filters / spamoptions.php
1 <?php
2
3 /**
4 * Message and Spam Filter Plugin - Spam Options
5 *
6 * @copyright &copy; 1999-2006 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('username', $username, SQ_SESSION);
24 sqgetGlobalVar('key', $key, SQ_COOKIE);
25 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
26 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
27
28 sqgetGlobalVar('action', $action, SQ_GET);
29 /* end globals */
30
31 displayPageHeader($color, 'None');
32
33 if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) {
34 $spam_filters = load_spam_filters();
35
36 // setting spam folder
37 sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST);
38 if (isset($filters_spam_folder_set)) {
39 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
40 } else {
41 echo _("You must select a spam folder.");
42 }
43
44 // setting scan type
45 sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST);
46 if (isset($filters_spam_scan_set)) {
47 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
48 } else {
49 echo _("You must select a scan type.");
50 }
51
52 foreach ($spam_filters as $Key => $Value) {
53 $input = $spam_filters[$Key]['prefname'] . '_set';
54 if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) {
55 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
56 } else {
57 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
58 }
59 }
60 }
61
62 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
63 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
64 $filters = load_filters();
65
66 echo html_tag( 'table',
67 html_tag( 'tr',
68 html_tag( 'th', _("Spam Filtering"), 'center' )
69 ) ,
70 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
71
72 if ($SpamFilters_YourHop == ' ') {
73 echo '<br />' .
74 html_tag( 'div', '<b>' .
75 sprintf(_("WARNING! Tell the administrator to set the %s variable."), '&quot;SpamFilters_YourHop&quot;') .
76 '</b>' ,
77 'center' ) .
78 '<br />';
79 }
80
81
82 if (isset($action) && $action == 'spam') {
83 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
84 $boxes = sqimap_mailbox_list($imapConnection);
85 sqimap_logout($imapConnection);
86 $numboxes = count($boxes);
87
88 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
89 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
90 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
91 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
92 $filters_spam_folder = $boxes[$i]['unformatted'];
93 }
94 }
95
96 echo '<form method="post" action="spamoptions.php">'.
97 '<div style="text-align: center;">'.
98 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
99 html_tag( 'tr' ) .
100 html_tag( 'th', _("Move spam to:"), 'right', '', 'style="white-space: nowrap;"' ) .
101 html_tag( 'td', '', 'left' ) .
102 '<select name="filters_spam_folder_set">';
103
104 $selected = 0;
105 if ( isset($filters_spam_folder) )
106 $selected = array(strtolower($filters_spam_folder));
107 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
108 echo '</select>'.
109 '</td>'.
110 '</tr>'.
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', '', 'style="white-space: nowrap;"' ) .
119 html_tag( 'td' ) .
120 '<select name="filters_spam_scan_set">'.
121 '<option value=""';
122 if ($filters_spam_scan == '') {
123 echo ' selected="selected"';
124 }
125 echo '>' . _("All messages") . '</option>'.
126 '<option value="new"';
127 if ($filters_spam_scan == 'new') {
128 echo ' selected="selected"';
129 }
130 echo '>' . _("Unread messages only") . '</option>' .
131 '</select>'.
132 '</td>'.
133 '</tr>'.
134 html_tag( 'tr',
135 html_tag( 'td', '&nbsp;' ) .
136 html_tag( 'td',
137 _("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.") ,
138 'left' )
139 );
140
141 $spam_filters = load_spam_filters();
142
143 foreach ($spam_filters as $Key => $Value) {
144 echo html_tag( 'tr' ) .
145 html_tag( 'th', $Key, 'right', '', 'style="white-space: nowrap;"' ) ."\n" .
146 html_tag( 'td' ) .
147 '<input type="checkbox" name="' .
148 $spam_filters[$Key]['prefname'] .
149 '_set"';
150 if ($spam_filters[$Key]['enabled']) {
151 echo ' checked="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 }
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
169 }
170 echo html_tag( 'tr',
171 html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
172 ) . "\n" .
173 '</table>'.
174 '</div>'.
175 '</form>';
176 } else {
177 // action is not set or action is not spam
178 echo html_tag( 'p', '', 'center' ) .
179 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
180 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</div><br /><br />';
181 printf( _("Spam is sent to %s."), ($filters_spam_folder?'<b>'.htmlspecialchars(imap_utf7_decode_local($filters_spam_folder)).'</b>':'[<i>'._("not set yet").'</i>]' ) );
182 echo '<br />';
183 printf( _("Spam scan is limited to %s."), '<b>' . ( ($filters_spam_scan == 'new')?_("Unread messages only"):_("All messages") ) . '</b>' );
184 echo '</p>'.
185 '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
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 </body></html>