filters.php 37 KB

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