+2004-01-06 Teodor Zlatanov <tzz@bwh.harvard.edu>
+
+ * spam.el (spam-cache-lookups, spam-caches, spam-clear-cache):
+ first attempt at some caching support (done for BBDB only now)
+ (spam-find-spam): set spam-cache-lookups if there are more than 2
+ addresses to be checked
+ (spam-clear-cache-BBDB): new function, to be invoked by
+ bbdb-change-hook, and triggering spam-clear-cache of 'spam-use-BBDB
+ (spam-check-BBDB): check and use the caches, if
+ spam-cache-lookups is on
+ remove superfluous (provide)
+
2004-01-06 Reiner Steib <Reiner.Steib@gmx.de>
* gnus-art.el (gnus-treat-ansi-sequences): Changed default.
"Msx" gnus-summary-mark-as-spam
"\M-d" gnus-summary-mark-as-spam)
+(defvar spam-cache-lookups nil
+ "Whether spam.el will try to cache lookups using spam-caches.")
+
+(defvar spam-caches (make-hash-table
+ :size 10
+ :test 'equal)
+ "Cache of spam detection entries.")
+
(defvar spam-old-ham-articles nil
"List of old ham articles, generated when a group is entered.")
finds ham or spam.")
;; convenience functions
+(defun spam-clear-cache (symbol)
+ (remhash symbol spam-caches))
+
(defun spam-xor (a b)
"Logical exclusive `or'."
(and (or a b) (not (and a b))))
(let* ((group gnus-newsgroup-name)
(autodetect (gnus-parameter-spam-autodetect group))
(methods (gnus-parameter-spam-autodetect-methods group))
- (first-method (nth 0 methods)))
- (when (and autodetect
- (not (equal first-method 'none)))
+ (first-method (nth 0 methods))
+ (articles (if spam-autodetect-recheck-messages
+ gnus-newsgroup-articles
+ gnus-newsgroup-unseen))
+ (spam-cache-lookups (< 2 (length articles))))
+
+ (when (and autodetect
+ (not (equal first-method 'none)))
(mapcar
(lambda (article)
(let ((id (spam-fetch-field-message-id-fast article))
(when (zerop (gnus-registry-group-count id))
(gnus-registry-add-group
id group subject sender))
-
+
(spam-log-processing-to-registry
id
'incoming
split-return
spam-split-last-successful-check
group))))))
- (if spam-autodetect-recheck-messages
- gnus-newsgroup-articles
- gnus-newsgroup-unseen)))))
+ articles))))
(defvar spam-registration-functions
;; first the ham register, second the spam register function
(require 'bbdb)
(require 'bbdb-com)
+ ;; when the BBDB changes, we want to clear out our cache
+ (defun spam-clear-cache-BBDB (&rest immaterial)
+ (spam-clear-cache 'spam-use-BBDB))
+
+ (add-hook 'bbdb-change-hook 'spam-clear-cache-BBDB)
+
(defun spam-enter-ham-BBDB (addresses &optional remove)
"Enter an address into the BBDB; implies ham (non-spam) sender"
(dolist (from addresses)
(let ((who (nnmail-fetch-field "from"))
(spam-split-group (if spam-split-symbolic-return
'spam
- spam-split-group)))
+ spam-split-group))
+ bbdb-cache)
+
+ (when spam-cache-lookups
+ (setq bbdb-cache (gethash 'spam-use-BBDB spam-caches))
+ (unless bbdb-cache
+ (setq bbdb-cache (bbdb-hashtable))
+ (puthash 'spam-use-BBDB bbdb-cache spam-caches)))
+
(when who
(setq who (nth 1 (gnus-extract-address-components who)))
- (if (bbdb-search-simple nil who)
+ (if
+ (if spam-cache-lookups
+ (bbdb-gethash who bbdb-cache)
+ (bbdb-search-simple nil who))
t
(if spam-use-BBDB-exclusive
spam-split-group
(file-error (progn
(defalias 'bbdb-search-simple 'ignore)
+ (defalias 'bbdb-hashtable 'ignore)
+ (defalias 'bbdb-gethash 'ignore)
(defalias 'spam-check-BBDB 'ignore)
(defalias 'spam-BBDB-register-routine 'ignore)
(defalias 'spam-enter-ham-BBDB 'ignore)
(provide 'spam)
;;; spam.el ends here.
-
-(provide 'spam)
-
-;;; spam.el ends here