set value returned by ini_get to boolean
[squirrelmail.git] / plugins / filters / spamoptions.php
CommitLineData
63277aaa 1<?php
15e6162e 2/**
b2d8bc6c 3 * Message and Spam Filter Plugin - Spam Options
15e6162e 4 *
5 * This plugin filters your inbox into different folders based upon given
6 * criteria. It is most useful for people who are subscibed to mailing lists
7 * to help organize their messages. The argument stands that filtering is
8 * not the place of the client, which is why this has been made a plugin for
9 * SquirrelMail. You may be better off using products such as Sieve or
10 * Procmail to do your filtering so it happens even when SquirrelMail isn't
11 * running.
12 *
13 * If you need help with this, or see improvements that can be made, please
14 * email me directly at the address above. I definately welcome suggestions
15 * and comments. This plugin, as is the case with all SquirrelMail plugins,
16 * is not directly supported by the developers. Please come to me off the
17 * mailing list if you have trouble with it.
18 *
19 * Also view plugins/README.plugins for more information.
20 *
5b4ba967 21 * @version $Id$
b2d8bc6c 22 * @copyright (c) 1999-2004 The SquirrelMail Project Team
23 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
ea5f4b8e 24 * @package plugins
25 * @subpackage filters
15e6162e 26 */
63277aaa 27
5b4ba967 28/**
29 * Path for SquirrelMail required files.
30 * @ignore
31 */
08185f2a 32define('SM_PATH','../../');
33
34/* SquirrelMail required files. */
fca6d99e 35require_once(SM_PATH . 'include/validate.php');
08185f2a 36require_once(SM_PATH . 'functions/page_header.php');
37require_once(SM_PATH . 'functions/imap.php');
fca6d99e 38require_once(SM_PATH . 'include/load_prefs.php');
08185f2a 39require_once(SM_PATH . 'functions/html.php');
fca6d99e 40require_once(SM_PATH . 'plugins/filters/filters.php');
10a26cea 41global $AllowSpamFilters;
42
3c66c567 43/* get globals */
44sqgetGlobalVar('username', $username, SQ_SESSION);
45sqgetGlobalVar('key', $key, SQ_COOKIE);
46sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
47sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
41100fce 48
3c66c567 49sqgetGlobalVar('action', $action, SQ_GET);
50/* end globals */
41100fce 51
10a26cea 52displayPageHeader($color, 'None');
53
0a1dc88e 54if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) {
10a26cea 55 $spam_filters = load_spam_filters();
0a1dc88e 56
91e0dccc 57 // setting spam folder
0a1dc88e 58 sqgetGlobalVar('filters_spam_folder_set',$filters_spam_folder_set,SQ_POST);
59 if (isset($filters_spam_folder_set)) {
60 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
61 } else {
91e0dccc 62 echo _("You must select a spam folder.");
0a1dc88e 63 }
64
65 // setting scan type
66 sqgetGlobalVar('filters_spam_scan_set',$filters_spam_scan_set,SQ_POST);
67 if (isset($filters_spam_scan_set)) {
91e0dccc 68 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
0a1dc88e 69 } else {
91e0dccc 70 echo _("You must select a scan type.");
0a1dc88e 71 }
72
10a26cea 73 foreach ($spam_filters as $Key => $Value) {
74 $input = $spam_filters[$Key]['prefname'] . '_set';
0a1dc88e 75 if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) {
76 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
51199e7a 77 } else {
78 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
10a26cea 79 }
80 }
81}
82
83$filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
84$filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
85$filters = load_filters();
86
b01b21d0 87echo html_tag( 'table',
88 html_tag( 'tr',
89 html_tag( 'th', _("Spam Filtering"), 'center' )
90 ) ,
91 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
10a26cea 92
93if ($SpamFilters_YourHop == ' ') {
0a1dc88e 94 echo '<br />' .
b01b21d0 95 html_tag( 'div', '<b>' .
6d440be5 96 sprintf(_("WARNING! Tell the administrator to set the %s variable."), '&quot;SpamFilters_YourHop&quot;') .
b01b21d0 97 '</b>' ,
98 'center' ) .
0a1dc88e 99 '<br />';
10a26cea 100}
101
102
103if (isset($action) && $action == 'spam') {
104 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
105 $boxes = sqimap_mailbox_list($imapConnection);
106 sqimap_logout($imapConnection);
ae48f757 107 $numboxes = count($boxes);
108
109 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
41100fce 110 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
111 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
112 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
10a26cea 113 $filters_spam_folder = $boxes[$i]['unformatted'];
114 }
5e2e3895 115 }
116
0a1dc88e 117 echo '<form method="post" action="spamoptions.php">'.
10a26cea 118 '<center>'.
b01b21d0 119 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
120 html_tag( 'tr' ) .
121 html_tag( 'th', _("Move spam to:"), 'right', '', 'nowrap' ) .
122 html_tag( 'td', '', 'left' ) .
123 '<select name="filters_spam_folder_set">';
10a26cea 124
ae8a7931 125 $selected = 0;
126 if ( isset($filters_spam_folder) )
127 $selected = array(strtolower($filters_spam_folder));
128 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
10a26cea 129 echo '</select>'.
130 '</td>'.
131 '</tr>'.
b01b21d0 132 html_tag( 'tr',
133 html_tag( 'td', '&nbsp;' ) .
134 html_tag( 'td',
135 _("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.") ,
136 'left' )
137 ) .
138 html_tag( 'tr' ) .
139 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
140 html_tag( 'td' ) .
141 '<select name="filters_spam_scan_set">'.
10a26cea 142 '<option value=""';
143 if ($filters_spam_scan == '') {
743715c6 144 echo ' selected="selected"';
10a26cea 145 }
146 echo '>' . _("All messages") . '</option>'.
147 '<option value="new"';
148 if ($filters_spam_scan == 'new') {
743715c6 149 echo ' selected="selected"';
10a26cea 150 }
74091b64 151 echo '>' . _("Unread messages only") . '</option>' .
10a26cea 152 '</select>'.
153 '</td>'.
154 '</tr>'.
b01b21d0 155 html_tag( 'tr',
156 html_tag( 'td', '&nbsp;' ) .
157 html_tag( 'td',
74091b64 158 _("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 159 'left' )
160 );
10a26cea 161
162 $spam_filters = load_spam_filters();
163
164 foreach ($spam_filters as $Key => $Value) {
b01b21d0 165 echo html_tag( 'tr' ) .
166 html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
167 html_tag( 'td' ) .
0a1dc88e 168 '<input type="checkbox" name="' .
10a26cea 169 $spam_filters[$Key]['prefname'] .
170 '_set"';
171 if ($spam_filters[$Key]['enabled']) {
9374fbf7 172 echo ' checked="checked"';
10a26cea 173 }
0a1dc88e 174 echo ' /> - ';
10a26cea 175 if ($spam_filters[$Key]['link']) {
176 echo '<a href="' .
177 $spam_filters[$Key]['link'] .
178 '" target="_blank">';
179 }
180 echo $spam_filters[$Key]['name'];
181 if ($spam_filters[$Key]['link']) {
182 echo '</a>';
183 }
b01b21d0 184 echo '</td></tr>' .
185 html_tag( 'tr',
186 html_tag( 'td', '&nbsp;' ) .
187 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
188 ) . "\n";
189
10a26cea 190 }
b01b21d0 191 echo html_tag( 'tr',
0a1dc88e 192 html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
b01b21d0 193 ) . "\n" .
10a26cea 194 '</table>'.
195 '</center>'.
196 '</form>';
0a1dc88e 197} else {
198 // action is not set or action is not spam
b01b21d0 199 echo html_tag( 'p', '', 'center' ) .
200 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
0a1dc88e 201 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br /><br />';
74091b64 202 printf( _("Spam is sent to %s."), ($filters_spam_folder?'<b>'.imap_utf7_decode_local($filters_spam_folder).'</b>':'[<i>'._("not set yet").'</i>]' ) );
203 echo '<br />';
3ee2d2ae 204 printf( _("Spam scan is limited to %s."), '<b>' . ( ($filters_spam_scan == 'new')?_("Unread messages only"):_("All messages") ) . '</b>' );
10a26cea 205 echo '</p>'.
0a1dc88e 206 '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
10a26cea 207
208 $spam_filters = load_spam_filters();
209
210 foreach ($spam_filters as $Key => $Value) {
b01b21d0 211 echo html_tag( 'tr' ) .
212 html_tag( 'th', '', 'center' );
10a26cea 213
214 if ($spam_filters[$Key]['enabled']) {
215 echo _("ON");
216 } else {
217 echo _("OFF");
218 }
219
91e0dccc 220 echo '</th>' .
b01b21d0 221 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
222 html_tag( 'td', '', 'left' );
10a26cea 223
224 if ($spam_filters[$Key]['link']) {
225 echo '<a href="' .
226 $spam_filters[$Key]['link'] .
227 '" target="_blank">';
228 }
229
230 echo $spam_filters[$Key]['name'];
231 if ($spam_filters[$Key]['link']) {
232 echo '</a>';
233 }
234 echo "</td></tr>\n";
235 }
236 echo '</table>';
237}
0a1dc88e 238?>
91e0dccc 239</body></html>