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