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