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.
65 The file format is one regular expression per line.
66 The regular expression is matched against the address.")
68 (defvar spam-blacklist (expand-file-name "blacklist" spam-directory)
69 "The location of the blacklist.
70 The file format is one regular expression per line.
71 The regular expression is matched against the address.")
73 (defvar spam-whitelist-cache nil)
74 (defvar spam-blacklist-cache nil)
76 (defun spam-enter-whitelist (address &optional blacklist)
77 "Enter ADDRESS into the whitelist.
78 Optional arg BLACKLIST, if non-nil, means to enter in the blacklist instead."
79 (interactive "sAddress: ")
80 (let ((file (if blacklist spam-blacklist spam-whitelist)))
81 (unless (file-exists-p (file-name-directory file))
82 (make-directory (file-name-directory file) t))
85 (find-file-noselect file))
86 (goto-char (point-max))
92 (defun spam-enter-blacklist (address)
93 "Enter ADDRESS into the blacklist."
94 (interactive "sAddress: ")
95 (spam-enter-whitelist address t))
97 (defun spam-parse-whitelist (&optional blacklist)
98 (let ((file (if blacklist spam-blacklist spam-whitelist))
100 (when (file-exists-p file)
102 (insert-file-contents file)
104 (setq address (buffer-substring (point) (point-at-eol)))
106 (unless (zerop (length address))
107 (setq address (regexp-quote address))
108 (while (string-match "\\\\\\*" address)
109 (setq address (replace-match ".*" t t address)))
110 (push address contents))))
111 (nreverse contents))))
113 (defun spam-refresh-list-cache ()
114 (setq spam-whitelist-cache (spam-parse-whitelist))
115 (setq spam-blacklist-cache (spam-parse-whitelist t)))
117 (defun spam-address-whitelisted-p (address &optional blacklist)
118 (let ((cache (if blacklist spam-blacklist-cache spam-whitelist-cache))
120 (while (and (not found)
122 (when (string-match (pop cache) address)
128 ;;; spam.el ends here