849bdf42 |
1 | <?php |
15e6162e |
2 | /** |
0a1dc88e |
3 | * Message and Spam Filter Plugin - Filtering Functions |
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 | |
ee27709d |
12 | /** load config */ |
8510adf2 |
13 | if (file_exists(SM_PATH . 'plugins/filters/config.php')) |
14 | include_once (SM_PATH . 'plugins/filters/config.php'); |
9c655416 |
15 | |
ea5f4b8e |
16 | /** |
9c655416 |
17 | * Init Hooks |
18 | * @access private |
19 | */ |
20 | function filters_init_hooks () { |
21 | global $squirrelmail_plugin_hooks; |
22 | if (!file_exists(SM_PATH . 'plugins/filters/config.php')) return; |
23 | if (sqgetGlobalVar('mailbox',$mailbox,SQ_FORM)) { |
24 | sqgetGlobalVar('mailbox',$mailbox,SQ_FORM); |
25 | } else { |
26 | $mailbox = 'INBOX'; |
27 | } |
28 | |
29 | $squirrelmail_plugin_hooks['left_main_before']['filters'] = 'start_filters_hook'; |
30 | if (isset($mailbox) && $mailbox == 'INBOX') { |
31 | $squirrelmail_plugin_hooks['right_main_after_header']['filters'] = 'start_filters_hook'; |
32 | } |
33 | $squirrelmail_plugin_hooks['optpage_register_block']['filters'] = 'filters_optpage_register_block_hook'; |
34 | $squirrelmail_plugin_hooks['special_mailbox']['filters'] = 'filters_special_mailbox'; |
35 | $squirrelmail_plugin_hooks['rename_or_delete_folder']['filters'] = 'update_for_folder_hook'; |
36 | $squirrelmail_plugin_hooks['webmail_bottom']['filters'] = 'start_filters_hook'; |
37 | } |
38 | |
39 | /** |
40 | * Register option blocks |
41 | * @access private |
42 | */ |
43 | function filters_optpage_register_block() { |
44 | global $optpage_blocks, $AllowSpamFilters; |
45 | if (!file_exists(SM_PATH . 'plugins/filters/config.php')) return; |
f8a1ed5a |
46 | |
9c655416 |
47 | $optpage_blocks[] = array( |
48 | 'name' => _("Message Filters"), |
49 | 'url' => SM_PATH . 'plugins/filters/options.php', |
50 | 'desc' => _("Filtering enables messages with different criteria to be automatically filtered into different folders for easier organization."), |
51 | 'js' => false |
52 | ); |
53 | |
54 | if ($AllowSpamFilters) { |
55 | $optpage_blocks[] = array( |
56 | 'name' => _("SPAM Filters"), |
57 | 'url' => SM_PATH . 'plugins/filters/spamoptions.php', |
58 | 'desc' => _("SPAM filters allow you to select from various DNS based blacklists to detect junk email in your INBOX and move it to another folder (like Trash)."), |
59 | 'js' => false |
60 | ); |
61 | } |
62 | } |
63 | |
64 | /** |
65 | * Saves the DNS Cache to disk |
0a1dc88e |
66 | * @access private |
5b4ba967 |
67 | */ |
a2a566eb |
68 | function filters_SaveCache () { |
69 | global $data_dir, $SpamFilters_DNScache; |
70 | |
ae48f757 |
71 | if (file_exists($data_dir . '/dnscache')) { |
72 | $fp = fopen($data_dir . '/dnscache', 'r'); |
a2a566eb |
73 | } else { |
74 | $fp = false; |
75 | } |
76 | if ($fp) { |
77 | flock($fp,LOCK_EX); |
78 | } else { |
ae48f757 |
79 | $fp = fopen($data_dir . '/dnscache', 'w+'); |
a2a566eb |
80 | fclose($fp); |
ae48f757 |
81 | $fp = fopen($data_dir . '/dnscache', 'r'); |
a2a566eb |
82 | flock($fp,LOCK_EX); |
83 | } |
9c655416 |
84 | $fp1 = fopen($data_dir . '/dnscache', 'w+'); |
a2a566eb |
85 | |
86 | foreach ($SpamFilters_DNScache as $Key=> $Value) { |
87 | $tstr = $Key . ',' . $Value['L'] . ',' . $Value['T'] . "\n"; |
88 | fputs ($fp1, $tstr); |
89 | } |
90 | fclose($fp1); |
91 | flock($fp,LOCK_UN); |
92 | fclose($fp); |
93 | } |
94 | |
0a1dc88e |
95 | /** |
9c655416 |
96 | * Loads the DNS Cache from disk |
0a1dc88e |
97 | * @access private |
98 | */ |
a2a566eb |
99 | function filters_LoadCache () { |
100 | global $data_dir, $SpamFilters_DNScache; |
101 | |
ae48f757 |
102 | if (file_exists($data_dir . '/dnscache')) { |
6ade76e0 |
103 | $SpamFilters_DNScache = array(); |
ae48f757 |
104 | if ($fp = fopen ($data_dir . '/dnscache', 'r')) { |
a2a566eb |
105 | flock($fp,LOCK_SH); |
9c655416 |
106 | while ($data = fgetcsv($fp,1024)) { |
a2a566eb |
107 | if ($data[2] > time()) { |
108 | $SpamFilters_DNScache[$data[0]]['L'] = $data[1]; |
109 | $SpamFilters_DNScache[$data[0]]['T'] = $data[2]; |
110 | } |
111 | } |
a2a566eb |
112 | flock($fp,LOCK_UN); |
113 | } |
114 | } |
115 | } |
116 | |
0a1dc88e |
117 | /** |
9c655416 |
118 | * Uses the BulkQuery executable to query all the RBLs at once |
119 | * @param array $filters Array of SPAM Fitlers |
120 | * @param array $IPs Array of IP Addresses |
0a1dc88e |
121 | * @access private |
122 | */ |
fb577a4d |
123 | function filters_bulkquery($filters, $IPs) { |
ce68b76b |
124 | global $attachment_dir, $username, |
6ade76e0 |
125 | $SpamFilters_DNScache, $SpamFilters_BulkQuery, |
126 | $SpamFilters_CacheTTL; |
a2a566eb |
127 | |
a2a566eb |
128 | if (count($IPs) > 0) { |
129 | $rbls = array(); |
130 | foreach ($filters as $key => $value) { |
131 | if ($filters[$key]['enabled']) { |
132 | if ($filters[$key]['dns']) { |
133 | $rbls[$filters[$key]['dns']] = true; |
134 | } |
135 | } |
136 | } |
137 | |
ae48f757 |
138 | $bqfil = $attachment_dir . $username . '-bq.in'; |
139 | $fp = fopen($bqfil, 'w'); |
6ade76e0 |
140 | fputs ($fp, $SpamFilters_CacheTTL . "\n"); |
a2a566eb |
141 | foreach ($rbls as $key => $value) { |
ae48f757 |
142 | fputs ($fp, '.' . $key . "\n"); |
a2a566eb |
143 | } |
144 | fputs ($fp, "----------\n"); |
145 | foreach ($IPs as $key => $value) { |
146 | fputs ($fp, $key . "\n"); |
147 | } |
148 | fclose ($fp); |
149 | $bqout = array(); |
ae48f757 |
150 | exec ($SpamFilters_BulkQuery . ' < ' . $bqfil, $bqout); |
a2a566eb |
151 | foreach ($bqout as $value) { |
152 | $Chunks = explode(',', $value); |
153 | $SpamFilters_DNScache[$Chunks[0]]['L'] = $Chunks[1]; |
154 | $SpamFilters_DNScache[$Chunks[0]]['T'] = $Chunks[2] + time(); |
155 | } |
156 | unlink($bqfil); |
157 | } |
158 | } |
159 | |
0a1dc88e |
160 | /** |
9c655416 |
161 | * Starts the filtering process |
0a1dc88e |
162 | * @access private |
163 | */ |
10a26cea |
164 | function start_filters() { |
ce68b76b |
165 | global $imapServerAddress, $imapPort, $imap_stream, $imapConnection, |
3c66c567 |
166 | $UseSeparateImapConnection, $AllowSpamFilters; |
f8a1ed5a |
167 | |
9c655416 |
168 | if (!file_exists(SM_PATH . 'plugins/filters/config.php')) return; |
f8a1ed5a |
169 | |
3c66c567 |
170 | sqgetGlobalVar('username', $username, SQ_SESSION); |
171 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
10a26cea |
172 | |
2714d4ff |
173 | // Detect if we have already connected to IMAP or not. |
174 | // Also check if we are forced to use a separate IMAP connection |
175 | if ((!isset($imap_stream) && !isset($imapConnection)) || |
176 | $UseSeparateImapConnection ) { |
177 | $stream = sqimap_login($username, $key, $imapServerAddress, |
178 | $imapPort, 10); |
179 | $previously_connected = false; |
180 | } else if (isset($imapConnection)) { |
181 | $stream = $imapConnection; |
182 | $previously_connected = true; |
183 | } else { |
184 | $previously_connected = true; |
185 | $stream = $imap_stream; |
186 | } |
187 | $aStatus = sqimap_status_messages ($stream, 'INBOX', array('MESSAGES')); |
4eee5968 |
188 | |
2714d4ff |
189 | if ($aStatus['MESSAGES']) { |
190 | sqimap_mailbox_select($stream, 'INBOX'); |
191 | // Filter spam from inbox before we sort them into folders |
192 | if ($AllowSpamFilters) { |
193 | spam_filters($stream); |
10a26cea |
194 | } |
4eee5968 |
195 | |
2714d4ff |
196 | // Sort into folders |
197 | user_filters($stream); |
198 | } |
199 | |
200 | if (!$previously_connected) { |
201 | sqimap_logout($stream); |
202 | } |
10a26cea |
203 | } |
204 | |
0a1dc88e |
205 | /** |
9c655416 |
206 | * Does the loop through each filter |
207 | * @param stream imap_stream the stream to read from |
0a1dc88e |
208 | * @access private |
209 | */ |
10a26cea |
210 | function user_filters($imap_stream) { |
c8a2c24d |
211 | global $data_dir, $username; |
10a26cea |
212 | $filters = load_filters(); |
213 | if (! $filters) return; |
c8a2c24d |
214 | $filters_user_scan = getPref($data_dir, $username, 'filters_user_scan'); |
10a26cea |
215 | |
fb577a4d |
216 | $expunge = false; |
53fcc494 |
217 | // For every rule |
ae48f757 |
218 | for ($i=0, $num = count($filters); $i < $num; $i++) { |
10a26cea |
219 | // If it is the "combo" rule |
220 | if ($filters[$i]['where'] == 'To or Cc') { |
53fcc494 |
221 | /* |
222 | * If it's "TO OR CC", we have to do two searches, one for TO |
223 | * and the other for CC. |
224 | */ |
fb577a4d |
225 | $expunge = filter_search_and_delete($imap_stream, 'TO', |
226 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
227 | $expunge = filter_search_and_delete($imap_stream, 'CC', |
228 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
8a7ccd82 |
229 | } else if ($filters[$i]['where'] == 'Header and Body') { |
230 | $expunge = filter_search_and_delete($imap_stream, 'TEXT', |
231 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
232 | } else if ($filters[$i]['where'] == 'Message Body') { |
233 | $expunge = filter_search_and_delete($imap_stream, 'BODY', |
f8a1ed5a |
234 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
10a26cea |
235 | } else { |
53fcc494 |
236 | /* |
237 | * If it's a normal TO, CC, SUBJECT, or FROM, then handle it |
238 | * normally. |
239 | */ |
fb577a4d |
240 | $expunge = filter_search_and_delete($imap_stream, $filters[$i]['where'], |
241 | $filters[$i]['what'], $filters[$i]['folder'], $filters_user_scan, $expunge); |
4eee5968 |
242 | } |
4eee5968 |
243 | } |
53fcc494 |
244 | // Clean out the mailbox whether or not auto_expunge is on |
245 | // That way it looks like it was redirected properly |
fb577a4d |
246 | if ($expunge) { |
4f6915b0 |
247 | sqimap_mailbox_expunge($imap_stream, 'INBOX'); |
53fcc494 |
248 | } |
10a26cea |
249 | } |
250 | |
0a1dc88e |
251 | /** |
9c655416 |
252 | * Creates and runs the IMAP command to filter messages |
253 | * @param string $where Which part of the message to search (TO, CC, SUBJECT, etc...) |
254 | * @param string $what String to search for |
255 | * @param string $where_to Folder it will move to |
256 | * @param string $user_scan Whether to search all or just unseen |
f8a1ed5a |
257 | * @param string $should_expunge |
9c655416 |
258 | * @param boolean $where Which part of location to search |
0a1dc88e |
259 | * @access private |
260 | */ |
2714d4ff |
261 | function filter_search_and_delete($imap_stream, $where, $what, $where_to, $user_scan, |
fb577a4d |
262 | $should_expunge) { |
6201339c |
263 | global $languages, $squirrelmail_language, $allow_charset_search, $imap_server_type; |
264 | |
174523e3 |
265 | if (strtolower($where_to) == 'inbox') { |
266 | return array(); |
267 | } |
268 | |
c8a2c24d |
269 | if ($user_scan == 'new') { |
270 | $category = 'UNSEEN'; |
271 | } else { |
272 | $category = 'ALL'; |
273 | } |
86e6d79f |
274 | $category .= ' UNDELETED'; |
c8a2c24d |
275 | |
3eea00ca |
276 | if ($allow_charset_search && |
277 | isset($languages[$squirrelmail_language]['CHARSET']) && |
53fcc494 |
278 | $languages[$squirrelmail_language]['CHARSET']) { |
3eea00ca |
279 | $search_str = 'SEARCH CHARSET ' |
280 | . strtoupper($languages[$squirrelmail_language]['CHARSET']) |
281 | . ' ' . $category; |
f9ca4be0 |
282 | } else { |
3eea00ca |
283 | $search_str = 'SEARCH CHARSET US-ASCII ' . $category; |
f9ca4be0 |
284 | } |
ae48f757 |
285 | if ($where == 'Header') { |
3eea00ca |
286 | $what = explode(':', $what); |
287 | $where = trim($where . ' ' . $what[0]); |
288 | $what = addslashes(trim($what[1])); |
9da6bdde |
289 | } |
f18ea37e |
290 | |
cf2aa192 |
291 | // see comments in squirrelmail sqimap_search function |
292 | if ($imap_server_type == 'macosx' || $imap_server_type == 'hmailserver') { |
91e0dccc |
293 | $search_str .= ' ' . $where . ' ' . $what; |
f18ea37e |
294 | } else { |
91e0dccc |
295 | $search_str .= ' ' . $where . ' {' . strlen($what) . "}\r\n" |
f18ea37e |
296 | . $what . "\r\n"; |
297 | } |
10a26cea |
298 | |
53fcc494 |
299 | /* read data back from IMAP */ |
6201339c |
300 | $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE); |
2714d4ff |
301 | if (isset($read[0])) { |
302 | $ids = array(); |
9c655416 |
303 | for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) { |
2714d4ff |
304 | if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) { |
305 | $ids = preg_split("/ /", trim($regs[1])); |
306 | break; |
fb577a4d |
307 | } |
2714d4ff |
308 | } |
309 | if ($response == 'OK' && count($ids)) { |
310 | if (sqimap_mailbox_exists($imap_stream, $where_to)) { |
311 | $should_expunge = true; |
4e6e5d2d |
312 | sqimap_msgs_list_move ($imap_stream, $ids, $where_to, false); |
4eee5968 |
313 | } |
314 | } |
315 | } |
fb577a4d |
316 | return $should_expunge; |
10a26cea |
317 | } |
4eee5968 |
318 | |
0a1dc88e |
319 | /** |
9c655416 |
320 | * Loops through all the Received Headers to find IP Addresses |
321 | * @param stream imap_stream the stream to read from |
0a1dc88e |
322 | * @access private |
323 | */ |
10a26cea |
324 | function spam_filters($imap_stream) { |
6201339c |
325 | global $data_dir, $username; |
10a26cea |
326 | global $SpamFilters_YourHop; |
327 | global $SpamFilters_DNScache; |
a2a566eb |
328 | global $SpamFilters_SharedCache; |
329 | global $SpamFilters_BulkQuery; |
fb577a4d |
330 | global $SpamFilters_CacheTTL; |
4eee5968 |
331 | |
10a26cea |
332 | $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan'); |
333 | $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder'); |
334 | $filters = load_spam_filters(); |
4eee5968 |
335 | |
a2a566eb |
336 | if ($SpamFilters_SharedCache) { |
337 | filters_LoadCache(); |
338 | } |
339 | |
fb577a4d |
340 | $run = false; |
4eee5968 |
341 | |
fb577a4d |
342 | foreach ($filters as $Key => $Value) { |
10a26cea |
343 | if ($Value['enabled']) { |
fb577a4d |
344 | $run = true; |
345 | break; |
4eee5968 |
346 | } |
10a26cea |
347 | } |
4eee5968 |
348 | |
10a26cea |
349 | // short-circuit |
fb577a4d |
350 | if (!$run) { |
10a26cea |
351 | return; |
352 | } |
4eee5968 |
353 | |
10a26cea |
354 | // Ask for a big list of all "Received" headers in the inbox with |
355 | // flags for each message. Kinda big. |
2714d4ff |
356 | |
357 | if ($filters_spam_scan == 'new') { |
358 | $search_array = array(); |
6201339c |
359 | $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE); |
2714d4ff |
360 | if (isset($read[0])) { |
9c655416 |
361 | for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) { |
2714d4ff |
362 | if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) { |
6174dcc7 |
363 | $search_array = preg_split("/ /", trim($regs[1])); |
2714d4ff |
364 | break; |
6174dcc7 |
365 | } |
c8a2c24d |
366 | } |
2714d4ff |
367 | } |
c8a2c24d |
368 | } |
2714d4ff |
369 | if ($filters_spam_scan == 'new' && count($search_array)) { |
d3fae94f |
370 | $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array()); |
2714d4ff |
371 | } else if ($filters_spam_scan != 'new') { |
d3fae94f |
372 | $headers = sqimap_get_small_header_list ($imap_stream, null , array('Received'),array()); |
2714d4ff |
373 | } else { |
374 | return; |
375 | } |
376 | if (!count($headers)) { |
10a26cea |
377 | return; |
378 | } |
fb577a4d |
379 | $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true : false); |
380 | $IPs = array(); |
381 | $aSpamIds = array(); |
382 | foreach ($headers as $id => $aValue) { |
2714d4ff |
383 | if (isset($aValue['UID'])) { |
fb577a4d |
384 | $MsgNum = $aValue['UID']; |
385 | } else { |
386 | $MsgNum = $id; |
10a26cea |
387 | } |
10a26cea |
388 | // Look through all of the Received headers for IP addresses |
2714d4ff |
389 | if (isset($aValue['RECEIVED'])) { |
390 | foreach ($aValue['RECEIVED'] as $received) { |
fb577a4d |
391 | // Check to see if this line is the right "Received from" line |
392 | // to check |
2714d4ff |
393 | |
394 | // $aValue['Received'] is an array with all the received lines. |
fb577a4d |
395 | // We should check them from bottom to top and only check the first 2. |
396 | // Currently we check only the header where $SpamFilters_YourHop in occures |
2714d4ff |
397 | |
fb577a4d |
398 | if (is_int(strpos($received, $SpamFilters_YourHop))) { |
399 | if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) { |
400 | $isspam = false; |
401 | if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) { |
402 | $aSpamIds[] = $MsgNum; |
403 | $isspam = true; |
404 | } |
405 | if ($bulkquery) { |
406 | array_shift($aMatch); |
407 | $IP = explode('.',$aMatch); |
408 | foreach ($filters as $key => $value) { |
409 | if ($filters[$key]['enabled'] && $filters[$key]['dns']) { |
410 | if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) { |
411 | $IPs[$IP] = true; |
412 | break; |
413 | } |
414 | } |
415 | } |
c8a2c24d |
416 | } |
417 | // If we've checked one IP and YourHop is |
418 | // just a space |
fb577a4d |
419 | if ($SpamFilters_YourHop == ' ' || $isspam) { |
c8a2c24d |
420 | break; // don't check any more |
a9aa7ab7 |
421 | } |
a9aa7ab7 |
422 | } |
4eee5968 |
423 | } |
4eee5968 |
424 | } |
4eee5968 |
425 | } |
10a26cea |
426 | } |
fb577a4d |
427 | // Lookie! It's spam! Yum! |
428 | if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) { |
429 | sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder); |
430 | sqimap_mailbox_expunge($imap_stream, 'INBOX'); |
431 | } |
4eee5968 |
432 | |
fb577a4d |
433 | if ($bulkquery && count($IPs)) { |
434 | filters_bulkquery($filters, $IPs); |
435 | } |
4eee5968 |
436 | |
a2a566eb |
437 | if ($SpamFilters_SharedCache) { |
438 | filters_SaveCache(); |
439 | } else { |
41100fce |
440 | sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache'); |
a2a566eb |
441 | } |
10a26cea |
442 | } |
4eee5968 |
443 | |
0a1dc88e |
444 | /** |
0a1dc88e |
445 | * Does the loop through each enabled filter for the specified IP address. |
446 | * IP format: $a.$b.$c.$d |
9c655416 |
447 | * @param int $a First subset of IP |
448 | * @param int $b Second subset of IP |
449 | * @param int $c Third subset of IP |
450 | * @param int $d Forth subset of IP |
451 | * @param array $filters The Spam Filters |
452 | * @return boolean Whether the IP is Spam |
0a1dc88e |
453 | * @access private |
454 | */ |
10a26cea |
455 | function filters_spam_check_site($a, $b, $c, $d, &$filters) { |
a2a566eb |
456 | global $SpamFilters_DNScache, $SpamFilters_CacheTTL; |
10a26cea |
457 | foreach ($filters as $key => $value) { |
458 | if ($filters[$key]['enabled']) { |
459 | if ($filters[$key]['dns']) { |
460 | $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' . |
461 | $filters[$key]['dns']; |
ae48f757 |
462 | |
463 | if(!isset($SpamFilters_DNScache[$filter_revip]['L'])) |
464 | $SpamFilters_DNScache[$filter_revip]['L'] = ''; |
465 | |
466 | if(!isset($SpamFilters_DNScache[$filter_revip]['T'])) |
467 | $SpamFilters_DNScache[$filter_revip]['T'] = ''; |
468 | |
a7cd90dd |
469 | if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) { |
470 | $SpamFilters_DNScache[$filter_revip]['L'] = |
471 | gethostbyname($filter_revip); |
472 | $SpamFilters_DNScache[$filter_revip]['T'] = |
473 | time() + $SpamFilters_CacheTTL; |
474 | } |
475 | if ($SpamFilters_DNScache[$filter_revip]['L'] == |
476 | $filters[$key]['result']) { |
477 | return 1; |
4eee5968 |
478 | } |
479 | } |
480 | } |
4eee5968 |
481 | } |
10a26cea |
482 | return 0; |
483 | } |
484 | |
0a1dc88e |
485 | /** |
9c655416 |
486 | * Loads the filters from the user preferences |
487 | * @return array All the user filters |
0a1dc88e |
488 | * @access private |
489 | */ |
10a26cea |
490 | function load_filters() { |
491 | global $data_dir, $username; |
c8a2c24d |
492 | |
10a26cea |
493 | $filters = array(); |
9c655416 |
494 | for ($i = 0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) { |
10a26cea |
495 | $ary = explode(',', $fltr); |
496 | $filters[$i]['where'] = $ary[0]; |
497 | $filters[$i]['what'] = $ary[1]; |
498 | $filters[$i]['folder'] = $ary[2]; |
4eee5968 |
499 | } |
10a26cea |
500 | return $filters; |
501 | } |
502 | |
0a1dc88e |
503 | /** |
9c655416 |
504 | * Loads the Spam Filters and checks the preferences for the enabled status |
505 | * @return array All the spam filters |
0a1dc88e |
506 | * @access private |
507 | */ |
10a26cea |
508 | function load_spam_filters() { |
51199e7a |
509 | global $data_dir, $username, $SpamFilters_ShowCommercial; |
510 | |
511 | if ($SpamFilters_ShowCommercial) { |
512 | $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl'; |
513 | $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List'; |
514 | $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/'; |
515 | $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org'; |
516 | $filters['MAPS RBL']['result'] = '127.0.0.2'; |
517 | $filters['MAPS RBL']['comment'] = |
518 | _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from."); |
519 | |
520 | $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss'; |
521 | $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper'; |
522 | $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/'; |
523 | $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org'; |
524 | $filters['MAPS RSS']['result'] = '127.0.0.2'; |
525 | $filters['MAPS RSS']['comment'] = |
99aaff8b |
526 | _("COMMERCIAL - Servers that are configured (or misconfigured) to allow spam to be relayed through their system will be banned with this. Another good one to use."); |
51199e7a |
527 | |
528 | $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul'; |
529 | $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List'; |
530 | $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/'; |
531 | $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org'; |
532 | $filters['MAPS DUL']['result'] = '127.0.0.3'; |
533 | $filters['MAPS DUL']['comment'] = |
99aaff8b |
534 | _("COMMERCIAL - Dial-up users are often filtered out since they should use their ISP's mail servers to send mail. Spammers typically get a dial-up account and send spam directly from there."); |
51199e7a |
535 | |
536 | $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl'; |
537 | $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List'; |
538 | $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/'; |
539 | $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org'; |
540 | $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2'; |
541 | $filters['MAPS RBLplus-RBL']['comment'] = |
542 | _("COMMERCIAL - RBL+ Blackhole entries."); |
543 | |
544 | $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss'; |
545 | $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries'; |
546 | $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/'; |
547 | $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org'; |
548 | $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2'; |
549 | $filters['MAPS RBLplus-RSS']['comment'] = |
550 | _("COMMERCIAL - RBL+ OpenRelay entries."); |
551 | |
552 | $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul'; |
553 | $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries'; |
554 | $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/'; |
555 | $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org'; |
556 | $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3'; |
557 | $filters['MAPS RBLplus-DUL']['comment'] = |
558 | _("COMMERCIAL - RBL+ Dial-up entries."); |
559 | } |
10a26cea |
560 | |
10a26cea |
561 | $filters['ORDB']['prefname'] = 'filters_spam_ordb'; |
562 | $filters['ORDB']['name'] = 'Open Relay Database List'; |
563 | $filters['ORDB']['link'] = 'http://www.ordb.org/'; |
564 | $filters['ORDB']['dns'] = 'relays.ordb.org'; |
565 | $filters['ORDB']['result'] = '127.0.0.2'; |
566 | $filters['ORDB']['comment'] = |
567 | _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though."); |
568 | |
10a26cea |
569 | $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src'; |
570 | $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources'; |
571 | $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
572 | $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com'; |
573 | $filters['FiveTen Direct']['result'] = '127.0.0.2'; |
574 | $filters['FiveTen Direct']['comment'] = |
575 | _("FREE - Five-Ten-sg.com - Direct SPAM sources."); |
576 | |
577 | $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul'; |
578 | $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists'; |
579 | $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
580 | $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com'; |
581 | $filters['FiveTen DUL']['result'] = '127.0.0.3'; |
582 | $filters['FiveTen DUL']['comment'] = |
583 | _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs."); |
584 | |
585 | $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi'; |
586 | $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists'; |
587 | $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
588 | $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com'; |
589 | $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4'; |
590 | $filters['FiveTen Unc. OptIn']['comment'] = |
591 | _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in."); |
592 | |
593 | $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth'; |
594 | $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers'; |
595 | $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
596 | $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com'; |
597 | $filters['FiveTen Others']['result'] = '127.0.0.5'; |
598 | $filters['FiveTen Others']['comment'] = |
599 | _("FREE - Five-Ten-sg.com - Other misc. servers."); |
600 | |
601 | $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss'; |
602 | $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers'; |
603 | $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
604 | $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com'; |
605 | $filters['FiveTen Single Stage']['result'] = '127.0.0.6'; |
606 | $filters['FiveTen Single Stage']['comment'] = |
607 | _("FREE - Five-Ten-sg.com - Single Stage servers."); |
608 | |
609 | $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp'; |
610 | $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers'; |
611 | $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
612 | $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com'; |
613 | $filters['FiveTen SPAM Support']['result'] = '127.0.0.7'; |
614 | $filters['FiveTen SPAM Support']['comment'] = |
615 | _("FREE - Five-Ten-sg.com - SPAM Support servers."); |
616 | |
617 | $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf'; |
618 | $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs'; |
619 | $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php'; |
620 | $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com'; |
621 | $filters['FiveTen Web forms']['result'] = '127.0.0.8'; |
622 | $filters['FiveTen Web forms']['comment'] = |
623 | _("FREE - Five-Ten-sg.com - Web Form IPs."); |
624 | |
625 | $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks'; |
626 | $filters['Dorkslayers']['name'] = 'Dorkslayers Lists'; |
627 | $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com'; |
628 | $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com'; |
629 | $filters['Dorkslayers']['result'] = '127.0.0.2'; |
630 | $filters['Dorkslayers']['comment'] = |
631 | _("FREE - Dorkslayers appears to include only really bad open relays outside the US to avoid being sued. Interestingly enough, their website recommends you NOT use their service."); |
632 | |
633 | $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus'; |
634 | $filters['SPAMhaus']['name'] = 'SPAMhaus Lists'; |
635 | $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org'; |
636 | $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org'; |
637 | $filters['SPAMhaus']['result'] = '127.0.0.6'; |
638 | $filters['SPAMhaus']['comment'] = |
639 | _("FREE - SPAMhaus - A list of well-known SPAM sources."); |
640 | |
641 | $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop'; |
642 | $filters['SPAMcop']['name'] = 'SPAM Cop Lists'; |
643 | $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml'; |
644 | $filters['SPAMcop']['dns'] = 'bl.spamcop.net'; |
645 | $filters['SPAMcop']['result'] = '127.0.0.2'; |
646 | $filters['SPAMcop']['comment'] = |
ace4e0d3 |
647 | _("FREE, for now - SpamCop - An interesting solution that lists servers that have a very high spam to legit email ratio (85 percent or more)."); |
10a26cea |
648 | |
46a184ff |
649 | $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull'; |
650 | $filters['dev.null.dk']['name'] = 'dev.null.dk Lists'; |
651 | $filters['dev.null.dk']['link'] = 'http://dev.null.dk/'; |
652 | $filters['dev.null.dk']['dns'] = 'dev.null.dk'; |
653 | $filters['dev.null.dk']['result'] = '127.0.0.2'; |
654 | $filters['dev.null.dk']['comment'] = |
655 | _("FREE - dev.null.dk - I don't have any detailed info on this list."); |
656 | |
657 | $filters['visi.com']['prefname'] = 'filters_spam_visi'; |
658 | $filters['visi.com']['name'] = 'visi.com Relay Stop List'; |
659 | $filters['visi.com']['link'] = 'http://relays.visi.com'; |
660 | $filters['visi.com']['dns'] = 'relays.visi.com'; |
661 | $filters['visi.com']['result'] = '127.0.0.2'; |
662 | $filters['visi.com']['comment'] = |
663 | _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List."); |
664 | |
bd35ab2b |
665 | $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or'; |
666 | $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List'; |
667 | $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/'; |
668 | $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org'; |
669 | $filters['ahbl.org Open Relays']['result'] = '127.0.0.2'; |
670 | $filters['ahbl.org Open Relays']['comment'] = |
671 | _("FREE - ahbl.org Open Relays - Another list of Open Relays."); |
672 | |
673 | $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss'; |
674 | $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List'; |
675 | $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/'; |
676 | $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org'; |
677 | $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4'; |
678 | $filters['ahbl.org SPAM Source']['comment'] = |
679 | _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources."); |
680 | |
681 | $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp'; |
682 | $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List'; |
683 | $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/'; |
684 | $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org'; |
685 | $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7'; |
686 | $filters['ahbl.org SPAM ISPs']['comment'] = |
687 | _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs."); |
46a184ff |
688 | |
689 | $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul'; |
690 | $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List'; |
691 | $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/'; |
692 | $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net'; |
693 | $filters['Leadmon DUL']['result'] = '127.0.0.2'; |
694 | $filters['Leadmon DUL']['comment'] = |
695 | _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs."); |
696 | |
697 | $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss'; |
698 | $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List'; |
699 | $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/'; |
700 | $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net'; |
701 | $filters['Leadmon SPAM Source']['result'] = '127.0.0.3'; |
702 | $filters['Leadmon SPAM Source']['comment'] = |
703 | _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from."); |
704 | |
705 | $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm'; |
706 | $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List'; |
707 | $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/'; |
708 | $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net'; |
709 | $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4'; |
710 | $filters['Leadmon Bulk Mailers']['comment'] = |
711 | _("FREE - Leadmon Bulk Mailers - Bulk mailers that do not require confirmed opt-in or that have allowed known spammers to become clients and abuse their services."); |
712 | |
713 | $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or'; |
714 | $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List'; |
715 | $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/'; |
716 | $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net'; |
717 | $filters['Leadmon Open Relays']['result'] = '127.0.0.5'; |
718 | $filters['Leadmon Open Relays']['comment'] = |
719 | _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs."); |
720 | |
721 | $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms'; |
722 | $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List'; |
723 | $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/'; |
724 | $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net'; |
725 | $filters['Leadmon Multi-stage']['result'] = '127.0.0.6'; |
726 | $filters['Leadmon Multi-stage']['comment'] = |
727 | _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net."); |
728 | |
729 | $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb'; |
730 | $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List'; |
731 | $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/'; |
732 | $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net'; |
733 | $filters['Leadmon SpamBlock']['result'] = '127.0.0.7'; |
734 | $filters['Leadmon SpamBlock']['comment'] = |
735 | _("FREE - Leadmon SpamBlock - Sites on this listing have sent Leadmon.net direct SPAM from IPs in netblocks where the entire block has no DNS mappings. It's a list of BLOCKS of IPs being used by people who have SPAMmed Leadmon.net."); |
736 | |
737 | $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or'; |
738 | $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List'; |
739 | $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/'; |
740 | $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org'; |
741 | $filters['NJABL Open Relays']['result'] = '127.0.0.2'; |
742 | $filters['NJABL Open Relays']['comment'] = |
743 | _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources."); |
744 | |
745 | $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul'; |
746 | $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List'; |
747 | $filters['NJABL DUL']['link'] = 'http://www.njabl.org/'; |
748 | $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org'; |
749 | $filters['NJABL DUL']['result'] = '127.0.0.3'; |
750 | $filters['NJABL DUL']['comment'] = |
751 | _("FREE, for now - Not Just Another Blacklist - Dial-up IPs."); |
752 | |
18b078e9 |
753 | $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss'; |
754 | $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List'; |
755 | $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/'; |
756 | $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org'; |
757 | $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2'; |
758 | $filters['Conf DSBL.ORG Relay']['comment'] = |
759 | _("FREE - Distributed Sender Boycott List - Confirmed Relays"); |
760 | |
761 | $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms'; |
762 | $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List'; |
763 | $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/'; |
764 | $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org'; |
765 | $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2'; |
766 | $filters['Conf DSBL.ORG Multi-Stage']['comment'] = |
767 | _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays"); |
768 | |
769 | $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc'; |
770 | $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List'; |
771 | $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/'; |
772 | $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org'; |
773 | $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2'; |
774 | $filters['UN-Conf DSBL.ORG']['comment'] = |
775 | _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays"); |
776 | |
10a26cea |
777 | foreach ($filters as $Key => $Value) { |
9c655416 |
778 | $filters[$Key]['enabled'] = getPref($data_dir, $username, $filters[$Key]['prefname']); |
4eee5968 |
779 | } |
780 | |
10a26cea |
781 | return $filters; |
782 | } |
4eee5968 |
783 | |
0a1dc88e |
784 | /** |
9c655416 |
785 | * Removes a User filter |
786 | * @param int $id ID of the filter to remove |
0a1dc88e |
787 | * @access private |
788 | */ |
10a26cea |
789 | function remove_filter ($id) { |
790 | global $data_dir, $username; |
4eee5968 |
791 | |
9c655416 |
792 | while ($nextFilter = getPref($data_dir, $username, 'filter' . ($id + 1))) { |
10a26cea |
793 | setPref($data_dir, $username, 'filter' . $id, $nextFilter); |
794 | $id ++; |
4eee5968 |
795 | } |
796 | |
10a26cea |
797 | removePref($data_dir, $username, 'filter' . $id); |
798 | } |
4eee5968 |
799 | |
0a1dc88e |
800 | /** |
9c655416 |
801 | * Swaps two filters |
802 | * @param int $id1 ID of first filter to swap |
f8a1ed5a |
803 | * @param int $id2 ID of second filter to swap |
0a1dc88e |
804 | * @access private |
805 | */ |
10a26cea |
806 | function filter_swap($id1, $id2) { |
807 | global $data_dir, $username; |
4eee5968 |
808 | |
10a26cea |
809 | $FirstFilter = getPref($data_dir, $username, 'filter' . $id1); |
810 | $SecondFilter = getPref($data_dir, $username, 'filter' . $id2); |
811 | |
812 | if ($FirstFilter && $SecondFilter) { |
813 | setPref($data_dir, $username, 'filter' . $id2, $FirstFilter); |
814 | setPref($data_dir, $username, 'filter' . $id1, $SecondFilter); |
4eee5968 |
815 | } |
10a26cea |
816 | } |
4eec80a7 |
817 | |
0a1dc88e |
818 | /** |
9c655416 |
819 | * This updates the filter rules when renaming or deleting folders |
0a1dc88e |
820 | * @param array $args |
b2d8bc6c |
821 | * @access private |
0a1dc88e |
822 | */ |
f5ab1fb9 |
823 | function update_for_folder ($args) { |
9c655416 |
824 | |
825 | if (!file_exists(SM_PATH . 'plugins/filters/config.php')) return; |
f8a1ed5a |
826 | |
f5ab1fb9 |
827 | $old_folder = $args[0]; |
9c655416 |
828 | $new_folder = $args[2]; |
829 | $action = $args[1]; |
ce68b76b |
830 | global $data_dir, $username; |
4eec80a7 |
831 | $filters = array(); |
832 | $filters = load_filters(); |
833 | $filter_count = count($filters); |
834 | $p = 0; |
9c655416 |
835 | for ($i = 0; $i < $filter_count; $i++) { |
4eec80a7 |
836 | if (!empty($filters)) { |
837 | if ($old_folder == $filters[$i]['folder']) { |
838 | if ($action == 'rename') { |
839 | $filters[$i]['folder'] = $new_folder; |
840 | setPref($data_dir, $username, 'filter'.$i, |
841 | $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder); |
842 | } |
843 | elseif ($action == 'delete') { |
844 | remove_filter($p); |
845 | $p = $p-1; |
846 | } |
847 | } |
848 | $p++; |
849 | } |
850 | } |
851 | } |
0a1dc88e |
852 | |
0a1dc88e |
853 | /** |
854 | * Display formated error message |
855 | * @param string $string text message |
856 | * @return string html formated text message |
857 | * @access private |
858 | */ |
859 | function do_error($string) { |
860 | global $color; |
861 | echo "<p align=\"center\"><font color=\"$color[2]\">"; |
862 | echo $string; |
863 | echo "</font></p>\n"; |
864 | } |
9c655416 |
865 | |
866 | ?> |