Internationalization of the filter plugin.
[squirrelmail.git] / plugins / filters / options.php
1 <?php
2 /*
3 * Message and Spam Filter Plugin
4 * By Luke Ehresman <luke@squirrelmail.org>
5 * Tyler Akins
6 * Brent Bice
7 * (c) 2000 (GNU GPL - see ../../COPYING)
8 *
9 * This plugin filters your inbox into different folders based upon given
10 * criteria. It is most useful for people who are subscibed to mailing lists
11 * to help organize their messages. The argument stands that filtering is
12 * not the place of the client, which is why this has been made a plugin for
13 * SquirrelMail. You may be better off using products such as Sieve or
14 * Procmail to do your filtering so it happens even when SquirrelMail isn't
15 * running.
16 *
17 * If you need help with this, or see improvements that can be made, please
18 * email me directly at the address above. I definately welcome suggestions
19 * and comments. This plugin, as is the case with all SquirrelMail plugins,
20 * is not directly supported by the developers. Please come to me off the
21 * mailing list if you have trouble with it.
22 *
23 * Also view plugins/README.plugins for more information.
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($filter_submit)) {
37 if (!isset($theid)) $theid = 0;
38 $filter_what = str_replace(',', ' ', $filter_what);
39 $filter_what = str_replace("\\\\", "\\", $filter_what);
40 $filter_what = str_replace("\\\"", "\"", $filter_what);
41 $filter_what = str_replace("\"", "&quot;", $filter_what);
42
43 setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder);
44 $filters[$theid]['where'] = $filter_where;
45 $filters[$theid]['what'] = $filter_what;
46 $filters[$theid]['folder'] = $filter_folder;
47 } elseif (isset($spam_submit) && $AllowSpamFilters) {
48 $spam_filters = load_spam_filters();
49 setPref($data_dir, $username, 'filters_spam_folder', $filters_spam_folder_set);
50 setPref($data_dir, $username, 'filters_spam_scan', $filters_spam_scan_set);
51 foreach ($spam_filters as $Key => $Value)
52 {
53 $input = $spam_filters[$Key]['prefname'] . '_set';
54 setPref($data_dir, $username, $spam_filters[$Key]['prefname'],
55 $$input);
56 }
57 } elseif (isset($action) && $action == 'delete') {
58 remove_filter($theid);
59 } elseif (isset($action) && $action == 'move_up') {
60 filter_swap($theid, $theid - 1);
61 } elseif (isset($action) && $action == 'move_down') {
62 filter_swap($theid, $theid + 1);
63 }
64
65 if ($AllowSpamFilters) {
66 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
67 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
68 }
69 $filters = load_filters();
70
71 echo '<br>' .
72 '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'.
73 "<tr><td bgcolor=\"$color[0]\">".
74 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'.
75 '</td></tr></table>'.
76 '<br><center>[<a href="options.php?action=add">' . _("New") .
77 '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br>' .
78 '<table border=0 cellpadding=3 cellspacing=0 align=center>';
79
80 for ($i=0; $i < count($filters); $i++) {
81 if ($i % 2 == 0) {
82 $clr = $color[0];
83 } else {
84 $clr = $color[9];
85 }
86
87 $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
88
89 echo "<tr bgcolor=\"$clr\"><td><small>".
90 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
91 '</small></td><td><small>'.
92 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
93 '</small></td><td align=center><small>';
94
95 if (isset($filters[$i + 1])) {
96 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
97 if ($i > 0) {
98 echo ' | ';
99 }
100 }
101 if ($i > 0) {
102 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
103 }
104 echo ']</small></td><td> - ';
105 printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), $filters[$i]['where'], $filters[$i]['what'], $fdr );
106 echo '</td></tr>';
107
108 }
109
110 echo '</table>'.
111 '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
112 '<tr><td>&nbsp</td></tr>'.
113 '</table>';
114
115 if ($AllowSpamFilters) {
116
117 echo "<table width=95% align=center border=0 cellpadding=2 cellspacing=0 bgcolor=\"$color[0]\">".
118 '<tr><th align=center>' . _("Spam Filtering") . '</th></tr>'.
119 '</table>';
120 if (! isset($action) || $action != 'spam') {
121
122 echo '<p align=center>[<a href="options.php?action=spam">' . _("Edit") . '</a>]<br>';
123 printf( _("Spam is sent to <b>%s</b>"), ($filters_spam_folder?$filters_spam_folder:_("[<i>not set yet</i>]") ) );
124 echo '<br>';
125 printf( _("Spam scan is limited to <b>%s</b>"), (($filters_spam_scan == 'new')?_("New Messages Only"):_("All Messages") ) );
126 echo '</p>'.
127 "<table border=0 cellpadding=3 cellspacing=0 align=center bgcolor=\"$color[0]\">";
128
129 $spam_filters = load_spam_filters();
130
131 foreach ($spam_filters as $Key => $Value) {
132 echo '<tr><th align=center>';
133
134 if ($spam_filters[$Key]['enabled']) {
135 echo _("ON");
136 } else {
137 echo _("OFF");
138 }
139
140 echo '</th><td>&nbsp;-&nbsp;</td><td>';
141
142 if ($spam_filters[$Key]['link']) {
143 echo '<a href="' .
144 $spam_filters[$Key]['link'] .
145 '" target="_blank">';
146 }
147
148 echo $spam_filters[$Key]['name'];
149 if ($spam_filters[$Key]['link']) {
150 echo '</a>';
151 }
152 echo "</td></tr>\n";
153 }
154 echo '</table>';
155 }
156 }
157
158 if (isset($action) && ($action == 'add' || $action == 'edit')) {
159 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
160 $boxes = sqimap_mailbox_list($imapConnection);
161 sqimap_logout($imapConnection);
162 if ( !isset($theid) ) {
163 $theid = count($filters);
164 }
165 echo '<center>'.
166 '<form action="options.php" method=post>'.
167 '<br><table cellpadding=2 cellspacing=0 border=0>'.
168 '<tr>'.
169 '<td>&nbsp;</td>'.
170 '<td>'.
171 '<select name=filter_where>';
172
173 $L = isset($filters[$theid]['where']);
174
175 $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
176 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
177
178 $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
179 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
180
181 $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
182 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
183
184 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
185 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
186
187 $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
188 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
189
190 echo '</select>'.
191 '</td>'.
192 '</tr>'.
193 '<tr>'.
194 '<td align=right>'.
195 _("Contains:").
196 '</td>'.
197 '<td>'.
198 '<input type=text size=32 name=filter_what value="';
199 if (isset($filters[$theid]['what'])) {
200 echo $filters[$theid]["what"];
201 }
202 echo '">'.
203 '</td>'.
204 '</tr>'.
205 '<tr>'.
206 '<td>'.
207 _("Move to:").
208 '</td>'.
209 '<td>'.
210 '<tt>'.
211 '<select name=filter_folder>';
212
213 for ($i = 0; $i < count($boxes); $i++) {
214 if (! in_array('noselect', $boxes[$i]['flags'])) {
215 $box = $boxes[$i]['unformatted'];
216 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
217 if (isset($filters[$theid]['folder']) &&
218 $filters[$theid]['folder'] == $box)
219 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
220 else
221 echo "<OPTION VALUE=\"$box\">$box2</option>";
222 }
223 }
224 echo '</tt>'.
225 '</select>'.
226 '</td>'.
227 '</tr>'.
228 '</table>'.
229 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
230 "<input type=hidden name=theid value=$theid>".
231 '</form>'.
232 '</center>';
233
234 } else if (isset($action) && $action == 'spam' && $AllowSpamFilters) {
235 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
236 $boxes = sqimap_mailbox_list($imapConnection);
237 sqimap_logout($imapConnection);
238 for ($i = 0; $i < count($boxes) && $filters_spam_folder == ''; $i++) {
239 if ($boxes[$i]['flags'][0] != 'noselect' &&
240 $boxes[$i]['flags'][1] != 'noselect' &&
241 $boxes[$i]['flags'][2] != 'noselect') {
242 $filters_spam_folder = $boxes[$i]['unformatted'];
243 }
244 }
245
246 echo '<form method=post action="options.php">'.
247 '<center>'.
248 '<table width=85% cellpadding=2 cellspacing=0 border=0>'.
249 '<tr>'.
250 '<th align=right nowrap>' . _("Move spam to:") . '</th>'.
251 '<td><select name="filters_spam_folder_set">';
252
253 for ($i = 0; $i < count($boxes); $i++) {
254 if (! in_array('noselect', $boxes[$i]['flags'])) {
255 $box = $boxes[$i]['unformatted'];
256 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
257 if ($filters_spam_folder == $box)
258 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
259 else
260 echo "<OPTION VALUE=\"$box\">$box2</OPTION>\n";
261 }
262 }
263 echo '</select>'.
264 '</td>'.
265 '</tr>'.
266 '<tr><td></td><td>' .
267 _("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.") .
268 '</td></tr>'.
269 '<tr>'.
270 '<th align=right nowrap>' . _("What to Scan:") . '</th>'.
271 '<td><select name="filters_spam_scan_set">'.
272 '<option value=""';
273 if ($filters_spam_scan == '')
274 echo ' SELECTED';
275 echo '>' . _("All messages") . '</option>'.
276 '<option value="new"';
277 if ($filters_spam_scan == 'new')
278 echo ' SELECTED';
279 echo '>' . _("Only unread messages") . '</option>' .
280 '</select>'.
281 '</td>'.
282 '</tr>'.
283 '<tr>'.
284 '<td></td><td>'.
285 _("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.").
286 '</td></tr>';
287
288 $spam_filters = load_spam_filters();
289
290 foreach ($spam_filters as $Key => $Value) {
291 echo "<tr><th align=right nowrap>$Key</th>\n" .
292 '<td><input type=checkbox name="' .
293 $spam_filters[$Key]['prefname'] .
294 '_set"';
295 if ($spam_filters[$Key]['enabled'])
296 echo ' CHECKED';
297 echo '> - ';
298 if ($spam_filters[$Key]['link']) {
299 echo '<a href="' .
300 $spam_filters[$Key]['link'] .
301 '" target="_blank">';
302 }
303 echo $spam_filters[$Key]['name'];
304 if ($spam_filters[$Key]['link']) {
305 echo '</a>';
306 }
307 echo '</td></tr><tr><td></td><td>' .
308 $spam_filters[$Key]['comment'] .
309 "</td></tr>\n";
310 }
311 echo '<tr><td colspan=2 align=center><input type=submit name="spam_submit" value="' . _("Save") . '"></td></tr>'.
312 '</table>'.
313 '</center>'.
314 '</form>';
315
316 sqimap_logout($imapConnection);
317 }
318 ?>