849bdf42 |
1 | <?php |
15e6162e |
2 | /** |
0a1dc88e |
3 | * Message and Spam Filter Plugin - Filtering Options |
15e6162e |
4 | * |
15e6162e |
5 | * This plugin filters your inbox into different folders based upon given |
6 | * criteria. It is most useful for people who are subscibed to mailing lists |
7 | * to help organize their messages. The argument stands that filtering is |
8 | * not the place of the client, which is why this has been made a plugin for |
9 | * SquirrelMail. You may be better off using products such as Sieve or |
10 | * Procmail to do your filtering so it happens even when SquirrelMail isn't |
11 | * running. |
12 | * |
13 | * If you need help with this, or see improvements that can be made, please |
14 | * email me directly at the address above. I definately welcome suggestions |
15 | * and comments. This plugin, as is the case with all SquirrelMail plugins, |
16 | * is not directly supported by the developers. Please come to me off the |
17 | * mailing list if you have trouble with it. |
18 | * |
19 | * Also view plugins/README.plugins for more information. |
20 | * |
5b4ba967 |
21 | * @version $Id$ |
b2d8bc6c |
22 | * @copyright (c) 1999-2004 The SquirrelMail Project Team |
23 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
ea5f4b8e |
24 | * @package plugins |
25 | * @subpackage filters |
15e6162e |
26 | */ |
4eee5968 |
27 | |
5b4ba967 |
28 | /** |
29 | * Path for SquirrelMail required files. |
30 | * @ignore |
31 | */ |
08185f2a |
32 | define('SM_PATH','../../'); |
33 | |
34 | /* SquirrelMail required files. */ |
fca6d99e |
35 | require_once(SM_PATH . 'include/validate.php'); |
08185f2a |
36 | require_once(SM_PATH . 'functions/page_header.php'); |
37 | require_once(SM_PATH . 'functions/imap.php'); |
81f652a1 |
38 | require_once(SM_PATH . 'functions/imap_mailbox.php'); |
fca6d99e |
39 | require_once(SM_PATH . 'include/load_prefs.php'); |
a9e1e670 |
40 | require_once(SM_PATH . 'functions/forms.php'); |
fca6d99e |
41 | require_once(SM_PATH . 'plugins/filters/filters.php'); |
849bdf42 |
42 | |
3c66c567 |
43 | global $AllowSpamFilters; |
849bdf42 |
44 | |
3c66c567 |
45 | displayPageHeader($color, 'None'); |
849bdf42 |
46 | |
3c66c567 |
47 | /* get globals */ |
48 | sqgetGlobalVar('username', $username, SQ_SESSION); |
49 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
50 | sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); |
51 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
52 | |
53 | sqgetGlobalVar('theid', $theid); |
54 | sqgetGlobalVar('action', $action, SQ_GET); |
55 | |
0a1dc88e |
56 | if (sqgetGlobalVar('filter_submit',$filter_submit,SQ_POST)) { |
57 | |
58 | if(! isset($theid) ) $theid = 0; |
59 | |
60 | $complete_post=true; |
61 | |
62 | // FIXME: write human readable error messages |
63 | sqgetGlobalVar('filter_what', $filter_what, SQ_POST); |
64 | if (!sqgetGlobalVar('filter_what', $filter_what, SQ_POST)) { |
3b94163a |
65 | do_error("Post error"); |
66 | $complete_post=false; |
0a1dc88e |
67 | } |
68 | |
69 | sqgetGlobalVar('filter_where', $filter_where, SQ_POST); |
70 | if (!sqgetGlobalVar('filter_where', $filter_where, SQ_POST)) { |
3b94163a |
71 | do_error("Post error"); |
72 | $complete_post=false; |
0a1dc88e |
73 | } |
74 | |
75 | sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST); |
76 | if (!sqgetGlobalVar('filter_folder', $filter_folder, SQ_POST)) { |
3b94163a |
77 | do_error("Post error"); |
78 | $complete_post=false; |
0a1dc88e |
79 | } |
80 | |
81 | if ($complete_post) { |
3b94163a |
82 | $filter_what = str_replace(',', ' ', $filter_what); |
0a1dc88e |
83 | $filter_what = str_replace("\\\\", "\\", $filter_what); |
84 | $filter_what = str_replace("\\\"", '"', $filter_what); |
85 | $filter_what = str_replace('"', '"', $filter_what); |
86 | |
87 | if (($filter_where == 'Header') && (strchr($filter_what,':') == '')) { |
3b94163a |
88 | do_error(_("WARNING! Header filters should be of the format "Header: value"")); |
89 | $action = 'edit'; |
90 | } |
91 | setPref($data_dir, $username, 'filter'.$theid, $filter_where.','.$filter_what.','.$filter_folder); |
92 | $filters[$theid]['where'] = $filter_where; |
93 | $filters[$theid]['what'] = $filter_what; |
94 | $filters[$theid]['folder'] = $filter_folder; |
0a1dc88e |
95 | } |
3b94163a |
96 | } elseif (isset($action) && $action == 'delete') { |
849bdf42 |
97 | remove_filter($theid); |
3b94163a |
98 | } elseif (isset($action) && $action == 'move_up') { |
849bdf42 |
99 | filter_swap($theid, $theid - 1); |
3b94163a |
100 | } elseif (isset($action) && $action == 'move_down') { |
849bdf42 |
101 | filter_swap($theid, $theid + 1); |
3b94163a |
102 | } elseif (sqgetGlobalVar('user_submit',$user_submit,SQ_POST)) { |
103 | sqgetGlobalVar('filters_user_scan_set',$filters_user_scan_set,SQ_POST); |
104 | setPref($data_dir, $username, 'filters_user_scan', $filters_user_scan_set); |
105 | echo '<br /><center><b>'._("Saved Scan type")."</b></center>\n"; |
106 | } |
849bdf42 |
107 | |
849bdf42 |
108 | $filters = load_filters(); |
c8a2c24d |
109 | $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan'); |
849bdf42 |
110 | |
6206f6c4 |
111 | echo html_tag( 'table', |
b01b21d0 |
112 | html_tag( 'tr', |
113 | html_tag( 'td', |
3b94163a |
114 | '<center><b>' . _("Options") . ' - ' . _("Message Filtering") . '</b></center>' , |
115 | 'left', $color[0] |
116 | ) |
117 | ), |
118 | 'center', '', 'width="95%" border="0" cellpadding="2" cellspacing="0"' |
119 | ) . |
0a1dc88e |
120 | '<br /><form method="post" action="options.php">'. |
c8a2c24d |
121 | '<center>'. |
831a25d5 |
122 | html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) . |
b01b21d0 |
123 | html_tag( 'tr' ) . |
124 | html_tag( 'th', _("What to Scan:"), 'right', '', 'nowrap' ) . |
125 | html_tag( 'td', '', 'left' ) . |
126 | '<select name="filters_user_scan_set">'. |
c8a2c24d |
127 | '<option value=""'; |
128 | if ($filters_user_scan == '') { |
e1728a7a |
129 | echo ' selected="selected"'; |
c8a2c24d |
130 | } |
131 | echo '>' . _("All messages") . '</option>'. |
132 | '<option value="new"'; |
133 | if ($filters_user_scan == 'new') { |
e1728a7a |
134 | echo ' selected="selected"'; |
c8a2c24d |
135 | } |
136 | echo '>' . _("Only unread messages") . '</option>' . |
137 | '</select>'. |
138 | '</td>'. |
0a1dc88e |
139 | html_tag( 'td', '<input type="submit" name="user_submit" value="' . _("Save") . '" />', 'left' ) . |
c8a2c24d |
140 | '</table>'. |
141 | '</center>'. |
142 | '</form>'. |
143 | |
b01b21d0 |
144 | html_tag( 'div', '[<a href="options.php?action=add">' . _("New") . |
81f652a1 |
145 | '</a>] - [<a href="'.SM_PATH.'src/options.php">' . _("Done") . '</a>]' , |
0a1dc88e |
146 | 'center' ) . '<br />'; |
0e838332 |
147 | |
3fd1252d |
148 | if (isset($action) && ($action == 'add' || $action == 'edit')) { |
41100fce |
149 | |
3fd1252d |
150 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
151 | $boxes = sqimap_mailbox_list($imapConnection); |
152 | sqimap_logout($imapConnection); |
153 | if ( !isset($theid) ) { |
849bdf42 |
154 | $theid = count($filters); |
3fd1252d |
155 | } |
b01b21d0 |
156 | echo html_tag( 'div', '', 'center' ) . |
0a1dc88e |
157 | '<form action="options.php" method="post">'. |
831a25d5 |
158 | html_tag( 'table', '', '', '', 'border="0" cellpadding="2" cellspacing="0"' ) . |
b01b21d0 |
159 | html_tag( 'tr' ) . |
160 | html_tag( 'td', _("Match:"), 'left' ) . |
161 | html_tag( 'td', '', 'left' ) . |
0a1dc88e |
162 | '<select name="filter_where">'; |
849bdf42 |
163 | |
3fd1252d |
164 | $L = isset($filters[$theid]['where']); |
165 | |
e1728a7a |
166 | $sel = (($L && $filters[$theid]['where'] == 'From')?' selected="selected"':''); |
167 | echo "<option value=\"From\"$sel>" . _("From") . '</option>'; |
4eee5968 |
168 | |
e1728a7a |
169 | $sel = (($L && $filters[$theid]['where'] == 'To')?' selected="selected"':''); |
170 | echo "<option value=\"To\"$sel>" . _("To") . '</option>'; |
3fd1252d |
171 | |
e1728a7a |
172 | $sel = (($L && $filters[$theid]['where'] == 'Cc')?' selected="selected"':''); |
173 | echo "<option value=\"Cc\"$sel>" . _("Cc") . '</option>'; |
3fd1252d |
174 | |
e1728a7a |
175 | $sel = (($L && $filters[$theid]['where'] == 'To or Cc')?' selected="selected"':''); |
176 | echo "<option value=\"To or Cc\"$sel>" . _("To or Cc") . '</option>'; |
3fd1252d |
177 | |
e1728a7a |
178 | $sel = (($L && $filters[$theid]['where'] == 'Subject')?' selected="selected"':''); |
179 | echo "<option value=\"Subject\"$sel>" . _("Subject") . '</option>'; |
3fd1252d |
180 | |
e1728a7a |
181 | $sel = (($L && $filters[$theid]['where'] == 'Header')?' selected="selected"':''); |
182 | echo "<option value=\"Header\"$sel>" . _("Header") . '</option>'; |
9da6bdde |
183 | |
3fd1252d |
184 | echo '</select>'. |
4eee5968 |
185 | '</td>'. |
186 | '</tr>'. |
b01b21d0 |
187 | html_tag( 'tr' ) . |
188 | html_tag( 'td', _("Contains:"), 'right' ) . |
189 | html_tag( 'td', '', 'left' ) . |
0a1dc88e |
190 | '<input type="text" size="32" name="filter_what" value="'; |
3fd1252d |
191 | if (isset($filters[$theid]['what'])) { |
0a1dc88e |
192 | echo $filters[$theid]['what']; |
3fd1252d |
193 | } |
0a1dc88e |
194 | echo '" />'. |
4eee5968 |
195 | '</td>'. |
196 | '</tr>'. |
b01b21d0 |
197 | html_tag( 'tr' ) . |
198 | html_tag( 'td', _("Move to:"), 'left' ) . |
199 | html_tag( 'td', '', 'left' ) . |
4eee5968 |
200 | '<tt>'. |
0a1dc88e |
201 | '<select name="filter_folder">'; |
81f652a1 |
202 | $selected = 0; |
203 | if ( isset($filters[$theid]['folder']) ) |
204 | $selected = array(strtolower($filters[$theid]['folder'])); |
205 | echo sqimap_mailbox_option_list(0, $selected, 0, $boxes); |
3fd1252d |
206 | echo '</tt>'. |
4eee5968 |
207 | '</select>'. |
208 | '</td>'. |
209 | '</tr>'. |
3fd1252d |
210 | '</table>'. |
0a1dc88e |
211 | '<input type="submit" name="filter_submit" value="' . _("Submit") . "\" />\n". |
a9e1e670 |
212 | addHidden('theid', $theid). |
3fd1252d |
213 | '</form>'. |
b01b21d0 |
214 | '</div>'; |
3fd1252d |
215 | |
3fd1252d |
216 | } |
cb2ccf4b |
217 | |
3b94163a |
218 | echo html_tag( 'table', '', 'center', '', 'border="0" cellpadding="3" cellspacing="0"' ); |
cb2ccf4b |
219 | |
ae48f757 |
220 | for ($i=0, $num = count($filters); $i < $num; $i++) { |
cb2ccf4b |
221 | |
222 | $clr = (($i % 2)?$color[0]:$color[9]); |
223 | $fdr = ($folder_prefix)?str_replace($folder_prefix, "", $filters[$i]["folder"]):$filters[$i]["folder"]; |
831a25d5 |
224 | echo html_tag( 'tr', '', '', $clr ) . |
b01b21d0 |
225 | html_tag( 'td', |
226 | '<small>' . |
0a1dc88e |
227 | "[<a href=\"options.php?theid=$i&action=edit\">" . _("Edit") . '</a>]'. |
b01b21d0 |
228 | '</small>' , |
229 | 'left' ) . |
230 | html_tag( 'td', |
231 | '<small>' . |
0a1dc88e |
232 | "[<a href=\"options.php?theid=$i&action=delete\">" . _("Delete") . '</a>]'. |
b01b21d0 |
233 | '</small>' , |
3b94163a |
234 | 'left' ); |
235 | |
236 | if ($num > 1) { |
237 | echo html_tag( 'td', '', 'center' ) . '<small>['; |
238 | if (isset($filters[$i + 1])) { |
239 | echo "<a href=\"options.php?theid=$i&action=move_down\">" . _("Down") . '</a>'; |
240 | if ($i > 0) { |
241 | echo ' | '; |
242 | } |
243 | } |
cb2ccf4b |
244 | if ($i > 0) { |
3b94163a |
245 | echo "<a href=\"options.php?theid=$i&action=move_up\">" . _("Up") . '</a>'; |
cb2ccf4b |
246 | } |
3b94163a |
247 | echo ']</small></td>'; |
cb2ccf4b |
248 | } |
3b94163a |
249 | echo html_tag( 'td', '-', 'left' ) . |
250 | html_tag( 'td', '', 'left' ); |
0a1dc88e |
251 | printf( _("If %s contains %s then move to %s"), |
3b94163a |
252 | '<b>'.$filters[$i]['where'].'</b>', |
253 | '<b>'.$filters[$i]['what'].'</b>', |
254 | '<b>'.imap_utf7_decode_local($fdr).'</b>'); |
cb2ccf4b |
255 | echo '</td></tr>'; |
256 | |
257 | } |
258 | echo '</table>'. |
b01b21d0 |
259 | html_tag( 'table', |
260 | html_tag( 'tr', |
8e724112 |
261 | html_tag( 'td', ' ', 'left' ) |
b01b21d0 |
262 | ) , |
263 | 'center', '', 'width="80%" border="0" cellpadding="2" cellspacing="0"' ); |
dcc1cc82 |
264 | echo '</body></html>'; |
a9e1e670 |
265 | ?> |