1 ;;; spam.el --- Identifying spam
2 ;; Copyright (C) 2002 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
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)
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.
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.
33 (defvar spam-blackhole-servers
34 '("bl.spamcop.net" "relays.ordb.org" "dev.null.dk"
35 "relays.visi.com" "rbl.maps.vix.com")
36 "List of blackhole servers.")
38 (defun spam-check-blackholes ()
39 "Check the Recevieved headers for blackholed relays."
40 (let ((headers (message-fetch-field "received"))
44 (goto-char (point-min))
45 (while (re-search-forward
46 "\\[\\([0-9]+.[0-9]+.[0-9]+.[0-9]+\\)\\]" nil t)
47 (push (mapconcat 'identity
48 (nreverse (split-string (match-string 1) "\\."))
51 (dolist (server spam-blackhole-servers)
53 (when (query-dns (concat ip "." server))
54 (push (list ip server (query-dns (concat ip "." server) 'TXT))
58 ;;; Black- and white-lists
60 (defvar spam-directory "~/News/spam/"
61 "When spam files are kept.")
63 (defvar spam-whitelist (expand-file-name "whitelist" spam-directory)
64 "The location of the whitelist.")
66 (defvar spam-blacklist (expand-file-name "blacklist" spam-directory)
67 "The location of the whitelist.")
69 (defvar spam-whitelist-cache nil)
70 (defvar spam-blacklist-cache nil)
72 (defun spam-enter-whitelist (address &optional blacklist)
73 "Enter ADDRESS into the whitelist."
74 (interactive "sAddress: ")
75 (let ((file (if blacklist spam-blacklist spam-whitelist)))
76 (unless (file-exists-p (file-name-directory file))
77 (make-directory (file-name-directory file) t))
80 (find-file-noselect file))
81 (goto-char (point-max))
87 (defun spam-parse-whitelist (&optional blacklist)
88 (let ((file (if blacklist spam-blacklist spam-whitelist))
90 (when (file-exists-p file)
92 (insert-file-contents file)
94 (setq address (buffer-substring (point) (point-at-eol)))
96 (unless (zerop (length address))
97 (setq address (regexp-quote address))
98 (while (string-match "\\\\\\*" address)
99 (setq address (replace-match ".*" t t address)))
100 (push address contents))))
101 (nreverse contents))))
103 (defun spam-refresh-list-cache ()
104 (setq spam-whitelist-cache (spam-parse-whitelist))
105 (setq spam-blacklist-cache (spam-parse-whitelist t)))
107 (defun spam-address-whitelisted-p (address &optional blacklist)
108 (let ((cache (if blacklist spam-blacklist-cache spam-whitelist-cache))
110 (while (and (not found)
112 (when (string-match (pop cache) address)
118 ;;; spam.el ends here