* spam.el: New file.
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Sun, 31 Mar 2002 03:32:15 +0000 (03:32 +0000)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Sun, 31 Mar 2002 03:32:15 +0000 (03:32 +0000)
* dns.el (query-dns): Test.

lisp/ChangeLog
lisp/dns.el
lisp/spam.el [new file with mode: 0644]

index 3e27c8e..a1d0ffc 100644 (file)
@@ -1,5 +1,7 @@
 2002-03-31  Lars Magne Ingebrigtsen  <larsi@quimbies.gnus.org>
 
+       * spam.el: New file.
+
        * dns.el (query-dns): Test.
 
 2002-03-31  Lars Magne Ingebrigtsen  <larsi@gnus.org>
index 6586b9a..57a6c6d 100644 (file)
                                  (progn (forward-char length) (point)))
                name))))
     (if (stringp ended)
-       (concat (mapconcat 'identity (nreverse name) ".") "." ended)
+       (if (null name)
+           ended
+         (concat (mapconcat 'identity (nreverse name) ".") "." ended))
       (mapconcat 'identity (nreverse name) "."))))
 
 (defun dns-write (spec)
              (mapconcat 'number-to-string (nreverse bytes) ".")))
           ((eq type 'NS)
            (dns-read-string-name string buffer))
+          ((eq type 'CNAME)
+           (dns-read-string-name string buffer))
           (t string)))
       (goto-char point))))
 
 ;;; Interface functions.
 
-(defun query-dns (name &optional type)
-  "Query a DNS server for NAME of TYPE."
+(defun query-dns (name &optional type fullp)
+  "Query a DNS server for NAME of TYPE.
+If FULLP, return the entire record returned."
   (setq type (or type 'A))
   (mm-with-unibyte-buffer
     (let ((coding-system-for-read 'binary) 
              :service "domain"
              :type 'datagram))
            (step 100)
-           (times (* dns-timeout 1000)))
+           (times (* dns-timeout 1000))
+           (id (random 65000)))
        (process-send-string
         process
-        (dns-write `((id 4)
+        (dns-write `((id ,id)
                      (opcode query)
                      (queries ((,name (type ,type))))
                      (recursion-desired-p t))))
          (decf times step))
        (ignore-errors
          (delete-process process))
-       (let ((answer (car (dns-get 'answers (dns-read (buffer-string))))))
-         (when (eq type (dns-get 'type answer))
-           (dns-get 'data answer)))))))
+       (let ((result (dns-read (buffer-string))))
+         (if fullp
+             result
+           (let ((answer (car (dns-get 'answers result))))
+             (when (eq type (dns-get 'type answer))
+               (dns-get 'data answer)))))))))
     
 (provide 'dns)
 
diff --git a/lisp/spam.el b/lisp/spam.el
new file mode 100644 (file)
index 0000000..62dc36e
--- /dev/null
@@ -0,0 +1,57 @@
+;;; spam.el --- Identifying spam
+;; Copyright (C) 2002 Free Software Foundation, Inc.
+
+;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
+;; Keywords: network
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'dns)
+(require 'message)
+
+(defvar spam-blackhole-servers
+  '("bl.spamcop.net" "relays.ordb.org" "dev.null.dk"
+    "relays.visi.com" "rbl.maps.vix.com")
+  "List of blackhole servers.")
+
+(defun spam-check-blackholes ()
+  "Check the Recevieved headers for blackholed relays."
+  (let ((headers (message-fetch-field "received"))
+       ips matches)
+    (with-temp-buffer
+      (insert headers)
+      (goto-char (point-min))
+      (while (re-search-forward "\\[\\([0-9]+.[0-9]+.[0-9]+.[0-9]+\\)\\]" nil t)
+       (push (mapconcat 'identity
+                        (nreverse (split-string (match-string 1) "\\."))
+                        ".")
+             ips)))
+    (dolist (server spam-blackhole-servers)
+      (dolist (ip ips)
+       (when (query-dns (concat ip "." server))
+         (push (list ip server (query-dns (concat ip "." server) 'TXT))
+               matches))))
+    matches))
+
+(provide 'spam)
+
+;;; spam.el ends here