From 9954c7f04f3768cb05c875cfc82b32f6bb077431 Mon Sep 17 00:00:00 2001 From: yamaoka Date: Tue, 7 Jan 2003 05:16:00 +0000 Subject: [PATCH] Synch with Oort Gnus. --- lisp/ChangeLog | 16 +++++++ lisp/gnus.el | 6 +++ lisp/spam.el | 127 +++++++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 120 insertions(+), 29 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 66c5f20..925ea0a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,19 @@ +2003-01-07 Teodor Zlatanov + + * spam.el (spam-check-ifile, spam-ifile-register-with-ifile) + (spam-ifile-register-spam-routine) + (spam-ifile-register-ham-routine): added ifile functionality that + does not use ifile-gnus.el to classify and register articles + (spam-get-article-as-string): convenience function + (spam-summary-prepare-exit): added ifile spam and ham registration + (spam-ifile-all-categories, spam-ifile-spam-category) + (spam-ifile-path, spam-ifile): added customization options + + * gnus.el (gnus-group-ham-exit-processor-ifile): added ifile ham + exit processor + (spam-process): added gnus-group-ham-exit-processor-ifile to the + list of choices + 2003-01-07 Lars Magne Ingebrigtsen * gnus-score.el (gnus-score-followup): Also score immediate diff --git a/lisp/gnus.el b/lisp/gnus.el index aa8ef80..ea85969 100644 --- a/lisp/gnus.el +++ b/lisp/gnus.el @@ -1837,6 +1837,10 @@ Only applicable to spam groups.") "The Blacklist summary exit spam processor. Only applicable to spam groups.") +(defvar gnus-group-ham-exit-processor-ifile "ifile-ham" + "The ifile summary exit ham processor. +Only applicable to non-spam (unclassified and ham) groups.") + (defvar gnus-group-ham-exit-processor-whitelist "whitelist" "The whitelist summary exit ham processor. Only applicable to non-spam (unclassified and ham) groups.") @@ -1855,6 +1859,7 @@ Only applicable to non-spam (unclassified and ham) groups.") (variable-item gnus-group-spam-exit-processor-ifile) (variable-item gnus-group-spam-exit-processor-bogofilter) (variable-item gnus-group-spam-exit-processor-blacklist) + (variable-item gnus-group-ham-exit-processor-ifile) (variable-item gnus-group-ham-exit-processor-whitelist) (variable-item gnus-group-ham-exit-processor-BBDB)))) :function-document @@ -1875,6 +1880,7 @@ for mail groups." (variable-item gnus-group-spam-exit-processor-ifile) (variable-item gnus-group-spam-exit-processor-bogofilter) (variable-item gnus-group-spam-exit-processor-blacklist) + (variable-item gnus-group-ham-exit-processor-ifile) (variable-item gnus-group-ham-exit-processor-whitelist) (variable-item gnus-group-ham-exit-processor-BBDB)))) :parameter-document diff --git a/lisp/spam.el b/lisp/spam.el index 1c7417a..6355275 100644 --- a/lisp/spam.el +++ b/lisp/spam.el @@ -54,10 +54,6 @@ ;; executable-find is not autoloaded in Emacs 20 (autoload 'executable-find "executable")) -;; autoload ifile-spam-filter -(eval-and-compile - (autoload 'ifile-spam-filter "ifile-gnus")) - ;; autoload query-dig (eval-and-compile (autoload 'query-dig "dig")) @@ -172,6 +168,27 @@ Such articles will be transmitted to `bogofilter -s' on group exit." :type 'face :group 'spam) +(defgroup spam-ifile nil + "Spam ifile configuration." + :group 'spam) + +(defcustom spam-ifile-path (executable-find "ifile") + "File path of the ifile executable program." + :type '(choice (file :tag "Location of ifile") + (const :tag "ifile is not installed")) + :group 'spam-ifile) + +(defcustom spam-ifile-spam-category "spam" + "Name of the spam ifile category." + :type 'string + :group 'spam-ifile) + +(defcustom spam-ifile-all-categories nil + "Whether the spam-split invocation of ifile will return all categories, or just spam. +Set this to t if you want to use the spam-split invocation of ifile as your main source of newsgroup names." + :type 'boolean + :group 'spam-ifile) + (defgroup spam-bogofilter nil "Spam bogofilter configuration." :group 'spam) @@ -246,19 +263,22 @@ articles before they get registered by Bogofilter." (member processor (car (gnus-parameter-spam-process group))) nil)) -(defun spam-group-processor-bogofilter-p (group) +(defun spam-group-spam-processor-bogofilter-p (group) (spam-group-processor-p group 'gnus-group-spam-exit-processor-bogofilter)) -(defun spam-group-processor-ifile-p (group) +(defun spam-group-spam-processor-blacklist-p (group) + (spam-group-processor-p group 'gnus-group-spam-exit-processor-blacklist)) + +(defun spam-group-spam-processor-ifile-p (group) (spam-group-processor-p group 'gnus-group-spam-exit-processor-ifile)) -(defun spam-group-processor-blacklist-p (group) - (spam-group-processor-p group 'gnus-group-spam-exit-processor-blacklist)) +(defun spam-group-ham-processor-ifile-p (group) + (spam-group-processor-p group 'gnus-group-ham-exit-processor-ifile)) -(defun spam-group-processor-whitelist-p (group) +(defun spam-group-ham-processor-whitelist-p (group) (spam-group-processor-p group 'gnus-group-ham-exit-processor-whitelist)) -(defun spam-group-processor-BBDB-p (group) +(defun spam-group-ham-processor-BBDB-p (group) (spam-group-processor-p group 'gnus-group-ham-exit-processor-BBDB)) ;;; Hooks dispatching. A bit raw for now. @@ -269,13 +289,14 @@ articles before they get registered by Bogofilter." (defun spam-summary-prepare-exit () ;; The spam processors are invoked for any group, spam or ham or neither (when (and spam-bogofilter-path - (spam-group-processor-bogofilter-p gnus-newsgroup-name)) + (spam-group-spam-processor-bogofilter-p gnus-newsgroup-name)) (spam-bogofilter-register-routine)) - (when (spam-group-processor-ifile-p gnus-newsgroup-name) - (spam-ifile-register-routine)) + (when (and spam-ifile-path + (spam-group-spam-processor-ifile-p gnus-newsgroup-name)) + (spam-ifile-register-spam-routine)) - (when (spam-group-processor-bogofilter-p gnus-newsgroup-name) + (when (spam-group-spam-processor-bogofilter-p gnus-newsgroup-name) (spam-blacklist-register-routine)) ;; Only for spam groups, we expire and maybe move articles @@ -284,9 +305,11 @@ articles before they get registered by Bogofilter." (gnus-parameter-spam-process-destination gnus-newsgroup-name))) (when (spam-group-ham-contents-p gnus-newsgroup-name) - (when (spam-group-processor-whitelist-p gnus-newsgroup-name) + (when (spam-group-ham-processor-whitelist-p gnus-newsgroup-name) (spam-whitelist-register-routine)) - (when (spam-group-processor-BBDB-p gnus-newsgroup-name) + (when (spam-group-ham-processor-ifile-p gnus-newsgroup-name) + (spam-ifile-register-ham-routine)) + (when (spam-group-ham-processor-BBDB-p gnus-newsgroup-name) (spam-BBDB-register-routine)))) (add-hook 'gnus-summary-prepare-hook 'spam-summary-prepare) @@ -343,6 +366,16 @@ articles before they get registered by Bogofilter." ; mapcar it discards the ; return values +(defun spam-get-article-as-string (article) + (let ((article-string)) + (when (numberp article) + (save-window-excursion + (gnus-summary-goto-subject article) + (gnus-summary-show-article t) + (set-buffer gnus-article-buffer) + (setq article-string (buffer-string)))) + article-string)) + (defun spam-fetch-field-from-fast (article) "Fetch the `from' field quickly, using the internal gnus-data-list function" (if (and (numberp article) @@ -350,6 +383,13 @@ articles before they get registered by Bogofilter." (mail-header-from (gnus-data-header (assoc article (gnus-data-list nil)))) nil)) +(defun spam-fetch-field-subject-fast (article) + "Fetch the `subject' field quickly, using the internal gnus-data-list function" + (if (and (numberp article) + (assoc article (gnus-data-list nil))) + (mail-header-subject (gnus-data-header (assoc article (gnus-data-list nil)))) + nil)) + ;;;; Spam determination. @@ -473,23 +513,52 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details." ;;;; ifile -;;; uses ifile-gnus.el from -;;; http://www.ai.mit.edu/people/jhbrown/ifile-gnus.html - ;;; check the ifile backend; return nil if the mail was NOT classified ;;; as spam -;;; TODO: we can't (require 'ifile-gnus), because it will insinuate -;;; itself automatically (defun spam-check-ifile () - (let ((ifile-primary-spam-group spam-split-group)) - (ifile-spam-filter nil))) - -;; TODO: add ifile registration -;; We need ifile-gnus.el to support nnimap; we could feel the message -;; directly to ifile like we do with bogofilter but that's ugly. -(defun spam-ifile-register-routine () - (spam-generic-register-routine nil nil)) + "Check the ifile backend for the classification of this message" + (let ((article-buffer-name (buffer-name)) + category return) + (with-temp-buffer + (let ((temp-buffer-name (buffer-name))) + (save-excursion + (set-buffer article-buffer-name) + (call-process-region (point-min) (point-max) spam-ifile-path + nil temp-buffer-name nil "-q" "-c")) + (goto-char (point-min)) + (if (not (eobp)) + (setq category (buffer-substring (point) (spam-point-at-eol)))) + (when (not (zerop (length category))) ; we need a category here + (if spam-ifile-all-categories + (when (string-equal spam-ifile-spam-category category) + (setq return spam-split-group)) + (setq return category))))) ; always accept the ifile category + return)) + +(defun spam-ifile-register-with-ifile (article-string category) + "Register an article, given as a string, with a category. +Uses `gnus-newsgroup-name' if category is nil (for ham registration)." + (when (stringp article-string) + (let ((category (or category gnus-newsgroup-name))) + (with-temp-buffer + (insert-string article-string) + (call-process-region (point-min) (point-max) spam-ifile-path + nil nil nil "-h" "-i" category))))) + +(defun spam-ifile-register-spam-routine () + (spam-generic-register-routine + (lambda (article) + (spam-ifile-register-with-ifile + (spam-get-article-as-string article) spam-ifile-spam-category)) + nil)) + +(defun spam-ifile-register-ham-routine () + (spam-generic-register-routine + nil + (lambda (article) + (spam-ifile-register-with-ifile + (spam-get-article-as-string article) nil)))) ;;;; Blacklists and whitelists. -- 1.7.10.4