X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=elmo%2Felsp-bsfilter.el;h=980e939e62730d5149cd6bdd2ba44ed5ef8f65ae;hb=fceaa7d966c72630d1b8b146ae0414b4d144a8c6;hp=6ecf133d75bf9f5391f5a37365a0c11bd0a91f9b;hpb=a5913229c9b5f35b75a21402d4e9a642ac69e7af;p=elisp%2Fwanderlust.git diff --git a/elmo/elsp-bsfilter.el b/elmo/elsp-bsfilter.el index 6ecf133..980e939 100644 --- a/elmo/elsp-bsfilter.el +++ b/elmo/elsp-bsfilter.el @@ -56,7 +56,7 @@ :type '(repeat string) :group 'elmo-spam-bsfilter) -(defcustom elmo-spam-bsfilter-update-switch "--synchronous-auto-update" +(defcustom elmo-spam-bsfilter-update-switch "--auto-update" "*The switch that Bsfilter uses to update database with classify." :type 'string :group 'elmo-spam-bsfilter) @@ -77,6 +77,20 @@ :type 'integer :group 'elmo-spam-bsfilter) +(defcustom elmo-spam-bsfilter-use-remote + (and elmo-spam-bsfilter-shell-program + (let ((program (file-name-nondirectory + elmo-spam-bsfilter-shell-program)) + (remote-shells '("ssh" "rsh"))) + (catch 'found + (dolist (shell remote-shells) + (when (string-match (concat "\\`" shell) program) + (throw 'found t))) + nil))) + "*Non-nil disables local file feature." + :type 'boolean + :group 'elmo-spam-bsfilter) + (defcustom elmo-spam-bsfilter-debug nil "Non-nil to debug elmo bsfilter spam backend." :type 'boolean @@ -94,7 +108,8 @@ nil (append (if elmo-spam-bsfilter-shell-switch (list elmo-spam-bsfilter-shell-switch)) - (list elmo-spam-bsfilter-program) + (if elmo-spam-bsfilter-program + (list elmo-spam-bsfilter-program)) elmo-spam-bsfilter-args (if elmo-spam-bsfilter-database-directory (list "--homedir" elmo-spam-bsfilter-database-directory)) @@ -106,25 +121,56 @@ (= 0 (elsp-bsfilter-call-bsfilter (if register elmo-spam-bsfilter-update-switch))))) -(defsubst elsp-bsfilter-list-spam-files (targets) - (apply - #'call-process - elmo-spam-bsfilter-shell-program - nil - (list t (if elmo-spam-bsfilter-debug - (get-buffer-create "*Debug ELMO Bsfilter*"))) - nil - (append (if elmo-spam-bsfilter-shell-switch - (list elmo-spam-bsfilter-shell-switch)) - (list elmo-spam-bsfilter-program "--list-spam") - elmo-spam-bsfilter-args - (if elmo-spam-bsfilter-database-directory - (list "--homedir" elmo-spam-bsfilter-database-directory)) - targets))) +(defun elsp-bsfilter-list-spam-filter (process output) + (when (buffer-live-p (process-buffer process)) + (with-current-buffer (process-buffer process) + (save-excursion + (goto-char (process-mark process)) + (insert output) + (set-marker (process-mark process) (point))) + (while (re-search-forward "^combined probability.+\r?\n" nil t) + (delete-region (match-beginning 0) (match-end 0)) + (elmo-progress-notify 'elmo-spam-check-spam)) + (when elmo-spam-bsfilter-debug + (with-current-buffer (get-buffer-create "*Debug ELMO Bsfilter*") + (goto-char (point-max)) + (insert output)))))) + +(defsubst elsp-bsfilter-start-list-spam (targets) + (let ((process + (apply #'start-process + "elsp-bsfilter" + (current-buffer) + elmo-spam-bsfilter-shell-program + (append (if elmo-spam-bsfilter-shell-switch + (list elmo-spam-bsfilter-shell-switch)) + (if elmo-spam-bsfilter-program + (list elmo-spam-bsfilter-program)) + elmo-spam-bsfilter-args + (list "--list-spam") + (if elmo-spam-bsfilter-database-directory + (list "--homedir" + elmo-spam-bsfilter-database-directory)) + targets)))) + (set-process-filter process #'elsp-bsfilter-list-spam-filter) + process)) + +(defsubst elsp-bsfilter-read-list-spam (results hash) + (goto-char (point-min)) + (while (not (eobp)) + (let* ((filename (buffer-substring (point) (save-excursion + (end-of-line) + (point)))) + (number (elmo-get-hash-val filename hash))) + (when number + (setq results (cons number results))) + (forward-line))) + results) (luna-define-method elmo-spam-list-spam-messages :around ((processor elsp-bsfilter) folder &optional numbers) - (if (not (elmo-folder-message-file-p folder)) + (if (or elmo-spam-bsfilter-use-remote + (not (elmo-folder-message-file-p folder))) (luna-call-next-method) (let* ((nth-of-targets (1- (or elmo-spam-bsfilter-max-files-per-process 100))) @@ -143,18 +189,12 @@ (next (cdr last))) (when last (setcdr last nil)) - (elsp-bsfilter-list-spam-files targets) - (elmo-progress-notify 'elmo-spam-check-spam (length targets)) - (setq targets next))) - (goto-char (point-min)) - (while (not (eobp)) - (let* ((filename (buffer-substring (point) (save-excursion - (end-of-line) - (point)))) - (number (elmo-get-hash-val filename hash))) - (when number - (setq results (cons number results))) - (forward-line)))) + (let ((process (elsp-bsfilter-start-list-spam targets))) + (while (memq (process-status process) '(open run)) + (accept-process-output process 1)) + (setq results (elsp-bsfilter-read-list-spam results hash))) + (erase-buffer) + (setq targets next)))) results)))