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