"development team" -> "project team"
[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 }
06342d92 282 $category .= ' NOT DELETED';
c8a2c24d 283
3eea00ca 284 if ($allow_charset_search &&
285 isset($languages[$squirrelmail_language]['CHARSET']) &&
53fcc494 286 $languages[$squirrelmail_language]['CHARSET']) {
3eea00ca 287 $search_str = 'SEARCH CHARSET '
288 . strtoupper($languages[$squirrelmail_language]['CHARSET'])
289 . ' ' . $category;
f9ca4be0 290 } else {
3eea00ca 291 $search_str = 'SEARCH CHARSET US-ASCII ' . $category;
f9ca4be0 292 }
ae48f757 293 if ($where == 'Header') {
3eea00ca 294 $what = explode(':', $what);
295 $where = trim($where . ' ' . $what[0]);
296 $what = addslashes(trim($what[1]));
9da6bdde 297 }
f18ea37e 298
cf2aa192 299 // see comments in squirrelmail sqimap_search function
300 if ($imap_server_type == 'macosx' || $imap_server_type == 'hmailserver') {
91e0dccc 301 $search_str .= ' ' . $where . ' ' . $what;
f18ea37e 302 } else {
91e0dccc 303 $search_str .= ' ' . $where . ' {' . strlen($what) . "}\r\n"
f18ea37e 304 . $what . "\r\n";
305 }
10a26cea 306
53fcc494 307 /* read data back from IMAP */
6201339c 308 $read = sqimap_run_command($imap_stream, $search_str, true, $response, $message, TRUE);
2714d4ff 309 if (isset($read[0])) {
310 $ids = array();
9c655416 311 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) {
2714d4ff 312 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
313 $ids = preg_split("/ /", trim($regs[1]));
314 break;
fb577a4d 315 }
2714d4ff 316 }
317 if ($response == 'OK' && count($ids)) {
318 if (sqimap_mailbox_exists($imap_stream, $where_to)) {
319 $should_expunge = true;
320 sqimap_msgs_list_move ($imap_stream, $ids, $where_to);
4eee5968 321 }
322 }
323 }
fb577a4d 324 return $should_expunge;
10a26cea 325}
4eee5968 326
0a1dc88e 327/**
9c655416 328 * Loops through all the Received Headers to find IP Addresses
329 * @param stream imap_stream the stream to read from
0a1dc88e 330 * @access private
331 */
10a26cea 332function spam_filters($imap_stream) {
6201339c 333 global $data_dir, $username;
10a26cea 334 global $SpamFilters_YourHop;
335 global $SpamFilters_DNScache;
a2a566eb 336 global $SpamFilters_SharedCache;
337 global $SpamFilters_BulkQuery;
fb577a4d 338 global $SpamFilters_CacheTTL;
4eee5968 339
10a26cea 340 $filters_spam_scan = getPref($data_dir, $username, 'filters_spam_scan');
341 $filters_spam_folder = getPref($data_dir, $username, 'filters_spam_folder');
342 $filters = load_spam_filters();
4eee5968 343
a2a566eb 344 if ($SpamFilters_SharedCache) {
345 filters_LoadCache();
346 }
347
fb577a4d 348 $run = false;
4eee5968 349
fb577a4d 350 foreach ($filters as $Key => $Value) {
10a26cea 351 if ($Value['enabled']) {
fb577a4d 352 $run = true;
353 break;
4eee5968 354 }
10a26cea 355 }
4eee5968 356
10a26cea 357 // short-circuit
fb577a4d 358 if (!$run) {
10a26cea 359 return;
360 }
4eee5968 361
10a26cea 362 // Ask for a big list of all "Received" headers in the inbox with
363 // flags for each message. Kinda big.
2714d4ff 364
365 if ($filters_spam_scan == 'new') {
366 $search_array = array();
6201339c 367 $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, TRUE);
2714d4ff 368 if (isset($read[0])) {
9c655416 369 for ($i = 0, $iCnt = count($read); $i < $iCnt; ++$i) {
2714d4ff 370 if (preg_match("/^\* SEARCH (.+)$/", $read[$i], $regs)) {
6174dcc7 371 $search_array = preg_split("/ /", trim($regs[1]));
2714d4ff 372 break;
6174dcc7 373 }
c8a2c24d 374 }
2714d4ff 375 }
c8a2c24d 376 }
2714d4ff 377 if ($filters_spam_scan == 'new' && count($search_array)) {
d3fae94f 378 $headers = sqimap_get_small_header_list ($imap_stream, $search_array, array('Received'),array());
2714d4ff 379 } else if ($filters_spam_scan != 'new') {
d3fae94f 380 $headers = sqimap_get_small_header_list ($imap_stream, null , array('Received'),array());
2714d4ff 381 } else {
382 return;
383 }
384 if (!count($headers)) {
10a26cea 385 return;
386 }
fb577a4d 387 $bulkquery = (strlen($SpamFilters_BulkQuery) > 0 ? true : false);
388 $IPs = array();
389 $aSpamIds = array();
390 foreach ($headers as $id => $aValue) {
2714d4ff 391 if (isset($aValue['UID'])) {
fb577a4d 392 $MsgNum = $aValue['UID'];
393 } else {
394 $MsgNum = $id;
10a26cea 395 }
10a26cea 396 // Look through all of the Received headers for IP addresses
2714d4ff 397 if (isset($aValue['RECEIVED'])) {
398 foreach ($aValue['RECEIVED'] as $received) {
fb577a4d 399 // Check to see if this line is the right "Received from" line
400 // to check
2714d4ff 401
402 // $aValue['Received'] is an array with all the received lines.
fb577a4d 403 // We should check them from bottom to top and only check the first 2.
404 // Currently we check only the header where $SpamFilters_YourHop in occures
2714d4ff 405
fb577a4d 406 if (is_int(strpos($received, $SpamFilters_YourHop))) {
407 if (preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/',$received,$aMatch)) {
408 $isspam = false;
409 if (filters_spam_check_site($aMatch[1],$aMatch[2],$aMatch[3],$aMatch[4],$filters)) {
410 $aSpamIds[] = $MsgNum;
411 $isspam = true;
412 }
413 if ($bulkquery) {
414 array_shift($aMatch);
415 $IP = explode('.',$aMatch);
416 foreach ($filters as $key => $value) {
417 if ($filters[$key]['enabled'] && $filters[$key]['dns']) {
418 if (strlen($SpamFilters_DNScache[$IP.'.'.$filters[$key]['dns']]) == 0) {
419 $IPs[$IP] = true;
420 break;
421 }
422 }
423 }
c8a2c24d 424 }
425 // If we've checked one IP and YourHop is
426 // just a space
fb577a4d 427 if ($SpamFilters_YourHop == ' ' || $isspam) {
c8a2c24d 428 break; // don't check any more
a9aa7ab7 429 }
a9aa7ab7 430 }
4eee5968 431 }
4eee5968 432 }
4eee5968 433 }
10a26cea 434 }
fb577a4d 435 // Lookie! It's spam! Yum!
436 if (count($aSpamIds) && sqimap_mailbox_exists($imap_stream, $filters_spam_folder)) {
437 sqimap_msgs_list_move ($imap_stream, $aSpamIds, $filters_spam_folder);
438 sqimap_mailbox_expunge($imap_stream, 'INBOX');
439 }
4eee5968 440
fb577a4d 441 if ($bulkquery && count($IPs)) {
442 filters_bulkquery($filters, $IPs);
443 }
4eee5968 444
a2a566eb 445 if ($SpamFilters_SharedCache) {
446 filters_SaveCache();
447 } else {
41100fce 448 sqsession_register($SpamFilters_DNScache, 'SpamFilters_DNScache');
a2a566eb 449 }
10a26cea 450}
4eee5968 451
0a1dc88e 452/**
0a1dc88e 453 * Does the loop through each enabled filter for the specified IP address.
454 * IP format: $a.$b.$c.$d
9c655416 455 * @param int $a First subset of IP
456 * @param int $b Second subset of IP
457 * @param int $c Third subset of IP
458 * @param int $d Forth subset of IP
459 * @param array $filters The Spam Filters
460 * @return boolean Whether the IP is Spam
0a1dc88e 461 * @access private
462 */
10a26cea 463function filters_spam_check_site($a, $b, $c, $d, &$filters) {
a2a566eb 464 global $SpamFilters_DNScache, $SpamFilters_CacheTTL;
10a26cea 465 foreach ($filters as $key => $value) {
466 if ($filters[$key]['enabled']) {
467 if ($filters[$key]['dns']) {
468 $filter_revip = $d . '.' . $c . '.' . $b . '.' . $a . '.' .
469 $filters[$key]['dns'];
ae48f757 470
471 if(!isset($SpamFilters_DNScache[$filter_revip]['L']))
472 $SpamFilters_DNScache[$filter_revip]['L'] = '';
473
474 if(!isset($SpamFilters_DNScache[$filter_revip]['T']))
475 $SpamFilters_DNScache[$filter_revip]['T'] = '';
476
a7cd90dd 477 if (strlen($SpamFilters_DNScache[$filter_revip]['L']) == 0) {
478 $SpamFilters_DNScache[$filter_revip]['L'] =
479 gethostbyname($filter_revip);
480 $SpamFilters_DNScache[$filter_revip]['T'] =
481 time() + $SpamFilters_CacheTTL;
482 }
483 if ($SpamFilters_DNScache[$filter_revip]['L'] ==
484 $filters[$key]['result']) {
485 return 1;
4eee5968 486 }
487 }
488 }
4eee5968 489 }
10a26cea 490 return 0;
491}
492
0a1dc88e 493/**
9c655416 494 * Loads the filters from the user preferences
495 * @return array All the user filters
0a1dc88e 496 * @access private
497 */
10a26cea 498function load_filters() {
499 global $data_dir, $username;
c8a2c24d 500
10a26cea 501 $filters = array();
9c655416 502 for ($i = 0; $fltr = getPref($data_dir, $username, 'filter' . $i); $i++) {
10a26cea 503 $ary = explode(',', $fltr);
504 $filters[$i]['where'] = $ary[0];
505 $filters[$i]['what'] = $ary[1];
506 $filters[$i]['folder'] = $ary[2];
4eee5968 507 }
10a26cea 508 return $filters;
509}
510
0a1dc88e 511/**
9c655416 512 * Loads the Spam Filters and checks the preferences for the enabled status
513 * @return array All the spam filters
0a1dc88e 514 * @access private
515 */
10a26cea 516function load_spam_filters() {
51199e7a 517 global $data_dir, $username, $SpamFilters_ShowCommercial;
518
519 if ($SpamFilters_ShowCommercial) {
520 $filters['MAPS RBL']['prefname'] = 'filters_spam_maps_rbl';
521 $filters['MAPS RBL']['name'] = 'MAPS Realtime Blackhole List';
522 $filters['MAPS RBL']['link'] = 'http://www.mail-abuse.org/rbl/';
523 $filters['MAPS RBL']['dns'] = 'blackholes.mail-abuse.org';
524 $filters['MAPS RBL']['result'] = '127.0.0.2';
525 $filters['MAPS RBL']['comment'] =
526 _("COMMERCIAL - This list contains servers that are verified spam senders. It is a pretty reliable list to scan spam from.");
527
528 $filters['MAPS RSS']['prefname'] = 'filters_spam_maps_rss';
529 $filters['MAPS RSS']['name'] = 'MAPS Relay Spam Stopper';
530 $filters['MAPS RSS']['link'] = 'http://www.mail-abuse.org/rss/';
531 $filters['MAPS RSS']['dns'] = 'relays.mail-abuse.org';
532 $filters['MAPS RSS']['result'] = '127.0.0.2';
533 $filters['MAPS RSS']['comment'] =
99aaff8b 534 _("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 535
536 $filters['MAPS DUL']['prefname'] = 'filters_spam_maps_dul';
537 $filters['MAPS DUL']['name'] = 'MAPS Dial-Up List';
538 $filters['MAPS DUL']['link'] = 'http://www.mail-abuse.org/dul/';
539 $filters['MAPS DUL']['dns'] = 'dialups.mail-abuse.org';
540 $filters['MAPS DUL']['result'] = '127.0.0.3';
541 $filters['MAPS DUL']['comment'] =
99aaff8b 542 _("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 543
544 $filters['MAPS RBLplus-RBL']['prefname'] = 'filters_spam_maps_rblplus_rbl';
545 $filters['MAPS RBLplus-RBL']['name'] = 'MAPS RBL+ RBL List';
546 $filters['MAPS RBLplus-RBL']['link'] = 'http://www.mail-abuse.org/';
547 $filters['MAPS RBLplus-RBL']['dns'] = 'rbl-plus.mail-abuse.org';
548 $filters['MAPS RBLplus-RBL']['result'] = '127.0.0.2';
549 $filters['MAPS RBLplus-RBL']['comment'] =
550 _("COMMERCIAL - RBL+ Blackhole entries.");
551
552 $filters['MAPS RBLplus-RSS']['prefname'] = 'filters_spam_maps_rblplus_rss';
553 $filters['MAPS RBLplus-RSS']['name'] = 'MAPS RBL+ List RSS entries';
554 $filters['MAPS RBLplus-RSS']['link'] = 'http://www.mail-abuse.org/';
555 $filters['MAPS RBLplus-RSS']['dns'] = 'rbl-plus.mail-abuse.org';
556 $filters['MAPS RBLplus-RSS']['result'] = '127.0.0.2';
557 $filters['MAPS RBLplus-RSS']['comment'] =
558 _("COMMERCIAL - RBL+ OpenRelay entries.");
559
560 $filters['MAPS RBLplus-DUL']['prefname'] = 'filters_spam_maps_rblplus_dul';
561 $filters['MAPS RBLplus-DUL']['name'] = 'MAPS RBL+ List DUL entries';
562 $filters['MAPS RBLplus-DUL']['link'] = 'http://www.mail-abuse.org/';
563 $filters['MAPS RBLplus-DUL']['dns'] = 'rbl-plus.mail-abuse.org';
564 $filters['MAPS RBLplus-DUL']['result'] = '127.0.0.3';
565 $filters['MAPS RBLplus-DUL']['comment'] =
566 _("COMMERCIAL - RBL+ Dial-up entries.");
567 }
10a26cea 568
10a26cea 569 $filters['ORDB']['prefname'] = 'filters_spam_ordb';
570 $filters['ORDB']['name'] = 'Open Relay Database List';
571 $filters['ORDB']['link'] = 'http://www.ordb.org/';
572 $filters['ORDB']['dns'] = 'relays.ordb.org';
573 $filters['ORDB']['result'] = '127.0.0.2';
574 $filters['ORDB']['comment'] =
575 _("FREE - ORDB was born when ORBS went off the air. It seems to have fewer false positives than ORBS did though.");
576
10a26cea 577 $filters['FiveTen Direct']['prefname'] = 'filters_spam_fiveten_src';
578 $filters['FiveTen Direct']['name'] = 'Five-Ten-sg.com Direct SPAM Sources';
579 $filters['FiveTen Direct']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
580 $filters['FiveTen Direct']['dns'] = 'blackholes.five-ten-sg.com';
581 $filters['FiveTen Direct']['result'] = '127.0.0.2';
582 $filters['FiveTen Direct']['comment'] =
583 _("FREE - Five-Ten-sg.com - Direct SPAM sources.");
584
585 $filters['FiveTen DUL']['prefname'] = 'filters_spam_fiveten_dul';
586 $filters['FiveTen DUL']['name'] = 'Five-Ten-sg.com DUL Lists';
587 $filters['FiveTen DUL']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
588 $filters['FiveTen DUL']['dns'] = 'blackholes.five-ten-sg.com';
589 $filters['FiveTen DUL']['result'] = '127.0.0.3';
590 $filters['FiveTen DUL']['comment'] =
591 _("FREE - Five-Ten-sg.com - Dial-up lists - includes some DSL IPs.");
592
593 $filters['FiveTen Unc. OptIn']['prefname'] = 'filters_spam_fiveten_oi';
594 $filters['FiveTen Unc. OptIn']['name'] = 'Five-Ten-sg.com Unconfirmed OptIn Lists';
595 $filters['FiveTen Unc. OptIn']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
596 $filters['FiveTen Unc. OptIn']['dns'] = 'blackholes.five-ten-sg.com';
597 $filters['FiveTen Unc. OptIn']['result'] = '127.0.0.4';
598 $filters['FiveTen Unc. OptIn']['comment'] =
599 _("FREE - Five-Ten-sg.com - Bulk mailers that do not use confirmed opt-in.");
600
601 $filters['FiveTen Others']['prefname'] = 'filters_spam_fiveten_oth';
602 $filters['FiveTen Others']['name'] = 'Five-Ten-sg.com Other Misc. Servers';
603 $filters['FiveTen Others']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
604 $filters['FiveTen Others']['dns'] = 'blackholes.five-ten-sg.com';
605 $filters['FiveTen Others']['result'] = '127.0.0.5';
606 $filters['FiveTen Others']['comment'] =
607 _("FREE - Five-Ten-sg.com - Other misc. servers.");
608
609 $filters['FiveTen Single Stage']['prefname'] = 'filters_spam_fiveten_ss';
610 $filters['FiveTen Single Stage']['name'] = 'Five-Ten-sg.com Single Stage Servers';
611 $filters['FiveTen Single Stage']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
612 $filters['FiveTen Single Stage']['dns'] = 'blackholes.five-ten-sg.com';
613 $filters['FiveTen Single Stage']['result'] = '127.0.0.6';
614 $filters['FiveTen Single Stage']['comment'] =
615 _("FREE - Five-Ten-sg.com - Single Stage servers.");
616
617 $filters['FiveTen SPAM Support']['prefname'] = 'filters_spam_fiveten_supp';
618 $filters['FiveTen SPAM Support']['name'] = 'Five-Ten-sg.com SPAM Support Servers';
619 $filters['FiveTen SPAM Support']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
620 $filters['FiveTen SPAM Support']['dns'] = 'blackholes.five-ten-sg.com';
621 $filters['FiveTen SPAM Support']['result'] = '127.0.0.7';
622 $filters['FiveTen SPAM Support']['comment'] =
623 _("FREE - Five-Ten-sg.com - SPAM Support servers.");
624
625 $filters['FiveTen Web forms']['prefname'] = 'filters_spam_fiveten_wf';
626 $filters['FiveTen Web forms']['name'] = 'Five-Ten-sg.com Web Form IPs';
627 $filters['FiveTen Web forms']['link'] = 'http://www.five-ten-sg.com/blackhole.php';
628 $filters['FiveTen Web forms']['dns'] = 'blackholes.five-ten-sg.com';
629 $filters['FiveTen Web forms']['result'] = '127.0.0.8';
630 $filters['FiveTen Web forms']['comment'] =
631 _("FREE - Five-Ten-sg.com - Web Form IPs.");
632
633 $filters['Dorkslayers']['prefname'] = 'filters_spam_dorks';
634 $filters['Dorkslayers']['name'] = 'Dorkslayers Lists';
635 $filters['Dorkslayers']['link'] = 'http://www.dorkslayers.com';
636 $filters['Dorkslayers']['dns'] = 'orbs.dorkslayers.com';
637 $filters['Dorkslayers']['result'] = '127.0.0.2';
638 $filters['Dorkslayers']['comment'] =
639 _("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.");
640
641 $filters['SPAMhaus']['prefname'] = 'filters_spam_spamhaus';
642 $filters['SPAMhaus']['name'] = 'SPAMhaus Lists';
643 $filters['SPAMhaus']['link'] = 'http://www.spamhaus.org';
644 $filters['SPAMhaus']['dns'] = 'sbl.spamhaus.org';
645 $filters['SPAMhaus']['result'] = '127.0.0.6';
646 $filters['SPAMhaus']['comment'] =
647 _("FREE - SPAMhaus - A list of well-known SPAM sources.");
648
649 $filters['SPAMcop']['prefname'] = 'filters_spam_spamcop';
650 $filters['SPAMcop']['name'] = 'SPAM Cop Lists';
651 $filters['SPAMcop']['link'] = 'http://spamcop.net/bl.shtml';
652 $filters['SPAMcop']['dns'] = 'bl.spamcop.net';
653 $filters['SPAMcop']['result'] = '127.0.0.2';
654 $filters['SPAMcop']['comment'] =
ace4e0d3 655 _("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 656
46a184ff 657 $filters['dev.null.dk']['prefname'] = 'filters_spam_devnull';
658 $filters['dev.null.dk']['name'] = 'dev.null.dk Lists';
659 $filters['dev.null.dk']['link'] = 'http://dev.null.dk/';
660 $filters['dev.null.dk']['dns'] = 'dev.null.dk';
661 $filters['dev.null.dk']['result'] = '127.0.0.2';
662 $filters['dev.null.dk']['comment'] =
663 _("FREE - dev.null.dk - I don't have any detailed info on this list.");
664
665 $filters['visi.com']['prefname'] = 'filters_spam_visi';
666 $filters['visi.com']['name'] = 'visi.com Relay Stop List';
667 $filters['visi.com']['link'] = 'http://relays.visi.com';
668 $filters['visi.com']['dns'] = 'relays.visi.com';
669 $filters['visi.com']['result'] = '127.0.0.2';
670 $filters['visi.com']['comment'] =
671 _("FREE - visi.com - Relay Stop List. Very conservative OpenRelay List.");
672
bd35ab2b 673 $filters['ahbl.org Open Relays']['prefname'] = 'filters_spam_2mb_or';
674 $filters['ahbl.org Open Relays']['name'] = 'ahbl.org Open Relays List';
675 $filters['ahbl.org Open Relays']['link'] = 'http://www.ahbl.org/';
676 $filters['ahbl.org Open Relays']['dns'] = 'dnsbl.ahbl.org';
677 $filters['ahbl.org Open Relays']['result'] = '127.0.0.2';
678 $filters['ahbl.org Open Relays']['comment'] =
679 _("FREE - ahbl.org Open Relays - Another list of Open Relays.");
680
681 $filters['ahbl.org SPAM Source']['prefname'] = 'filters_spam_2mb_ss';
682 $filters['ahbl.org SPAM Source']['name'] = 'ahbl.org SPAM Source List';
683 $filters['ahbl.org SPAM Source']['link'] = 'http://www.ahbl.org/';
684 $filters['ahbl.org SPAM Source']['dns'] = 'dnsbl.ahbl.org';
685 $filters['ahbl.org SPAM Source']['result'] = '127.0.0.4';
686 $filters['ahbl.org SPAM Source']['comment'] =
687 _("FREE - ahbl.org SPAM Source - List of Direct SPAM Sources.");
688
689 $filters['ahbl.org SPAM ISPs']['prefname'] = 'filters_spam_2mb_isp';
690 $filters['ahbl.org SPAM ISPs']['name'] = 'ahbl.org SPAM-friendly ISP List';
691 $filters['ahbl.org SPAM ISPs']['link'] = 'http://www.ahbl.org/';
692 $filters['ahbl.org SPAM ISPs']['dns'] = 'dnsbl.ahbl.org';
693 $filters['ahbl.org SPAM ISPs']['result'] = '127.0.0.7';
694 $filters['ahbl.org SPAM ISPs']['comment'] =
695 _("FREE - ahbl.org SPAM ISPs - List of SPAM-friendly ISPs.");
46a184ff 696
697 $filters['Leadmon DUL']['prefname'] = 'filters_spam_lm_dul';
698 $filters['Leadmon DUL']['name'] = 'Leadmon.net DUL List';
699 $filters['Leadmon DUL']['link'] = 'http://www.leadmon.net/spamguard/';
700 $filters['Leadmon DUL']['dns'] = 'spamguard.leadmon.net';
701 $filters['Leadmon DUL']['result'] = '127.0.0.2';
702 $filters['Leadmon DUL']['comment'] =
703 _("FREE - Leadmon DUL - Another list of Dial-up or otherwise dynamically assigned IPs.");
704
705 $filters['Leadmon SPAM Source']['prefname'] = 'filters_spam_lm_ss';
706 $filters['Leadmon SPAM Source']['name'] = 'Leadmon.net SPAM Source List';
707 $filters['Leadmon SPAM Source']['link'] = 'http://www.leadmon.net/spamguard/';
708 $filters['Leadmon SPAM Source']['dns'] = 'spamguard.leadmon.net';
709 $filters['Leadmon SPAM Source']['result'] = '127.0.0.3';
710 $filters['Leadmon SPAM Source']['comment'] =
711 _("FREE - Leadmon SPAM Source - List of IPs Leadmon.net has received SPAM directly from.");
712
713 $filters['Leadmon Bulk Mailers']['prefname'] = 'filters_spam_lm_bm';
714 $filters['Leadmon Bulk Mailers']['name'] = 'Leadmon.net Bulk Mailers List';
715 $filters['Leadmon Bulk Mailers']['link'] = 'http://www.leadmon.net/spamguard/';
716 $filters['Leadmon Bulk Mailers']['dns'] = 'spamguard.leadmon.net';
717 $filters['Leadmon Bulk Mailers']['result'] = '127.0.0.4';
718 $filters['Leadmon Bulk Mailers']['comment'] =
719 _("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.");
720
721 $filters['Leadmon Open Relays']['prefname'] = 'filters_spam_lm_or';
722 $filters['Leadmon Open Relays']['name'] = 'Leadmon.net Open Relays List';
723 $filters['Leadmon Open Relays']['link'] = 'http://www.leadmon.net/spamguard/';
724 $filters['Leadmon Open Relays']['dns'] = 'spamguard.leadmon.net';
725 $filters['Leadmon Open Relays']['result'] = '127.0.0.5';
726 $filters['Leadmon Open Relays']['comment'] =
727 _("FREE - Leadmon Open Relays - Single Stage Open Relays that are not listed on other active RBLs.");
728
729 $filters['Leadmon Multi-stage']['prefname'] = 'filters_spam_lm_ms';
730 $filters['Leadmon Multi-stage']['name'] = 'Leadmon.net Multi-Stage Relay List';
731 $filters['Leadmon Multi-stage']['link'] = 'http://www.leadmon.net/spamguard/';
732 $filters['Leadmon Multi-stage']['dns'] = 'spamguard.leadmon.net';
733 $filters['Leadmon Multi-stage']['result'] = '127.0.0.6';
734 $filters['Leadmon Multi-stage']['comment'] =
735 _("FREE - Leadmon Multi-stage - Multi-Stage Open Relays that are not listed on other active RBLs and that have sent SPAM to Leadmon.net.");
736
737 $filters['Leadmon SpamBlock']['prefname'] = 'filters_spam_lm_sb';
738 $filters['Leadmon SpamBlock']['name'] = 'Leadmon.net SpamBlock Sites List';
739 $filters['Leadmon SpamBlock']['link'] = 'http://www.leadmon.net/spamguard/';
740 $filters['Leadmon SpamBlock']['dns'] = 'spamguard.leadmon.net';
741 $filters['Leadmon SpamBlock']['result'] = '127.0.0.7';
742 $filters['Leadmon SpamBlock']['comment'] =
743 _("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.");
744
745 $filters['NJABL Open Relays']['prefname'] = 'filters_spam_njabl_or';
746 $filters['NJABL Open Relays']['name'] = 'NJABL Open Relay/Direct Spam Source List';
747 $filters['NJABL Open Relays']['link'] = 'http://www.njabl.org/';
748 $filters['NJABL Open Relays']['dns'] = 'dnsbl.njabl.org';
749 $filters['NJABL Open Relays']['result'] = '127.0.0.2';
750 $filters['NJABL Open Relays']['comment'] =
751 _("FREE, for now - Not Just Another Blacklist - Both Open Relays and Direct SPAM Sources.");
752
753 $filters['NJABL DUL']['prefname'] = 'filters_spam_njabl_dul';
754 $filters['NJABL DUL']['name'] = 'NJABL Dial-ups List';
755 $filters['NJABL DUL']['link'] = 'http://www.njabl.org/';
756 $filters['NJABL DUL']['dns'] = 'dnsbl.njabl.org';
757 $filters['NJABL DUL']['result'] = '127.0.0.3';
758 $filters['NJABL DUL']['comment'] =
759 _("FREE, for now - Not Just Another Blacklist - Dial-up IPs.");
760
18b078e9 761 $filters['Conf DSBL.ORG Relay']['prefname'] = 'filters_spam_dsbl_conf_ss';
762 $filters['Conf DSBL.ORG Relay']['name'] = 'DSBL.org Confirmed Relay List';
763 $filters['Conf DSBL.ORG Relay']['link'] = 'http://www.dsbl.org/';
764 $filters['Conf DSBL.ORG Relay']['dns'] = 'list.dsbl.org';
765 $filters['Conf DSBL.ORG Relay']['result'] = '127.0.0.2';
766 $filters['Conf DSBL.ORG Relay']['comment'] =
767 _("FREE - Distributed Sender Boycott List - Confirmed Relays");
768
769 $filters['Conf DSBL.ORG Multi-Stage']['prefname'] = 'filters_spam_dsbl_conf_ms';
770 $filters['Conf DSBL.ORG Multi-Stage']['name'] = 'DSBL.org Confirmed Multi-Stage Relay List';
771 $filters['Conf DSBL.ORG Multi-Stage']['link'] = 'http://www.dsbl.org/';
772 $filters['Conf DSBL.ORG Multi-Stage']['dns'] = 'multihop.dsbl.org';
773 $filters['Conf DSBL.ORG Multi-Stage']['result'] = '127.0.0.2';
774 $filters['Conf DSBL.ORG Multi-Stage']['comment'] =
775 _("FREE - Distributed Sender Boycott List - Confirmed Multi-stage Relays");
776
777 $filters['UN-Conf DSBL.ORG']['prefname'] = 'filters_spam_dsbl_unc';
778 $filters['UN-Conf DSBL.ORG']['name'] = 'DSBL.org UN-Confirmed Relay List';
779 $filters['UN-Conf DSBL.ORG']['link'] = 'http://www.dsbl.org/';
780 $filters['UN-Conf DSBL.ORG']['dns'] = 'unconfirmed.dsbl.org';
781 $filters['UN-Conf DSBL.ORG']['result'] = '127.0.0.2';
782 $filters['UN-Conf DSBL.ORG']['comment'] =
783 _("FREE - Distributed Sender Boycott List - UN-Confirmed Relays");
784
10a26cea 785 foreach ($filters as $Key => $Value) {
9c655416 786 $filters[$Key]['enabled'] = getPref($data_dir, $username, $filters[$Key]['prefname']);
4eee5968 787 }
788
10a26cea 789 return $filters;
790}
4eee5968 791
0a1dc88e 792/**
9c655416 793 * Removes a User filter
794 * @param int $id ID of the filter to remove
0a1dc88e 795 * @access private
796 */
10a26cea 797function remove_filter ($id) {
798 global $data_dir, $username;
4eee5968 799
9c655416 800 while ($nextFilter = getPref($data_dir, $username, 'filter' . ($id + 1))) {
10a26cea 801 setPref($data_dir, $username, 'filter' . $id, $nextFilter);
802 $id ++;
4eee5968 803 }
804
10a26cea 805 removePref($data_dir, $username, 'filter' . $id);
806}
4eee5968 807
0a1dc88e 808/**
9c655416 809 * Swaps two filters
810 * @param int $id1 ID of first filter to swap
811 * @param int $id2 ID of second filter to swap
0a1dc88e 812 * @access private
813 */
10a26cea 814function filter_swap($id1, $id2) {
815 global $data_dir, $username;
4eee5968 816
10a26cea 817 $FirstFilter = getPref($data_dir, $username, 'filter' . $id1);
818 $SecondFilter = getPref($data_dir, $username, 'filter' . $id2);
819
820 if ($FirstFilter && $SecondFilter) {
821 setPref($data_dir, $username, 'filter' . $id2, $FirstFilter);
822 setPref($data_dir, $username, 'filter' . $id1, $SecondFilter);
4eee5968 823 }
10a26cea 824}
4eec80a7 825
0a1dc88e 826/**
9c655416 827 * This updates the filter rules when renaming or deleting folders
0a1dc88e 828 * @param array $args
b2d8bc6c 829 * @access private
0a1dc88e 830 */
f5ab1fb9 831function update_for_folder ($args) {
9c655416 832
833 if (!file_exists(SM_PATH . 'plugins/filters/config.php')) return;
834
f5ab1fb9 835 $old_folder = $args[0];
9c655416 836 $new_folder = $args[2];
837 $action = $args[1];
ce68b76b 838 global $data_dir, $username;
4eec80a7 839 $filters = array();
840 $filters = load_filters();
841 $filter_count = count($filters);
842 $p = 0;
9c655416 843 for ($i = 0; $i < $filter_count; $i++) {
4eec80a7 844 if (!empty($filters)) {
845 if ($old_folder == $filters[$i]['folder']) {
846 if ($action == 'rename') {
847 $filters[$i]['folder'] = $new_folder;
848 setPref($data_dir, $username, 'filter'.$i,
849 $filters[$i]['where'].','.$filters[$i]['what'].','.$new_folder);
850 }
851 elseif ($action == 'delete') {
852 remove_filter($p);
853 $p = $p-1;
854 }
855 }
856 $p++;
857 }
858 }
859}
0a1dc88e 860
0a1dc88e 861/**
862 * Display formated error message
863 * @param string $string text message
864 * @return string html formated text message
865 * @access private
866 */
867function do_error($string) {
868 global $color;
869 echo "<p align=\"center\"><font color=\"$color[2]\">";
870 echo $string;
871 echo "</font></p>\n";
872}
9c655416 873
874?>