Added new config flag 'allow_charset_search' for those unfortunate using
[squirrelmail.git] / plugins / filters / options.php
1 <?php
2
3 /**
4 * Message and Spam Filter Plugin
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file 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 * $Id$
26 */
27
28 chdir ('..');
29 require_once('../src/validate.php');
30 require_once('../functions/page_header.php');
31 require_once('../functions/imap.php');
32 require_once('../src/load_prefs.php');
33
34 global $AllowSpamFilters;
35
36 displayPageHeader($color, 'None');
37
38 if (isset($filter_submit)) {
39 if (!isset($theid)) $theid = 0;
40 $filter_what = ereg_replace(",", " ", $filter_what);
41 $filter_what = str_replace("\\\\", "\\", $filter_what);
42 $filter_what = str_replace("\\\"", "\"", $filter_what);
43 $filter_what = str_replace("\"", "&quot;", $filter_what);
44
45 if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) {
46 print ('WARNING! Header filters should be of the format "Header: value"<BR>');
47 $action = 'edit';
48 }
49 setPref($data_dir, $username, "filter".$theid, $filter_where.",".$filter_what.",".$filter_folder);
50 $filters[$theid]["where"] = $filter_where;
51 $filters[$theid]["what"] = $filter_what;
52 $filters[$theid]["folder"] = $filter_folder;
53 } elseif (isset($action) && $action == 'delete') {
54 remove_filter($theid);
55 } elseif (isset($action) && $action == 'move_up') {
56 filter_swap($theid, $theid - 1);
57 } elseif (isset($action) && $action == 'move_down') {
58 filter_swap($theid, $theid + 1);
59 } elseif (isset($user_submit)) {
60 echo "<br><center><b>"._("Saved Scan type")."</b></center>\n";
61 setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set);
62 }
63
64 $filters = load_filters();
65 $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan');
66
67 echo '<br>' .
68 '<table width=95% align=center border=0 cellpadding=2 cellspacing=0>'.
69 "<tr><td bgcolor=\"$color[0]\">".
70 '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>'.
71 '</td></tr></table>'.
72
73 '<br><form method=post action="options.php">'.
74 '<center>'.
75 '<table cellpadding=2 cellspacing=0 border=0>'.
76 '<tr>'.
77 '<th align=right nowrap>' . _("What to Scan:") . '</th>'.
78 '<td><select name="filters_user_scan_set">'.
79 '<option value=""';
80 if ($filters_user_scan == '') {
81 echo ' SELECTED';
82 }
83 echo '>' . _("All messages") . '</option>'.
84 '<option value="new"';
85 if ($filters_user_scan == 'new') {
86 echo ' SELECTED';
87 }
88 echo '>' . _("Only unread messages") . '</option>' .
89 '</select>'.
90 '</td>'.
91 '<td><input type=submit name="user_submit" value="' . _("Save") . '"></td></tr>'.
92 '</table>'.
93 '</center>'.
94 '</form>'.
95
96 '<center>[<a href="options.php?action=add">' . _("New") .
97 '</a>] - [<a href="../../src/options.php">' . _("Done") . '</a>]</center><br>';
98
99 if (isset($action) && ($action == 'add' || $action == 'edit')) {
100 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
101 $boxes = sqimap_mailbox_list($imapConnection);
102 sqimap_logout($imapConnection);
103 if ( !isset($theid) ) {
104 $theid = count($filters);
105 }
106 echo '<center>'.
107 '<form action="options.php" method=post>'.
108 '<table cellpadding=2 cellspacing=0 border=0>'.
109 '<tr>'.
110 '<td>' . _("Match:") . '</td>'.
111 '<td>'.
112 '<select name=filter_where>';
113
114 $L = isset($filters[$theid]['where']);
115
116 $sel = (($L && $filters[$theid]['where'] == 'From')?'selected':'');
117 echo "<option value=\"From\" $sel>" . _ ("From") . '</option>';
118
119 $sel = (($L && $filters[$theid]['where'] == 'To')?'selected':'');
120 echo "<option value=\"To\" $sel>" . _ ("To") . '</option>';
121
122 $sel = (($L && $filters[$theid]['where'] == 'Cc')?'selected':'');
123 echo "<option value=\"Cc\" $sel>" . _ ("Cc") . '</option>';
124
125 $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?'selected':'');
126 echo "<option value=\"To or Cc\" $sel>" . _ ("To or Cc") . '</option>';
127
128 $sel = (($L && $filters[$theid]['where'] == 'Subject')?'selected':'');
129 echo "<option value=\"Subject\" $sel>" . _ ("Subject") . '</option>';
130
131 $sel = (($L && $filters[$theid]['where'] == 'Header')?'selected':'');
132 echo "<option value=\"Header\" $sel>" . _ ("Header") . '</option>';
133
134 echo '</select>'.
135 '</td>'.
136 '</tr>'.
137 '<tr>'.
138 '<td align=right>'.
139 _("Contains:").
140 '</td>'.
141 '<td>'.
142 '<input type=text size=32 name=filter_what value="';
143 if (isset($filters[$theid]['what'])) {
144 echo $filters[$theid]["what"];
145 }
146 echo '">'.
147 '</td>'.
148 '</tr>'.
149 '<tr>'.
150 '<td>'.
151 _("Move to:").
152 '</td>'.
153 '<td>'.
154 '<tt>'.
155 '<select name=filter_folder>';
156
157 for ($i = 0; $i < count($boxes); $i++) {
158 if (! in_array('noselect', $boxes[$i]['flags'])) {
159 $box = $boxes[$i]['unformatted'];
160 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
161 if (isset($filters[$theid]['folder']) &&
162 $filters[$theid]['folder'] == $box)
163 echo "<OPTION VALUE=\"$box\" SELECTED>$box2</option>";
164 else
165 echo "<OPTION VALUE=\"$box\">$box2</option>";
166 }
167 }
168 echo '</tt>'.
169 '</select>'.
170 '</td>'.
171 '</tr>'.
172 '</table>'.
173 '<input type=submit name=filter_submit value=' . _("Submit") . '>'.
174 "<input type=hidden name=theid value=$theid>".
175 '</form>'.
176 '</center>';
177
178 }
179
180 echo '<table border=0 cellpadding=3 cellspacing=0 align=center>';
181
182 for ($i=0; $i < count($filters); $i++) {
183
184 $clr = (($i % 2)?$color[0]:$color[9]);
185 $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"];
186 echo "<tr bgcolor=\"$clr\"><td><small>".
187 "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'.
188 '</small></td><td><small>'.
189 "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'.
190 '</small></td><td align=center><small>[';
191
192 if (isset($filters[$i + 1])) {
193 echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>';
194 if ($i > 0) {
195 echo '&nbsp;|&nbsp;';
196 }
197 }
198 if ($i > 0) {
199 echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>';
200 }
201 echo ']</small></td><td>-</td><td>';
202 printf( _("If <b>%s</b> contains <b>%s</b> then move to <b>%s</b>"), _($filters[$i]['where']), $filters[$i]['what'], $fdr );
203 echo '</td></tr>';
204
205 }
206 echo '</table>'.
207 '<table width=80% align=center border=0 cellpadding=2 cellspacing=0">'.
208 '<tr><td>&nbsp</td></tr>'.
209 '</table>';
210
211 ?>