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