From: Lars Magne Ingebrigtsen Date: Sun, 31 Mar 2002 03:32:15 +0000 (+0000) Subject: * spam.el: New file. X-Git-Url: https://cgit.sxemacs.org/?a=commitdiff_plain;h=86d87933d1dec92ee49a67dc8a982cc8706ffc4e;p=gnus * spam.el: New file. * dns.el (query-dns): Test. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3e27c8eab..a1d0ffcd4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,7 @@ 2002-03-31 Lars Magne Ingebrigtsen + * spam.el: New file. + * dns.el (query-dns): Test. 2002-03-31 Lars Magne Ingebrigtsen diff --git a/lisp/dns.el b/lisp/dns.el index 6586b9ac5..57a6c6dfc 100644 --- a/lisp/dns.el +++ b/lisp/dns.el @@ -121,7 +121,9 @@ (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) @@ -254,13 +256,16 @@ (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) @@ -274,10 +279,11 @@ :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)))) @@ -287,9 +293,12 @@ (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 index 000000000..62dc36e53 --- /dev/null +++ b/lisp/spam.el @@ -0,0 +1,57 @@ +;;; spam.el --- Identifying spam +;; Copyright (C) 2002 Free Software Foundation, Inc. + +;; Author: Lars Magne Ingebrigtsen +;; 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