* spam.el (spam-enter-whitelist): New function.
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Sun, 31 Mar 2002 16:29:35 +0000 (16:29 +0000)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Sun, 31 Mar 2002 16:29:35 +0000 (16:29 +0000)
(spam-parse-whitelist): Ditto.
(spam-refresh-list-cache): Ditto.
(spam-address-whitelisted-p): New function.

lisp/ChangeLog
lisp/spam.el

index 3b210e2..902d9b3 100644 (file)
@@ -1,5 +1,10 @@
 2002-03-31  Lars Magne Ingebrigtsen  <larsi@quimbies.gnus.org>
 
+       * spam.el (spam-enter-whitelist): New function.
+       (spam-parse-whitelist): Ditto.
+       (spam-refresh-list-cache): Ditto.
+       (spam-address-whitelisted-p): New function.
+
        * dns.el (query-dns): Use TCP when make-network-process isn't
        available. 
        (dns-servers): New variable.
index 5e736b5..e2e4d93 100644 (file)
@@ -28,6 +28,8 @@
 (require 'dns)
 (require 'message)
 
+;;; Blackholes
+
 (defvar spam-blackhole-servers
   '("bl.spamcop.net" "relays.ordb.org" "dev.null.dk"
     "relays.visi.com" "rbl.maps.vix.com")
                matches))))
     matches))
 
+;;; Black- and white-lists
+
+(defvar spam-directory "~/News/spam/"
+  "When spam files are kept.")
+
+(defvar spam-whitelist (expand-file-name "whitelist" spam-directory)
+  "The location of the whitelist.")
+                                        
+(defvar spam-blacklist (expand-file-name "blacklist" spam-directory)
+  "The location of the whitelist.")
+
+(defvar spam-whitelist-cache nil)
+(defvar spam-blacklist-cache nil)
+
+(defun spam-enter-whitelist (address &optional blacklist)
+  "Enter ADDRESS into the whitelist."
+  (interactive "sAddress: ")
+  (let ((file (if blacklist spam-blacklist spam-whitelist)))
+    (unless (file-exists-p (file-name-directory file))
+      (make-directory (file-name-directory file) t))
+    (save-excursion
+      (set-buffer
+       (find-file-noselect file))
+      (goto-char (point-max))
+      (unless (bobp)
+       (insert "\n"))
+      (insert address "\n")
+      (save-buffer))))
+
+(defun spam-parse-whitelist (&optional blacklist)
+  (let ((file (if blacklist spam-blacklist spam-whitelist))
+       contents address)
+    (when (file-exists-p file)
+      (with-temp-buffer
+       (insert-file-contents file)
+       (while (not (eobp))
+         (setq address (buffer-substring (point) (point-at-eol)))
+         (forward-line 1)
+         (unless (zerop (length address))
+           (setq address (regexp-quote address))
+           (while (string-match "\\\\\\*" address)
+             (setq address (replace-match ".*" t t address)))
+           (push address contents))))
+      (nreverse contents))))
+
+(defun spam-refresh-list-cache ()
+  (setq spam-whitelist-cache (spam-parse-whitelist))
+  (setq spam-blacklist-cache (spam-parse-whitelist t)))
+
+(defun spam-address-whitelisted-p (address &optional blacklist)
+  (let ((cache (if blacklist spam-blacklist-cache spam-whitelist-cache))
+       found)
+    (while (and (not found)
+               cache)
+      (when (string-match (pop cache) address)
+       (setq found t)))
+    found))
+
 (provide 'spam)
 
 ;;; spam.el ends here