* elmo-archive.el (elmo-archive-get-archive-name): Cause an error when
[elisp/wanderlust.git] / wl / wl-summary.el
index 075114e..67ebaac 100644 (file)
@@ -1,8 +1,14 @@
 ;;; wl-summary.el -- Summary mode for Wanderlust.
 
-;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
+;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
+;; Copyright (C) 1998,1999,2000 Masahiro MURATA <muse@ba2.so-net.ne.jp>
+;; Copyright (C) 1999,2000      TSUMURA Tomoaki <tsumura@kuis.kyoto-u.ac.jp>
+;; Copyright (C) 1999,2000      Kenichi OKADA <okada@opaopa.org>
 
 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
+;;     Masahiro MURATA <muse@ba2.so-net.ne.jp>
+;;     TSUMURA Tomoaki <tsumura@kuis.kyoto-u.ac.jp>
+;;     Kenichi OKADA <okada@opaopa.org>
 ;; Keywords: mail, net news
 
 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
 (defvar wl-summary-buffer-saved-message nil)
 (defvar wl-summary-buffer-prev-folder-func nil)
 (defvar wl-summary-buffer-next-folder-func nil)
+(defvar wl-summary-buffer-next-message-func nil)
 (defvar wl-summary-buffer-exit-func nil)
+(defvar wl-summary-buffer-number-list nil)
+
 (defvar wl-thread-indent-level-internal nil)
 (defvar wl-thread-have-younger-brother-str-internal nil)
 (defvar wl-thread-youngest-child-str-internal nil)
 (defvar wl-summary-search-buf-name " *wl-search-subject*")
 (defvar wl-summary-delayed-update nil)
 
+(defvar wl-summary-get-petname-func 'wl-address-get-petname-1)
+
 (defvar wl-summary-message-regexp "^ *\\([0-9]+\\)")
 
 (defvar wl-summary-shell-command-last "")
 (make-variable-buffer-local 'wl-thread-space-str-internal)
 (make-variable-buffer-local 'wl-summary-buffer-prev-folder-func)
 (make-variable-buffer-local 'wl-summary-buffer-next-folder-func)
+(make-variable-buffer-local 'wl-summary-buffer-next-message-func)
 (make-variable-buffer-local 'wl-summary-buffer-exit-func)
+(make-variable-buffer-local 'wl-summary-buffer-number-list)
 
 ;; internal functions (dummy)
 (unless (fboundp 'wl-summary-append-message-func-internal)
                                 (eword-decode-string
                                  (if wl-use-petname
                                      (or
-                                      (wl-address-get-petname-1 to)
+                                      (funcall wl-summary-get-petname-func to)
                                       (car
                                        (std11-extract-address-components to))
                                       to)
                         entity "newsgroups"))
               (setq retval (concat "Ng:" ng)))))
       (if wl-use-petname
-         (setq retval (or (wl-address-get-petname-1 from)
+         (setq retval (or (funcall wl-summary-get-petname-func from)
                           (car (std11-extract-address-components from))
                           from))
        (setq retval from)))
 
 (defun wl-summary-simple-from (string)
   (if wl-use-petname
-      (or (wl-address-get-petname-1 string)
+      (or (funcall wl-summary-get-petname-func string)
          (car (std11-extract-address-components string))
          string)
     string))
   (define-key wl-summary-mode-map "p"    'wl-summary-prev)
   (define-key wl-summary-mode-map "N"    'wl-summary-down)
   (define-key wl-summary-mode-map "P"    'wl-summary-up)
-;  (define-key wl-summary-mode-map "w"    'wl-draft)
+;;;(define-key wl-summary-mode-map "w"    'wl-draft)
   (define-key wl-summary-mode-map "w"    'wl-summary-write)
-  (define-key wl-summary-mode-map "W"    'wl-summary-write-current-newsgroup)
-;  (define-key wl-summary-mode-map "e"     'wl-draft-open-file)
+  (define-key wl-summary-mode-map "W"    'wl-summary-write-current-folder)
+;;;(define-key wl-summary-mode-map "e"     'wl-draft-open-file)
   (define-key wl-summary-mode-map "e"     'wl-summary-save)
   (define-key wl-summary-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
   (define-key wl-summary-mode-map "H"    'wl-summary-redisplay-all-header)
   (if wl-summary-buffer-disp-msg
       (wl-summary-redisplay)))
 
-(defun wl-summary-collect-unread (mark-alist &optional folder)
-  (let (mark ret-val)
-    (while mark-alist
-      (setq mark (cadr (car mark-alist)))
-      (and mark
-          (or (string= mark wl-summary-new-mark)
-              (string= mark wl-summary-unread-uncached-mark)
-              (string= mark wl-summary-unread-cached-mark))
-          (setq ret-val (cons (car (car mark-alist)) ret-val)))
-      (setq mark-alist (cdr mark-alist)))
-    ret-val))
-
 (defun wl-summary-count-unread (mark-alist &optional folder)
   (let ((new 0)
        (unread 0)
 
 (defun wl-summary-reedit (&optional arg)
   "Re-edit current message.
-If optional argument is non-nil, Supersedes message"
+If ARG is non-nil, Supersedes message"
   (interactive "P")
   (if arg
       (wl-summary-supersedes-message)
@@ -592,7 +593,7 @@ you."
        (cond
         ((and
           (re-search-forward
-           (concat "^\\($\\|[Cc]ontent-[Tt]ype:[ \t]+multipart/report\\)") nil t)
+           (concat "^\\($\\|[Cc]ontent-[Tt]ype:[ \t]+multipart/\\(report\\|mixed\\)\\)") nil t)
           (not (bolp))
           (re-search-forward "boundary=\"\\([^\"]+\\)\"" nil t))
          (let ((boundary (buffer-substring (match-beginning 1) (match-end 1)))
@@ -600,6 +601,7 @@ you."
            (cond
             ((and (setq start (re-search-forward
                           (concat "^--" boundary "\n"
+                                  "\\([Cc]ontent-[Dd]escription:.*\n\\)?"
                                   "[Cc]ontent-[Tt]ype:[ \t]+"
                                   "\\(message/rfc822\\|text/rfc822-headers\\)\n"
                                   "\\(.+\n\\)*\n") nil t))
@@ -666,7 +668,7 @@ you."
       (message "Resending message to %s...done" address))))
 
 (defun wl-summary-msgdb-load-async (folder)
-  "Loading msgdb and selecting folder is executed asynchronously in IMAP4."
+  "Loading msgdb and selecting FOLDER is executed asynchronously in IMAP4."
   (if (and (elmo-folder-plugged-p folder)
           (eq (elmo-folder-get-type folder) 'imap4))
       (let ((spec (elmo-folder-get-spec folder))
@@ -743,61 +745,22 @@ you."
 
 (defun wl-summary-mode ()
   "Major mode for reading threaded messages.
-The keys that are defined for this mode are:\\<wl-summary-mode-map>
-
-SPC    Read messages.
-DEL    Back-scroll this message.
-.      Force to display this message.
-RET    Make this message scroll up with one line.
-M-RET -        Make this message scroll down with one line.
-
-C-n    Go to the next line.
-C-p    Go to the previous line.
-n      Move to below then display.
-N       Move to next unread.
-p      Move to above then display.
-P       Move to previous unread.
-s      Sync current folder.
-t       Same as 's' but force update.
-g      Go to the folder which you input.
-w      Write a message. A new draft is prepared.
-a      Answer to this message. A new draft is prepared in Draft mode.
-f      Forward this message to a third person. A new draft is prepared in
-       Draft mode and this message is automatically attached.
-v      Toggle \"Summary and Folder view\".
-        You can quickly put the delete marks since the next message is not
-        displayed.
-i       Prefetch message if uncached.
-o      Put the refile mark('o') on this message.
-!      Mark current message as unread.
-$      Toggle mark current message as important.
-d      Put the delete mark('D') on this message.
-c       Check all messages as read.
-*      Put the temporal mark('*') on this message.
-u      Cancel the mark on this message.
-x      Process marked messages.
-
-mo     Put the refile mark onto all messages marked with '*'.
-       This is very convenient to refile all messages picked by '?'.
-md     Put the delete mark onto all messages marked with '*'.
-mi      Prefetch all messages marked with '*'.
-mu     Unmark all target-marked messages.
-mt      Put the '*' mark onto all messages which belong to th current thread.
-ma      Put the '*' mark onto all messages.
-?      Pick messages according to a pick pattern which you input,
-       then put the '*' mark onto them.
-q      Goto folder mode.
-"
+See Info under Wanderlust for full documentation.
+
+Special commands:
+\\{wl-summary-mode-map}
+
+Entering Folder mode calls the value of `wl-summary-mode-hook'."
   (interactive)
   (unless (interactive-p) (kill-all-local-variables))
   (setq major-mode 'wl-summary-mode)
   (setq mode-name "Summary")
   (use-local-map wl-summary-mode-map)
-;; (setq default-directory (or wl-tmp-dir (expand-file-name "~/")))
+;;;(setq default-directory (or wl-tmp-dir (expand-file-name "~/")))
   (setq buffer-read-only t)
   (setq truncate-lines t)
-;; (make-local-variable 'tab-width)
-;; (setq tab-width 1)
+;;;(make-local-variable 'tab-width)
+;;;(setq tab-width 1)
   (buffer-disable-undo (current-buffer))
   (if wl-use-semi
       (setq wl-summary-buffer-message-redisplay-func
@@ -808,12 +771,15 @@ q Goto folder mode.
                                        wl-summary-buffer-folder-indicator
                                        wl-summary-buffer-unread-status))
   (easy-menu-add wl-summary-mode-menu)
+  (when wl-summary-lazy-highlight
+    (make-local-hook 'window-scroll-functions)
+    (add-hook 'window-scroll-functions 'wl-highlight-summary-window nil t))
   ;; This hook may contain the function `wl-setup-summary' for reasons
   ;; of system internal to accord facilities for the Emacs variants.
   (run-hooks 'wl-summary-mode-hook))
 
 (defun wl-summary-overview-entity-compare-by-date (x y)
-  "Compare entity by date"
+  "Compare entity X and Y by date."
   (condition-case nil
       (string<
        (timezone-make-date-sortable
@@ -823,13 +789,13 @@ q Goto folder mode.
     (error))) ;; ignore error.
 
 (defun wl-summary-overview-entity-compare-by-number (x y)
-  "Compare entity by number"
+   "Compare entity X and Y by number."
   (<
    (elmo-msgdb-overview-entity-get-number x)
    (elmo-msgdb-overview-entity-get-number y)))
 
 (defun wl-summary-overview-entity-compare-by-from (x y)
-  "Compare entity by from"
+  "Compare entity X and Y by from."
   (string<
    (wl-address-header-extract-address
     (or (elmo-msgdb-overview-entity-get-from-no-decode x)
@@ -839,7 +805,7 @@ q   Goto folder mode.
        wl-summary-no-from-message))))
 
 (defun wl-summary-overview-entity-compare-by-subject (x y)
-  "Compare entity by subject"
+  "Compare entity X and Y by subject."
   (string< (elmo-msgdb-overview-entity-get-subject-no-decode x)
           (elmo-msgdb-overview-entity-get-subject-no-decode y)))
 
@@ -873,6 +839,7 @@ q   Goto folder mode.
         expunged)
     (fset 'wl-summary-append-message-func-internal
          (wl-summary-get-append-message-func))
+    (wl-summary-buffer-number-column-detect nil)
     (erase-buffer)
     (message "Re-scanning...")
     (setq i 0)
@@ -891,6 +858,7 @@ q   Goto folder mode.
     (setq wl-thread-entity-hashtb (elmo-make-hash (* (length overview) 2)))
     (setq wl-thread-entity-list nil)
     (setq wl-thread-entities nil)
+    (setq wl-summary-buffer-number-list nil)
     (setq wl-summary-buffer-target-mark-list nil)
     (setq wl-summary-buffer-refile-list nil)
     (setq wl-summary-buffer-delete-list nil)
@@ -918,12 +886,14 @@ q Goto folder mode.
         (cdar wl-summary-delayed-update)
         overview mark-alist nil t)
        (setq wl-summary-delayed-update (cdr wl-summary-delayed-update))))
-    (message "Constructing summary structure...done.")
+    (message "Constructing summary structure...done")
     (set-buffer cur-buf)
-    (when (eq wl-summary-buffer-view 'thread)
-      (message "Inserting thread...")
-      (wl-thread-insert-top)
-      (message "Inserting thread...done."))
+    (if (eq wl-summary-buffer-view 'thread)
+       (progn
+         (message "Inserting thread...")
+         (wl-thread-insert-top)
+         (message "Inserting thread...done"))
+      (wl-summary-make-number-list))
     (when wl-use-scoring
       (setq wl-summary-scored nil)
       (wl-summary-score-headers nil msgdb
@@ -1021,12 +991,12 @@ q        Goto folder mode.
          (elmo-msgdb-mark-save
           path
           (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
-;;       (elmo-folder-set-info-hashtb
-;;        (elmo-string wl-summary-buffer-folder-name)
-;;        nil nil
-;;        0
-;;        (+ wl-summary-buffer-new-count wl-summary-buffer-unread-count))
-;;       (setq wl-folder-info-alist-modified t)
+;;;      (elmo-folder-set-info-hashtb
+;;;       (elmo-string wl-summary-buffer-folder-name)
+;;;       nil nil
+;;;       0
+;;;       (+ wl-summary-buffer-new-count wl-summary-buffer-unread-count))
+;;;      (setq wl-folder-info-alist-modified t)
          (setq wl-summary-buffer-mark-modified nil)
          (run-hooks 'wl-summary-buffer-mark-saved-hook))))))
 
@@ -1034,7 +1004,7 @@ q Goto folder mode.
   (if (or wl-summary-buffer-refile-list
          wl-summary-buffer-copy-list
          wl-summary-buffer-delete-list)
-      (if (y-or-n-p "Marks remain to be executed. Execute them?")
+      (if (y-or-n-p "Marks remain to be executed.  Execute them? ")
          (progn
            (wl-summary-exec)
            (if (or wl-summary-buffer-refile-list
@@ -1067,12 +1037,12 @@ q       Goto folder mode.
     (wl-summary-msgdb-save)))
 
 (defun wl-summary-force-exit ()
-  "Exit current summary. Buffer is deleted even the buffer is sticky"
+  "Exit current summary.  Buffer is deleted even the buffer is sticky."
   (interactive)
   (wl-summary-exit 'force-exit))
 
 (defun wl-summary-exit (&optional force-exit)
-  "Exit current summary. if FORCE-EXIT, exits even the summary is sticky."
+  "Exit current summary.  if FORCE-EXIT, exits even the summary is sticky."
   (interactive "P")
   (let ((summary-buf (current-buffer))
        (sticky (wl-summary-sticky-p))
@@ -1098,12 +1068,25 @@ q       Goto folder mode.
        (if (setq message-buf (get-buffer wl-message-buf-name))
            (if (setq message-win (get-buffer-window message-buf))
                (delete-window message-win)))
+       (if (and wl-summary-use-frame
+                (> (length (visible-frame-list)) 1))
+           (delete-frame))
        (if (setq folder-buf (get-buffer wl-folder-buffer-name))
-           (if (setq folder-win (get-buffer-window folder-buf))
-               ;; folder win is already displayed.
-               (select-window folder-win)
-             ;; folder win is not displayed.
-             (switch-to-buffer folder-buf))
+           (if wl-summary-use-frame
+               (let (select-frame)
+                 (save-selected-window
+                   (dolist (frame (visible-frame-list))
+                     (select-frame frame)
+                     (if (get-buffer-window folder-buf)
+                         (setq select-frame frame))))
+                 (if select-frame
+                     (select-frame select-frame)
+                   (switch-to-buffer folder-buf)))
+             (if (setq folder-win (get-buffer-window folder-buf))
+                 ;; folder win is already displayed.
+                 (select-window folder-win)
+               ;; folder win is not displayed.
+               (switch-to-buffer folder-buf)))
          ;; currently no folder buffer
          (wl-folder))
        (and wl-folder-move-cur-folder
@@ -1147,7 +1130,7 @@ q Goto folder mode.
                    (let* ((msgdb wl-summary-buffer-msgdb)
                           (number-alist (elmo-msgdb-get-number-alist msgdb)))
                      (elmo-mark-as-read wl-summary-buffer-folder-name
-                                        (mapcar 
+                                        (mapcar
                                          (lambda (msgid)
                                            (car (rassoc msgid number-alist)))
                                          seen-list) msgdb)))
@@ -1157,6 +1140,24 @@ q        Goto folder mode.
        (message "%s" ret-val))
     ret-val))
 
+(defsubst wl-summary-sync-all-init ()
+  (wl-summary-cleanup-temp-marks)
+  (erase-buffer)
+  (wl-summary-set-message-modified)
+  (wl-summary-set-mark-modified)
+  (setq wl-thread-entity-hashtb (elmo-make-hash
+                                (* (length (elmo-msgdb-get-number-alist
+                                            wl-summary-buffer-msgdb)) 2)))
+  (setq wl-summary-buffer-msgdb (elmo-msgdb-clear)) ;;'(nil nil nil nil))
+  (setq wl-thread-entity-list nil)
+  (setq wl-thread-entities nil)
+  (setq wl-summary-buffer-number-list nil)
+  (setq wl-summary-buffer-target-mark-list nil)
+  (setq wl-summary-buffer-refile-list nil)
+  (setq wl-summary-buffer-copy-list nil)
+  (setq wl-summary-buffer-delete-list nil)
+  (wl-summary-buffer-number-column-detect nil))
+
 (defun wl-summary-sync (&optional unset-cursor force-range)
   (interactive)
   (let* ((folder wl-summary-buffer-folder-name)
@@ -1165,12 +1166,12 @@ q       Goto folder mode.
         (msgdb-dir (elmo-msgdb-expand-path
                     folder))
         (range (or force-range (wl-summary-input-range folder)))
-        mes seen-list)
-    (cond ((string= range "all")
+        mes seen-list killed-list)
+    (cond ((or (string= range "all")
+              (string= range "all-visible"))
           ;; initialize buffer local databases.
           (unless (elmo-folder-plugged-p folder) ; forbidden
             (error "Unplugged"))
-          (wl-summary-cleanup-temp-marks)
           (setq seen-list
                 (nconc
                  (elmo-msgdb-mark-alist-to-seen-list
@@ -1181,22 +1182,18 @@ q       Goto folder mode.
                   (concat wl-summary-important-mark
                           wl-summary-read-uncached-mark))
                  (elmo-msgdb-seen-load msgdb-dir)))
-          (setq wl-thread-entity-hashtb (elmo-make-hash
-                                         (* (length (elmo-msgdb-get-number-alist
-                                                     wl-summary-buffer-msgdb)) 2)))
-          (setq wl-summary-buffer-msgdb (elmo-msgdb-clear)) ;;'(nil nil nil nil))
-          (setq wl-thread-entity-list nil)
-          (setq wl-thread-entities nil)
-          (setq wl-summary-buffer-target-mark-list nil)
-          (setq wl-summary-buffer-refile-list nil)
-          (setq wl-summary-buffer-copy-list nil)
-          (setq wl-summary-buffer-delete-list nil)
-          (wl-summary-buffer-number-column-detect nil)
-          (elmo-clear-killed folder)
-          (setq mes (wl-summary-sync-update3 seen-list unset-cursor))
+          (setq killed-list (elmo-msgdb-killed-list-load msgdb-dir))
+          (elmo-clear-killed wl-summary-buffer-folder-name)
+          (condition-case nil
+              (setq mes (wl-summary-sync-update3 seen-list unset-cursor
+                                                 (string= range "all")))
+            (quit
+             ;; Resume killed-list if quit.
+             (message "") ; clear minibuffer.
+             (elmo-msgdb-killed-list-save msgdb-dir killed-list)))
           (elmo-msgdb-seen-save msgdb-dir nil) ; delete all seen.
           (if mes (message "%s" mes)))
-;         (wl-summary-sync-all folder t))
+;;;       (wl-summary-sync-all folder t))
          ((string= range "rescan")
           (let ((msg (wl-summary-message-number)))
             (wl-summary-rescan)
@@ -1271,8 +1268,12 @@ q        Goto folder mode.
           the-email
           (elmo-get-hash-val the-email wl-address-petname-hash)
           (wl-address-header-extract-realname
-           (cdr (assoc (downcase the-email)
-                       wl-address-completion-list))) t)
+           (cdr (assoc
+                 (let ((completion-ignore-case t) comp)
+                   (setq comp
+                         (try-completion the-email wl-address-completion-list))
+                   (if (equal comp t) the-email comp))
+                 wl-address-completion-list))) t)
          "edited")
         ((eq char ?d)
          ;; Delete Addresses
@@ -1330,13 +1331,13 @@ Optional argument ADDR-STR is used as a target address if specified."
                       (nth 1 address)
                       (nth 0 address)
                       result)))
-       ;; i'd like to update summary-buffer, but...
-       ;;(wl-summary-rescan)
+;;; i'd like to update summary-buffer, but...
+;;;    (wl-summary-rescan)
        (run-hooks 'wl-summary-edit-addresses-hook)))))
 
 (defun wl-summary-incorporate (&optional arg)
   "Check and prefetch all uncached messages.
-If optional argument is non-nil, checking is omitted."
+If ARG is non-nil, checking is omitted."
   (interactive "P")
   (unless arg
     (save-excursion
@@ -1372,7 +1373,7 @@ If optional argument is non-nil, checking is omitted."
                          (widen)
                          (y-or-n-p
                           (format
-                           "Message from %s has %d bytes. Prefetch it?"
+                           "Message from %s has %d bytes.  Prefetch it? "
                            (concat
                             "[ "
                             (save-match-data
@@ -1445,10 +1446,10 @@ If optional argument is non-nil, checking is omitted."
                            wl-summary-buffer-new-count)))
                      new-mark))))))))
 
-;(defvar wl-summary-message-uncached-marks
-;  (list wl-summary-new-mark
-;      wl-summary-unread-uncached-mark
-;      wl-summary-read-uncached-mark))
+;;(defvar wl-summary-message-uncached-marks
+;;  (list wl-summary-new-mark
+;;     wl-summary-unread-uncached-mark
+;;     wl-summary-read-uncached-mark))
 
 (defun wl-summary-prefetch-region (beg end &optional prefetch-marks)
   (interactive "r")
@@ -1587,7 +1588,7 @@ If optional argument is non-nil, checking is omitted."
            (wl-highlight-summary-current-line))))))
 
 (defun wl-summary-delete-all-marks (mark-alist mark)
-  "Delete all MARKs in MARK-ALIST"
+  "Delete all MARKs in MARK-ALIST."
   (let ((malist mark-alist)
        (ret-val mark-alist)
        entity)
@@ -1604,8 +1605,10 @@ If optional argument is non-nil, checking is omitted."
   (interactive "r")
   (save-excursion
     (save-restriction
-      (narrow-to-region beg end);(save-excursion (goto-char end)
-                                       ;    (end-of-line) (point)))
+      (narrow-to-region beg end)
+;;; use narrowing.
+;;;   (save-excursion (goto-char end)
+;;;                  (end-of-line) (point)))
       (goto-char (point-min))
       (if (eq wl-summary-buffer-view 'thread)
          (progn
@@ -1634,8 +1637,10 @@ If optional argument is non-nil, checking is omitted."
   (interactive "r")
   (save-excursion
     (save-restriction
-      (narrow-to-region beg end);(save-excursion (goto-char end)
-                                       ;    (end-of-line) (point)))
+      (narrow-to-region beg end)
+;;; use narrowing.
+;;;      (save-excursion (goto-char end)
+;;;                  (end-of-line) (point)))
       (goto-char (point-min))
       (if (eq wl-summary-buffer-view 'thread)
          (progn
@@ -1695,11 +1700,11 @@ If optional argument is non-nil, checking is omitted."
 (defun wl-summary-mark-as-read-all ()
   (interactive)
   (if (or (not (interactive-p))
-         (y-or-n-p "Mark all messages as read?"))
+         (y-or-n-p "Mark all messages as read? "))
       (let* ((folder wl-summary-buffer-folder-name)
             (cur-buf (current-buffer))
             (msgdb wl-summary-buffer-msgdb)
-            ;;(number-alist (elmo-msgdb-get-number-alist msgdb))
+            (number-alist (elmo-msgdb-get-number-alist msgdb))
             (mark-alist (elmo-msgdb-get-mark-alist msgdb))
             (malist mark-alist)
             (inhibit-read-only t)
@@ -1707,7 +1712,14 @@ If optional argument is non-nil, checking is omitted."
             (case-fold-search nil)
             msg mark)
        (message "Setting all msgs as read...")
-       (elmo-mark-as-read folder (wl-summary-collect-unread mark-alist)
+       (elmo-mark-as-read folder
+                          (elmo-list-folder-unread
+                           folder
+                           number-alist
+                           mark-alist
+                           (list wl-summary-unread-cached-mark
+                                 wl-summary-unread-uncached-mark
+                                 wl-summary-new-mark))
                           msgdb)
        (save-excursion
          (goto-char (point-min))
@@ -1724,14 +1736,16 @@ If optional argument is non-nil, checking is omitted."
                    (setq mark-alist
                          (elmo-msgdb-mark-set
                           mark-alist
-                          msg ;(cdr (assq msg number-alist))
+                          msg
+;;; Use msg instead of (cdr (assq msg number-alist)).
+;;;                       (cdr (assq msg number-alist))
                           nil)))
                ;; New mark and unread-uncached mark
                (insert wl-summary-read-uncached-mark)
                (setq mark-alist
                      (elmo-msgdb-mark-set mark-alist
                                           msg
-                                       ; (cdr (assq msg number-alist))
+;;;                                       (cdr (assq msg number-alist))
                                           wl-summary-read-uncached-mark)))
              (if wl-summary-highlight
                  (wl-highlight-summary-current-line nil nil t)))))
@@ -1743,7 +1757,7 @@ If optional argument is non-nil, checking is omitted."
        (setq wl-summary-buffer-unread-count 0)
        (setq wl-summary-buffer-new-count    0)
        (wl-summary-update-modeline)
-       (message "Setting all msgs as read...done.")
+       (message "Setting all msgs as read...done")
        (set-buffer-modified-p nil))))
 
 (defun wl-summary-delete-cache ()
@@ -1758,7 +1772,7 @@ If optional argument is non-nil, checking is omitted."
           (number-alist (elmo-msgdb-get-number-alist msgdb))
           (case-fold-search nil)
           mark number unread new-mark)
-;      (re-search-backward "^ *[0-9]+..[0-9]+/[0-9]+" nil t) ; set cursor line
+;;;   (re-search-backward "^ *[0-9]+..[0-9]+/[0-9]+" nil t) ; set cursor line
       (beginning-of-line)
       (when (looking-at "^ *\\([0-9]+\\)[^0-9]\\([^0-9]\\)")
        (progn
@@ -1837,13 +1851,13 @@ If optional argument is non-nil, checking is omitted."
       (elmo-msgdb-set-mark-alist msgdb mark-alist)
       (wl-summary-count-unread mark-alist)
       (wl-summary-update-modeline)
-      (message "Resuming cache status...done.")
+      (message "Resuming cache status...done")
       (set-buffer-modified-p nil))))
 
 (defun wl-summary-resume-marks-and-highlight ()
   (let* ((msgdb wl-summary-buffer-msgdb)
         (mark-alist (elmo-msgdb-get-mark-alist msgdb))
-        ;;(number-alist (elmo-msgdb-get-number-alist msgdb))
+;;;     (number-alist (elmo-msgdb-get-number-alist msgdb))
         (count (count-lines (point-min)(point-max)))
         (i 0)
         msg-num percent smark)
@@ -1866,7 +1880,7 @@ If optional argument is non-nil, checking is omitted."
           'wl-summary-resume-marks-and-highlight "Resuming all marks..."
           percent))
        (forward-line 1)))
-    (message "Resuming all marks...done.")))
+    (message "Resuming all marks...done")))
 
 (defun wl-summary-resume-marks ()
   (let* ((msgdb wl-summary-buffer-msgdb)
@@ -1880,7 +1894,8 @@ If optional argument is non-nil, checking is omitted."
       (while mark-alist
        (setq entity (car mark-alist))
        (if (setq msg-num (car (rassoc (car entity) number-alist)))
-           (progn ;(goto-char (point-min))
+           (progn 
+;;;          (goto-char (point-min))
              (if (re-search-forward (format "^ *%s \\( \\)" msg-num) nil t)
                  (progn
                    (delete-region (match-beginning 1) (match-end 1))
@@ -1899,7 +1914,7 @@ If optional argument is non-nil, checking is omitted."
           'wl-summary-resume-marks "Resuming all marks..."
           percent))
        (setq mark-alist (cdr mark-alist)))
-      (message "Resuming all marks...done."))))
+      (message "Resuming all marks...done"))))
 
 (defun wl-summary-delete-messages-on-buffer (msgs &optional deleting-info)
   (interactive)
@@ -1925,7 +1940,8 @@ If optional argument is non-nil, checking is omitted."
              (progn
                (delete-region (match-beginning 0) (match-end 0))
                (delete-char 1) ; delete '\n'
-               )))
+               (setq wl-summary-buffer-number-list
+                     (delq (car msgs) wl-summary-buffer-number-list)))))
        (when (and deleting-info
                   (> len elmo-display-progress-threshold))
          (setq i (1+ i))
@@ -1967,7 +1983,7 @@ If optional argument is non-nil, checking is omitted."
     ret-val))
 
 (defun wl-summary-set-status-marks (mark-alist before after)
-  "Set the BEFORE marks to AFTER"
+  "Set the BEFORE marks to AFTER."
   (let ((ret-val mark-alist)
        entity)
     (while mark-alist
@@ -1980,7 +1996,7 @@ If optional argument is non-nil, checking is omitted."
     ret-val))
 
 (defun wl-summary-set-status-marks-on-buffer (before after)
-  "Set the MARKS marks on buffer"
+  "Set the MARKS marks on buffer."
   (interactive)
   (save-excursion
     (goto-char (point-min))
@@ -2027,7 +2043,7 @@ If optional argument is non-nil, checking is omitted."
 (defun wl-summary-get-append-message-func ()
   (if (eq wl-summary-buffer-view 'thread)
       'wl-summary-insert-thread-entity
-;      'wl-summary-insert-thread
+;;;   'wl-summary-insert-thread
     'wl-summary-insert-summary))
 
 (defun wl-summary-sort ()
@@ -2119,38 +2135,34 @@ If optional argument is non-nil, checking is omitted."
       (if (interactive-p) (message mes)))))
 
 (defun wl-summary-confirm-appends (appends)
-  (condition-case nil
-      (let ((len (length appends))
-           in)
-       (if (> len wl-summary-update-confirm-threshold)
-           (if (y-or-n-p (format "Too many messages(%d). Continue?" len))
-               appends
-             (setq in wl-summary-update-confirm-threshold)
-             (catch 'end
-               (while t
-                 (setq in (read-from-minibuffer "Update number: "
-                                                (int-to-string in))
-                       in (string-to-int in))
-                 (if (< len in)
-                     (throw 'end len))
-                 (if (y-or-n-p (format "%d messages are disappeared. OK?"
-                                       (max (- len in) 0)))
-                     (throw 'end in))))
-             (nthcdr (max (- len in) 0) appends))
-         appends))
-    (quit nil)
-    (error nil))) ;
-
-(defun wl-summary-sync-update3 (&optional seen-list unset-cursor)
+  (let ((len (length appends))
+       in)
+    (if (> len wl-summary-update-confirm-threshold)
+       (if (y-or-n-p (format "Too many messages(%d).  Continue? " len))
+           appends
+         (setq in wl-summary-update-confirm-threshold)
+         (catch 'end
+           (while t
+             (setq in (read-from-minibuffer "Update number: "
+                                            (int-to-string in))
+                   in (string-to-int in))
+             (if (< len in)
+                 (throw 'end len))
+             (if (y-or-n-p (format "%d messages are disappeared.  OK? "
+                                   (max (- len in) 0)))
+                 (throw 'end in))))
+         (nthcdr (max (- len in) 0) appends))
+      appends)))
+
+(defun wl-summary-sync-update3 (&optional seen-list unset-cursor sync-all)
   "Update the summary view."
   (interactive)
   (let* ((folder wl-summary-buffer-folder-name)
         (cur-buf (current-buffer))
-        (msgdb wl-summary-buffer-msgdb)
-        (number-alist (elmo-msgdb-get-number-alist msgdb))
-        (mark-alist (elmo-msgdb-get-mark-alist msgdb))
-        (overview (elmo-msgdb-get-overview msgdb))
-        ;;(location (elmo-msgdb-get-location msgdb))
+        (number-alist (elmo-msgdb-get-number-alist wl-summary-buffer-msgdb))
+        (mark-alist (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
+        (overview (elmo-msgdb-get-overview wl-summary-buffer-msgdb))
+;;;     (location (elmo-msgdb-get-location msgdb))
         (case-fold-search nil)
         (elmo-mime-charset wl-summary-buffer-mime-charset)
         (inhibit-read-only t)
@@ -2161,10 +2173,10 @@ If optional argument is non-nil, checking is omitted."
         in-folder
         in-db curp
         overview-append
-        entity ret-val crossed crossed2 sync-all
+        entity ret-val crossed crossed2
         update-thread update-top-list mark
         expunged msgs unreads importants)
-    ;(setq seen-list nil) ;for debug.
+;;; (setq seen-list nil) ;for debug.
     (fset 'wl-summary-append-message-func-internal
          (wl-summary-get-append-message-func))
     ;; Flush pending append operations (disconnected operation).
@@ -2174,16 +2186,8 @@ If optional argument is non-nil, checking is omitted."
     (wl-folder-confirm-existence folder 'force)
     (message "Checking folder diff...")
     (elmo-commit folder)
-    (setq in-folder (elmo-list-folder folder))
-    (setq in-db (sort (mapcar 'car number-alist) '<))
-    (when (or (eq msgdb nil) ; trick for unplugged...
-             (and (null overview)
-                  (null number-alist)
-                  (null mark-alist)))
-      (setq sync-all t)
-      (wl-summary-set-message-modified)
-      (wl-summary-set-mark-modified)
-      (erase-buffer))
+    (setq in-folder (elmo-list-folder folder sync-all))
+    (setq in-db (unless sync-all (sort (mapcar 'car number-alist) '<)))
     (if (not elmo-use-killed-list)
        (setq diff (if (eq (elmo-folder-get-type folder) 'multi)
                       (elmo-multi-list-bigger-diff in-folder in-db)
@@ -2191,7 +2195,16 @@ If optional argument is non-nil, checking is omitted."
       (setq diff (elmo-list-diff in-folder in-db)))
     (setq initial-append-list (car diff))
     (setq delete-list (cadr diff))
-    (message "Checking folder diff...done.")
+    (message "Checking folder diff...done")
+    ;; Confirm appended message number.
+    (setq append-list (wl-summary-confirm-appends initial-append-list))
+    (when (and elmo-use-killed-list
+              (not (eq (length initial-append-list)
+                       (length append-list)))
+              (setq diff (elmo-list-diff initial-append-list append-list)))
+      (elmo-msgdb-append-to-killed-list folder (car diff)))
+    ;; Setup sync-all
+    (if sync-all (wl-summary-sync-all-init))
     ;; Don't delete important-marked msgs other than 'internal.
     (unless (eq (elmo-folder-get-type folder) 'internal)
       (setq delete-list
@@ -2201,7 +2214,9 @@ If optional argument is non-nil, checking is omitted."
             (elmo-nntp-max-number-precedes-list-active-p))
        ;; XXX this does not work correctly in rare case.
        (setq delete-list
-             (wl-summary-delete-canceled-msgs-from-list delete-list msgdb)))
+             (wl-summary-delete-canceled-msgs-from-list
+              delete-list
+              wl-summary-buffer-msgdb)))
     (if (or (equal diff '(nil nil))
            (equal diff '(nil))
            (and (eq (length delete-list) 0)
@@ -2209,17 +2224,18 @@ If optional argument is non-nil, checking is omitted."
        (progn
          ;; For max-number update...
          (if (and (elmo-folder-contains-type folder 'nntp)
-                    (elmo-nntp-max-number-precedes-list-active-p)
-                    (elmo-update-number folder msgdb))
+                  (elmo-nntp-max-number-precedes-list-active-p)
+                  (elmo-update-number folder wl-summary-buffer-msgdb))
              (wl-summary-set-message-modified)
            (setq ret-val (format "No update is needed for \"%s\"" folder))))
       (when delete-list
        (message "Deleting...")
-       (elmo-msgdb-delete-msgs folder delete-list msgdb t) ; reserve cache.
-       ;;(set-buffer cur-buf)
+       (elmo-msgdb-delete-msgs folder delete-list
+                               wl-summary-buffer-msgdb t) ; reserve cache.
+;;;    (set-buffer cur-buf)
        (wl-summary-delete-messages-on-buffer delete-list "Deleting...")
-       (message "Deleting...done."))
-      ;;(set-buffer cur-buf)
+       (message "Deleting...done"))
+;;;   (set-buffer cur-buf)
       ;; Change "New" marks to "Uncached Unread" marks.
       (wl-summary-set-status-marks mark-alist
                                   wl-summary-new-mark
@@ -2227,13 +2243,6 @@ If optional argument is non-nil, checking is omitted."
       (wl-summary-set-status-marks-on-buffer
        wl-summary-new-mark
        wl-summary-unread-uncached-mark)
-      ;; Confirm appended message number.
-      (setq append-list (wl-summary-confirm-appends initial-append-list))
-      (when (and elmo-use-killed-list
-                (not (eq (length initial-append-list)
-                         (length append-list)))
-                (setq diff (elmo-list-diff initial-append-list append-list)))
-       (elmo-msgdb-append-to-killed-list folder (car diff)))
       (setq num (length append-list))
       (if append-list
          (progn
@@ -2249,16 +2258,19 @@ If optional argument is non-nil, checking is omitted."
            ;; delete duplicated messages.
            (when (elmo-folder-contains-multi folder)
              (setq crossed (elmo-multi-delete-crossposts
-                            msgdb result))
+                            wl-summary-buffer-msgdb result))
              (setq result (cdr crossed))
              (setq crossed (car crossed)))
            (setq overview-append (car result))
-           (setq msgdb (elmo-msgdb-append msgdb result t))
+           (setq wl-summary-buffer-msgdb
+                 (elmo-msgdb-append wl-summary-buffer-msgdb result t))
            ;; set these value for append-message-func
-           (setq overview (elmo-msgdb-get-overview msgdb))
-           (setq number-alist (elmo-msgdb-get-number-alist msgdb))
-           (setq mark-alist (elmo-msgdb-get-mark-alist msgdb))
-           ;; (setq location (elmo-msgdb-get-location msgdb))
+           (setq overview (elmo-msgdb-get-overview wl-summary-buffer-msgdb))
+           (setq number-alist (elmo-msgdb-get-number-alist
+                               wl-summary-buffer-msgdb))
+           (setq mark-alist (elmo-msgdb-get-mark-alist
+                             wl-summary-buffer-msgdb))
+;;;        (setq location (elmo-msgdb-get-location msgdb))
            (setq curp overview-append)
            (setq num (length curp))
            (setq wl-summary-delayed-update nil)
@@ -2298,18 +2310,19 @@ If optional argument is non-nil, checking is omitted."
                       update-top-list)
              (wl-thread-update-indent-string-thread
               (elmo-uniq-list update-top-list)))
-           (message "Updating thread...done.")
-           ;;(set-buffer cur-buf)
+           (message "Updating thread...done")
+;;;        (set-buffer cur-buf)
            ))
+      (unless (eq wl-summary-buffer-view 'thread)
+       (wl-summary-make-number-list))
       (wl-summary-set-message-modified)
       (wl-summary-set-mark-modified)
-      (setq wl-summary-buffer-msgdb msgdb)
       (when (and sync-all (eq wl-summary-buffer-view 'thread))
        (elmo-kill-buffer wl-summary-search-buf-name)
        (message "Inserting thread...")
        (setq wl-thread-entity-cur 0)
        (wl-thread-insert-top)
-       (message "Inserting thread...done."))
+       (message "Inserting thread...done"))
       (if elmo-use-database
          (elmo-database-close))
       (run-hooks 'wl-summary-sync-updated-hook)
@@ -2321,7 +2334,7 @@ If optional argument is non-nil, checking is omitted."
     ;; scoring
     (when wl-use-scoring
       (setq wl-summary-scored nil)
-      (wl-summary-score-headers nil msgdb
+      (wl-summary-score-headers nil wl-summary-buffer-msgdb
                                (and sync-all
                                     (wl-summary-rescore-msgs number-alist))
                                sync-all)
@@ -2346,7 +2359,7 @@ If optional argument is non-nil, checking is omitted."
     (wl-folder-set-folder-updated folder (list 0
                                               (wl-summary-count-unread
                                                (elmo-msgdb-get-mark-alist
-                                                msgdb))
+                                                wl-summary-buffer-msgdb))
                                               (length in-folder)))
     (wl-summary-update-modeline)
     (wl-summary-buffer-number-column-detect t)
@@ -2438,7 +2451,7 @@ If optional argument is non-nil, checking is omitted."
              (elmo-display-progress
               'wl-summary-highlight-msgs "Highlighting..."
               (/ (* i 100) len)))))
-      (message "Highlighting...done."))))
+      (message "Highlighting...done"))))
 
 (defun wl-summary-message-number ()
   (save-excursion
@@ -2449,9 +2462,9 @@ If optional argument is non-nil, checking is omitted."
 
 (defun wl-summary-move (src dsts-msgs)
   (let* ((dsts (car dsts-msgs))                ; (+foo +bar)
-;;      (msgs (cdr dsts-msgs))         ; (1 2 3)
-;;      (msgdb wl-summary-buffer-msgdb)
-;;      result)
+;;;     (msgs (cdr dsts-msgs))         ; (1 2 3)
+;;;     (msgdb wl-summary-buffer-msgdb)
+;;;     result)
         )
     (while dsts
       (setq dsts (cdr dsts)))))
@@ -2484,7 +2497,7 @@ If optional argument is non-nil, checking is omitted."
          (elmo-msgdb-delete-msgs wl-summary-buffer-folder-name
                                  dels wl-summary-buffer-msgdb t)
          (wl-summary-delete-messages-on-buffer dels)
-         (message "Resuming summary status...done."))
+         (message "Resuming summary status...done"))
        ;; delete resume-file
        (elmo-dop-append-list-save wl-summary-buffer-folder-name nil t)
        (when append-list
@@ -2499,7 +2512,7 @@ If optional argument is non-nil, checking is omitted."
     (set-buffer cur-buf)
     (if (null dels)
        (message "No message to delete.")
-      (if (y-or-n-p (format "%s has %d message(s). Delete all?"
+      (if (y-or-n-p (format "%s has %d message(s).  Delete all? "
                            wl-summary-buffer-folder-name
                            (length dels)))
          (progn
@@ -2508,13 +2521,13 @@ If optional argument is non-nil, checking is omitted."
                              wl-summary-buffer-msgdb)
            (elmo-msgdb-delete-msgs wl-summary-buffer-folder-name
                                    dels wl-summary-buffer-msgdb)
-           ;;(elmo-msgdb-save wl-summary-buffer-folder-name nil)
+;;;        (elmo-msgdb-save wl-summary-buffer-folder-name nil)
            (wl-summary-set-message-modified)
            (wl-summary-set-mark-modified)
            (wl-folder-set-folder-updated wl-summary-buffer-folder-name
                                          (list 0 0 0))
-           ;; for thread.
-           ;; (setq wl-thread-top-entity '(nil t nil nil))
+;;; for thread.
+;;;        (setq wl-thread-top-entity '(nil t nil nil))
            (setq wl-summary-buffer-unread-count 0)
            (setq wl-summary-buffer-new-count    0)
            (wl-summary-update-modeline)
@@ -2522,13 +2535,14 @@ If optional argument is non-nil, checking is omitted."
            (let ((inhibit-read-only t)
                  (buffer-read-only nil))
              (erase-buffer))
-           ;;    (if wl-summary-cache-use (wl-summary-save-view-cache))
-           (message "Deleting...done.")
+;;;        (if wl-summary-cache-use (wl-summary-save-view-cache))
+           (message "Deleting...done")
            t)
        nil))))
 
 (defun wl-summary-toggle-thread (&optional arg)
-  "Toggle thread status (T)hread and (S)equencial."
+  "Toggle thread status (T)hread and (S)equential.
+If ARG, without confirm."
   (interactive "P")
   (when (or arg
            (y-or-n-p (format "Toggle threading? (y=%s): "
@@ -2555,7 +2569,7 @@ If optional argument is non-nil, checking is omitted."
        (setq ret-val
              (condition-case nil
                  (read (current-buffer))
-               (error (error "reading failed")))))
+               (error (error "Reading failed")))))
       (kill-buffer tmp-buffer)
       ret-val)))
 
@@ -2587,14 +2601,14 @@ If optional argument is non-nil, checking is omitted."
   (interactive "P")
   (if (wl-summary-sticky-p)
       (message "Current summary buffer is already sticky.")
-    (when (or force (y-or-n-p "Stick current summary buffer?"))
+    (when (or force (y-or-n-p "Stick current summary buffer? "))
       (wl-summary-toggle-disp-msg 'off)
       (wl-summary-switch-to-clone-buffer
        (wl-summary-sticky-buffer-name
        wl-summary-buffer-folder-name))
 ;;; ???hang up
-;      (rename-buffer (wl-summary-sticky-buffer-name
-;                    wl-summary-buffer-folder-name)))
+;;;   (rename-buffer (wl-summary-sticky-buffer-name
+;;;                  wl-summary-buffer-folder-name)))
       (message "Folder `%s' is now sticky." wl-summary-buffer-folder-name))))
 
 (defun wl-summary-switch-to-clone-buffer (buffer-name)
@@ -2613,7 +2627,8 @@ If optional argument is non-nil, checking is omitted."
                   wl-summary-buffer-number-regexp
                   wl-summary-buffer-message-modified
                   wl-summary-buffer-mark-modified
-                  wl-summary-buffer-thread-modified)
+                  wl-summary-buffer-thread-modified
+                  wl-summary-buffer-number-list)
                 (and (eq wl-summary-buffer-view 'thread)
                      '(wl-thread-entity-hashtb
                        wl-thread-entities
@@ -2689,9 +2704,23 @@ If optional argument is non-nil, checking is omitted."
       (delete-window mes-win)
       (run-hooks 'wl-summary-toggle-disp-off-hook))))
 
+(defun wl-summary-make-number-list ()
+  (setq wl-summary-buffer-number-list
+       (mapcar
+        (lambda (x) (elmo-msgdb-overview-entity-get-number x))
+        (elmo-msgdb-get-overview wl-summary-buffer-msgdb))))
+
+(defun wl-summary-auto-select-msg-p (unread-msg)
+  (and unread-msg
+       (not (string=
+            (cadr (assoc unread-msg
+                         (elmo-msgdb-get-mark-alist
+                          wl-summary-buffer-msgdb)))
+            wl-summary-important-mark))))
+
 (defun wl-summary-goto-folder-subr (&optional folder scan-type other-window
                                              sticky interactive scoring)
-  "Display target folder on summary"
+  "Display target folder on summary."
   (interactive)
   (let* ((keep-cursor (memq this-command
                            wl-summary-keep-cursor-command))
@@ -2728,15 +2757,21 @@ If optional argument is non-nil, checking is omitted."
          (let ((case-fold-search nil)
                (inhibit-read-only t)
                (buffer-read-only nil))
+           ;; Load msgdb
+           (setq wl-summary-buffer-msgdb nil) ; new msgdb
+           (setq wl-summary-buffer-msgdb
+                 (wl-summary-msgdb-load-async fld))
+           (if (null wl-summary-buffer-msgdb)
+               (setq wl-summary-buffer-msgdb
+                     (elmo-msgdb-load (elmo-string fld))))
            (erase-buffer)
-           ;; resume summary cache
+           ;; Resume summary view
            (if wl-summary-cache-use
                (let* ((dir (elmo-msgdb-expand-path fld))
                       (cache (expand-file-name wl-summary-cache-file dir))
                       (view (expand-file-name wl-summary-view-file dir)))
                  (when (file-exists-p cache)
-                   (as-binary-input-file
-                    (insert-file-contents cache))
+                   (insert-file-contents-as-binary cache)
                    (elmo-set-buffer-multibyte
                     default-enable-multibyte-characters)
                    (decode-mime-charset-region
@@ -2746,21 +2781,20 @@ If optional argument is non-nil, checking is omitted."
                    (setq wl-summary-buffer-view
                          (wl-summary-load-file-object view)))
                  (if (eq wl-summary-buffer-view 'thread)
-                     (wl-thread-resume-entity fld))))
-           ;; Load msgdb
-           (setq wl-summary-buffer-msgdb nil) ; new msgdb
-           (setq wl-summary-buffer-msgdb
-                 (wl-summary-msgdb-load-async fld))
-           (if (null wl-summary-buffer-msgdb)
-               (setq wl-summary-buffer-msgdb
-                     (elmo-msgdb-load (elmo-string fld))))
+                     (wl-thread-resume-entity fld)
+                   (wl-summary-make-number-list)))
+             (setq wl-summary-buffer-view
+                   (wl-summary-load-file-object
+                    (expand-file-name wl-summary-view-file
+                                      (elmo-msgdb-expand-path fld))))
+             (wl-summary-rescan))
            (wl-summary-count-unread
             (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
            (wl-summary-update-modeline)))
       (wl-summary-buffer-number-column-detect t)
       (wl-summary-disp-msg fld (and reuse-buf keep-cursor))
       (unless (and reuse-buf keep-cursor)
-       (setq hilit wl-summary-highlight)
+       ;(setq hilit wl-summary-highlight)
        (unwind-protect
            (let ((wl-summary-highlight (if reuse-buf wl-summary-highlight))
                  (wl-use-scoring
@@ -2788,21 +2822,25 @@ If optional argument is non-nil, checking is omitted."
          (set-buffer-modified-p nil)
          (goto-char (point-min))
          (if (wl-summary-cursor-down t)
-             (let ((unreadp (wl-thread-next-mark-p
-                             (wl-thread-entity-get-mark
-                              (wl-summary-message-number))
-                             wl-summary-move-order)))
-               (cond ((and wl-auto-select-first unreadp)
+             (let ((unreadp (wl-summary-next-message 
+                             (wl-summary-message-number)
+                             'down t)))
+               (cond ((and wl-auto-select-first
+                           (wl-summary-auto-select-msg-p unreadp))
+                      ;; wl-auto-select-first is non-nil and
+                      ;; unreadp is non-nil but not important
                       (setq retval 'disp-msg))
-                     ((not unreadp)
+                     ((not (wl-summary-auto-select-msg-p unreadp))
+                      ;; unreadp is nil or important
                       (setq retval 'more-next))))
            (goto-char (point-max))
            (if (elmo-folder-plugged-p folder)
                (forward-line -1)
              (wl-summary-prev))
            (setq retval 'more-next))
-         (setq wl-summary-highlight hilit)
+         ;(setq wl-summary-highlight hilit)
          (if (and wl-summary-highlight
+                  (not wl-summary-lazy-highlight)
                   (not reuse-buf))
              (if (and wl-summary-highlight-partial-threshold
                       (> (count-lines (point-min) (point-max))
@@ -2838,7 +2876,7 @@ If optional argument is non-nil, checking is omitted."
     retval))
 
 (defun wl-summary-summary-line-already-exists-p (parent-number buffer)
-  "returns the depth."
+  "Return the depth."
   (set-buffer buffer)
   (goto-char (point-max))
   (let ((depth 0))
@@ -2909,7 +2947,7 @@ If optional argument is non-nil, checking is omitted."
 
 (defun wl-summary-default-subject-filter (subject)
   (let ((case-fold-search t))
-    (setq subject (elmo-replace-in-string subject "[ \t]*\\(re\\|was\\):" ""))
+    (setq subject (elmo-replace-in-string subject "[ \t]*\\(re\\|was\\)[:>]" ""))
     (setq subject (elmo-replace-in-string subject "[ \t]" ""))
     (elmo-replace-in-string subject "^\\[.*\\]" "")))
 
@@ -3003,7 +3041,7 @@ If optional argument is non-nil, checking is omitted."
       (let* ((this-id (elmo-msgdb-overview-entity-get-id entity))
             (parent-entity
              (elmo-msgdb-overview-get-parent-entity entity overview));; temp
-            ;;(parent-id (elmo-msgdb-overview-entity-get-id parent-entity))
+;;;         (parent-id (elmo-msgdb-overview-entity-get-id parent-entity))
             (parent-number (elmo-msgdb-overview-entity-get-number parent-entity))
             (case-fold-search t)
             msg overview2 cur-entity linked retval delayed-entity)
@@ -3096,7 +3134,7 @@ If optional argument is non-nil, checking is omitted."
          (folder wl-summary-buffer-folder-name)
          (msgdb wl-summary-buffer-msgdb)
          (mark-alist (elmo-msgdb-get-mark-alist msgdb))
-         ;;(number-alist (elmo-msgdb-get-number-alist msgdb))
+;;;      (number-alist (elmo-msgdb-get-number-alist msgdb))
          new-mark visible mark)
       (if number
          (progn
@@ -3305,12 +3343,12 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
        (goto-char start)               ; avoid moving cursor to
                                        ; the bottom line.
        (while dst-msgs
-         ;;(elmo-msgdb-add-msgs-to-seen-list
-         ;; (car (car dst-msgs)) ;dst-folder
-         ;; (cdr (car dst-msgs)) ;msgs
-         ;; wl-summary-buffer-msgdb
-         ;; (concat wl-summary-important-mark
-         ;;  wl-summary-read-uncached-mark))
+;;;      (elmo-msgdb-add-msgs-to-seen-list
+;;;       (car (car dst-msgs))         ;dst-folder
+;;;       (cdr (car dst-msgs))         ;msgs
+;;;       wl-summary-buffer-msgdb
+;;;       (concat wl-summary-important-mark
+;;;               wl-summary-read-uncached-mark))
          (setq result nil)
          (condition-case nil
              (setq result (elmo-move-msgs wl-summary-buffer-folder-name
@@ -3340,12 +3378,12 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
        ;; begin cOpy...
        (setq dst-msgs (wl-inverse-alist copies wl-summary-buffer-copy-list))
        (while dst-msgs
-         ;;(elmo-msgdb-add-msgs-to-seen-list
-         ;; (car (car dst-msgs)) ;dst-folder
-         ;; (cdr (car dst-msgs)) ;msgs
-         ;; wl-summary-buffer-msgdb
-         ;; (concat wl-summary-important-mark
-         ;;  wl-summary-read-uncached-mark))
+;;;      (elmo-msgdb-add-msgs-to-seen-list
+;;;       (car (car dst-msgs))         ;dst-folder
+;;;       (cdr (car dst-msgs))         ;msgs
+;;;       wl-summary-buffer-msgdb
+;;;       (concat wl-summary-important-mark
+;;;               wl-summary-read-uncached-mark))
          (setq result nil)
          (condition-case nil
              (setq result (elmo-move-msgs wl-summary-buffer-folder-name
@@ -3397,12 +3435,12 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                    wl-folder-entity-hashtb))
              nil nil (or init wl-default-spec)
              'wl-read-folder-hist)))
-    (setq fld (elmo-string (wl-folder-get-realname fld)))
-    (if (string-match "\n" fld)
-       (error "Not supported folder name: %s" fld))
     (if (or (string= fld wl-default-spec)
            (string= fld ""))
        (setq fld default))
+    (setq fld (elmo-string (wl-folder-get-realname fld)))
+    (if (string-match "\n" fld)
+       (error "Not supported folder name: %s" fld))    
     (unless no-create
       (if ignore-error
          (ignore-errors (wl-folder-confirm-existence fld))
@@ -3424,6 +3462,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       (while (< c len)
        (forward-char -1)
        (setq c (+ c (char-width (following-char)))))
+      (and (> c len) (setq folder (concat " " folder)))
       (setq rs (point))
       (put-text-property rs re 'invisible t)
       (put-text-property rs re 'wl-summary-destination t)
@@ -3438,14 +3477,14 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
   (defun wl-summary-remove-destination ()))
 
 (defsubst wl-summary-get-mark (number)
-  "Returns a temporal mark of message specified by NUMBER."
+  "Return a temporal mark of message specified by NUMBER."
   (or (and (memq number wl-summary-buffer-delete-list) "D")
       (and (assq number wl-summary-buffer-copy-list) "O")
       (and (assq number wl-summary-buffer-refile-list) "o")
-      (and (assq number wl-summary-buffer-target-mark-list) "*")))
+      (and (memq number wl-summary-buffer-target-mark-list) "*")))
 
 (defsubst wl-summary-reserve-temp-mark-p (mark)
-  "Returns t if temporal MARK should be reserved."
+  "Return t if temporal MARK should be reserved."
   (member mark wl-summary-reserve-mark-list))
 
 (defun wl-summary-refile (&optional dst number)
@@ -3508,7 +3547,8 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                                 (or (wl-refile-guess entity) wl-trash-folder)
                                 (format "for %s" copy-or-refile)))))
       ;; Cache folder hack by okada@opaopa.org
-      (if (and (eq (car (elmo-folder-get-spec folder)) 'cache)
+      (if (and (eq (car (elmo-folder-get-spec
+                        (wl-folder-get-realname folder))) 'cache)
               (not (string= folder
                             (setq tmp-folder
                                   (concat "'cache/"
@@ -3550,7 +3590,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       msg-num)))
 
 (defun wl-summary-refile-prev-destination ()
-  "Refile message to previously refiled destination"
+  "Refile message to previously refiled destination."
   (interactive)
   (wl-summary-refile wl-summary-buffer-prev-refile-destination
                     (wl-summary-message-number))
@@ -3559,7 +3599,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
     (wl-summary-next)))
 
 (defun wl-summary-copy-prev-destination ()
-  "Refile message to previously refiled destination"
+  "Refile message to previously refiled destination."
   (interactive)
   (wl-summary-copy wl-summary-buffer-prev-copy-destination
                   (wl-summary-message-number))
@@ -3571,7 +3611,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
   (member (cadr (assq msg mark-alist)) wl-summary-auto-refile-skip-marks))
 
 (defun wl-summary-auto-refile (&optional open-all)
-  "Set refile mark automatically according to wl-refile-guess-by-rule."
+  "Set refile mark automatically according to 'wl-refile-guess-by-rule'."
   (interactive "P")
   (message "Marking...")
   (save-excursion
@@ -3592,9 +3632,10 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
        (when (and (not (wl-summary-no-auto-refile-message-p number
                                                             mark-alist))
                   (setq dst
-                        (wl-refile-guess-by-rule
-                         (elmo-msgdb-overview-get-entity
-                          number wl-summary-buffer-msgdb)))
+                        (wl-folder-get-realname
+                         (wl-refile-guess-by-rule
+                          (elmo-msgdb-overview-get-entity
+                           number wl-summary-buffer-msgdb))))
                   (not (equal dst spec)))
          (when (not (member dst checked-dsts))
            (wl-folder-confirm-existence dst)
@@ -3851,7 +3892,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
     (setq beg (point))
     (end-of-line)
     (wl-summary-goto-bottom-of-current-thread)
-;    (forward-line -1)
+;;; (forward-line -1)
     (beginning-of-line)
     (setq end (point))
     (wl-summary-target-mark-region beg end)))
@@ -3866,7 +3907,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 
 (defun wl-summary-pick (&optional from-list delete-marks)
   (interactive)
-  (let ((result (elmo-msgdb-search 
+  (let ((result (elmo-msgdb-search
                 wl-summary-buffer-folder-name
                 (elmo-read-search-condition wl-summary-pick-field-default)
                 wl-summary-buffer-msgdb)))
@@ -3895,7 +3936,8 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
     (error "This folder is not filtered")))
 
 (defun wl-summary-virtual (&optional arg)
-  "Goto virtual folder."
+  "Goto virtual folder.
+If ARG, exit virtual folder."
   (interactive "P")
   (if arg
       (wl-summary-unvirtual)
@@ -3914,7 +3956,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
     (while (not (eobp))
       (wl-summary-unmark)
       (forward-line))
-    (message "Unmarking...done.")
+    (message "Unmarking...done")
     (setq wl-summary-buffer-target-mark-list nil)
     (setq wl-summary-buffer-delete-list nil)
     (setq wl-summary-buffer-refile-list nil)
@@ -3940,7 +3982,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
              (delq pair wl-summary-buffer-refile-list))))))))
 
 (defun wl-summary-mark-line (mark)
-  "Put MARK on current line. Returns message number."
+  "Put MARK on current line.  Return message number."
   (save-excursion
     (beginning-of-line)
     (let ((inhibit-read-only t)
@@ -3952,7 +3994,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
        (setq cur-mark (wl-match-buffer 2))
        (goto-char (match-end 1))
        (delete-region (match-beginning 2) (match-end 2))
-       ;(wl-summary-delete-mark msg-num)
+;;;    (wl-summary-delete-mark msg-num)
        (insert mark)
        (if wl-summary-highlight
            (wl-highlight-summary-current-line nil nil t))
@@ -4115,7 +4157,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       (setq mlist wl-summary-buffer-target-mark-list)
       (while mlist
        (wl-summary-mark-as-unread (car mlist))
-       ;; (wl-thread-msg-mark-as-unread (car mlist))
+;;;    (wl-thread-msg-mark-as-unread (car mlist))
        (setq wl-summary-buffer-target-mark-list
              (delq (car mlist) wl-summary-buffer-target-mark-list))
        (setq mlist (cdr mlist)))
@@ -4188,7 +4230,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
           (folder wl-summary-buffer-folder-name)
           (msgdb wl-summary-buffer-msgdb)
           (mark-alist (elmo-msgdb-get-mark-alist msgdb))
-          ;;(number-alist (elmo-msgdb-get-number-alist msgdb))
+;;;       (number-alist (elmo-msgdb-get-number-alist msgdb))
           (case-fold-search nil)
           mark stat visible uncached new-mark marked)
       (if number
@@ -4309,6 +4351,9 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                  (unless no-server-update
                    (elmo-unmark-important folder (list number) msgdb)
                    (elmo-msgdb-global-mark-delete message-id))
+                 ;; Remove cache if local folder.
+                 (if (elmo-folder-local-p folder)
+                     (elmo-cache-delete message-id folder number))
                  (when visible
                    (delete-region (match-beginning 2) (match-end 2))
                    (insert " "))
@@ -4466,115 +4511,93 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
        (wl-match-string 1 wday-str)
       (elmo-date-get-week year month mday))))
 
-(defmacro wl-summary-cursor-move-regex ()
-  (` (let ((mark-alist
-           (if (elmo-folder-plugged-p wl-summary-buffer-folder-name)
-               (cond ((eq wl-summary-move-order 'new)
-                      (list
-                       (list
-                        wl-summary-new-mark)
-                       (list
-                        wl-summary-unread-uncached-mark
-                        wl-summary-unread-cached-mark
-                        wl-summary-important-mark)))
-                     ((eq wl-summary-move-order 'unread)
-                      (list
-                      (list
-                       wl-summary-unread-uncached-mark
-                       wl-summary-unread-cached-mark
-                       wl-summary-new-mark)
-                      (list
-                       wl-summary-important-mark)))
-                     (t
-                      (list
-                      (list
-                       wl-summary-unread-uncached-mark
-                       wl-summary-unread-cached-mark
-                       wl-summary-new-mark
-                       wl-summary-important-mark))))
-             (cond ((eq wl-summary-move-order 'unread)
-                    (list
-                    (list
-                     wl-summary-unread-cached-mark)
-                    (list
-                     wl-summary-important-mark)))
-                   (t
-                    (list
-                    (list
-                     wl-summary-unread-cached-mark
-                     wl-summary-important-mark)))))))
-       (mapcar
-       (function
-        (lambda (mark-list)
-          (concat wl-summary-message-regexp
-                  ".\\("
-                  (mapconcat 'regexp-quote
-                             mark-list
-                             "\\|")
-                  "\\)\\|"
-                  wl-summary-message-regexp "\\*")))
-       mark-alist))))
-
-;;
-;; Goto unread or important
-;;
-(defun wl-summary-cursor-up (&optional hereto)
-  (interactive "P")
-  (if (and (not wl-summary-buffer-target-mark-list)
-          (eq wl-summary-buffer-view 'thread))
-      (progn
-       (if (eobp)
-           (forward-line -1))
-       (wl-thread-jump-to-prev-unread hereto))
-    (if hereto
-       (end-of-line)
-      (beginning-of-line))
-    (let ((case-fold-search nil)
-         regex-list)
-      (setq regex-list (wl-summary-cursor-move-regex))
-      (catch 'done
-       (while regex-list
-         (when (re-search-backward
-                (car regex-list)
-                nil t nil)
-           (beginning-of-line)
-           (throw 'done t))
-         (setq regex-list (cdr regex-list)))
-       (beginning-of-line)
-       (throw 'done nil)))))
-
+(defvar wl-summary-move-spec-plugged-alist
+  (list (cons 'new (list (cons 't nil)
+                        (cons 'p wl-summary-new-mark)
+                        (cons 'p (wl-regexp-opt
+                                  (list wl-summary-unread-uncached-mark
+                                        wl-summary-unread-cached-mark)))
+                        (cons 'p (regexp-quote wl-summary-important-mark))))
+       (cons 'unread (list (cons 't nil)
+                           (cons 'p (wl-regexp-opt
+                                     (list wl-summary-new-mark
+                                           wl-summary-unread-uncached-mark
+                                           wl-summary-unread-cached-mark)))
+                           (cons 'p (regexp-quote
+                                     wl-summary-important-mark))))))
+
+(defvar wl-summary-move-spec-unplugged-alist
+  (list (cons 'new (list (cons 't nil)
+                        (cons 'p wl-summary-unread-cached-mark)
+                        (cons 'p (regexp-quote wl-summary-important-mark))))
+       (cons 'unread (list (cons 't nil)
+                           (cons 'p wl-summary-unread-cached-mark)
+                           (cons 'p (regexp-quote
+                                     wl-summary-important-mark))))))
+
+(defsubst wl-summary-next-message (num direction hereto)
+  (if wl-summary-buffer-next-message-func
+      (funcall wl-summary-buffer-next-message-func num direction hereto)  
+    (let ((cur-spec (cdr (assq wl-summary-move-order 
+                              (if (elmo-folder-plugged-p 
+                                   wl-summary-buffer-folder-name)
+                                  wl-summary-move-spec-plugged-alist
+                                wl-summary-move-spec-unplugged-alist))))
+         (nums (memq num (if (eq direction 'up)
+                             (reverse wl-summary-buffer-number-list)
+                           wl-summary-buffer-number-list)))
+         marked-list nums2)
+      (unless hereto (setq nums (cdr nums)))
+      (setq nums2 nums)
+      (if cur-spec
+         (catch 'done
+           (while cur-spec
+             (setq nums nums2)
+             (cond ((eq (car (car cur-spec)) 'p)
+                    (if (setq marked-list (elmo-msgdb-list-messages-mark-match
+                                           wl-summary-buffer-msgdb
+                                           (cdr (car cur-spec))))
+                        (while nums
+                          (if (memq (car nums) marked-list)
+                              (throw 'done (car nums)))
+                          (setq nums (cdr nums)))))
+                   ((eq (car (car cur-spec)) 't)
+                    (while nums
+                      (if (and wl-summary-buffer-target-mark-list
+                               (memq (car nums)
+                                     wl-summary-buffer-target-mark-list))
+                          (throw 'done (car nums)))
+                      (setq nums (cdr nums)))))
+             (setq cur-spec (cdr cur-spec))))
+       (car nums)))))
+
+(defsubst wl-summary-cursor-move (direction hereto)
+  (when (and (eq direction 'up)
+            (eobp))
+    (forward-line -1)
+    (setq hereto t))
+  (let (num)
+    (when (setq num (wl-summary-next-message (wl-summary-message-number)
+                                            direction hereto))
+      (if (numberp num)
+         (wl-thread-jump-to-msg num))
+      t)))
 ;;
 ;; Goto unread or important
 ;; returns t if next message exists in this folder.
 (defun wl-summary-cursor-down (&optional hereto)
   (interactive "P")
-  (if (and (null wl-summary-buffer-target-mark-list)
-          (eq wl-summary-buffer-view 'thread))
-      (wl-thread-jump-to-next-unread hereto)
-    (if hereto
-       (beginning-of-line)
-      (end-of-line))
-    (let ((case-fold-search nil)
-         regex-list)
-      (setq regex-list (wl-summary-cursor-move-regex))
-      (catch 'done
-       (while regex-list
-         (when (re-search-forward
-                (car regex-list)
-                nil t nil)
-           (beginning-of-line)
-           (throw 'done t))
-         (setq regex-list (cdr regex-list)))
-       (beginning-of-line)
-       (throw 'done nil)))))
+  (wl-summary-cursor-move 'down hereto))
+
+(defun wl-summary-cursor-up (&optional hereto)
+  (interactive "P")
+  (wl-summary-cursor-move 'up hereto))
 
 (defun wl-summary-save-view-cache ()
   (save-excursion
     (let* ((dir (elmo-msgdb-expand-path wl-summary-buffer-folder-name))
           (cache (expand-file-name wl-summary-cache-file dir))
           (view (expand-file-name wl-summary-view-file dir))
-          ;;(coding-system-for-write wl-cs-cache)
-          ;;(output-coding-system wl-cs-cache)
           (save-view wl-summary-buffer-view)
           (tmp-buffer (get-buffer-create " *wl-summary-save-view-cache*"))
           (charset wl-summary-buffer-mime-charset))
@@ -4593,11 +4616,8 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                (widen)
                (encode-mime-charset-region
                 (point-min) (point-max) charset)
-               (as-binary-output-file
-                (write-region (point-min)
-                              (point-max) cache nil 'no-msg))
-               (write-region (point-min) (point-max) cache nil
-                             'no-msg)))
+               (write-region-as-binary (point-min)(point-max)
+                                       cache nil 'no-msg)))
            (when (file-writable-p view) ; 'thread or 'sequence
              (save-excursion
                (set-buffer tmp-buffer)
@@ -4621,7 +4641,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
   "returns update or all or rescan."
   ;; for the case when parts are expanded in the bottom of the folder
   (let ((input-range-list '("update" "all" "rescan" "first:" "last:"
-                           "no-sync" "rescan-noscore"))
+                           "no-sync" "rescan-noscore" "all-visible"))
        (default (or (wl-get-assoc-list-value
                      wl-folder-sync-range-alist
                      folder)
@@ -4694,31 +4714,30 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
              (run-hooks 'wl-summary-toggle-disp-folder-message-resumed-hook)
              (select-window (get-buffer-window cur-buf)))
            )
-       (save-excursion
-         ;; hide message window
-         (let ((mes-win (get-buffer-window view-message-buffer))
-               (wl-stay-folder-window t))
-           (if mes-win (delete-window mes-win))
-           (select-window (get-buffer-window cur-buf))
-           ;; display wl-folder window!!
-           (if (setq fld-buf (get-buffer wl-folder-buffer-name))
-               (if (setq fld-win (get-buffer-window fld-buf))
-                   ;; folder win is already displayed.
-                   (select-window fld-win)
-                 ;; folder win is not displayed...occupy all.
-                 (switch-to-buffer fld-buf))
-             ;; no folder buf
-             (wl-folder))
-           (split-window-horizontally wl-folder-window-width)
-           (other-window 1)
-           (switch-to-buffer cur-buf)
-           ;; resume message window.
-           (run-hooks 'wl-summary-toggle-disp-folder-on-hook)
-           (when mes-win
-             (wl-select-buffer view-message-buffer)
-             (run-hooks 'wl-summary-toggle-disp-folder-message-resumed-hook)
-             (select-window (get-buffer-window cur-buf))))
-         )))))
+       ;; hide message window
+       (let ((mes-win (get-buffer-window view-message-buffer))
+             (wl-stay-folder-window t))
+         (if mes-win (delete-window mes-win))
+         (select-window (get-buffer-window cur-buf))
+         ;; display wl-folder window!!
+         (if (setq fld-buf (get-buffer wl-folder-buffer-name))
+             (if (setq fld-win (get-buffer-window fld-buf))
+                 ;; folder win is already displayed.
+                 (select-window fld-win)
+               ;; folder win is not displayed...occupy all.
+               (switch-to-buffer fld-buf))
+           ;; no folder buf
+           (wl-folder))
+         (split-window-horizontally wl-folder-window-width)
+         (other-window 1)
+         (switch-to-buffer cur-buf)
+         ;; resume message window.
+         (run-hooks 'wl-summary-toggle-disp-folder-on-hook)
+         (when mes-win
+           (wl-select-buffer view-message-buffer)
+           (run-hooks 'wl-summary-toggle-disp-folder-message-resumed-hook)
+           (select-window (get-buffer-window cur-buf))))
+       ))))
   (run-hooks 'wl-summary-toggle-disp-folder-hook))
 
 (defun wl-summary-toggle-disp-msg (&optional arg)
@@ -4751,10 +4770,10 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       (if wl-summary-buffer-disp-msg
          (progn
            (wl-summary-redisplay)
-           ;; hide your folder window
-;;             (setq fld-buf (get-buffer wl-folder-buffer-name))
-;;             (if (setq fld-win (get-buffer-window fld-buf))
-;;                 (delete-window fld-win)))
+;;; hide your folder window
+;;;        (setq fld-buf (get-buffer wl-folder-buffer-name))
+;;;        (if (setq fld-win (get-buffer-window fld-buf))
+;;;            (delete-window fld-win)))
            (run-hooks 'wl-summary-toggle-disp-on-hook))
        (wl-delete-all-overlays)
        (save-excursion
@@ -4762,7 +4781,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
          (delete-window)
          (select-window (get-buffer-window cur-buf))
          (run-hooks 'wl-summary-toggle-disp-off-hook))
-       ;;(switch-to-buffer cur-buf)
+;;;    (switch-to-buffer cur-buf)
        )))))
 
 (defun wl-summary-next-line-content ()
@@ -4895,8 +4914,8 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
         (errmsg
          (format "No message with id \"%s\" in the folder." msgid)))
     (if (setq msg (car (rassoc msgid number-alist)))
-       ;;(wl-summary-jump-to-msg-internal
-       ;;wl-summary-buffer-folder-name msg 'no-sync)
+;;;    (wl-summary-jump-to-msg-internal
+;;;     wl-summary-buffer-folder-name msg 'no-sync)
        (progn
          (wl-thread-jump-to-msg msg)
          t)
@@ -5058,11 +5077,11 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
             nil)
            ((and msg-id (wl-summary-jump-to-msg-by-message-id msg-id))
             (wl-summary-redisplay)
-            (message "Searching parent message...done.")
+            (message "Searching parent message...done")
             t)
            ((and msg-num (wl-summary-jump-to-msg msg-num))
             (wl-summary-redisplay)
-            (message "Searching parent message...done.")
+            (message "Searching parent message...done")
             t)
            (t ; failed.
             (message "Parent message was not found.")
@@ -5070,7 +5089,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 
 (defun wl-summary-reply (&optional arg without-setup-hook)
   "Reply to current message. Default is \"wide\" reply.
-Reply to author if invoked with argument."
+Reply to author if invoked with ARG."
   (interactive "P")
   (let ((folder wl-summary-buffer-folder-name)
        (number (wl-summary-message-number))
@@ -5088,7 +5107,7 @@ Reply to author if invoked with argument."
                  (split-window-vertically))
              (other-window 1)
              (when (setq mes-buf (wl-message-get-original-buffer))
-               (wl-draft-reply mes-buf (not arg) summary-buf)
+               (wl-draft-reply mes-buf arg summary-buf)
                (unless without-setup-hook
                  (run-hooks 'wl-mail-setup-hook)))
              t)))))
@@ -5101,29 +5120,39 @@ Reply to author if invoked with argument."
   (run-hooks 'wl-mail-setup-hook)
   (mail-position-on-field "To"))
 
-(defun wl-summary-write-current-newsgroup (&optional folder)
+(defvar wl-summary-write-current-folder-functions
+  '(wl-folder-get-newsgroups
+    wl-folder-guess-mailing-list-by-refile-rule
+    wl-folder-guess-mailing-list-by-folder-name)
+  "Newsgroups or Mailing List address guess functions list.
+Call from `wl-summary-write-current-folder'")
+
+(defun wl-summary-write-current-folder (&optional folder)
+  "Write message to current FOLDER's newsgroup or mailing-list.
+Use function list is `wl-summary-write-current-folder-functions'."
   (interactive)
-  (let* ((folder (or folder wl-summary-buffer-folder-name))
-        (flist (elmo-folder-get-primitive-folder-list folder))
-        newsgroups fld ret)
-    (while (setq fld (car flist))
-      (if (setq ret
-               (cond ((eq 'nntp (elmo-folder-get-type fld))
-                      (nth 1 (elmo-folder-get-spec fld)))
-                     ((eq 'localnews (elmo-folder-get-type fld))
-                      (elmo-replace-in-string
-                       (nth 1 (elmo-folder-get-spec fld)) "/" "\\."))))
-         (setq newsgroups (cond (newsgroups
-                                 (concat newsgroups "," ret))
-                                (t ret))))
-      (setq flist (cdr flist)))
-    (if newsgroups
-       (progn
-         (wl-draft nil nil nil nil nil newsgroups)
-         (run-hooks 'wl-mail-setup-hook))
-      (error "%s is not newsgroup" folder))))
+  (let (newsgroups to cc)
+    ;; default FOLDER is current buffer folder
+    (setq folder (or folder wl-summary-buffer-folder-name))
+    (let ((flist wl-summary-write-current-folder-functions)
+         guess-list)
+      (while flist
+       (setq guess-list (funcall (car flist) folder))
+       (if (or (nth 0 guess-list)      ; To:
+;;;            (nth 1 guess-list)      ; Cc:
+               (nth 2 guess-list))     ; Newsgroups:
+           (setq flist nil)
+         (setq flist (cdr flist))))
+      (when (null guess-list)
+       (error "Can't guess by folder %s" folder))
+      (wl-draft (nth 0 guess-list) nil nil ; To:
+               (nth 1 guess-list) nil  ; Cc:
+               (nth 2 guess-list))     ; Newsgroups:
+      (run-hooks 'wl-mail-setup-hook)
+      (mail-position-on-field "Subject"))))
 
 (defun wl-summary-forward (&optional without-setup-hook)
+  ""
   (interactive)
   (let ((folder wl-summary-buffer-folder-name)
        (number (wl-summary-message-number))
@@ -5161,6 +5190,7 @@ Reply to author if invoked with argument."
   (wl-summary-read))
 
 (defun wl-summary-read ()
+  ""
   (interactive)
   (let ((folder wl-summary-buffer-folder-name)
        (number (wl-summary-message-number))
@@ -5185,12 +5215,13 @@ Reply to author if invoked with argument."
        (progn
          (if (wl-summary-next-page)
              (wl-summary-down t)))
-;          (wl-summary-scroll-up-content)))
+;;;        (wl-summary-scroll-up-content)))
       (if (wl-summary-no-mime-p folder)
          (wl-summary-redisplay-no-mime folder number)
        (wl-summary-redisplay-internal folder number)))))
 
 (defun wl-summary-prev (&optional interactive)
+  ""
   (interactive)
   (if wl-summary-move-direction-toggle
       (setq wl-summary-move-direction-downward nil))
@@ -5230,6 +5261,7 @@ Reply to author if invoked with argument."
              (wl-summary-entity-info-msg next-entity finfo))))))))
 
 (defun wl-summary-next (&optional interactive)
+  ""
   (interactive)
   (if wl-summary-move-direction-toggle
       (setq wl-summary-move-direction-downward t))
@@ -5269,6 +5301,7 @@ Reply to author if invoked with argument."
              (wl-summary-entity-info-msg next-entity finfo))))))))
 
 (defun wl-summary-up (&optional interactive skip-no-unread)
+  ""
   (interactive)
   (if wl-summary-move-direction-toggle
       (setq wl-summary-move-direction-downward nil))
@@ -5398,7 +5431,10 @@ Reply to author if invoked with argument."
              (if (setq fld-win (get-buffer-window fld-buf))
                  (delete-window fld-win)))
           (setq wl-current-summary-buffer (current-buffer))
-         (if (wl-message-redisplay fld num 'mime msgdb force-reload)
+         (if (wl-message-redisplay fld num 'mime msgdb
+                                   (or force-reload
+                                       ;; if draft folder, force reload.
+                                       (string= fld wl-draft-folder)))
              (wl-summary-mark-as-read nil
                                       ;; cached, then change server-mark.
                                       (if wl-message-cache-used
@@ -5440,7 +5476,9 @@ Reply to author if invoked with argument."
          (setq wl-summary-buffer-last-displayed-msg
                wl-summary-buffer-current-msg)
          (setq wl-current-summary-buffer (current-buffer))
-         (wl-normal-message-redisplay fld num 'no-mime msgdb)
+         (wl-normal-message-redisplay fld num 'no-mime msgdb
+                                      ;; if draft folder, force reload.
+                                      (string= fld wl-draft-folder))
          (wl-summary-mark-as-read nil nil t)
          (setq wl-summary-buffer-current-msg num)
          (when wl-summary-recenter
@@ -5467,7 +5505,9 @@ Reply to author if invoked with argument."
          (setq wl-summary-buffer-last-displayed-msg
                wl-summary-buffer-current-msg)
          (setq wl-current-summary-buffer (current-buffer))
-         (if (wl-message-redisplay fld num 'all-header msgdb); t if displayed.
+         (if (wl-message-redisplay fld num 'all-header msgdb
+                                   ;; if draft folder, force reload.
+                                   (string= fld wl-draft-folder))
              (wl-summary-mark-as-read nil nil t))
          (setq wl-summary-buffer-current-msg num)
          (when wl-summary-recenter
@@ -5500,7 +5540,14 @@ Reply to author if invoked with argument."
       (if (setq message-buf (wl-message-get-original-buffer))
          (set-buffer message-buf))
       (unless (wl-message-news-p)
-       (error "This is not a news article; canceling is impossible"))
+       (set-buffer summary-buf)
+       (if (and (eq (elmo-folder-get-type wl-summary-buffer-folder-name)
+                    'nntp)
+                (y-or-n-p "Cannot get Newsgroups. Fetch again? "))
+           (progn
+             (wl-summary-redisplay t)
+             (wl-summary-supersedes-message))
+         (error "This is not a news article; supersedes is impossible")))
       (when (yes-or-no-p "Do you really want to cancel this article? ")
        (let (from newsgroups message-id distribution buf)
          (save-excursion
@@ -5542,7 +5589,14 @@ Reply to author if invoked with argument."
     (if (setq message-buf (wl-message-get-original-buffer))
        (set-buffer message-buf))
     (unless (wl-message-news-p)
-      (error "This is not a news article; supersedes is impossible"))
+      (set-buffer summary-buf)
+      (if (and (eq (elmo-folder-get-type wl-summary-buffer-folder-name)
+                  'nntp)
+              (y-or-n-p "Cannot get Newsgroups. Fetch again? "))
+         (progn
+           (wl-summary-redisplay t)
+           (wl-summary-supersedes-message))
+       (error "This is not a news article; supersedes is impossible")))
     (save-excursion
       (setq from (std11-field-body "from"))
       ;; Make sure that this article was written by the user.
@@ -5580,7 +5634,7 @@ Reply to author if invoked with argument."
          (wl-summary-set-message-buffer-or-redisplay)
          (set-buffer (wl-message-get-original-buffer))
          (if (and (null arg) (file-exists-p filename))
-             (if (y-or-n-p "file already exists. override it?")
+             (if (y-or-n-p "File already exists.  override it? ")
                  (write-region (point-min) (point-max) filename))
            (write-region (point-min) (point-max) filename)))
       (message "No message to save."))
@@ -5637,10 +5691,10 @@ Reply to author if invoked with argument."
     (save-excursion
       (wl-summary-set-message-buffer-or-redisplay)
       (if (or (not (interactive-p))
-             (y-or-n-p "Print ok?"))
+             (y-or-n-p "Print ok? "))
          (progn
            (let* ((message-buffer (get-buffer wl-message-buf-name))
-                  ;; (summary-buffer (get-buffer wl-summary-buffer-name))
+;;;               (summary-buffer (get-buffer wl-summary-buffer-name))
                   (buffer (generate-new-buffer " *print*")))
              (set-buffer message-buffer)
              (copy-to-buffer buffer (point-min) (point-max))
@@ -5655,11 +5709,11 @@ Reply to author if invoked with argument."
       (message "No message.")
     (setq filename (ps-print-preprint current-prefix-arg))
     (if (or (not (interactive-p))
-           (y-or-n-p "Print ok?"))
+           (y-or-n-p "Print ok? "))
        (let ((summary-buffer (current-buffer))
              wl-break-pages)
          (save-excursion
-           ;;(wl-summary-set-message-buffer-or-redisplay)
+;;;        (wl-summary-set-message-buffer-or-redisplay)
            (wl-summary-redisplay-internal)
            (let* ((message-buffer (get-buffer wl-message-buf-name))
                   (buffer (generate-new-buffer " *print*"))
@@ -5839,7 +5893,7 @@ Reply to author if invoked with argument."
                                   orig-buf tmp-buf t
                                   (= i k)))
                   nil
-                (error "Can't find begin line.")))
+                (error "Can't find begin line")))
              ((< i k)
               (wl-message-uu-substring orig-buf tmp-buf))
              (t ; last
@@ -5872,7 +5926,7 @@ Reply to author if invoked with argument."
                           wl-prog-uudecode-arg))))
            (when (not (= 0 rc))
              (setq errmsg (buffer-substring (point-min)(point-max)))
-             (error "uudecode error: %s" errmsg))
+             (error "Uudecode error: %s" errmsg))
            (if (not wl-prog-uudecode-no-stdout-option)
                (let (file-name-handler-alist) ;; void jka-compr
                  (as-binary-output-file
@@ -5891,7 +5945,7 @@ Reply to author if invoked with argument."
   (if (elmo-folder-pipe-p wl-summary-buffer-folder-name)
       (error "You cannot drop unsync messages in this folder"))
   (if (or (not (interactive-p))
-         (y-or-n-p "Drop all unsync messages?"))
+         (y-or-n-p "Drop all unsync messages? "))
       (let* ((folder-list (elmo-folder-get-primitive-folder-list
                           wl-summary-buffer-folder-name))
             (is-multi (elmo-multi-p wl-summary-buffer-folder-name))
@@ -5918,25 +5972,16 @@ Reply to author if invoked with argument."
                                            (+ wl-summary-buffer-unread-count
                                               wl-summary-buffer-new-count)
                                            sum))
-       (message "Dropping...done."))))
+       (message "Dropping...done"))))
 
 (defun wl-summary-default-get-next-msg (msg)
-  (let (next)
-    (if (and (not wl-summary-buffer-target-mark-list)
-            (eq wl-summary-buffer-view 'thread)
-            (if (eq wl-summary-move-direction-downward nil)
-                (setq next (wl-thread-get-prev-unread msg))
-              (setq next (wl-thread-get-next-unread msg))))
-       next
-      (save-excursion
-       (wl-summary-jump-to-msg msg)
-       (let (wl-summary-buffer-disp-msg)
-         (if (eq wl-summary-move-direction-downward nil)
-             (unless (wl-summary-cursor-up)
-               (wl-summary-prev))
-           (unless (wl-summary-cursor-down)
-             (wl-summary-next)))
-         (wl-summary-message-number))))))
+  (or (wl-summary-next-message msg
+                              (if wl-summary-move-direction-downward 'down
+                                'up)
+                              nil)
+      (cadr (memq msg (if wl-summary-move-direction-downward
+                         wl-summary-buffer-number-list
+                       (reverse wl-summary-buffer-number-list))))))
 
 (defsubst wl-cache-prefetch-p (fld &optional num)
   (cond ((and num wl-cache-prefetch-folder-type-list)
@@ -5960,8 +6005,8 @@ Reply to author if invoked with argument."
 
 (defun wl-cache-prefetch-next (fld msg &optional summary)
   (if (wl-cache-prefetch-p fld)
-      (if (not elmo-use-buffer-cache)
-        ;; (message "`elmo-use-buffer-cache' is nil, cache prefetch is disable.")
+      (if elmo-use-buffer-cache
+;;;      (message "`elmo-use-buffer-cache' is nil, cache prefetch is disable.")
        (save-excursion
          (set-buffer (or summary (get-buffer wl-summary-buffer-name)))
          (let ((next (funcall wl-cache-prefetch-get-next-func msg)))
@@ -5999,7 +6044,7 @@ Reply to author if invoked with argument."
                                                              folder next)))))
                  (if wl-cache-prefetch-debug
                      (message "Reading %d..." msg))
-                 (elmo-buffer-cache-message folder next msgdb)
+                 (elmo-buffer-cache-message folder next msgdb nil 'unread)
                  (if wl-cache-prefetch-debug
                      (message "Reading %d... done" msg))))))))))