removing gifs. system uses png images.
[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
41100fce 55if (isset($_POST['spam_submit'])) {
10a26cea 56 $spam_filters = load_spam_filters();
41100fce 57 setPref($data_dir, $username, 'filters_spam_folder', $_POST['filters_spam_folder_set']);
58 setPref($data_dir, $username, 'filters_spam_scan', $_POST['filters_spam_scan_set']);
10a26cea 59 foreach ($spam_filters as $Key => $Value) {
60 $input = $spam_filters[$Key]['prefname'] . '_set';
41100fce 61 if ( isset( $_POST[$input] ) ) {
10a26cea 62 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],
41100fce 63 $_POST[$input]);
51199e7a 64 } else {
65 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
10a26cea 66 }
67 }
68}
69
70$filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
71$filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
72$filters = load_filters();
73
b01b21d0 74echo html_tag( 'table',
75 html_tag( 'tr',
76 html_tag( 'th', _("Spam Filtering"), 'center' )
77 ) ,
78 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
10a26cea 79
80if ($SpamFilters_YourHop == ' ') {
b01b21d0 81 echo '<br>' .
82 html_tag( 'div', '<b>' .
83 _("WARNING! Tell your admin to set the SpamFilters_YourHop variable") .
84 '</b>' ,
85 'center' ) .
86 '<br>';
10a26cea 87}
88
89
90if (isset($action) && $action == 'spam') {
91 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
92 $boxes = sqimap_mailbox_list($imapConnection);
93 sqimap_logout($imapConnection);
ae48f757 94 $numboxes = count($boxes);
95
96 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
41100fce 97 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
98 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
99 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
10a26cea 100 $filters_spam_folder = $boxes[$i]['unformatted'];
101 }
5e2e3895 102 }
103
10a26cea 104 echo '<form method=post action="spamoptions.php">'.
105 '<center>'.
b01b21d0 106 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
107 html_tag( 'tr' ) .
108 html_tag( 'th', _("Move spam to:"), 'right', '', 'nowrap' ) .
109 html_tag( 'td', '', 'left' ) .
110 '<select name="filters_spam_folder_set">';
10a26cea 111
ae8a7931 112 $selected = 0;
113 if ( isset($filters_spam_folder) )
114 $selected = array(strtolower($filters_spam_folder));
115 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
10a26cea 116 echo '</select>'.
117 '</td>'.
118 '</tr>'.
b01b21d0 119 html_tag( 'tr',
120 html_tag( 'td', '&nbsp;' ) .
121 html_tag( 'td',
122 _("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.") ,
123 'left' )
124 ) .
125 html_tag( 'tr' ) .
126 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
127 html_tag( 'td' ) .
128 '<select name="filters_spam_scan_set">'.
10a26cea 129 '<option value=""';
130 if ($filters_spam_scan == '') {
131 echo ' SELECTED';
132 }
133 echo '>' . _("All messages") . '</option>'.
134 '<option value="new"';
135 if ($filters_spam_scan == 'new') {
136 echo ' SELECTED';
137 }
138 echo '>' . _("Only unread messages") . '</option>' .
139 '</select>'.
140 '</td>'.
141 '</tr>'.
b01b21d0 142 html_tag( 'tr',
143 html_tag( 'td', '&nbsp;' ) .
144 html_tag( 'td',
145 _("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.") ,
146 'left' )
147 );
10a26cea 148
149 $spam_filters = load_spam_filters();
150
151 foreach ($spam_filters as $Key => $Value) {
b01b21d0 152 echo html_tag( 'tr' ) .
153 html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
154 html_tag( 'td' ) .
155 '<input type=checkbox name="' .
10a26cea 156 $spam_filters[$Key]['prefname'] .
157 '_set"';
158 if ($spam_filters[$Key]['enabled']) {
159 echo ' CHECKED';
160 }
161 echo '> - ';
162 if ($spam_filters[$Key]['link']) {
163 echo '<a href="' .
164 $spam_filters[$Key]['link'] .
165 '" target="_blank">';
166 }
167 echo $spam_filters[$Key]['name'];
168 if ($spam_filters[$Key]['link']) {
169 echo '</a>';
170 }
b01b21d0 171 echo '</td></tr>' .
172 html_tag( 'tr',
173 html_tag( 'td', '&nbsp;' ) .
174 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
175 ) . "\n";
176
10a26cea 177 }
b01b21d0 178 echo html_tag( 'tr',
179 html_tag( 'td', '<input type=submit name="spam_submit" value="' . _("Save") . '">', 'center', '', 'colspan="2"' )
180 ) . "\n" .
10a26cea 181 '</table>'.
182 '</center>'.
183 '</form>';
dcc1cc82 184 echo '</body></html>';
10a26cea 185}
186
41100fce 187if (! isset($_GET['action']) || $_GET['action'] != 'spam') {
10a26cea 188
b01b21d0 189 echo html_tag( 'p', '', 'center' ) .
190 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
10a26cea 191 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br><br>';
192 printf( _("Spam is sent to <b>%s</b>"), ($filters_spam_folder?$filters_spam_folder:_("[<i>not set yet</i>]") ) );
193 echo '<br>';
194 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) );
195 echo '</p>'.
196 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
197
198 $spam_filters = load_spam_filters();
199
200 foreach ($spam_filters as $Key => $Value) {
b01b21d0 201 echo html_tag( 'tr' ) .
202 html_tag( 'th', '', 'center' );
10a26cea 203
204 if ($spam_filters[$Key]['enabled']) {
205 echo _("ON");
206 } else {
207 echo _("OFF");
208 }
209
b01b21d0 210 echo '</th>' .
211 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
212 html_tag( 'td', '', 'left' );
10a26cea 213
214 if ($spam_filters[$Key]['link']) {
215 echo '<a href="' .
216 $spam_filters[$Key]['link'] .
217 '" target="_blank">';
218 }
219
220 echo $spam_filters[$Key]['name'];
221 if ($spam_filters[$Key]['link']) {
222 echo '</a>';
223 }
224 echo "</td></tr>\n";
225 }
226 echo '</table>';
dcc1cc82 227 echo '</body></html>';
10a26cea 228}
63277aaa 229
c528d955 230?>