Centralized init
[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/**
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 */
23sqgetGlobalVar('username', $username, SQ_SESSION);
24sqgetGlobalVar('key', $key, SQ_COOKIE);
25sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
26sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
41100fce 27
3c66c567 28sqgetGlobalVar('action', $action, SQ_GET);
29/* end globals */
41100fce 30
10a26cea 31displayPageHeader($color, 'None');
32
0a1dc88e 33if (sqgetGlobalVar('spam_submit',$spam_submit,SQ_POST)) {
10a26cea 34 $spam_filters = load_spam_filters();
0a1dc88e 35
91e0dccc 36 // setting spam folder
0a1dc88e 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 {
91e0dccc 41 echo _("You must select a spam folder.");
0a1dc88e 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)) {
91e0dccc 47 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
0a1dc88e 48 } else {
91e0dccc 49 echo _("You must select a scan type.");
0a1dc88e 50 }
51
10a26cea 52 foreach ($spam_filters as $Key => $Value) {
53 $input = $spam_filters[$Key]['prefname'] . '_set';
0a1dc88e 54 if ( sqgetGlobalVar($input,$input_key,SQ_POST) ) {
55 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],$input_key);
51199e7a 56 } else {
57 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
10a26cea 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
b01b21d0 66echo 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"' );
10a26cea 71
72if ($SpamFilters_YourHop == ' ') {
0a1dc88e 73 echo '<br />' .
b01b21d0 74 html_tag( 'div', '<b>' .
6d440be5 75 sprintf(_("WARNING! Tell the administrator to set the %s variable."), '&quot;SpamFilters_YourHop&quot;') .
b01b21d0 76 '</b>' ,
77 'center' ) .
0a1dc88e 78 '<br />';
10a26cea 79}
80
81
82if (isset($action) && $action == 'spam') {
83 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
84 $boxes = sqimap_mailbox_list($imapConnection);
85 sqimap_logout($imapConnection);
ae48f757 86 $numboxes = count($boxes);
87
88 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
41100fce 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')) {
10a26cea 92 $filters_spam_folder = $boxes[$i]['unformatted'];
93 }
5e2e3895 94 }
95
0a1dc88e 96 echo '<form method="post" action="spamoptions.php">'.
f265009a 97 '<div style="text-align: center;">'.
b01b21d0 98 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
99 html_tag( 'tr' ) .
c435f076 100 html_tag( 'th', _("Move spam to:"), 'right', '', 'style="white-space: nowrap;"' ) .
b01b21d0 101 html_tag( 'td', '', 'left' ) .
102 '<select name="filters_spam_folder_set">';
10a26cea 103
ae8a7931 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);
10a26cea 108 echo '</select>'.
109 '</td>'.
110 '</tr>'.
b01b21d0 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' ) .
c435f076 118 html_tag( 'th', _("What to Scan:"), 'right', '', 'style="white-space: nowrap;"' ) .
b01b21d0 119 html_tag( 'td' ) .
120 '<select name="filters_spam_scan_set">'.
10a26cea 121 '<option value=""';
122 if ($filters_spam_scan == '') {
743715c6 123 echo ' selected="selected"';
10a26cea 124 }
125 echo '>' . _("All messages") . '</option>'.
126 '<option value="new"';
127 if ($filters_spam_scan == 'new') {
743715c6 128 echo ' selected="selected"';
10a26cea 129 }
74091b64 130 echo '>' . _("Unread messages only") . '</option>' .
10a26cea 131 '</select>'.
132 '</td>'.
133 '</tr>'.
b01b21d0 134 html_tag( 'tr',
135 html_tag( 'td', '&nbsp;' ) .
136 html_tag( 'td',
74091b64 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.") ,
b01b21d0 138 'left' )
139 );
10a26cea 140
141 $spam_filters = load_spam_filters();
142
143 foreach ($spam_filters as $Key => $Value) {
b01b21d0 144 echo html_tag( 'tr' ) .
c435f076 145 html_tag( 'th', $Key, 'right', '', 'style="white-space: nowrap;"' ) ."\n" .
b01b21d0 146 html_tag( 'td' ) .
0a1dc88e 147 '<input type="checkbox" name="' .
10a26cea 148 $spam_filters[$Key]['prefname'] .
149 '_set"';
150 if ($spam_filters[$Key]['enabled']) {
9374fbf7 151 echo ' checked="checked"';
10a26cea 152 }
0a1dc88e 153 echo ' /> - ';
10a26cea 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 }
b01b21d0 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
10a26cea 169 }
b01b21d0 170 echo html_tag( 'tr',
0a1dc88e 171 html_tag( 'td', '<input type="submit" name="spam_submit" value="' . _("Save") . '" />', 'center', '', 'colspan="2"' )
b01b21d0 172 ) . "\n" .
10a26cea 173 '</table>'.
f265009a 174 '</div>'.
10a26cea 175 '</form>';
0a1dc88e 176} else {
177 // action is not set or action is not spam
b01b21d0 178 echo html_tag( 'p', '', 'center' ) .
179 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
f265009a 180 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</div><br /><br />';
92657342 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>]' ) );
74091b64 182 echo '<br />';
3ee2d2ae 183 printf( _("Spam scan is limited to %s."), '<b>' . ( ($filters_spam_scan == 'new')?_("Unread messages only"):_("All messages") ) . '</b>' );
10a26cea 184 echo '</p>'.
0a1dc88e 185 '<table border="0" cellpadding="3" cellspacing="0" align="center" bgcolor="' . $color[0] . "\">\n";
10a26cea 186
187 $spam_filters = load_spam_filters();
188
189 foreach ($spam_filters as $Key => $Value) {
b01b21d0 190 echo html_tag( 'tr' ) .
191 html_tag( 'th', '', 'center' );
10a26cea 192
193 if ($spam_filters[$Key]['enabled']) {
194 echo _("ON");
195 } else {
196 echo _("OFF");
197 }
198
91e0dccc 199 echo '</th>' .
b01b21d0 200 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
201 html_tag( 'td', '', 'left' );
10a26cea 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}
0a1dc88e 217?>
4b4abf93 218</body></html>