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