* wl-vars.el (wl-draft-sendlog-max-size): Add nil to range.
[elisp/wanderlust.git] / wl / wl-spam.el
index 31cc3b0..ad1febc 100644 (file)
@@ -41,7 +41,7 @@
   "Spam configuration for wanderlust."
   :group 'wl)
 
-(defcustom wl-spam-folder-name "+spam"
+(defcustom wl-spam-folder "+spam"
   "*Spam folder."
   :type 'string
   :group 'wl-spam)
   :type '(repeat (regexp :tag "Folder Regexp"))
   :group 'wl-spam)
 
-(defcustom wl-spam-auto-check-folder-regexp-list '("[+.]inbox")
+(defcustom wl-spam-auto-check-folder-regexp-list nil
   "*List of Folder regexp which check spam automatically."
   :type '(repeat (regexp :tag "Folder Regexp"))
   :group 'wl-spam)
 
 (defcustom wl-spam-auto-check-marks
-  (list wl-summary-new-mark)
+  (list wl-summary-new-uncached-mark
+       wl-summary-new-cached-mark)
   "Persistent marks to check spam automatically."
   :type '(choice (const :tag "All marks" all)
                 (repeat (string :tag "Mark")))
@@ -102,7 +103,7 @@ See `wl-summary-mark-action-list' for the detail of element."
   :group 'wl-spam)
 
 (defun wl-spam-domain (folder-name)
-  (cond ((string= folder-name wl-spam-folder-name)
+  (cond ((string= folder-name wl-spam-folder)
         'spam)
        ((wl-string-match-member folder-name
                                 wl-spam-undecided-folder-regexp-list)
@@ -151,8 +152,9 @@ See `wl-summary-mark-action-list' for the detail of element."
 
 (defun wl-spam-save-status (&optional force)
   (interactive "P")
-  (let ((processor (elmo-spam-processor)))
-    (when (or force (elmo-spam-modified-p processor))
+  (let ((processor (elmo-spam-processor (not force))))
+    (when (or force
+             (and processor (elmo-spam-modified-p processor)))
       (elmo-spam-save-status processor))))
 
 ;; insinuate into summary mode
@@ -196,11 +198,12 @@ See `wl-summary-mark-action-list' for the detail of element."
        (when (wl-spam-auto-check-message-p wl-summary-buffer-elmo-folder
                                            number)
          (setq numbers (cons number numbers)))))
-    (if numbers
-       (wl-spam-map-spam-messages wl-summary-buffer-elmo-folder
-                                  numbers
-                                  #'wl-summary-spam)
-      (message "No message to test."))))
+    (cond (numbers
+          (wl-spam-map-spam-messages wl-summary-buffer-elmo-folder
+                                     numbers
+                                     #'wl-summary-spam))
+         ((interactive-p)
+          (message "No message to test.")))))
 
 (defun wl-summary-register-as-spam ()
   (interactive)
@@ -260,6 +263,7 @@ See `wl-summary-mark-action-list' for the detail of element."
   (let ((domain (wl-spam-domain (elmo-folder-name-internal
                                 wl-summary-buffer-elmo-folder)))
        (total (length mark-list)))
+    (wl-folder-confirm-existence (elmo-make-folder wl-spam-folder))
     (when (memq domain '(undecided good))
       (message "Registering spam...")
       (elmo-with-progress-display (> total elmo-display-progress-threshold)
@@ -270,7 +274,7 @@ See `wl-summary-mark-action-list' for the detail of element."
                                          (eq domain 'good)))
       (message "Registering spam...done"))
     (wl-summary-move-mark-list-messages mark-list
-                                       wl-spam-folder-name
+                                       wl-spam-folder
                                        "Refiling spam...")))
 
 (defun wl-summary-exec-action-refile-with-register (mark-list)
@@ -289,17 +293,22 @@ See `wl-summary-mark-action-list' for the detail of element."
        (spam (setq spam-list nil))
        (good (setq good-list nil)))
       (when (or spam-list good-list)
-       (message "Registering spam...")
-       (setq total (+ (length spam-list) (length good-list)))
-       (elmo-with-progress-display (> total elmo-display-progress-threshold)
-           (elmo-spam-register total "Registering spam...")
-         (when spam-list
+       (when spam-list
+         (setq total (length spam-list))
+         (message "Registering spam...")
+         (elmo-with-progress-display (> total elmo-display-progress-threshold)
+             (elmo-spam-register total "Registering spam...")
            (elmo-spam-register-spam-messages processor folder spam-list
                                              (eq domain 'good)))
-         (when good-list
+         (message "Registering spam...done"))
+       (when good-list
+         (setq total (length good-list))
+         (message "Registering good...")
+         (elmo-with-progress-display (> total elmo-display-progress-threshold)
+             (elmo-spam-register total "Registering good...")
            (elmo-spam-register-good-messages processor folder good-list
-                                             (eq domain 'spam))))
-       (message "Registering spam...done")))
+                                             (eq domain 'spam)))
+         (message "Registering good...done"))))
     ;; execute refile messages
     (wl-summary-exec-action-refile mark-list)))
 
@@ -308,20 +317,28 @@ See `wl-summary-mark-action-list' for the detail of element."
        (number wl-message-buffer-cur-number)
        spam)
     (message "Cheking spam...")
-    (when (elmo-spam-buffer-spam-p (elmo-spam-processor) original)
+    (when (setq spam (elmo-spam-buffer-spam-p (elmo-spam-processor) original))
       (with-current-buffer wl-message-buffer-cur-summary-buffer
        (wl-summary-spam number)))
     (message "Cheking spam...done")
-    (when (interactive-p)
-      (message "No: %d is %sa spam message." number (if spam "" "not ")))))
+    (message "No: %d is %sa spam message." number (if spam "" "not "))))
 
 (defun wl-refile-guess-by-spam (entity)
   (when (elmo-spam-message-spam-p (elmo-spam-processor)
                                  wl-summary-buffer-elmo-folder
                                  (elmo-message-entity-number entity))
-    wl-spam-folder-name))
+    wl-spam-folder))
 
 (defun wl-spam-setup ()
+  (add-hook 'wl-summary-prepared-hook #'wl-summary-auto-check-spam)
+  (let ((actions wl-summary-mark-action-list)
+       action)
+    (while actions
+      (setq action  (car actions)
+           actions (cdr actions))
+      (when (eq (wl-summary-action-symbol action) 'refile)
+       (setcar (nthcdr 4 action) 'wl-summary-exec-action-refile-with-register)
+       (setq actions nil))))
   (when wl-spam-mark-action-list
     (setq wl-summary-mark-action-list (append
                                       wl-summary-mark-action-list
@@ -334,8 +351,12 @@ See `wl-summary-mark-action-list' for the detail of element."
            (cons (wl-summary-action-mark action)
                  wl-summary-skip-mark-list))))
   (define-key wl-summary-mode-map "k" wl-summary-spam-map)
-  (define-key wl-summary-mode-map "ms" 'wl-summary-target-mark-register-as-spam)
-  (define-key wl-summary-mode-map "mn" 'wl-summary-target-mark-register-as-good))
+  (define-key
+    wl-summary-mode-map "mk" 'wl-summary-target-mark-spam)
+  (define-key
+    wl-summary-mode-map "ms" 'wl-summary-target-mark-register-as-spam)
+  (define-key
+    wl-summary-mode-map "mn" 'wl-summary-target-mark-register-as-good))
 
 (require 'product)
 (product-provide (provide 'wl-spam) (require 'wl-version))