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