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