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