return nil if both 'spam and 'ham are found
(spam-check-BBDB): expand all the BBDB macros here so we can have
a reasonably fast local cache without the loading errors
+ (spam-cache-lookups): set to t by default
+ (spam-find-spam): don't try to guess spam-cache-lookups
+ (spam-enter-whitelist, spam-enter-blacklist): also clear the
+ spam-caches entry
+ (spam-filelist-build-cache, spam-filelist-check-cache): better
+ caching of whitelist/blacklist entries
+ (spam-check-whitelist, spam-check-blacklist): invoke
+ spam-from-listed-p with a type, not a cache variable
+ (spam-from-listed-p): wrap around spam-filelist-check-cache
2004-01-07 Jesper Harder <harder@ifa.au.dk>
"Msx" gnus-summary-mark-as-spam
"\M-d" gnus-summary-mark-as-spam)
-(defvar spam-cache-lookups nil
+(defvar spam-cache-lookups t
"Whether spam.el will try to cache lookups using spam-caches.")
(defvar spam-caches (make-hash-table
(first-method (nth 0 methods))
(articles (if spam-autodetect-recheck-messages
gnus-newsgroup-articles
- gnus-newsgroup-unseen))
- (spam-cache-lookups (< 2 (length articles))))
+ gnus-newsgroup-unseen)))
(when (and autodetect
(not (equal first-method 'none)))
With a non-nil REMOVE, remove them."
(interactive "sAddress: ")
(spam-enter-list address spam-whitelist remove)
- (setq spam-whitelist-cache nil))
+ (setq spam-whitelist-cache nil)
+ (spam-clear-cache 'spam-use-whitelist))
;;; address can be a list, too
(defun spam-enter-blacklist (address &optional remove)
With a non-nil REMOVE, remove them."
(interactive "sAddress: ")
(spam-enter-list address spam-blacklist remove)
- (setq spam-blacklist-cache nil))
+ (setq spam-blacklist-cache nil)
+ (spam-clear-cache 'spam-use-whitelist))
(defun spam-enter-list (addresses file &optional remove)
"Enter ADDRESSES into the given FILE.
(insert a "\n")))))
(save-buffer))))
+(defun spam-filelist-build-cache (type)
+ (let ((cache (if (eq type 'spam-use-blacklist)
+ spam-blacklist-cache
+ spam-whitelist-cache))
+ parsed-cache)
+ (unless (gethash type spam-caches)
+ (while cache
+ (let ((address (pop cache)))
+ (unless (zerop (length address)) ; 0 for a nil address too
+ (setq address (regexp-quote address))
+ ;; fix regexp-quote's treatment of user-intended regexes
+ (while (string-match "\\\\\\*" address)
+ (setq address (replace-match ".*" t t address))))
+ (push address parsed-cache)))
+ (puthash type parsed-cache spam-caches))))
+
+(defun spam-filelist-check-cache (type from)
+ (when (stringp from)
+ (spam-filelist-build-cache type)
+ (let (found)
+ (dolist (address (gethash type spam-caches))
+ (when (and address (string-match address from))
+ (setq found t)
+ (return)))
+ found)))
+
;;; returns t if the sender is in the whitelist, nil or
;;; spam-split-group otherwise
(defun spam-check-whitelist ()
spam-split-group)))
(unless spam-whitelist-cache
(setq spam-whitelist-cache (spam-parse-list spam-whitelist)))
- (if (spam-from-listed-p spam-whitelist-cache)
+ (if (spam-from-listed-p 'spam-use-whitelist)
t
(if spam-use-whitelist-exclusive
spam-split-group
spam-split-group)))
(unless spam-blacklist-cache
(setq spam-blacklist-cache (spam-parse-list spam-blacklist)))
- (and (spam-from-listed-p spam-blacklist-cache) spam-split-group)))
+ (and (spam-from-listed-p 'spam-use-blacklist) spam-split-group)))
(defun spam-parse-list (file)
(when (file-readable-p file)
(push (or pure-address address) contents)))))
(nreverse contents))))
-(defun spam-from-listed-p (cache)
+(defun spam-from-listed-p (type)
(let ((from (nnmail-fetch-field "from"))
found)
- (while cache
- (let ((address (pop cache)))
- (unless (zerop (length address)) ; 0 for a nil address too
- (setq address (regexp-quote address))
- ;; fix regexp-quote's treatment of user-intended regexes
- (while (string-match "\\\\\\*" address)
- (setq address (replace-match ".*" t t address))))
- (when (and address (string-match address from))
- (setq found t
- cache nil))))
- found))
+ (spam-filelist-check-cache type from)))
(defun spam-filelist-register-routine (articles blacklist &optional unregister)
(let ((de-symbol (if blacklist 'spam-use-whitelist 'spam-use-blacklist))