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