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