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