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