(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)
--- /dev/null
+;;; 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