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