* dns.el (query-dns): Use TCP when make-network-process isn't
[gnus] / lisp / spam.el
1 ;;; spam.el --- Identifying spam
2 ;; Copyright (C) 2002 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: network
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (require 'dns)
29 (require 'message)
30
31 (defvar spam-blackhole-servers
32   '("bl.spamcop.net" "relays.ordb.org" "dev.null.dk"
33     "relays.visi.com" "rbl.maps.vix.com")
34   "List of blackhole servers.")
35
36 (defun spam-check-blackholes ()
37   "Check the Recevieved headers for blackholed relays."
38   (let ((headers (message-fetch-field "received"))
39         ips matches)
40     (with-temp-buffer
41       (insert headers)
42       (goto-char (point-min))
43       (while (re-search-forward
44               "\\[\\([0-9]+.[0-9]+.[0-9]+.[0-9]+\\)\\]" nil t)
45         (push (mapconcat 'identity
46                          (nreverse (split-string (match-string 1) "\\."))
47                          ".")
48               ips)))
49     (dolist (server spam-blackhole-servers)
50       (dolist (ip ips)
51         (when (query-dns (concat ip "." server))
52           (push (list ip server (query-dns (concat ip "." server) 'TXT))
53                 matches))))
54     matches))
55
56 (provide 'spam)
57
58 ;;; spam.el ends here