Add closing Body and HTML tags, remove Newlines at end of files (just incase)
[squirrelmail.git] / plugins / filters / spamoptions.php
CommitLineData
63277aaa 1<?php
15e6162e 2/**
3 * Message and Spam Filter Plugin
4 *
76911253 5 * Copyright (c) 1999-2003 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 *
24 * $Id$
ea5f4b8e 25 * @package plugins
26 * @subpackage filters
15e6162e 27 */
63277aaa 28
ea5f4b8e 29/** Path for SquirrelMail required files. */
08185f2a 30define('SM_PATH','../../');
31
32/* SquirrelMail required files. */
fca6d99e 33require_once(SM_PATH . 'include/validate.php');
08185f2a 34require_once(SM_PATH . 'functions/page_header.php');
35require_once(SM_PATH . 'functions/imap.php');
fca6d99e 36require_once(SM_PATH . 'include/load_prefs.php');
08185f2a 37require_once(SM_PATH . 'functions/html.php');
fca6d99e 38require_once(SM_PATH . 'plugins/filters/filters.php');
10a26cea 39global $AllowSpamFilters;
40
3c66c567 41/* get globals */
42sqgetGlobalVar('username', $username, SQ_SESSION);
43sqgetGlobalVar('key', $key, SQ_COOKIE);
44sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
45sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
41100fce 46
3c66c567 47sqgetGlobalVar('action', $action, SQ_GET);
48/* end globals */
41100fce 49
10a26cea 50displayPageHeader($color, 'None');
51
41100fce 52if (isset($_POST['spam_submit'])) {
10a26cea 53 $spam_filters = load_spam_filters();
41100fce 54 setPref($data_dir, $username, 'filters_spam_folder', $_POST['filters_spam_folder_set']);
55 setPref($data_dir, $username, 'filters_spam_scan', $_POST['filters_spam_scan_set']);
10a26cea 56 foreach ($spam_filters as $Key => $Value) {
57 $input = $spam_filters[$Key]['prefname'] . '_set';
41100fce 58 if ( isset( $_POST[$input] ) ) {
10a26cea 59 setPref( $data_dir, $username, $spam_filters[$Key]['prefname'],
41100fce 60 $_POST[$input]);
51199e7a 61 } else {
62 removePref($data_dir, $username, $spam_filters[$Key]['prefname']);
10a26cea 63 }
64 }
65}
66
67$filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
68$filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
69$filters = load_filters();
70
b01b21d0 71echo html_tag( 'table',
72 html_tag( 'tr',
73 html_tag( 'th', _("Spam Filtering"), 'center' )
74 ) ,
75 'center', $color[0], 'width="95%" border="0" cellpadding="2" cellspacing="0"' );
10a26cea 76
77if ($SpamFilters_YourHop == ' ') {
b01b21d0 78 echo '<br>' .
79 html_tag( 'div', '<b>' .
80 _("WARNING! Tell your admin to set the SpamFilters_YourHop variable") .
81 '</b>' ,
82 'center' ) .
83 '<br>';
10a26cea 84}
85
86
87if (isset($action) && $action == 'spam') {
88 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
89 $boxes = sqimap_mailbox_list($imapConnection);
90 sqimap_logout($imapConnection);
ae48f757 91 $numboxes = count($boxes);
92
93 for ($i = 0; $i < $numboxes && $filters_spam_folder == ''; $i++) {
41100fce 94 if ((isset($boxes[$i]['flags'][0]) && $boxes[$i]['flags'][0] != 'noselect') &&
95 (isset($boxes[$i]['flags'][1]) && $boxes[$i]['flags'][1] != 'noselect') &&
96 (isset($boxes[$i]['flags'][2]) && $boxes[$i]['flags'][2] != 'noselect')) {
10a26cea 97 $filters_spam_folder = $boxes[$i]['unformatted'];
98 }
5e2e3895 99 }
100
10a26cea 101 echo '<form method=post action="spamoptions.php">'.
102 '<center>'.
b01b21d0 103 html_tag( 'table', '', '', '', 'width="85%" border="0" cellpadding="2" cellspacing="0"' ) .
104 html_tag( 'tr' ) .
105 html_tag( 'th', _("Move spam to:"), 'right', '', 'nowrap' ) .
106 html_tag( 'td', '', 'left' ) .
107 '<select name="filters_spam_folder_set">';
10a26cea 108
ae8a7931 109 $selected = 0;
110 if ( isset($filters_spam_folder) )
111 $selected = array(strtolower($filters_spam_folder));
112 echo sqimap_mailbox_option_list(0, $selected, 0, $boxes);
10a26cea 113 echo '</select>'.
114 '</td>'.
115 '</tr>'.
b01b21d0 116 html_tag( 'tr',
117 html_tag( 'td', '&nbsp;' ) .
118 html_tag( 'td',
119 _("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.") ,
120 'left' )
121 ) .
122 html_tag( 'tr' ) .
123 html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) .
124 html_tag( 'td' ) .
125 '<select name="filters_spam_scan_set">'.
10a26cea 126 '<option value=""';
127 if ($filters_spam_scan == '') {
128 echo ' SELECTED';
129 }
130 echo '>' . _("All messages") . '</option>'.
131 '<option value="new"';
132 if ($filters_spam_scan == 'new') {
133 echo ' SELECTED';
134 }
135 echo '>' . _("Only unread messages") . '</option>' .
136 '</select>'.
137 '</td>'.
138 '</tr>'.
b01b21d0 139 html_tag( 'tr',
140 html_tag( 'td', '&nbsp;' ) .
141 html_tag( 'td',
142 _("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.") ,
143 'left' )
144 );
10a26cea 145
146 $spam_filters = load_spam_filters();
147
148 foreach ($spam_filters as $Key => $Value) {
b01b21d0 149 echo html_tag( 'tr' ) .
150 html_tag( 'th', $Key, 'right', '', 'nowrap' ) ."\n" .
151 html_tag( 'td' ) .
152 '<input type=checkbox name="' .
10a26cea 153 $spam_filters[$Key]['prefname'] .
154 '_set"';
155 if ($spam_filters[$Key]['enabled']) {
156 echo ' CHECKED';
157 }
158 echo '> - ';
159 if ($spam_filters[$Key]['link']) {
160 echo '<a href="' .
161 $spam_filters[$Key]['link'] .
162 '" target="_blank">';
163 }
164 echo $spam_filters[$Key]['name'];
165 if ($spam_filters[$Key]['link']) {
166 echo '</a>';
167 }
b01b21d0 168 echo '</td></tr>' .
169 html_tag( 'tr',
170 html_tag( 'td', '&nbsp;' ) .
171 html_tag( 'td', $spam_filters[$Key]['comment'], 'left' )
172 ) . "\n";
173
10a26cea 174 }
b01b21d0 175 echo html_tag( 'tr',
176 html_tag( 'td', '<input type=submit name="spam_submit" value="' . _("Save") . '">', 'center', '', 'colspan="2"' )
177 ) . "\n" .
10a26cea 178 '</table>'.
179 '</center>'.
180 '</form>';
c528d955 181 echo '</body></html>';
10a26cea 182}
183
41100fce 184if (! isset($_GET['action']) || $_GET['action'] != 'spam') {
10a26cea 185
b01b21d0 186 echo html_tag( 'p', '', 'center' ) .
187 '[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
10a26cea 188 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br><br>';
189 printf( _("Spam is sent to <b>%s</b>"), ($filters_spam_folder?$filters_spam_folder:_("[<i>not set yet</i>]") ) );
190 echo '<br>';
191 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) );
192 echo '</p>'.
193 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
194
195 $spam_filters = load_spam_filters();
196
197 foreach ($spam_filters as $Key => $Value) {
b01b21d0 198 echo html_tag( 'tr' ) .
199 html_tag( 'th', '', 'center' );
10a26cea 200
201 if ($spam_filters[$Key]['enabled']) {
202 echo _("ON");
203 } else {
204 echo _("OFF");
205 }
206
b01b21d0 207 echo '</th>' .
208 html_tag( 'td', '&nbsp;-&nbsp;', 'left' ) .
209 html_tag( 'td', '', 'left' );
10a26cea 210
211 if ($spam_filters[$Key]['link']) {
212 echo '<a href="' .
213 $spam_filters[$Key]['link'] .
214 '" target="_blank">';
215 }
216
217 echo $spam_filters[$Key]['name'];
218 if ($spam_filters[$Key]['link']) {
219 echo '</a>';
220 }
221 echo "</td></tr>\n";
222 }
223 echo '</table>';
c528d955 224 echo '</body></html>';
10a26cea 225}
63277aaa 226
c528d955 227?>