This is Philippe Mingo
[squirrelmail.git] / plugins / filters / spamoptions.php
CommitLineData
63277aaa 1<?php
15e6162e 2/**
3 * Message and Spam Filter Plugin
4 *
5 * Copyright (c) 1999-2002 The SquirrelMail Project Team
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$
25 */
63277aaa 26
27 chdir ('..');
28 require_once('../src/validate.php');
29 require_once('../functions/page_header.php');
30 require_once('../functions/imap.php');
31 require_once('../src/load_prefs.php');
32
33 global $AllowSpamFilters;
34
35 displayPageHeader($color, 'None');
36
37 if (isset($spam_submit)) {
38 $spam_filters = load_spam_filters();
39 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
40 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
41 foreach ($spam_filters as $Key => $Value) {
42 $input = $spam_filters[$Key]['prefname'] . '_set';
43 setPref($data_dir, $username, $spam_filters[$Key]['prefname'],
44 $$input);
45 }
46 }
47
48 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
49 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
50 $filters = load_filters();
51
52 echo "<table width=95% align=center border=0 cellpadding=2 cellspacing=0 bgcolor=\"$color[0]\">".
53 '<tr><th align=center>' . _("Spam Filtering") . '</th></tr>'.
54 '</table>';
55
5e2e3895 56 if ($SpamFilters_YourHop == ' ') {
b188caac 57 echo '<BR><center><b>' . _("WARNING! Tell your admin to set the SpamFilters_YourHop variable") . '</b></center><BR>';
5e2e3895 58 }
59
63277aaa 60
61 if (isset($action) && $action == 'spam') {
62 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
63 $boxes = sqimap_mailbox_list($imapConnection);
64 sqimap_logout($imapConnection);
65 for ($i = 0; $i < count($boxes) && $filters_spam_folder == ''; $i++) {
66 if ($boxes[$i]['flags'][0] != 'noselect' &&
67 $boxes[$i]['flags'][1] != 'noselect' &&
68 $boxes[$i]['flags'][2] != 'noselect') {
69 $filters_spam_folder = $boxes[$i]['unformatted'];
70 }
71 }
72
73 echo '<form method=post action="spamoptions.php">'.
74 '<center>'.
75 '<table width=85% cellpadding=2 cellspacing=0 border=0>'.
76 '<tr>'.
77 '<th align=right nowrap>' . _("Move spam to:") . '</th>'.
78 '<td><select name="filters_spam_folder_set">';
79
80 for ($i = 0; $i < count($boxes); $i++) {
81 if (! in_array('noselect', $boxes[$i]['flags'])) {
82 $box = $boxes[$i]['unformatted'];
83 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
84 if ($filters_spam_folder == $box)
85 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
86 else
87 echo "<OPTION VALUE=\"$box\">$box2</OPTION>\n";
88 }
89 }
90 echo '</select>'.
91 '</td>'.
92 '</tr>'.
93 '<tr><td></td><td>' .
94 _("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.") .
95 '</td></tr>'.
96 '<tr>'.
97 '<th align=right nowrap>' . _("What to Scan:") . '</th>'.
98 '<td><select name="filters_spam_scan_set">'.
99 '<option value=""';
100 if ($filters_spam_scan == '')
101 echo ' SELECTED';
102 echo '>' . _("All messages") . '</option>'.
103 '<option value="new"';
104 if ($filters_spam_scan == 'new')
105 echo ' SELECTED';
106 echo '>' . _("Only unread messages") . '</option>' .
107 '</select>'.
108 '</td>'.
109 '</tr>'.
110 '<tr>'.
111 '<td></td><td>'.
112 _("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.").
113 '</td></tr>';
114
115 $spam_filters = load_spam_filters();
116
117 foreach ($spam_filters as $Key => $Value) {
118 echo "<tr><th align=right nowrap>$Key</th>\n" .
119 '<td><input type=checkbox name="' .
120 $spam_filters[$Key]['prefname'] .
121 '_set"';
122 if ($spam_filters[$Key]['enabled'])
123 echo ' CHECKED';
124 echo '> - ';
125 if ($spam_filters[$Key]['link']) {
126 echo '<a href="' .
127 $spam_filters[$Key]['link'] .
128 '" target="_blank">';
129 }
130 echo $spam_filters[$Key]['name'];
131 if ($spam_filters[$Key]['link']) {
132 echo '</a>';
133 }
134 echo '</td></tr><tr><td></td><td>' .
135 $spam_filters[$Key]['comment'] .
136 "</td></tr>\n";
137 }
138 echo '<tr><td colspan=2 align=center><input type=submit name="spam_submit" value="' . _("Save") . '"></td></tr>'.
139 '</table>'.
140 '</center>'.
141 '</form>';
142
63277aaa 143 }
144
145 if (! isset($action) || $action != 'spam') {
146
147 echo '<p align=center>[<a href="spamoptions.php?action=spam">' . _("Edit") . '</a>]' .
148 ' - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br><br>';
149 printf( _("Spam is sent to <b>%s</b>"), ($filters_spam_folder?$filters_spam_folder:_("[<i>not set yet</i>]") ) );
150 echo '<br>';
151 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) );
152 echo '</p>'.
153 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
154
155 $spam_filters = load_spam_filters();
156
157 foreach ($spam_filters as $Key => $Value) {
158 echo '<tr><th align=center>';
159
160 if ($spam_filters[$Key]['enabled']) {
161 echo _("ON");
162 } else {
163 echo _("OFF");
164 }
165
166 echo '</th><td>&nbsp;-&nbsp;</td><td>';
167
168 if ($spam_filters[$Key]['link']) {
169 echo '<a href="' .
170 $spam_filters[$Key]['link'] .
171 '" target="_blank">';
172 }
173
174 echo $spam_filters[$Key]['name'];
175 if ($spam_filters[$Key]['link']) {
176 echo '</a>';
177 }
178 echo "</td></tr>\n";
179 }
180 echo '</table>';
181 }
182
183?>