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