* elmo-vars.el (elmo-network-stream-type-alist): Add direct.
[elisp/wanderlust.git] / elmo / elmo-split.el
index db175a4..57bf966 100644 (file)
 ;; according to the definition of `elmo-split-rule'.
 ;;
 
+;;; Code:
+(eval-when-compile (require 'cl))
 (require 'elmo)
 
-;;; Code:
+(eval-when-compile
+  ;; Avoid compile warnings
+  (require 'elmo-spam))
+
 (defcustom elmo-split-rule nil
   "Split rule for the command `elmo-split'.
 The format of this variable is a list of RULEs which has form like:
@@ -72,7 +77,15 @@ FIELD-NAME is a symbol of the field name.
 `or'                ... True if one of the argument returns true.
 `and'               ... True if all of the arguments return true.
 
-4. A symbol.
+`spam-p'            ... True if contents of the message is guessed as spam.
+                        Rest arguments are property list which consists
+                        following.
+
+                        `:register' ... If this value is non-nil,
+                                        Register according to
+                                        the classification.
+
+5. A symbol.
 
 When a symbol is specified, it is evaluated.
 
@@ -211,6 +224,12 @@ It can be some ACTION as in `elmo-split-rule'."
                         (symbol-name field)))))
       (equal field-value value))))
 
+(defun elmo-split-spam-p (buffer &rest plist)
+  (require 'elmo-spam)
+  (elmo-spam-buffer-spam-p (elmo-spam-processor)
+                          buffer
+                          (plist-get plist :register)))
+
 (defun elmo-split-match (buffer field value)
   (with-current-buffer buffer
     (let ((field-value (and elmo-split-message-entity
@@ -272,7 +291,8 @@ If prefix argument ARG is specified, do a reharsal (no harm)."
        (format "%d messages are splitted" count)))
       (if (eq fcount 0)
          "."
-       (format " (%d failure)." fcount))))))
+       (format " (%d failure)." fcount))))
+    count))
 
 (defun elmo-split-subr (folder &optional reharsal)
   (let ((elmo-inhibit-display-retrieval-progress t)
@@ -280,7 +300,7 @@ If prefix argument ARG is specified, do a reharsal (no harm)."
        (fcount 0)
        (default-rule `((t ,elmo-split-default-action)))
        msgs action target-folder failure delete-substance
-       record-log log-string)
+       record-log log-string flags)
     (message "Splitting...")
     (elmo-folder-open-internal folder)
     (setq msgs (elmo-folder-list-messages folder))
@@ -296,6 +316,9 @@ If prefix argument ARG is specified, do a reharsal (no harm)."
                                          nil (current-buffer) 'unread))
                (run-hooks 'elmo-split-fetch-hook)
                (setq elmo-split-message-entity (mime-parse-buffer))
+               (setq flags (or (elmo-message-flags folder msg)
+                               (and (elmo-message-entity folder msg)
+                                    '(read))))
                (catch 'terminate
                  (dolist (rule (append elmo-split-rule default-rule))
                    (setq elmo-split-match-string-internal nil)
@@ -327,7 +350,10 @@ If prefix argument ARG is specified, do a reharsal (no harm)."
                                         action)))
                                    (elmo-folder-create target-folder)))
                                (elmo-folder-open-internal target-folder)
-                               (elmo-folder-append-buffer target-folder)
+                               (setq failure (not
+                                              (elmo-folder-append-buffer
+                                               target-folder
+                                               flags)))
                                (elmo-folder-close-internal target-folder))
                            (error (setq failure t)
                                   (incf fcount)))