* wl-summary.el (wl-summary-collect-unread): Eliminated.
[elisp/wanderlust.git] / wl / wl-summary.el
index beed4d1..67ebaac 100644 (file)
@@ -1,10 +1,15 @@
 ;;; 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
-;; Time-stamp: <00/04/28 10:27:22 teranisi>
 
 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
 
 ;;
 
 ;;; Commentary:
-;; 
+;;
 
 ;;; Code:
-;; 
+;;
 
 (require 'elmo2)
 (require 'elmo-multi)
 (require 'wl-highlight)
 (require 'wl-refile)
 (require 'wl-util)
-(condition-case ()
-    (progn
-      (require 'timezone)
-      (require 'easymenu))
-  (error))
+(condition-case nil (require 'timezone) (error nil))
+(condition-case nil (require 'easymenu) (error nil))
 (require 'elmo-date)
-(condition-case nil
-    (require 'ps-print)
-  (error))
+(condition-case nil (require 'ps-print) (error nil))
 
 (eval-when-compile
   (require 'cl)
   (condition-case () (require 'timer) (error nil))
-  (mapcar
-   (function
-    (lambda (symbol)
-      (unless (boundp symbol)
-       (set (make-local-variable symbol) nil))))
-   '(dragdrop-drop-functions scrollbar-height mail-reply-buffer))
-  (defun-maybe ps-print-buffer-with-faces (a))
-  (defun-maybe elmo-database-msgid-put (a b c))
-  (defun-maybe elmo-database-close ())
-  (defun-maybe elmo-database-msgid-get (a))
-  (defun-maybe run-with-idle-timer (secs repeat function &rest args)))
+  (defalias-maybe 'ps-print-buffer-with-faces 'ignore)
+  (defalias-maybe 'elmo-database-msgid-put 'ignore)
+  (defalias-maybe 'elmo-database-close 'ignore)
+  (defalias-maybe 'elmo-database-msgid-get 'ignore)
+  (defalias-maybe 'run-with-idle-timer 'ignore)
+  (defalias-maybe 'ps-print-preprint 'ignore))
+
+(defvar dragdrop-drop-functions)
+(defvar scrollbar-height)
+(defvar mail-reply-buffer)
 
 (defvar wl-summary-buffer-name "Summary")
 (defvar wl-summary-mode-map nil)
 
 (defvar wl-summary-buffer-msgdb       nil)
 (defvar wl-summary-buffer-folder-name nil)
+(defvar wl-summary-buffer-folder-indicator nil)
 (defvar wl-summary-buffer-disp-msg    nil)
 (defvar wl-summary-buffer-disp-folder nil)
-(defvar wl-summary-buffer-refile-list nil) 
-(defvar wl-summary-buffer-delete-list nil) 
+(defvar wl-summary-buffer-refile-list nil)
+(defvar wl-summary-buffer-delete-list nil)
 (defvar wl-summary-buffer-last-displayed-msg nil)
 (defvar wl-summary-buffer-current-msg nil)
 (defvar wl-summary-buffer-unread-status " (0 new/0 unread)")
 (defvar wl-summary-buffer-view 'thread)
 (defvar wl-summary-buffer-message-modified nil)
 (defvar wl-summary-buffer-mark-modified nil)
+(defvar wl-summary-buffer-thread-modified nil)
 (defvar wl-summary-buffer-number-column nil)
 (defvar wl-summary-buffer-number-regexp nil)
 (defvar wl-summary-buffer-persistent nil)
 (defvar wl-summary-buffer-thread-nodes nil)
 (defvar wl-summary-buffer-target-mark-list nil)
-(defvar wl-summary-buffer-copy-list nil) 
+(defvar wl-summary-buffer-copy-list nil)
 (defvar wl-summary-buffer-prev-refile-destination nil)
 (defvar wl-summary-buffer-prev-copy-destination nil)
+(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-read-folder-hist nil)
 (defvar wl-summary-scored nil)
 (defvar wl-crosspost-alist-modified nil)
+(defvar wl-summary-alike-hashtb 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-ps-preprint-hook nil)
 (defvar wl-ps-print-hook nil)
 
-(mapcar 
- (function make-variable-buffer-local)
- (list 'wl-summary-buffer-msgdb
-       'wl-summary-buffer-disp-msg
-       'wl-summary-buffer-disp-folder
-       'wl-summary-buffer-refile-list
-       'wl-summary-buffer-copy-list
-       'wl-summary-buffer-target-mark-list
-       'wl-summary-buffer-delete-list
-       'wl-summary-buffer-folder-name
-       'wl-summary-buffer-last-displayed-msg
-       'wl-summary-buffer-unread-status
-       'wl-summary-buffer-unread-count
-       'wl-summary-buffer-new-count
-       'wl-summary-buffer-mime-charset
-       'wl-summary-buffer-weekday-name-lang
-       'wl-summary-buffer-thread-indent-set
-       'wl-summary-buffer-message-redisplay-func
-       'wl-summary-buffer-view
-       'wl-summary-buffer-message-modified
-       'wl-summary-buffer-mark-modified
-       'wl-summary-buffer-number-column
-       'wl-summary-buffer-number-regexp
-       'wl-summary-buffer-persistent
-       'wl-summary-buffer-thread-nodes
-       'wl-summary-buffer-prev-refile-destination
-       'wl-summary-scored
-       'wl-summary-default-score
-       'wl-summary-move-direction-downward
-       'wl-summary-important-above
-       'wl-summary-temp-above
-       'wl-summary-mark-below
-       'wl-summary-expunge-below
-       'wl-thread-indent-level-internal
-       'wl-thread-have-younger-brother-str-internal
-       'wl-thread-youngest-child-str-internal
-       'wl-thread-vertical-str-internal
-       'wl-thread-horizontal-str-internal
-       'wl-thread-space-str-internal))
+(make-variable-buffer-local 'wl-summary-buffer-msgdb)
+(make-variable-buffer-local 'wl-summary-buffer-disp-msg)
+(make-variable-buffer-local 'wl-summary-buffer-disp-folder)
+(make-variable-buffer-local 'wl-summary-buffer-refile-list)
+(make-variable-buffer-local 'wl-summary-buffer-copy-list)
+(make-variable-buffer-local 'wl-summary-buffer-target-mark-list)
+(make-variable-buffer-local 'wl-summary-buffer-delete-list)
+(make-variable-buffer-local 'wl-summary-buffer-folder-name)
+(make-variable-buffer-local 'wl-summary-buffer-folder-indicator)
+(make-variable-buffer-local 'wl-summary-buffer-last-displayed-msg)
+(make-variable-buffer-local 'wl-summary-buffer-unread-status)
+(make-variable-buffer-local 'wl-summary-buffer-unread-count)
+(make-variable-buffer-local 'wl-summary-buffer-new-count)
+(make-variable-buffer-local 'wl-summary-buffer-mime-charset)
+(make-variable-buffer-local 'wl-summary-buffer-weekday-name-lang)
+(make-variable-buffer-local 'wl-summary-buffer-thread-indent-set)
+(make-variable-buffer-local 'wl-summary-buffer-message-redisplay-func)
+(make-variable-buffer-local 'wl-summary-buffer-view)
+(make-variable-buffer-local 'wl-summary-buffer-message-modified)
+(make-variable-buffer-local 'wl-summary-buffer-mark-modified)
+(make-variable-buffer-local 'wl-summary-buffer-thread-modified)
+(make-variable-buffer-local 'wl-summary-buffer-number-column)
+(make-variable-buffer-local 'wl-summary-buffer-number-regexp)
+(make-variable-buffer-local 'wl-summary-buffer-persistent)
+(make-variable-buffer-local 'wl-summary-buffer-thread-nodes)
+(make-variable-buffer-local 'wl-summary-buffer-prev-refile-destination)
+(make-variable-buffer-local 'wl-summary-buffer-saved-message)
+(make-variable-buffer-local 'wl-summary-scored)
+(make-variable-buffer-local 'wl-summary-default-score)
+(make-variable-buffer-local 'wl-summary-move-direction-downward)
+(make-variable-buffer-local 'wl-summary-important-above)
+(make-variable-buffer-local 'wl-summary-target-above)
+(make-variable-buffer-local 'wl-summary-mark-below)
+(make-variable-buffer-local 'wl-summary-expunge-below)
+(make-variable-buffer-local 'wl-thread-indent-level-internal)
+(make-variable-buffer-local 'wl-thread-have-younger-brother-str-internal)
+(make-variable-buffer-local 'wl-thread-youngest-child-str-internal)
+(make-variable-buffer-local 'wl-thread-vertical-str-internal)
+(make-variable-buffer-local 'wl-thread-horizontal-str-internal)
+(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)
-  (defun wl-summary-append-message-func-internal (entity overview 
-                                                        mark-alist update)))
+  (defun wl-summary-append-message-func-internal (entity overview
+                                                        mark-alist update
+                                                        &optional force-insert)))
 (unless (fboundp 'wl-summary-from-func-internal)
   (defun wl-summary-from-func-internal (from)
     from))
                               (lambda (to)
                                 (eword-decode-string
                                  (if wl-use-petname
-                                     (wl-address-get-petname to)
-                                   (car 
-                                    (std11-extract-address-components to))))))
+                                     (or
+                                      (funcall wl-summary-get-petname-func to)
+                                      (car
+                                       (std11-extract-address-components to))
+                                      to)
+                                   to))))
                              (wl-parse-addresses tos)
                              ","))))
              ((setq ng (elmo-msgdb-overview-entity-get-extra-field
                         entity "newsgroups"))
               (setq retval (concat "Ng:" ng)))))
       (if wl-use-petname
-         (setq retval (wl-address-get-petname from))
+         (setq retval (or (funcall wl-summary-get-petname-func from)
+                          (car (std11-extract-address-components from))
+                          from))
        (setq retval from)))
     retval))
 
 (defun wl-summary-simple-from (string)
   (if wl-use-petname
-      (wl-address-get-petname string)
+      (or (funcall wl-summary-get-petname-func string)
+         (car (std11-extract-address-components string))
+         string)
     string))
 
 (defvar wl-summary-mode-menu-spec
      ["By Number" wl-summary-sort-by-number t]
      ["By Date" wl-summary-sort-by-date t]
      ["By From" wl-summary-sort-by-from t]
-     ["By Subject" wl-summary-sort-by-subject t])    
+     ["By Subject" wl-summary-sort-by-subject t])
     "----"
     ("Message Operation"
      ["Mark as read"    wl-summary-mark-as-read t]
     (defun wl-summary-setup-mouse ()
       (define-key wl-summary-mode-map 'button4 'wl-summary-prev)
       (define-key wl-summary-mode-map 'button5 'wl-summary-next)
-      (define-key wl-summary-mode-map [(shift button4)] 
+      (define-key wl-summary-mode-map [(shift button4)]
        'wl-summary-up)
-      (define-key wl-summary-mode-map [(shift button5)] 
+      (define-key wl-summary-mode-map [(shift button5)]
        'wl-summary-down)
       (define-key wl-summary-mode-map 'button2 'wl-summary-click))
   (if wl-on-nemacs
   (define-key wl-summary-mode-map "g"    'wl-summary-goto-folder)
   (define-key wl-summary-mode-map "c"    'wl-summary-mark-as-read-all)
   (define-key wl-summary-mode-map "D"    'wl-summary-drop-unsync)
-  
+
   (define-key wl-summary-mode-map "a"    'wl-summary-reply)
   (define-key wl-summary-mode-map "A"    'wl-summary-reply-with-citation)
   (define-key wl-summary-mode-map "C"    'wl-summary-cancel-message)
   (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)
   (define-key wl-summary-mode-map "|"    'wl-summary-pipe-message)
   (define-key wl-summary-mode-map "q"    'wl-summary-exit)
   (define-key wl-summary-mode-map "Q"    'wl-summary-force-exit)
-  
+
   (define-key wl-summary-mode-map "j"    'wl-summary-jump-to-current-message)
   (define-key wl-summary-mode-map "J"    'wl-thread-jump-to-msg)
   (define-key wl-summary-mode-map "I"    'wl-summary-incorporate)
   (define-key wl-summary-mode-map "\M-j" 'wl-summary-jump-to-msg-by-message-id)
   (define-key wl-summary-mode-map "^"    'wl-summary-jump-to-parent-message)
   (define-key wl-summary-mode-map "!"    'wl-summary-mark-as-unread)
-  
+
   (define-key wl-summary-mode-map "s"    'wl-summary-sync)
   (define-key wl-summary-mode-map "S"    'wl-summary-sort)
   (define-key wl-summary-mode-map "\M-s"    'wl-summary-stick)
   (define-key wl-summary-mode-map "?"    'wl-summary-pick)
   (define-key wl-summary-mode-map "\ee"  'wl-summary-expire)
 
+  ;; copy & paste.
+  (define-key wl-summary-mode-map "\ew"  'wl-summary-save-current-message)
+  (define-key wl-summary-mode-map "\C-y"  'wl-summary-yank-saved-message)
+
   ;; line commands
   (define-key wl-summary-mode-map "R"    'wl-summary-mark-as-read)
   (define-key wl-summary-mode-map "i"    'wl-summary-prefetch)
   (define-key wl-summary-mode-map "O"    'wl-summary-copy)
   (define-key wl-summary-mode-map "\M-o" 'wl-summary-refile-prev-destination)
 ;  (define-key wl-summary-mode-map "\M-O" 'wl-summary-copy-prev-destination)
-  (define-key wl-summary-mode-map "\C-o" 'wl-summary-auto-refile)  
+  (define-key wl-summary-mode-map "\C-o" 'wl-summary-auto-refile)
   (define-key wl-summary-mode-map "d"    'wl-summary-delete)
   (define-key wl-summary-mode-map "u"    'wl-summary-unmark)
   (define-key wl-summary-mode-map "U"    'wl-summary-unmark-all)
   (define-key wl-summary-mode-map "t!" 'wl-thread-mark-as-unread)
   (define-key wl-summary-mode-map "t$" 'wl-thread-mark-as-important)
   (define-key wl-summary-mode-map "ty" 'wl-thread-save)
+  (define-key wl-summary-mode-map "ts" 'wl-thread-set-parent)
 
   ;; target-mark commands
   (define-key wl-summary-mode-map "m"    (make-sparse-keymap))
   (define-key wl-summary-mode-map "mA"   'wl-summary-target-mark-reply-with-citation)
   (define-key wl-summary-mode-map "mf"   'wl-summary-target-mark-forward)
   (define-key wl-summary-mode-map "m?"   'wl-summary-target-mark-pick)
-  
+
   ;; region commands
   (define-key wl-summary-mode-map "r"    (make-sparse-keymap))
   (define-key wl-summary-mode-map "rR"   'wl-summary-mark-as-read-region)
   (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)
     (while mark-alist
       (setq mark (cadr (car mark-alist)))
       (and mark
-          (cond 
+          (cond
            ((string= mark wl-summary-new-mark)
             (setq new (+ 1 new)))
            ((or (string= mark wl-summary-unread-uncached-mark)
             (setq unread (+ 1 unread)))))
       (setq mark-alist (cdr mark-alist)))
     (if (eq major-mode 'wl-summary-mode)
-       (setq wl-summary-buffer-new-count new 
+       (setq wl-summary-buffer-new-count new
              wl-summary-buffer-unread-count unread))
     (+ new unread)))
 
-(defun wl-summary-make-modeline ()
-  "Create new modeline format for Wanderlust"
-  (let* ((duplicated (copy-sequence mode-line-format))
-        (cur-entry duplicated)
-        return-modeline)
-    (if (memq 'wl-plug-state-indicator mode-line-format)
-       duplicated
-      (catch 'done
-       (while cur-entry
-         (if (or (and (symbolp (car cur-entry))
-                      (eq 'mode-line-buffer-identification 
-                             (car cur-entry)))
-                 (and (consp (car cur-entry))
-                      (or 
-                       (eq 'modeline-buffer-identification 
-                              (car (car cur-entry)))
-                       (eq 'modeline-buffer-identification 
-                              (cdr (car cur-entry))))))
-             (progn
-               (setq return-modeline (append return-modeline
-                                             (list 
-                                              'wl-plug-state-indicator
-                                              (car cur-entry)
-                                              'wl-summary-buffer-unread-status)
-                                             (cdr cur-entry)))
-               (throw 'done return-modeline))
-           (setq return-modeline (append return-modeline
-                                         (list (car cur-entry)))))
-         (setq cur-entry (cdr cur-entry)))))))
-
 (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)
@@ -582,10 +571,12 @@ If optional argument is non-nil, Supersedes message"
              (delete-other-windows)))
       (save-excursion
        (let ((mmelmo-force-fetch-entire-message t))
-         (wl-summary-set-message-buffer-or-redisplay)
-         (set-buffer (wl-message-get-original-buffer))
-         (wl-draft-edit-string (buffer-substring (point-min)
-                                                 (point-max))))))))
+         (if (null (wl-summary-message-number))
+             (message "No message.")
+           (wl-summary-set-message-buffer-or-redisplay)
+           (set-buffer (wl-message-get-original-buffer))
+           (wl-draft-edit-string (buffer-substring (point-min)
+                                                   (point-max)))))))))
 
 (defun wl-summary-resend-bounced-mail ()
   "Re-mail the current message.
@@ -602,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)))
@@ -610,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))
@@ -676,54 +668,54 @@ 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.
-Returns nil if selecting folder was in failure."
+  "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))
-            (connection (elmo-imap4-get-connection spec))
-            (process (elmo-imap4-connection-get-process connection))
-            msgdb response)
-       (save-excursion
-         (unwind-protect
-             (progn
-               (elmo-imap4-send-command (process-buffer process)
-                                        process
-                                        (format "select \"%s\"" 
-                                                (elmo-imap4-spec-folder
-                                                 spec)))
-               (setq msgdb (elmo-msgdb-load (elmo-string folder)))
-               (setq response (elmo-imap4-read-response 
-                               (process-buffer process)
-                               process)))
-           (if (null response)
-               (progn
-                 (setcar (cddr connection) nil)
-                 (error "Select folder failed"))
-             (setcar (cddr connection) (elmo-imap4-spec-folder spec))))
-         (if response msgdb)))
+      (let ((spec (elmo-folder-get-spec folder))
+           session mailbox
+           msgdb response tag)
+       (unwind-protect
+           (progn
+             (setq session (elmo-imap4-get-session spec)
+                   mailbox (elmo-imap4-spec-mailbox spec)
+                   tag (elmo-imap4-send-command session
+                                                (list "select "
+                                                      (elmo-imap4-mailbox
+                                                       mailbox))))
+             (setq msgdb (elmo-msgdb-load (elmo-string folder)))
+             (setq response (elmo-imap4-read-response session tag)))
+         (if response
+             (elmo-imap4-session-set-current-mailbox-internal session mailbox)
+           (and session
+                (elmo-imap4-session-set-current-mailbox-internal session nil))
+           (message "Select mailbox %s failed" mailbox)))
+       msgdb)
     (elmo-msgdb-load (elmo-string folder))))
 
 (defun wl-summary-buffer-set-folder (folder)
   (setq wl-summary-buffer-folder-name folder)
+  (setq wl-summary-buffer-folder-indicator
+       (if (memq 'modeline wl-use-folder-petname)
+           (wl-folder-get-petname folder)
+         folder))
   (when (wl-summary-sticky-p)
     (make-local-variable 'wl-message-buf-name)
     (setq wl-message-buf-name (format "%s:%s" wl-message-buf-name folder)))
-  (setq wl-summary-buffer-mime-charset (or (wl-get-assoc-list-value 
+  (setq wl-summary-buffer-mime-charset (or (wl-get-assoc-list-value
                                            wl-folder-mime-charset-alist
                                            folder)
                                           wl-mime-charset))
-  (setq wl-summary-buffer-weekday-name-lang 
-       (or (wl-get-assoc-list-value 
+  (setq wl-summary-buffer-weekday-name-lang
+       (or (wl-get-assoc-list-value
             wl-folder-weekday-name-lang-alist
             folder)
            wl-summary-weekday-name-lang))
   (setq wl-summary-buffer-thread-indent-set
-       (wl-get-assoc-list-value 
+       (wl-get-assoc-list-value
         wl-folder-thread-indent-set-alist
         folder))
   (setq wl-summary-buffer-persistent (wl-folder-persistent-p folder))
-  (setq 
+  (setq
    wl-thread-indent-level-internal
    (or (nth 0 wl-summary-buffer-thread-indent-set)
        wl-thread-indent-level)
@@ -742,8 +734,8 @@ Returns nil if selecting folder was in failure."
    wl-thread-space-str-internal
    (or (nth 5 wl-summary-buffer-thread-indent-set)
        wl-thread-space-str))
-  (setq wl-thread-indent-regexp 
-       (concat 
+  (setq wl-thread-indent-regexp
+       (concat
         (regexp-quote wl-thread-have-younger-brother-str-internal) "\\|"
         (regexp-quote wl-thread-youngest-child-str-internal) "\\|"
         (regexp-quote wl-thread-vertical-str-internal) "\\|"
@@ -753,95 +745,57 @@ Returns nil if selecting folder was in failure."
 
 (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 wl-summary-buffer-refile-list nil)
-  (setq wl-summary-buffer-target-mark-list nil)
-  (setq wl-summary-buffer-delete-list nil)
-  (setq wl-summary-scored nil)
-  (setq wl-summary-buffer-disp-msg nil)  
-;; (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 
+      (setq wl-summary-buffer-message-redisplay-func
            'wl-mmelmo-message-redisplay)
     (setq wl-summary-buffer-message-redisplay-func
          'wl-normal-message-redisplay))
-  (wl-xmas-setup-summary) ; setup toolbar, dnd, etc.
-  (when wl-show-plug-status-on-modeline 
-    (setq mode-line-format (wl-summary-make-modeline)))
+  (wl-mode-line-buffer-identification '("Wanderlust: "
+                                       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 
+       (timezone-make-date-sortable
        (elmo-msgdb-overview-entity-get-date x))
-       (timezone-make-date-sortable 
+       (timezone-make-date-sortable
        (elmo-msgdb-overview-entity-get-date y)))
     (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)
@@ -851,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)))
 
@@ -872,7 +826,7 @@ q   Goto folder mode.
   "Rescan current folder without updating."
   (interactive)
   (let* ((cur-buf (current-buffer))
-        (msgdb wl-summary-buffer-msgdb) 
+        (msgdb wl-summary-buffer-msgdb)
         (overview (elmo-msgdb-get-overview msgdb))
         (number-alist (elmo-msgdb-get-number-alist msgdb))
         (mark-alist (elmo-msgdb-get-mark-alist msgdb))
@@ -883,8 +837,9 @@ q   Goto folder mode.
         (inhibit-read-only t)
         (buffer-read-only nil)
         expunged)
-    (fset 'wl-summary-append-message-func-internal 
+    (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)
@@ -903,40 +858,57 @@ 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)
-    (message "Constructing summary structure..." percent)
+    (setq wl-summary-delayed-update nil)
+    (elmo-kill-buffer wl-summary-search-buf-name)
+    (message "Constructing summary structure...")
     (while curp
       (setq entity (car curp))
       (wl-summary-append-message-func-internal entity overview mark-alist
                                               nil)
       (setq curp (cdr curp))
-      (setq i (+ i 1))
-      (elmo-display-progress
-       'wl-summary-rescan "Constructing summary structure..."
-       (/ (* i 100) num)))
-    (message "Constructing summary structure...done." percent)
+      (when (> num elmo-display-progress-threshold)
+       (setq i (+ i 1))
+       (if (or (zerop (% i 5)) (= i num))
+           (elmo-display-progress
+            'wl-summary-rescan "Constructing summary structure..."
+            (/ (* i 100) num)))))
+    (when wl-summary-delayed-update
+      (while wl-summary-delayed-update
+       (message "Parent (%d) of message %d is no entity"
+                (caar wl-summary-delayed-update)
+                (elmo-msgdb-overview-entity-get-number
+                 (cdar wl-summary-delayed-update)))
+       (wl-summary-append-message-func-internal
+        (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")
     (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
                                (wl-summary-rescore-msgs number-alist)
                                t)
-      (setq expunged (wl-summary-score-update-all-lines))
-      (if expunged
-         (message "%d message(s) are expunged by scoring." (length expunged))))
+      (when (and wl-summary-scored
+                (setq expunged (wl-summary-score-update-all-lines)))
+       (message "%d message(s) are expunged by scoring." (length expunged))))
     (wl-summary-set-message-modified)
     (wl-summary-count-unread mark-alist)
-    (wl-summary-update-modeline)    
+    (wl-summary-update-modeline)
     (goto-char (point-max))
     (forward-line -1)
     (set-buffer-modified-p nil)))
-    
+
 (defun wl-summary-next-folder-or-exit (&optional next-entity upward)
   (if (and next-entity
           wl-auto-select-next)
@@ -944,7 +916,7 @@ q   Goto folder mode.
        (wl-summary-toggle-disp-msg 'off)
        (unwind-protect
            (setq retval
-                 (wl-summary-goto-folder-subr next-entity 
+                 (wl-summary-goto-folder-subr next-entity
                                               'force-update
                                               nil
                                               nil ; not sticky
@@ -973,8 +945,8 @@ q   Goto folder mode.
             "%" "%%")
            (if (null (car finfo))
                " (? new/? unread)"
-             (format 
-              " (%d new/%d unread)" 
+             (format
+              " (%d new/%d unread)"
               (nth 0 finfo)
               (+ (nth 0 finfo)
                  (nth 1 finfo))))))
@@ -988,6 +960,10 @@ q  Goto folder mode.
   (setq wl-summary-buffer-mark-modified t))
 (defun wl-summary-mark-modified-p ()
   wl-summary-buffer-mark-modified)
+(defun wl-summary-set-thread-modified ()
+  (setq wl-summary-buffer-thread-modified t))
+(defun wl-summary-thread-modified-p ()
+  wl-summary-buffer-thread-modified)
 
 (defun wl-summary-msgdb-save ()
   "Save msgdb if modified."
@@ -996,37 +972,39 @@ q Goto folder mode.
       (let (path)
        (when (wl-summary-message-modified-p)
          (setq path (elmo-msgdb-expand-path wl-summary-buffer-folder-name))
-         (elmo-msgdb-overview-save 
-          path 
+         (elmo-msgdb-overview-save
+          path
           (elmo-msgdb-get-overview wl-summary-buffer-msgdb))
-         (elmo-msgdb-number-save 
-          path 
+         (elmo-msgdb-number-save
+          path
           (elmo-msgdb-get-number-alist wl-summary-buffer-msgdb))
          (elmo-folder-set-info-max-by-numdb
           (elmo-string wl-summary-buffer-folder-name)
           (elmo-msgdb-get-number-alist
            wl-summary-buffer-msgdb))
-         (setq wl-summary-buffer-message-modified nil))
+         (setq wl-summary-buffer-message-modified nil)
+         (run-hooks 'wl-summary-buffer-message-saved-hook))
        (when (wl-summary-mark-modified-p)
-         (or path 
+         (or path
              (setq path (elmo-msgdb-expand-path
                          wl-summary-buffer-folder-name)))
-         (elmo-msgdb-mark-save 
+         (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)
-         (setq wl-summary-buffer-mark-modified nil))))))
+;;;      (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))))))
 
 (defsubst wl-summary-cleanup-temp-marks (&optional sticky)
   (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
@@ -1050,20 +1028,21 @@ q       Goto folder mode.
   ;; already in summary buffer.
   (when wl-summary-buffer-persistent
     ;; save the current summary buffer view.
-    (if (and wl-summary-cache-use 
+    (if (and wl-summary-cache-use
             (or (wl-summary-message-modified-p)
-                (wl-summary-mark-modified-p)))
-       (wl-summary-save-view-cache sticky))
-    ;; save msgdb ... 
+                (wl-summary-mark-modified-p)
+                (wl-summary-thread-modified-p)))
+       (wl-summary-save-view-cache))
+    ;; save msgdb ...
     (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))
@@ -1071,66 +1050,114 @@ q      Goto folder mode.
        summary-win
        message-buf message-win
        folder-buf folder-win)
-    (wl-summary-cleanup-temp-marks sticky)
-    (unwind-protect
-       ;; save summary status
-       (progn
-         (wl-summary-save-status sticky)
-         ;(wl-summary-msgdb-save)
-         (if wl-use-scoring
-             (wl-score-save)))
-      ;; for sticky summary
-      (wl-delete-all-overlays)
-      (setq wl-summary-buffer-disp-msg nil)
-      ;; delete message window if displayed.
-      (if (setq message-buf (get-buffer wl-message-buf-name))
-         (if (setq message-win (get-buffer-window message-buf))
-             (delete-window message-win)))
-      (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))
-       ;; currently no folder buffer
-       (wl-folder))
-      (and wl-folder-move-cur-folder
-          wl-folder-buffer-cur-point
-          (goto-char wl-folder-buffer-cur-point))
-      (setq wl-folder-buffer-cur-path nil)
-      (setq wl-folder-buffer-cur-entity-id nil)
-      (wl-delete-all-overlays)
-      (if wl-summary-exit-next-move
-         (wl-folder-next-unsync t)
-       (beginning-of-line))
-      (if (setq summary-win (get-buffer-window summary-buf))
-         (delete-window summary-win))
-      (if (or force-exit 
-             (not sticky))
+    (if wl-summary-buffer-exit-func
+       (funcall wl-summary-buffer-exit-func)
+      (wl-summary-cleanup-temp-marks sticky)
+      (unwind-protect
+         ;; save summary status
          (progn
-           (set-buffer summary-buf)
-           (and (get-buffer wl-message-buf-name)
-                (kill-buffer wl-message-buf-name))
-           ;; kill buffers of mime-view-caesar
-           (wl-kill-buffers
-            (format "^%s-([0-9 ]+)$" (regexp-quote wl-message-buf-name)))
-           (kill-buffer summary-buf)))
-      (run-hooks 'wl-summary-exit-hook))))
+           (wl-summary-save-status sticky)
+           (elmo-commit wl-summary-buffer-folder-name)
+           (if wl-use-scoring
+               (wl-score-save)))
+       ;; for sticky summary
+       (wl-delete-all-overlays)
+       (setq wl-summary-buffer-disp-msg nil)
+       (elmo-kill-buffer wl-summary-search-buf-name)
+       ;; delete message window if displayed.
+       (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 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
+            wl-folder-buffer-cur-point
+            (goto-char wl-folder-buffer-cur-point))
+       (setq wl-folder-buffer-cur-path nil)
+       (setq wl-folder-buffer-cur-entity-id nil)
+       (wl-delete-all-overlays)
+       (if wl-summary-exit-next-move
+           (wl-folder-next-unsync t)
+         (beginning-of-line))
+       (if (setq summary-win (get-buffer-window summary-buf))
+           (delete-window summary-win))
+       (if (or force-exit
+               (not sticky))
+           (progn
+             (set-buffer summary-buf)
+             (and (get-buffer wl-message-buf-name)
+                  (kill-buffer wl-message-buf-name))
+             ;; kill buffers of mime-view-caesar
+             (wl-kill-buffers
+              (format "^%s-([0-9 ]+)$" (regexp-quote wl-message-buf-name)))
+             (kill-buffer summary-buf)))
+       (run-hooks 'wl-summary-exit-hook)))))
 
 (defun wl-summary-sync-force-update (&optional unset-cursor)
   (interactive)
   (let ((msgdb-dir (elmo-msgdb-expand-path wl-summary-buffer-folder-name))
+       (type (elmo-folder-get-type wl-summary-buffer-folder-name))
        ret-val seen-list)
     (unwind-protect
        (progn
-         (setq seen-list (elmo-msgdb-seen-load msgdb-dir))
+         (if wl-summary-buffer-persistent
+             (setq seen-list (elmo-msgdb-seen-load msgdb-dir)))
          (setq ret-val (wl-summary-sync-update3 seen-list unset-cursor))
-         (elmo-msgdb-seen-save msgdb-dir nil))
+         (if wl-summary-buffer-persistent
+             (progn
+               (if (and (eq type 'imap4)
+                        (not (elmo-folder-plugged-p
+                              wl-summary-buffer-folder-name)))
+                   (let* ((msgdb wl-summary-buffer-msgdb)
+                          (number-alist (elmo-msgdb-get-number-alist msgdb)))
+                     (elmo-mark-as-read wl-summary-buffer-folder-name
+                                        (mapcar
+                                         (lambda (msgid)
+                                           (car (rassoc msgid number-alist)))
+                                         seen-list) msgdb)))
+               (elmo-msgdb-seen-save msgdb-dir nil))))
       (set-buffer (current-buffer)))
     (if (interactive-p)
        (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)
@@ -1139,37 +1166,34 @@ 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
                   (elmo-msgdb-get-number-alist
                    wl-summary-buffer-msgdb)
-                  (elmo-msgdb-get-mark-alist 
+                  (elmo-msgdb-get-mark-alist
                    wl-summary-buffer-msgdb)
                   (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 '(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)
-          (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)
@@ -1186,7 +1210,7 @@ q Goto folder mode.
          ((string= range "no-sync")
           ;; do nothing.
           )
-         (t 
+         (t
           (setq seen-list (elmo-msgdb-seen-load msgdb-dir))
           (setq mes (wl-summary-sync-update3 seen-list unset-cursor))
           (elmo-msgdb-seen-save msgdb-dir nil) ; delete all seen.
@@ -1200,7 +1224,7 @@ q Goto folder mode.
   (let ((fields wl-summary-edit-addresses-candidate-fields)
        body candidates components)
     (while fields
-      (setq body 
+      (setq body
            (mapconcat 'identity (elmo-multiple-field-body (car fields))
                       ","))
       (setq body (wl-parse-addresses body))
@@ -1240,12 +1264,16 @@ q       Goto folder mode.
              (eq char ?\r)
              (eq char ? ))
          ;; Change Addresses
-         (wl-address-petname-add-or-change 
+         (wl-address-petname-add-or-change
           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
@@ -1259,7 +1287,7 @@ q Goto folder mode.
         (t (message "")
            nil)))
     ;; Add Petname
-    (wl-address-petname-add-or-change 
+    (wl-address-petname-add-or-change
      the-email name-in-addr name-in-addr)
     "added"))
 
@@ -1268,46 +1296,48 @@ q       Goto folder mode.
 Optional argument ADDR-STR is used as a target address if specified."
   (interactive (if current-prefix-arg
                   (list (read-from-minibuffer "Target address: "))))
-  (save-excursion
-    (wl-summary-set-message-buffer-or-redisplay))
-  (let* ((charset wl-summary-buffer-mime-charset)
-        (candidates
-         (with-current-buffer (wl-message-get-original-buffer)
-           (wl-summary-edit-addresses-collect-candidate-fields
-            charset)))
-        address pair result)
-    (if addr-str
-       (setq address addr-str)
-      (when candidates
-       (setq address (car (car candidates)))
-       (setq address
-             (completing-read 
-              (format "Target address (%s): " address)
-              (mapcar
-               (function (lambda (x) (cons (car x) (car x))))
-               candidates)
-              nil nil nil nil address))))
-    (when address
-      (setq pair (assoc address candidates))
-      (unless pair
-       (setq pair (cons address nil)))
-      (when (setq result (wl-summary-edit-addresses-subr (car pair) (cdr pair)))
-       ;; update alias
-       (wl-status-update)
-       (setq address (assoc (car pair) wl-address-list))
-       (if address
-           (message "%s, %s, <%s> is %s."
-                    (nth 2 address)
-                    (nth 1 address)
-                    (nth 0 address)
-                    result)))
-      ;; i'd like to update summary-buffer, but...
-      ;;(wl-summary-rescan)
-      (run-hooks 'wl-summary-edit-addresses-hook))))
+  (if (null (wl-summary-message-number))
+      (message "No message.")
+    (save-excursion
+      (wl-summary-set-message-buffer-or-redisplay))
+    (let* ((charset wl-summary-buffer-mime-charset)
+          (candidates
+           (with-current-buffer (wl-message-get-original-buffer)
+             (wl-summary-edit-addresses-collect-candidate-fields
+              charset)))
+          address pair result)
+      (if addr-str
+         (setq address addr-str)
+       (when candidates
+         (setq address (car (car candidates)))
+         (setq address
+               (completing-read
+                (format "Target address (%s): " address)
+                (mapcar
+                 (function (lambda (x) (cons (car x) (car x))))
+                 candidates)
+                nil nil nil nil address))))
+      (when address
+       (setq pair (assoc address candidates))
+       (unless pair
+         (setq pair (cons address nil)))
+       (when (setq result (wl-summary-edit-addresses-subr (car pair) (cdr pair)))
+         ;; update alias
+         (wl-status-update)
+         (setq address (assoc (car pair) wl-address-list))
+         (if address
+             (message "%s, %s, <%s> is %s."
+                      (nth 2 address)
+                      (nth 1 address)
+                      (nth 0 address)
+                      result)))
+;;; 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
@@ -1315,109 +1345,111 @@ If optional argument is non-nil, checking is omitted."
   (wl-summary-prefetch-region (point-min) (point-max)
                              wl-summary-incorporate-marks))
 
-(defun wl-summary-prefetch-msg (number)
+(defun wl-summary-prefetch-msg (number &optional arg)
   "Returns status-mark. if skipped, returns nil."
   ;; prefetching procedure.
   (save-excursion
     (let* ((msgdb wl-summary-buffer-msgdb)
-          (mark-alist (elmo-msgdb-get-mark-alist msgdb))         
+          (mark-alist (elmo-msgdb-get-mark-alist msgdb))
           (number-alist (elmo-msgdb-get-number-alist msgdb))
           (message-id (cdr (assq number number-alist)))
-          (ov (assoc message-id 
+          (ov (assoc message-id
                      (elmo-msgdb-get-overview msgdb)))
           (entity ov)
           (size (elmo-msgdb-overview-entity-get-size ov))
           (inhibit-read-only t)
-          (buffer-read-only nil)          
+          (buffer-read-only nil)
           (force-read (and size
                            (or (null wl-prefetch-threshold)
                                (< size wl-prefetch-threshold))))
           mark new-mark)
-      (unwind-protect
-         (progn
-           (when (and size (not force-read) wl-prefetch-confirm)
-             (setq force-read
-                   (save-restriction
-                     (widen)
-                     (y-or-n-p
-                      (format
-                       "Message from %s has %d bytes. Prefetch it?" 
-                       (concat 
-                        "[ "
-                        (save-match-data 
-                          (wl-set-string-width 
-                           wl-from-width
-                           (wl-summary-from-func-internal
-                            (eword-decode-string
-                             (elmo-delete-char 
-                              ?\"
-                              (or 
-                               (elmo-msgdb-overview-entity-get-from ov)
-                               "??")))))) " ]")
-                       size))))
-             (message "")); flush.
-           (setq mark (cadr (assq number mark-alist)))
-            (if force-read
-             (save-excursion
-               (save-match-data
-                 (if (and (null (elmo-folder-plugged-p
-                                 wl-summary-buffer-folder-name))
-                          elmo-enable-disconnected-operation)
-                     (progn ;; append-queue for offline
-                       (elmo-dop-prefetch-msgs
-                        wl-summary-buffer-folder-name (list number))
-                       (setq new-mark
-                             (cond
-                              ((string= mark
-                                        wl-summary-unread-uncached-mark)
-                               wl-summary-unread-cached-mark)
-                              ((string= mark wl-summary-new-mark)
-                               (setq wl-summary-buffer-new-count
-                                     (- wl-summary-buffer-new-count 1))
-                               (setq wl-summary-buffer-unread-count
-                                     (+ wl-summary-buffer-unread-count 1))
-                               wl-summary-unread-cached-mark)
-                              ((or (null mark)
-                                   (string= mark wl-summary-read-uncached-mark))
-                               (setq wl-summary-buffer-unread-count
-                                     (+ wl-summary-buffer-unread-count 1))
-                               wl-summary-unread-cached-mark)
-                              (t mark))))
-                   ;; online
-                   (elmo-prefetch-msg wl-summary-buffer-folder-name
-                                      number
-                                      (wl-message-get-original-buffer)
-                                      msgdb)
-                   (setq new-mark
-                         (cond
-                          ((string= mark 
-                                    wl-summary-unread-uncached-mark)
-                           wl-summary-unread-cached-mark)
-                          ((string= mark wl-summary-new-mark)
-                           (setq wl-summary-buffer-new-count 
-                                 (- wl-summary-buffer-new-count 1))
-                           (setq wl-summary-buffer-unread-count
-                                 (+ wl-summary-buffer-unread-count 1))
-                           wl-summary-unread-cached-mark)
-                          ((string= mark wl-summary-read-uncached-mark)
-                           nil)
-                          (t mark))))
-                 (setq mark-alist (elmo-msgdb-mark-set
-                                   mark-alist number new-mark))
-                 (or new-mark (setq new-mark " "))
-                 (elmo-msgdb-set-mark-alist msgdb mark-alist)
-                 (wl-summary-set-mark-modified)
-                 (wl-summary-update-modeline)
-                 (wl-folder-update-unread
-                  wl-summary-buffer-folder-name
-                  (+ wl-summary-buffer-unread-count
-                     wl-summary-buffer-new-count)))
-               new-mark)))))))
+      (if (or arg
+             (null (elmo-cache-exists-p message-id)))
+         (unwind-protect
+             (progn
+               (when (and size (not force-read) wl-prefetch-confirm)
+                 (setq force-read
+                       (save-restriction
+                         (widen)
+                         (y-or-n-p
+                          (format
+                           "Message from %s has %d bytes.  Prefetch it? "
+                           (concat
+                            "[ "
+                            (save-match-data
+                              (wl-set-string-width
+                               wl-from-width
+                               (wl-summary-from-func-internal
+                                (eword-decode-string
+                                 (elmo-delete-char
+                                  ?\"
+                                  (or
+                                   (elmo-msgdb-overview-entity-get-from ov)
+                                   "??")))))) " ]")
+                           size))))
+                 (message ""))         ; flush.
+               (setq mark (cadr (assq number mark-alist)))
+               (if force-read
+                   (save-excursion
+                     (save-match-data
+                       (if (and (null (elmo-folder-plugged-p
+                                       wl-summary-buffer-folder-name))
+                                elmo-enable-disconnected-operation)
+                           (progn;; append-queue for offline
+                             (elmo-dop-prefetch-msgs
+                              wl-summary-buffer-folder-name (list number))
+                             (setq new-mark
+                                   (cond
+                                    ((string= mark
+                                              wl-summary-unread-uncached-mark)
+                                     wl-summary-unread-cached-mark)
+                                    ((string= mark wl-summary-new-mark)
+                                     (setq wl-summary-buffer-new-count
+                                           (- wl-summary-buffer-new-count 1))
+                                     (setq wl-summary-buffer-unread-count
+                                           (+ wl-summary-buffer-unread-count 1))
+                                     wl-summary-unread-cached-mark)
+                                    ((or (null mark)
+                                         (string= mark wl-summary-read-uncached-mark))
+                                     (setq wl-summary-buffer-unread-count
+                                           (+ wl-summary-buffer-unread-count 1))
+                                     wl-summary-unread-cached-mark)
+                                    (t mark))))
+                         ;; online
+                         (elmo-prefetch-msg wl-summary-buffer-folder-name
+                                            number
+                                            (wl-message-get-original-buffer)
+                                            msgdb)
+                         (setq new-mark
+                               (cond
+                                ((string= mark
+                                          wl-summary-unread-uncached-mark)
+                                 wl-summary-unread-cached-mark)
+                                ((string= mark wl-summary-new-mark)
+                                 (setq wl-summary-buffer-new-count
+                                       (- wl-summary-buffer-new-count 1))
+                                 (setq wl-summary-buffer-unread-count
+                                       (+ wl-summary-buffer-unread-count 1))
+                                 wl-summary-unread-cached-mark)
+                                ((string= mark wl-summary-read-uncached-mark)
+                                 nil)
+                                (t mark))))
+                       (setq mark-alist (elmo-msgdb-mark-set
+                                         mark-alist number new-mark))
+                       (or new-mark (setq new-mark " "))
+                       (elmo-msgdb-set-mark-alist msgdb mark-alist)
+                       (wl-summary-set-mark-modified)
+                       (wl-summary-update-modeline)
+                       (wl-folder-update-unread
+                        wl-summary-buffer-folder-name
+                        (+ wl-summary-buffer-unread-count
+                           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")
@@ -1483,9 +1515,9 @@ If optional argument is non-nil, checking is omitted."
        (message "Prefetched %d/%d message(s)" count length)
        (cons count length)))))
 
-(defun wl-summary-prefetch ()
+(defun wl-summary-prefetch (&optional arg)
   "Prefetch current message."
-  (interactive)
+  (interactive "P")
   (save-excursion
     (save-match-data
       (beginning-of-line)
@@ -1495,7 +1527,7 @@ If optional argument is non-nil, checking is omitted."
              (buffer-read-only nil)
              mark)
          (setq mark (wl-summary-prefetch-msg
-                     (string-to-int (wl-match-buffer 1))))
+                     (string-to-int (wl-match-buffer 1)) arg))
          (when mark
            (delete-region (match-beginning 2)
                           (match-end 2))
@@ -1512,32 +1544,33 @@ If optional argument is non-nil, checking is omitted."
     (let ((inhibit-read-only t)
          (buffer-read-only nil)
          (case-fold-search nil))
-      (while (re-search-forward 
+      (while (re-search-forward
              (concat "^" wl-summary-buffer-number-regexp ".\\(.\\)") nil t)
        (delete-region (match-beginning 1) (match-end 1))
        (insert " ")))))
 
-(defun wl-summary-delete-copy-marks-on-buffer (cpys)
-  (mapcar (function
-          (lambda (x)
-            (wl-summary-unmark x)))
-         cpys))
+(defun wl-summary-delete-marks-on-buffer (marks)
+  (while marks
+    (wl-summary-unmark (pop marks))))
+
+(defun wl-summary-delete-copy-marks-on-buffer (copies)
+  (wl-summary-delete-marks-on-buffer copies))
 
 (defun wl-summary-delete-all-refile-marks ()
-  (mapcar (function
-          (lambda (x)
-            (wl-summary-unmark (car x)))) wl-summary-buffer-refile-list))
+  (let ((marks wl-summary-buffer-refile-list))
+    (while marks
+      (wl-summary-unmark (car (pop marks))))))
 
 (defun wl-summary-delete-all-copy-marks ()
-  (mapcar (function
-          (lambda (x)
-            (wl-summary-unmark (car x)))) wl-summary-buffer-copy-list))
+  (let ((marks wl-summary-buffer-copy-list))
+    (while marks
+      (wl-summary-unmark (car (pop marks))))))
+
 (defun wl-summary-delete-all-delete-marks ()
-  (mapcar 'wl-summary-unmark wl-summary-buffer-delete-list))
+  (wl-summary-delete-marks-on-buffer wl-summary-buffer-delete-list))
 
 (defun wl-summary-delete-all-target-marks ()
-  (mapcar 'wl-summary-unmark wl-summary-buffer-target-mark-list))
+  (wl-summary-delete-marks-on-buffer wl-summary-buffer-target-mark-list))
 
 (defun wl-summary-delete-all-temp-marks-on-buffer (&optional sticky)
   ;; for summary view cache saving.
@@ -1555,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)
@@ -1572,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
@@ -1588,8 +1623,8 @@ If optional argument is non-nil, checking is omitted."
                  ;; closed
                  (wl-summary-mark-as-read t) ; mark itself.
                  (setq children (wl-thread-get-children-msgs number))
-                 (while children 
-                   (wl-thread-msg-mark-as-read (car children))
+                 (while children
+                   (wl-summary-mark-as-read t nil nil (car children))
                    (setq children (cdr children))))
                (forward-line 1))))
        (while (not (eobp))
@@ -1602,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
@@ -1617,10 +1654,10 @@ If optional argument is non-nil, checking is omitted."
                    (wl-summary-mark-as-unread)
                  ;; closed
                  (wl-summary-mark-as-unread) ; mark itself.
-                 (setq children 
+                 (setq children
                        (delq number (wl-thread-get-children-msgs number)))
-                 (while children 
-                   (wl-thread-msg-mark-as-unread (car children))
+                 (while children
+                   (wl-summary-mark-as-unread (car children))
                    (setq children (cdr children))))
                (forward-line 1))))
        (while (not (eobp))
@@ -1648,9 +1685,9 @@ If optional argument is non-nil, checking is omitted."
                    (wl-summary-mark-as-important)
                  ;; closed
                  (wl-summary-mark-as-important) ; mark itself.
-                 (setq children 
+                 (setq children
                        (delq number (wl-thread-get-children-msgs number)))
-                 (while children 
+                 (while children
                    (wl-thread-msg-mark-as-important (car children))
                    (setq children (cdr children))))
                (forward-line 1))))
@@ -1663,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)
@@ -1675,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))
@@ -1690,16 +1734,18 @@ If optional argument is non-nil, checking is omitted."
                  (progn
                    (insert " ")
                    (setq mark-alist
-                         (elmo-msgdb-mark-set 
+                         (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)))))
@@ -1709,9 +1755,9 @@ If optional argument is non-nil, checking is omitted."
        (elmo-msgdb-set-mark-alist msgdb mark-alist)
        (wl-folder-update-unread wl-summary-buffer-folder-name 0)
        (setq wl-summary-buffer-unread-count 0)
-       (setq wl-summary-buffer-new-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 ()
@@ -1726,12 +1772,12 @@ 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
          (setq mark (wl-match-buffer 2))
-         (cond 
+         (cond
           ((or (string= mark wl-summary-new-mark)
                (string= mark wl-summary-unread-uncached-mark)
                (string= mark wl-summary-important-mark))
@@ -1739,7 +1785,7 @@ If optional argument is non-nil, checking is omitted."
            )
           ((string= mark wl-summary-unread-cached-mark)
            (setq new-mark wl-summary-unread-uncached-mark))
-          (t 
+          (t
            (setq new-mark wl-summary-read-uncached-mark)))
          (when new-mark
            (setq number (string-to-int (wl-match-buffer 1)))
@@ -1756,7 +1802,7 @@ If optional argument is non-nil, checking is omitted."
            (if wl-summary-highlight
                (wl-highlight-summary-current-line nil nil t))
            (set-buffer-modified-p nil)))))))
-  
+
 (defun wl-summary-resume-cache-status ()
   "Resume the cache status of all messages in the current folder."
   (interactive)
@@ -1786,17 +1832,17 @@ If optional argument is non-nil, checking is omitted."
                (setq set-mark wl-summary-unread-cached-mark)
              (if (string= mark wl-summary-read-uncached-mark)  ; u -> ' '
                  (setq set-mark " ")))
-         (if (string= mark " ")                            
+         (if (string= mark " ")
              (setq set-mark wl-summary-read-uncached-mark)     ;' ' -> u
-           (if (string= mark wl-summary-unread-cached-mark) 
+           (if (string= mark wl-summary-unread-cached-mark)
                (setq set-mark wl-summary-unread-uncached-mark) ; !  -> U
              )))
        (when set-mark
          (delete-region (match-beginning 2) (match-end 2))
          (insert set-mark)
          (setq mark-alist
-               (elmo-msgdb-mark-set 
-                mark-alist msg ; msgid 
+               (elmo-msgdb-mark-set
+                mark-alist msg ; msgid
                 (if (string= set-mark " ") nil set-mark)))
          (if wl-summary-highlight
              (wl-highlight-summary-current-line))))
@@ -1805,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)
@@ -1827,13 +1873,14 @@ If optional argument is non-nil, checking is omitted."
              (delete-region (match-beginning 1) (match-end 1))
              (insert (or smark " "))))
        (wl-highlight-summary-current-line smark)
-       (setq i (+ i 1))
-       (setq percent (/ (* i 100) count))
-       (elmo-display-progress
-        'wl-summary-resume-marks-and-highlight "Resuming all marks..."
-        percent)
+       (when (> count elmo-display-progress-threshold)
+         (setq i (+ i 1))
+         (setq percent (/ (* i 100) count))
+         (elmo-display-progress
+          '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)
@@ -1847,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))
@@ -1859,13 +1907,14 @@ If optional argument is non-nil, checking is omitted."
                      (delete-region (match-beginning 1) (match-end 1))
                      (insert (or (cadr entity)
                                  " ")))))))
-       (setq i (+ i 1))
-       (setq percent (/ (* i 100) count))
-       (elmo-display-progress
-        'wl-summary-resume-marks "Resuming all marks..."
-        percent)
+       (when (> count elmo-display-progress-threshold)
+         (setq i (+ i 1))
+         (setq percent (/ (* i 100) count))
+         (elmo-display-progress
+          '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)
@@ -1876,44 +1925,46 @@ If optional argument is non-nil, checking is omitted."
          (len (length msgs))
          (i 0)
          update-list)
+      (elmo-kill-buffer wl-summary-search-buf-name)
       (while msgs
        (if (eq wl-summary-buffer-view 'thread)
            (progn
+             ;; don't use wl-append(nconc), because list is broken. ...why?
              (setq update-list
-                   (wl-append update-list
-                              (wl-thread-delete-message (car msgs))))
-             (setq update-list (and update-list
-                                    (delete (car msgs) update-list))))
+                   (append update-list
+                           (wl-thread-delete-message (car msgs))))
+             (setq update-list (delq (car msgs) update-list)))
          (goto-char (point-min))
-         (if (re-search-forward (format "^ *%d[^0-9]\\([^0-9]\\).*$" 
+         (if (re-search-forward (format "^ *%d[^0-9]\\([^0-9]\\).*$"
                                         (car msgs)) nil t)
              (progn
                (delete-region (match-beginning 0) (match-end 0))
                (delete-char 1) ; delete '\n'
-               )))
-       (when deleting-info
+               (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))
-         (and (zerop (% i 10))
-              (elmo-display-progress
-               'wl-summary-delete-messages-on-buffer "Deleting..."
-               (/ (* i 100) len))))
+         (if (or (zerop (% i 5)) (= i len))
+             (elmo-display-progress
+              'wl-summary-delete-messages-on-buffer deleting-info
+              (/ (* i 100) len))))
        (setq msgs (cdr msgs)))
-      (elmo-display-progress
-       'wl-summary-delete-messages-on-buffer "Deleting..." 100)
-      (if (eq wl-summary-buffer-view 'thread)
-         (wl-thread-update-line-msgs (elmo-uniq-list update-list)))
-      (wl-thread-cleanup-symbols msgs2)
-      (wl-summary-count-unread 
+      (when (eq wl-summary-buffer-view 'thread)
+       (wl-thread-update-line-msgs (elmo-uniq-list update-list)
+                                   (unless deleting-info 'no-msg))
+       (wl-thread-cleanup-symbols msgs2))
+      (wl-summary-count-unread
        (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
-      (wl-summary-update-modeline)         
+      (wl-summary-update-modeline)
       (wl-folder-update-unread
        wl-summary-buffer-folder-name
        (+ wl-summary-buffer-unread-count wl-summary-buffer-new-count)))))
 
 (defun wl-summary-set-as-read-mark-alist (mark-alist)
-  (let ((marks (list (cons wl-summary-unread-cached-mark 
+  (let ((marks (list (cons wl-summary-unread-cached-mark
                           nil)
-                    (cons wl-summary-unread-uncached-mark 
+                    (cons wl-summary-unread-uncached-mark
                           wl-summary-read-uncached-mark)
                     (cons wl-summary-new-mark
                           wl-summary-read-uncached-mark)))
@@ -1932,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
@@ -1945,14 +1996,14 @@ 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))
     (let ((inhibit-read-only t)
          (buffer-read-only nil)
          (regexp (concat "^" wl-summary-buffer-number-regexp ".\\(\\%s\\)")))
-      (while (re-search-forward 
+      (while (re-search-forward
              (format regexp (regexp-quote before)) nil t)
        (delete-region (match-beginning 1) (match-end 1))
        (insert after)
@@ -1971,11 +2022,11 @@ If optional argument is non-nil, checking is omitted."
            (t;; (equal type 'trash)
             wl-trash-folder)))))
 
-(defun wl-summary-delete-important-msgs-from-list (delete-list 
+(defun wl-summary-delete-important-msgs-from-list (delete-list
                                                   mark-alist)
   (let ((dlist delete-list))
     (while dlist
-      (if (string= wl-summary-important-mark 
+      (if (string= wl-summary-important-mark
                   (car (cdr (assq (car dlist) mark-alist))))
          (setq delete-list (delete (car dlist) delete-list)))
       (setq dlist (cdr dlist)))
@@ -1988,11 +2039,11 @@ If optional argument is non-nil, checking is omitted."
          (setq delete-list (delete (car dlist) delete-list)))
       (setq dlist (cdr dlist)))
     delete-list))
-  
+
 (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 ()
@@ -2001,9 +2052,9 @@ If optional argument is non-nil, checking is omitted."
                       (default "date")
                       in)
                   (setq in
-                        (completing-read 
+                        (completing-read
                          (format "Sort by (%s): " default)
-                         (mapcar 
+                         (mapcar
                           (function (lambda (x) (cons x x)))
                           input-range-list)))
                   (if (string= in "")
@@ -2018,11 +2069,12 @@ If optional argument is non-nil, checking is omitted."
   (interactive)
   (let ((plugged (elmo-folder-plugged-p wl-summary-buffer-folder-name))
        (last-progress 0)
-       mark-alist unread-marks msgs mark importants unreads 
+       (i 0)
+       mark-alist unread-marks msgs mark importants unreads
        importants-in-db unreads-in-db has-imap4 diff diffs
-       mes num-ma ma-length progress)
+       mes num-ma progress)
     ;; synchronize marks.
-    (when (not (eq (elmo-folder-get-type 
+    (when (not (eq (elmo-folder-get-type
                    wl-summary-buffer-folder-name)
                   'internal))
       (message "Updating marks...")
@@ -2031,23 +2083,15 @@ If optional argument is non-nil, checking is omitted."
                               wl-summary-new-mark)
            mark-alist (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb)
             num-ma (length mark-alist)
-           ma-length num-ma
-           importants (elmo-list-folder-important 
+           importants (elmo-list-folder-important
                        wl-summary-buffer-folder-name
-                       (elmo-msgdb-get-overview wl-summary-buffer-msgdb))
-           has-imap4 (elmo-folder-contains-type 
-                      wl-summary-buffer-folder-name 'imap4)
-           unreads (if (and has-imap4 plugged)
-                       (elmo-list-folder-unread 
-                        wl-summary-buffer-folder-name
-                        mark-alist unread-marks)))
+                       (elmo-msgdb-get-number-alist wl-summary-buffer-msgdb))
+           unreads (elmo-list-folder-unread
+                    wl-summary-buffer-folder-name
+                    (elmo-msgdb-get-number-alist wl-summary-buffer-msgdb)
+                    (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb)
+                    unread-marks))
       (while mark-alist
-       (setq progress (/ (* (- num-ma ma-length) 100) num-ma))
-       (if (not (eq progress last-progress))
-           (elmo-display-progress 'wl-summary-sync-marks
-                                  "Updating marks..."
-                                  progress))
-       (setq last-progress progress)
        (if (string= (cadr (car mark-alist))
                     wl-summary-important-mark)
            (setq importants-in-db (cons (car (car mark-alist))
@@ -2055,11 +2099,15 @@ If optional argument is non-nil, checking is omitted."
          (if (member (cadr (car mark-alist)) unread-marks)
              (setq unreads-in-db (cons (car (car mark-alist))
                                        unreads-in-db))))
-       (setq mark-alist (cdr mark-alist)
-             ma-length (1- ma-length)))
-      (elmo-display-progress 'wl-summary-sync-marks
-                            "Updating marks..."
-                            100)
+       (setq mark-alist (cdr mark-alist))
+       (when (> num-ma elmo-display-progress-threshold)
+         (setq i (1+ i)
+               progress (/ (* i 100) num-ma))
+         (if (not (eq progress last-progress))
+             (elmo-display-progress 'wl-summary-sync-marks
+                                    "Updating marks..."
+                                    progress))
+         (setq last-progress progress)))
       (setq diff (elmo-list-diff importants importants-in-db))
       (setq diffs (cadr diff)) ; important-deletes
       (setq mes (format "Updated (-%d" (length diffs)))
@@ -2073,130 +2121,134 @@ If optional argument is non-nil, checking is omitted."
       (while diffs
        (wl-summary-mark-as-important (car diffs) " " 'no-server)
        (setq diffs (cdr diffs)))
-      (when (and has-imap4 plugged)
-       (setq diff (elmo-list-diff unreads unreads-in-db))
-       (setq diffs (cadr diff))
-       (setq mes (concat mes (format "(-%d" (length diffs))))
-       (while diffs
-         (wl-summary-mark-as-read t 'no-server nil (car diffs) 'no-cache)
-         (setq diffs (cdr diffs)))
-       (setq diffs (car diff)) ; unread-appends
-       (setq mes (concat mes (format "/+%d) unread mark(s)." (length diffs))))
-       (while diffs
-         (wl-summary-mark-as-unread (car diffs) 'no-server 'no-modeline)
-         (setq diffs (cdr diffs))))
+      (setq diff (elmo-list-diff unreads unreads-in-db))
+      (setq diffs (cadr diff))
+      (setq mes (concat mes (format "(-%d" (length diffs))))
+      (while diffs
+       (wl-summary-mark-as-read t 'no-server nil (car diffs))
+       (setq diffs (cdr diffs)))
+      (setq diffs (car diff)) ; unread-appends
+      (setq mes (concat mes (format "/+%d) unread mark(s)." (length diffs))))
+      (while diffs
+       (wl-summary-mark-as-unread (car diffs) 'no-server 'no-modeline)
+       (setq diffs (cdr diffs)))
       (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 (y-or-n-p (format "%d messages are disappeared. OK?" 
-                                       (- len in)))
-                     (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)
         (buffer-read-only nil)
-        diff append-list delete-list
-        i percent num result
+        diff initial-append-list append-list delete-list has-nntp
+        i num result
         gc-message
         in-folder
         in-db curp
         overview-append
-        entity ret-val crossed crossed2 sync-all
-        top-num update-top-list mark
+        entity ret-val crossed crossed2
+        update-thread update-top-list mark
         expunged msgs unreads importants)
-    ;(setq seen-list nil) ;for debug.
-    (fset 'wl-summary-append-message-func-internal 
+;;; (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).
     (setq seen-list
          (wl-summary-flush-pending-append-operations seen-list))
     (goto-char (point-max))
+    (wl-folder-confirm-existence folder 'force)
     (message "Checking folder diff...")
-    (setq in-folder (elmo-list-folder folder))
-    (setq in-db (sort (mapcar 'car number-alist) '<))
-    (when (or (eq msgdb nil) ; trick for unplugged...
-             (equal msgdb '(nil nil nil nil)))
-      (setq sync-all t)
-      (wl-summary-set-message-modified)
-      (wl-summary-set-mark-modified)
-      (erase-buffer))
-    (setq diff (if (eq (elmo-folder-get-type folder) 'multi)
-                  (elmo-multi-list-bigger-diff in-folder in-db)
-                (elmo-list-bigger-diff in-folder in-db)))
-    (setq append-list (car diff))
+    (elmo-commit folder)
+    (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)
+                    (elmo-list-bigger-diff in-folder in-db)))
+      (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
-           (wl-summary-delete-important-msgs-from-list delete-list 
+           (wl-summary-delete-important-msgs-from-list delete-list
                                                        mark-alist)))
-    (if (and (elmo-folder-contains-type folder 'nntp)
+    (if (and has-nntp
             (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)
-                (eq (length append-list) 0)))
+                (eq (length initial-append-list) 0)))
        (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)
-       (wl-summary-delete-messages-on-buffer delete-list t)
-       (message "Deleting...done."))
-      ;;(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)
       ;; Change "New" marks to "Uncached Unread" marks.
-      (wl-summary-set-status-marks mark-alist 
-                                  wl-summary-new-mark 
+      (wl-summary-set-status-marks mark-alist
+                                  wl-summary-new-mark
                                   wl-summary-unread-uncached-mark)
-      (wl-summary-set-status-marks-on-buffer 
-       wl-summary-new-mark 
+      (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 append-list))
       (setq num (length append-list))
       (if append-list
          (progn
            (setq i 0)
-           (setq result (elmo-msgdb-create 
-                         folder 
+           (setq result (elmo-msgdb-create
+                         folder
                          append-list
                          wl-summary-new-mark
                          wl-summary-unread-cached-mark ; !
@@ -2206,58 +2258,75 @@ 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))
+           (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)
+           (elmo-kill-buffer wl-summary-search-buf-name)
            (while curp
              (setq entity (car curp))
-             (setq top-num
-                   (wl-summary-append-message-func-internal 
-                    entity overview mark-alist 
-                    (not sync-all)))
-             (when top-num
-               (wl-append update-top-list (list top-num)))
+             (when (setq update-thread
+                         (wl-summary-append-message-func-internal
+                          entity overview mark-alist
+                          (not sync-all)))
+               (wl-append update-top-list update-thread))
              (if elmo-use-database
-                 (elmo-database-msgid-put 
+                 (elmo-database-msgid-put
                   (car entity) folder
                   (elmo-msgdb-overview-entity-get-number entity)))
              (setq curp (cdr curp))
-             (setq i (+ i 1))
-             (setq percent (/ (* i 100) num))
-             (elmo-display-progress
-              'wl-summary-sync-update3 "Updating thread..."
-              percent))
-           (setq update-top-list
-                 (elmo-uniq-list update-top-list))
+             (when (> num elmo-display-progress-threshold)
+               (setq i (+ i 1))
+               (if (or (zerop (% i 5)) (= i num))
+                   (elmo-display-progress
+                    'wl-summary-sync-update3 "Updating thread..."
+                    (/ (* i 100) num)))))
+           (when wl-summary-delayed-update
+             (while wl-summary-delayed-update
+               (message "Parent (%d) of message %d is no entity"
+                        (caar wl-summary-delayed-update)
+                        (elmo-msgdb-overview-entity-get-number
+                         (cdar wl-summary-delayed-update)))
+               (when (setq update-thread
+                           (wl-summary-append-message-func-internal
+                            (cdar wl-summary-delayed-update)
+                            overview mark-alist (not sync-all) t))
+                 (wl-append update-top-list update-thread))
+               (setq wl-summary-delayed-update
+                     (cdr wl-summary-delayed-update))))
            (when (and (eq wl-summary-buffer-view 'thread)
-                      update-top-list )
-             (message "Updating indent...")
-             (wl-thread-update-indent-string-thread update-top-list)
-             (message "Updating indent...done."))
-           (message "Updating thread...done.")
-           ;;(set-buffer cur-buf)
+                      update-top-list)
+             (wl-thread-update-indent-string-thread
+              (elmo-uniq-list update-top-list)))
+           (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)
-      (setq ret-val (format "Updated (-%d/+%d) message(s)" 
+      (setq ret-val (format "Updated (-%d/+%d) message(s)"
                            (length delete-list) num)))
     ;; synchronize marks.
     (if wl-summary-auto-sync-marks
@@ -2265,15 +2334,15 @@ 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)
-      (setq expunged (wl-summary-score-update-all-lines))
-      (if expunged
-         (setq ret-val (concat ret-val 
-                               (format " (%d expunged)" 
-                                       (length expunged))))))
+      (when (and wl-summary-scored
+                (setq expunged (wl-summary-score-update-all-lines)))
+       (setq ret-val (concat ret-val
+                             (format " (%d expunged)"
+                                     (length expunged))))))
     ;; crosspost
     (setq crossed2 (wl-summary-update-crosspost))
     (if (or crossed crossed2)
@@ -2287,12 +2356,13 @@ If optional argument is non-nil, checking is omitted."
       (and ret-val
           (setq ret-val (concat ret-val "."))))
     ;; Update Folder mode
-    (wl-folder-set-folder-updated folder (list 0 
-                                              (wl-summary-count-unread 
+    (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)
     ;;
     (unless unset-cursor
       (goto-char (point-min))
@@ -2303,7 +2373,7 @@ If optional argument is non-nil, checking is omitted."
        (if (and wl-summary-highlight
                 (not (get-text-property (point) 'face)))
            (save-excursion
-             (forward-line (- 0 
+             (forward-line (- 0
                               (or
                                wl-summary-partial-highlight-above-lines
                                wl-summary-highlight-partial-threshold)))
@@ -2341,7 +2411,7 @@ If optional argument is non-nil, checking is omitted."
               "+")))))
 
 (defun wl-summary-update-modeline ()
-  (setq wl-summary-buffer-unread-status 
+  (setq wl-summary-buffer-unread-status
        (format " {%s}(%d new/%d unread)"
                (if (eq wl-summary-buffer-view 'thread)
                    "T" "S")
@@ -2351,8 +2421,8 @@ If optional argument is non-nil, checking is omitted."
 
 (defsubst wl-summary-jump-to-msg (&optional number)
   (interactive)
-  (let ((num (or number 
-                (string-to-int 
+  (let ((num (or number
+                (string-to-int
                  (read-from-minibuffer "Jump to Message(No.): ")))))
     (setq num (int-to-string num))
     (if (re-search-forward (concat "^[ \t]*" num "[^0-9]") nil t)
@@ -2372,14 +2442,16 @@ If optional argument is non-nil, checking is omitted."
       (message "Hilighting...")
       (setq i 0)
       (while msgs
-       (setq i (+ i 1))
-       (elmo-display-progress
-        'wl-summary-highlight-msgs "Highlighting..."
-        (/ (* i 100) len))
        (if (wl-summary-jump-to-msg (car msgs))
            (wl-highlight-summary-current-line))
-       (setq msgs (cdr msgs)))
-      (message "Highlighting...done."))))
+       (setq msgs (cdr msgs))
+       (when (> len elmo-display-progress-threshold)
+         (setq i (+ i 1))
+         (if (or (zerop (% i 5)) (= i len))
+             (elmo-display-progress
+              'wl-summary-highlight-msgs "Highlighting..."
+              (/ (* i 100) len)))))
+      (message "Highlighting...done"))))
 
 (defun wl-summary-message-number ()
   (save-excursion
@@ -2390,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)))))
@@ -2401,9 +2473,9 @@ If optional argument is non-nil, checking is omitted."
   "Execute append operations that are done while offline status."
   (when (and (elmo-folder-plugged-p wl-summary-buffer-folder-name)
             elmo-enable-disconnected-operation)
-    (let* ((resumed-list (elmo-dop-append-list-load 
+    (let* ((resumed-list (elmo-dop-append-list-load
                          wl-summary-buffer-folder-name t))
-          (append-list (elmo-dop-append-list-load 
+          (append-list (elmo-dop-append-list-load
                         wl-summary-buffer-folder-name))
           (appends (append resumed-list append-list))
           (number-alist (elmo-msgdb-get-number-alist wl-summary-buffer-msgdb))
@@ -2425,11 +2497,11 @@ 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
-         (elmo-dop-flush-pending-append-operations 
+         (elmo-dop-flush-pending-append-operations
           wl-summary-buffer-folder-name append-list)))))
   seen-list)
 
@@ -2440,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
@@ -2449,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)
@@ -2463,16 +2535,17 @@ 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): " 
+           (y-or-n-p (format "Toggle threading? (y=%s): "
                              (if (eq wl-summary-buffer-view 'thread)
                                  "\"off\"" "\"on\""))))
     (if (eq wl-summary-buffer-view 'thread)
@@ -2487,7 +2560,7 @@ If optional argument is non-nil, checking is omitted."
   (save-excursion
     (let ((tmp-buffer (get-buffer-create " *wl-summary-load-file-object*"))
          insert-file-contents-pre-hook   ; To avoid autoconv-xmas...
-         insert-file-contents-post-hook 
+         insert-file-contents-post-hook
          ret-val)
       (if (not (file-readable-p filename))
          ()
@@ -2495,8 +2568,8 @@ If optional argument is non-nil, checking is omitted."
        (as-binary-input-file (insert-file-contents filename))
        (setq ret-val
              (condition-case nil
-                 (read (current-buffer)) 
-               (error (error "reading failed")))))
+                 (read (current-buffer))
+               (error (error "Reading failed")))))
       (kill-buffer tmp-buffer)
       ret-val)))
 
@@ -2519,22 +2592,23 @@ If optional argument is non-nil, checking is omitted."
       (get-buffer (wl-summary-sticky-buffer-name fld))
     (not (string= wl-summary-buffer-name (buffer-name)))))
 
-(defmacro wl-summary-always-sticky-folder-p (fld)
-  (` (wl-string-match-member (, fld) wl-summary-always-sticky-folder-list)))
+(defun wl-summary-always-sticky-folder-p (fld)
+  (or (eq t wl-summary-always-sticky-folder-list)
+      (wl-string-match-member fld wl-summary-always-sticky-folder-list)))
 
 (defun wl-summary-stick (&optional force)
   "Make current summary buffer sticky."
   (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-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)
@@ -2552,7 +2626,9 @@ If optional argument is non-nil, checking is omitted."
                   wl-summary-buffer-number-column
                   wl-summary-buffer-number-regexp
                   wl-summary-buffer-message-modified
-                  wl-summary-buffer-mark-modified)
+                  wl-summary-buffer-mark-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
@@ -2568,26 +2644,20 @@ If optional argument is non-nil, checking is omitted."
                      '(wl-current-score-file
                        wl-score-alist)))))
     (set-buffer buf)
-    (wl-summary-buffer-set-folder folder)
     (wl-summary-mode)
+    (wl-summary-buffer-set-folder folder)
     (let ((buffer-read-only nil))
       (insert-buffer cur-buf))
     (set-buffer-modified-p nil)
-    (mapcar
-     (function
-      (lambda (var)
-       (set var (save-excursion
-                  (set-buffer cur-buf)
-                  (symbol-value var)))))
-     copy-variables)
+    (while copy-variables
+      (set (car copy-variables)
+          (save-excursion
+            (set-buffer cur-buf)
+            (symbol-value (car copy-variables))))
+      (setq copy-variables (cdr copy-variables)))
     (switch-to-buffer buf)
     (kill-buffer cur-buf)
-    (setq mode-line-buffer-identification
-         (format "Wanderlust: %s" 
-                 (if (memq 'modeline wl-use-folder-petname)
-                     (wl-folder-get-petname folder)
-                   folder)))
-    (wl-summary-count-unread 
+    (wl-summary-count-unread
      (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
     (wl-summary-update-modeline)
     (if msg
@@ -2604,7 +2674,7 @@ If optional argument is non-nil, checking is omitted."
 
 (defun wl-summary-get-buffer-create (folder &optional force-sticky)
   (if force-sticky
-      (get-buffer-create 
+      (get-buffer-create
        (wl-summary-sticky-buffer-name folder))
     (or (get-buffer (wl-summary-sticky-buffer-name folder))
        (get-buffer-create wl-summary-buffer-name))))
@@ -2630,13 +2700,27 @@ If optional argument is non-nil, checking is omitted."
     (if (not disp)
        (setq wl-summary-buffer-disp-msg nil))
     (when (and (not disp)
-              (setq mes-win (wl-message-buffer-window)))
+              (setq mes-win (wl-message-buffer-window)))
       (delete-window mes-win)
       (run-hooks 'wl-summary-toggle-disp-off-hook))))
 
-(defun wl-summary-goto-folder-subr (&optional folder scan-type other-window 
+(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))
@@ -2664,53 +2748,53 @@ If optional argument is non-nil, checking is omitted."
          (if other-window
              (delete-other-windows))
          (set-buffer buf)
-         (wl-summary-buffer-set-folder fld)
          (unless (eq major-mode 'wl-summary-mode)
            (wl-summary-mode))
+         (wl-summary-buffer-set-folder fld)
          (setq wl-summary-buffer-disp-msg nil)
          (setq wl-summary-buffer-last-displayed-msg nil)
          (setq wl-summary-buffer-current-msg nil)
          (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)
-           (setq mode-line-buffer-identification
-                 (format "Wanderlust: %s" 
-                         (if (memq 'modeline wl-use-folder-petname)
-                             (wl-folder-get-petname fld)
-                           fld)))
-             ;; 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
                     (point-min)(point-max)
                     wl-summary-buffer-mime-charset))
                  (when (file-exists-p view)
-                   (setq wl-summary-buffer-view 
+                   (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-summary-count-unread 
+                     (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
@@ -2719,7 +2803,7 @@ If optional argument is non-nil, checking is omitted."
                       interactive
                       (not wl-ask-range))
                  (setq scan-type (wl-summary-get-sync-range fld)))
-             (cond 
+             (cond
               ((eq scan-type nil)
                (wl-summary-sync 'unset-cursor))
               ((eq scan-type 'all)
@@ -2738,35 +2822,39 @@ 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) 
+           (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))
                          wl-summary-highlight-partial-threshold))
                  (save-excursion
-                   (forward-line (- 
-                                  0 
+                   (forward-line (-
+                                  0
                                   (or
                                    wl-summary-partial-highlight-above-lines
                                    wl-summary-highlight-partial-threshold)))
                    (wl-highlight-summary (point) (point-max)))
                (wl-highlight-summary (point-min) (point-max))))
          (if (null wl-summary-buffer-msgdb) ;; one more try.
-             (setq wl-summary-buffer-msgdb 
+             (setq wl-summary-buffer-msgdb
                    (elmo-msgdb-load (elmo-string fld))))
          (if (eq retval 'disp-msg)
              (wl-summary-redisplay))
@@ -2788,53 +2876,53 @@ 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))
     (when (re-search-backward (format "^ *%s..../..\(.*\)..:.. "
                                      parent-number) nil t)
       (goto-char (match-end 0))
-      (while (string-match wl-thread-indent-regexp 
+      (while (string-match wl-thread-indent-regexp
                           (char-to-string
-                           (char-after (point))))        
+                           (char-after (point))))
        (setq depth (+ 1 depth))
        (forward-char))
       (/ depth wl-thread-indent-level-internal))))
 
 (defun wl-summary-goto-bottom-of-current-thread ()
-  (if (re-search-forward (concat "^" wl-summary-buffer-number-regexp 
-                                "..../..\(.*\)..:.. \\[") nil t)
+  (if (re-search-forward (concat "^" wl-summary-buffer-number-regexp
+                                "..../..\(.*\)..:.. [[<]") nil t)
       ()
     (goto-char (point-max))))
 
 (defun wl-summary-goto-top-of-current-thread ()
   (wl-summary-jump-to-msg
    (wl-thread-entity-get-number
-    (wl-thread-entity-get-top-entity (wl-thread-get-entity 
+    (wl-thread-entity-get-top-entity (wl-thread-get-entity
                                      (wl-summary-message-number))))))
 
 (defun wl-summary-goto-bottom-of-sub-thread (&optional depth)
   (interactive)
-  (let ((depth (or depth 
+  (let ((depth (or depth
                   (wl-thread-get-depth-of-current-line))))
     (forward-line 1)
     (while (and (not (eobp))
-               (>= (wl-thread-get-depth-of-current-line) 
+               (>= (wl-thread-get-depth-of-current-line)
                    depth))
       (forward-line 1))
     (beginning-of-line)))
 
 (defun wl-summary-insert-line (line)
   "Insert LINE in the Summary."
-  (if wl-use-highlight-mouse-line 
+  (if wl-use-highlight-mouse-line
       ;; remove 'mouse-face of current line.
       (put-text-property
        (save-excursion (beginning-of-line)(point))
        (save-excursion (end-of-line)(point))
        'mouse-face nil))
   (insert line "\n")
-  (if wl-use-highlight-mouse-line 
+  (if wl-use-highlight-mouse-line
       ;; remove 'mouse-face of current line.
       (put-text-property
        (save-excursion (beginning-of-line)(point))
@@ -2845,12 +2933,12 @@ If optional argument is non-nil, checking is omitted."
     (error (ding)
           (message "Error in wl-summary-line-inserted-hook"))))
 
-(defun wl-summary-insert-summary (entity database mark-alist dummy)
+(defun wl-summary-insert-summary (entity database mark-alist dummy &optional dummy)
   (let ((overview-entity entity)
        summary-line msg)
     (setq msg (elmo-msgdb-overview-entity-get-number entity))
     (when (setq summary-line
-               (wl-summary-overview-create-summary-line 
+               (wl-summary-overview-create-summary-line
                 msg entity nil 0 mark-alist))
       (let ((inhibit-read-only t)
            buffer-read-only)
@@ -2859,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 "^\\[.*\\]" "")))
 
@@ -2867,28 +2955,146 @@ If optional argument is non-nil, checking is omitted."
   (string= (wl-summary-subject-filter-func-internal subject1)
           (wl-summary-subject-filter-func-internal subject2)))
 
-(defun wl-summary-insert-thread-entity (entity overview mark-alist update)
-  (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-number (elmo-msgdb-overview-entity-get-number parent-entity))
-        msg)
-    (if (and parent-number
-            wl-summary-divide-thread-when-subject-changed
-            (not (wl-summary-subject-equal 
-                  (or (elmo-msgdb-overview-entity-get-subject 
-                       entity) "")
-                  (or (elmo-msgdb-overview-entity-get-subject 
-                       parent-entity) ""))))
-       (setq parent-number nil))
-    (setq msg (elmo-msgdb-overview-entity-get-number entity))
-    (wl-thread-insert-message entity overview mark-alist
-                             msg parent-number update)))
-
-(defun wl-summary-update-thread (entity 
-                                overview 
-                                mark-alist 
+(defmacro wl-summary-put-alike (alike)
+  (` (elmo-set-hash-val (format "#%d" (wl-count-lines))
+                       (, alike)
+                       wl-summary-alike-hashtb)))
+
+(defmacro wl-summary-get-alike ()
+  (` (elmo-get-hash-val (format "#%d" (wl-count-lines))
+                       wl-summary-alike-hashtb)))
+
+(defun wl-summary-insert-headers (overview func mime-decode)
+  (let (ov this last alike)
+    (buffer-disable-undo (current-buffer))
+    (make-local-variable 'wl-summary-alike-hashtb)
+    (setq wl-summary-alike-hashtb (elmo-make-hash (* (length overview) 2)))
+    (when mime-decode
+      (elmo-set-buffer-multibyte default-enable-multibyte-characters))
+    (while (setq ov (pop overview))
+      (setq this (funcall func ov))
+      (and this (setq this (std11-unfold-string this)))
+      (if (equal last this)
+         (wl-append alike (list ov))
+       (when last
+         (wl-summary-put-alike alike)
+         (insert last ?\n))
+       (setq alike (list ov)
+             last this)))
+    (when last
+      (wl-summary-put-alike alike)
+      (insert last ?\n))
+    (when mime-decode
+      (decode-mime-charset-region (point-min) (point-max)
+                                 elmo-mime-charset)
+      (when (eq mime-decode 'mime)
+       (eword-decode-region (point-min) (point-max))))
+    (run-hooks 'wl-summary-insert-headers-hook)))
+
+(defun wl-summary-search-by-subject (entity overview)
+  (let ((buf (get-buffer-create wl-summary-search-buf-name))
+       (folder-name wl-summary-buffer-folder-name)
+       match founds found-entity)
+    (save-excursion
+      (set-buffer buf)
+      (let ((case-fold-search t))
+       (when (or (not (string= wl-summary-buffer-folder-name folder-name))
+                 (zerop (buffer-size)))
+         (setq wl-summary-buffer-folder-name folder-name)
+         (wl-summary-insert-headers
+          overview
+          (function
+           (lambda (x)
+             (wl-summary-subject-filter-func-internal
+              (elmo-msgdb-overview-entity-get-subject-no-decode x))))
+          t))
+       (setq match (wl-summary-subject-filter-func-internal
+                    (elmo-msgdb-overview-entity-get-subject entity)))
+       (if (string= match "")
+           (setq match "\n"))
+       (goto-char (point-max))
+       (while (and (not founds)
+                   (not (= (point) (point-min)))
+                   (search-backward match nil t))
+         ;; check exactly match
+         (when (and (bolp)
+                    (= (point-at-eol)
+                       (match-end 0)))
+           (setq found-entity (wl-summary-get-alike))
+           (if (and found-entity
+                    ;; Is founded entity myself or children?
+                    (not (string=
+                          (elmo-msgdb-overview-entity-get-id entity)
+                          (elmo-msgdb-overview-entity-get-id (car found-entity))))
+                    (not (wl-thread-descendant-p
+                          (elmo-msgdb-overview-entity-get-number entity)
+                          (elmo-msgdb-overview-entity-get-number (car found-entity)))))
+               ;; return matching entity
+               (setq founds found-entity))))
+       (if founds
+           (car founds))))))
+
+(defun wl-summary-insert-thread-entity (entity overview mark-alist update
+                                              &optional force-insert)
+  (let (update-list entity-stack)
+    (while entity
+      (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-number (elmo-msgdb-overview-entity-get-number parent-entity))
+            (case-fold-search t)
+            msg overview2 cur-entity linked retval delayed-entity)
+       (setq msg (elmo-msgdb-overview-entity-get-number entity))
+       (if (and parent-number
+                (not (wl-thread-get-entity parent-number))
+                (not force-insert))
+           ;; parent is exists in overview, but not exists in wl-thread-entities
+           (progn
+             (wl-append wl-summary-delayed-update
+                        (list (cons parent-number entity)))
+             (setq entity nil)) ;; exit loop
+         ;; Search parent by subject.
+         (when (and (null parent-number)
+                    wl-summary-search-parent-by-subject-regexp
+                    (string-match wl-summary-search-parent-by-subject-regexp
+                                  (elmo-msgdb-overview-entity-get-subject entity)))
+           (let ((found (wl-summary-search-by-subject entity overview)))
+             (when (and found
+                        (not (member found wl-summary-delayed-update)))
+               (setq parent-entity found)
+               (setq parent-number
+                     (elmo-msgdb-overview-entity-get-number parent-entity))
+               (setq linked t))))
+         ;; If subject is change, divide thread.
+         (if (and parent-number
+                  wl-summary-divide-thread-when-subject-changed
+                  (not (wl-summary-subject-equal
+                        (or (elmo-msgdb-overview-entity-get-subject
+                             entity) "")
+                        (or (elmo-msgdb-overview-entity-get-subject
+                             parent-entity) ""))))
+             (setq parent-number nil))
+         ;;
+         (setq retval
+               (wl-thread-insert-message entity overview mark-alist
+                                         msg parent-number update linked))
+         (and retval
+              (wl-append update-list (list retval)))
+         (setq entity nil) ; exit loop
+         (while (setq delayed-entity (assq msg wl-summary-delayed-update))
+           (setq wl-summary-delayed-update
+                 (delete delayed-entity wl-summary-delayed-update))
+           ;; update delayed message
+           (wl-append entity-stack (list (cdr delayed-entity)))))
+       (if (and (not entity)
+                entity-stack)
+           (setq entity (pop entity-stack)))))
+    update-list))
+
+(defun wl-summary-update-thread (entity
+                                overview
+                                mark-alist
                                 thr-entity
                                 parent-entity)
   (let* ((depth 0)
@@ -2897,27 +3103,27 @@ If optional argument is non-nil, checking is omitted."
         (parent-id (elmo-msgdb-overview-entity-get-id parent-entity))
         (parent-number (elmo-msgdb-overview-entity-get-number parent-entity))
         summary-line msg subject-differ)
-    (cond 
+    (cond
      ((or (not parent-id)
          (string= this-id parent-id))
       (goto-char (point-max))
       (beginning-of-line))
      ;; parent already exists in buffer.
-     ((setq depth (or (wl-summary-summary-line-already-exists-p 
+     ((setq depth (or (wl-summary-summary-line-already-exists-p
                       parent-number (current-buffer)) -1))
       (setq depth (+ 1 depth))
       (wl-thread-goto-bottom-of-sub-thread)))
-    (if (and (elmo-msgdb-overview-entity-get-number entity))
+    (if (and (setq msg (elmo-msgdb-overview-entity-get-number entity)))
        (if (setq summary-line
-                 (wl-summary-overview-create-summary-line 
-                  (elmo-msgdb-overview-entity-get-number entity)
-                  entity parent-entity depth mark-alist nil nil
-                  thr-entity))
+                 (wl-summary-overview-create-summary-line
+                  msg entity parent-entity depth mark-alist
+                  (wl-thread-maybe-get-children-num msg)
+                  nil thr-entity))
            (let ((inhibit-read-only t)
                  (buffer-read-only nil))
              (wl-summary-insert-line summary-line))))))
 
-(defun wl-summary-mark-as-unread (&optional number 
+(defun wl-summary-mark-as-unread (&optional number
                                            no-server-update
                                            no-modeline-update)
   (interactive)
@@ -2928,25 +3134,28 @@ 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 
+      (if number
          (progn
            (setq visible (wl-summary-jump-to-msg number))
            (unless (setq mark (cadr (assq number mark-alist)))
              (setq mark " ")))
        ;; interactive
        (setq visible t))
-      (end-of-line)
-      (setq eol (point))
-      (re-search-backward (concat "^" wl-summary-buffer-number-regexp
-                                 "..../..")) ; set cursor line
-      (beginning-of-line)
+      (when visible
+       (if (null (wl-summary-message-number))
+           (message "No message.")
+         (end-of-line)
+         (setq eol (point))
+         (re-search-backward (concat "^" wl-summary-buffer-number-regexp
+                                     "..../..")) ; set cursor line
+         (beginning-of-line)))
       (if (or (and (not visible)
                   ;; already exists in msgdb.
                   (assq number (elmo-msgdb-get-number-alist msgdb)))
-             (re-search-forward 
-              (format (concat "^ *\\(" 
+             (re-search-forward
+              (format (concat "^ *\\("
                               (if number (int-to-string number)
                                 "[0-9]+")
                               "\\)[^0-9]\\(%s\\|%s\\)")
@@ -2964,8 +3173,9 @@ If optional argument is non-nil, checking is omitted."
                                 wl-summary-unread-uncached-mark))))
            ;; server side mark
            (unless no-server-update
-             (elmo-mark-as-unread folder (list number)
-                                  msgdb))
+             (unless (elmo-mark-as-unread folder (list number)
+                                          msgdb)
+               (error "Setting mark failed")))
            (when visible
              (delete-region (match-beginning 2) (match-end 2))
              (insert new-mark))
@@ -2975,12 +3185,12 @@ If optional argument is non-nil, checking is omitted."
                                       new-mark))
            (elmo-msgdb-set-mark-alist msgdb mark-alist)
            (unless no-modeline-update
-             (setq wl-summary-buffer-unread-count 
+             (setq wl-summary-buffer-unread-count
                    (+ 1 wl-summary-buffer-unread-count))
              (wl-summary-update-modeline)
-             (wl-folder-update-unread 
+             (wl-folder-update-unread
               folder
-              (+ wl-summary-buffer-unread-count 
+              (+ wl-summary-buffer-unread-count
                  wl-summary-buffer-new-count)))
            (wl-summary-set-mark-modified)
            (if (and visible wl-summary-highlight)
@@ -3064,7 +3274,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                  ;; opened...only myself is checked.
                  (if (wl-summary-check-mark number mark)
                      (wl-append msglist (list number)))
-                 (unless (wl-thread-entity-get-opened entity) 
+                 (unless (wl-thread-entity-get-opened entity)
                    ;; closed...children is also checked.
                    (if (setq result (wl-thread-get-children-msgs-with-mark
                                      number
@@ -3073,7 +3283,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                  (forward-line 1)))
              (elmo-uniq-list msglist))
          (let* ((case-fold-search nil)
-                (re (format (concat wl-summary-message-regexp "%s") 
+                (re (format (concat wl-summary-message-regexp "%s")
                             (regexp-quote mark))))
            (while (re-search-forward re nil t)
              (setq msglist (cons (wl-summary-message-number) msglist)))
@@ -3098,22 +3308,27 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
     (wl-summary-exec-subr (wl-summary-mark-collect "o" beg end)
                          (wl-summary-mark-collect "D" beg end)
                          (wl-summary-mark-collect "O" beg end))))
-  
-(defun wl-summary-exec-subr (msgs dels cpys)
-  (save-excursion
-    (let* ((del-fld (wl-summary-get-delete-folder 
-                    wl-summary-buffer-folder-name))
-          (start (point))
-          dst tmp msg msgs2 cpys2
-          msg-dst dst-msgs len 
-          refile-failures 
-          copy-failures
-          succeeds result executed)
-      (if (not (or msgs dels cpys))
-         (message "No marks")
+
+(defun wl-summary-exec-subr (moves dels copies)
+  (if (not (or moves dels copies))
+      (message "No marks")
+    (save-excursion
+      (let ((del-fld (wl-summary-get-delete-folder
+                     wl-summary-buffer-folder-name))
+           (start (point))
+           (unread-marks (list wl-summary-unread-cached-mark
+                               wl-summary-unread-uncached-mark
+                               wl-summary-new-mark))
+           (refiles (append moves dels))
+           (refile-executed 0)
+           (refile-failures 0)
+           (copy-executed 0)
+           (copy-failures 0)
+           (copy-len (length copies))
+           refile-len
+           dst-msgs                    ; loop counter
+           result)
        (message "Executing ...")
-       (setq msgs (append msgs dels))
-       (setq msgs2 msgs)
        (while dels
          (when (not (assq (car dels) wl-summary-buffer-refile-list))
            (wl-append wl-summary-buffer-refile-list
@@ -3121,113 +3336,80 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
            (setq wl-summary-buffer-delete-list
                  (delete (car dels) wl-summary-buffer-delete-list)))
          (setq dels (cdr dels)))
-       (setq len (length msgs2))
        ;; begin refile...
-       (while msgs
-         (setq msg (car msgs))
-         (setq msgs (cdr msgs))
-         (setq msg-dst (assq msg wl-summary-buffer-refile-list))
-         (setq dst (cdr msg-dst))
-         (if dst
-             (if (setq tmp (assoc dst dst-msgs))
-                 (setq dst-msgs (cons (append tmp (list msg))
-                                        (delete tmp dst-msgs)))
-               (setq dst-msgs (cons (list dst msg) dst-msgs)))))
-       (setq refile-failures 0)
-       (goto-char start) ; avoid moving cursor to the bottom line.
-       (setq executed 0)
+       (setq refile-len (length refiles))
+       (setq dst-msgs
+             (wl-inverse-alist refiles wl-summary-buffer-refile-list))
+       (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 
+             (setq result (elmo-move-msgs wl-summary-buffer-folder-name
                                           (cdr (car dst-msgs))
                                           (car (car dst-msgs))
-                                          wl-summary-buffer-msgdb 
-                                          len executed (cdr dst-msgs)
+                                          wl-summary-buffer-msgdb
+                                          refile-len
+                                          refile-executed
+                                          (not (null (cdr dst-msgs)))
                                           nil ; no-delete
                                           nil ; same-number
-                                          (list wl-summary-unread-cached-mark
-                                                wl-summary-unread-uncached-mark
-                                                wl-summary-new-mark)))
+                                          unread-marks))
            (error nil))
-         (if result ; succeeded.
+         (if result                    ; succeeded.
              (progn
                ;; update buffer.
-               (wl-summary-delete-messages-on-buffer 
-                (cdr (car dst-msgs)))
+               (wl-summary-delete-messages-on-buffer (cdr (car dst-msgs)))
                ;; update refile-alist.
-               (mapcar 
-                (function 
-                 (lambda (x)
-                   (setq wl-summary-buffer-refile-list
-                         (delq (assq x wl-summary-buffer-refile-list)
-                               wl-summary-buffer-refile-list))))
-                (cdr (car dst-msgs))))
-           (setq refile-failures 
+               (setq wl-summary-buffer-refile-list
+                     (wl-delete-associations (cdr (car dst-msgs))
+                                            wl-summary-buffer-refile-list)))
+           (setq refile-failures
                  (+ refile-failures (length (cdr (car dst-msgs))))))
-         (setq executed (+ executed (length (cdr (car dst-msgs)))))
+         (setq refile-executed (+ refile-executed (length (cdr (car dst-msgs)))))
          (setq dst-msgs (cdr dst-msgs)))
        ;; end refile
        ;; begin cOpy...
-       (setq cpys2 cpys)
-       (setq len (length cpys2))
-       (while cpys
-         (setq msg (car cpys))
-         (setq cpys (cdr cpys))
-         (setq msg-dst (assq msg wl-summary-buffer-copy-list))
-         (setq dst (cdr msg-dst))
-         (if dst
-             (if (setq tmp (assoc dst dst-msgs))
-                 (setq dst-msgs (cons (append tmp (list msg))
-                                      (delete tmp dst-msgs)))
-               (setq dst-msgs (cons (list dst msg) dst-msgs)))))
-       (setq copy-failures 0)
-       (setq executed 0)
+       (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 
+             (setq result (elmo-move-msgs wl-summary-buffer-folder-name
                                           (cdr (car dst-msgs))
                                           (car (car dst-msgs))
-                                          wl-summary-buffer-msgdb 
-                                          len executed 
-                                          (cdr dst-msgs) 
+                                          wl-summary-buffer-msgdb
+                                          copy-len
+                                          copy-executed
+                                          (not (null (cdr dst-msgs)))
                                           t ; t is no-delete (copy)
                                           nil ; same number
-                                          (list 
-                                           wl-summary-unread-cached-mark
-                                           wl-summary-unread-uncached-mark
-                                           wl-summary-new-mark)))
+                                          unread-marks))
            (error nil))
-         (if result ; succeeded.
+         (if result                    ; succeeded.
              (progn
                ;; update buffer.
                (wl-summary-delete-copy-marks-on-buffer (cdr (car dst-msgs)))
                ;; update copy-alist
-               (mapcar
-                (function
-                 (lambda (x)
-                   (setq wl-summary-buffer-copy-list
-                         (delq (assq x wl-summary-buffer-copy-list)
-                               wl-summary-buffer-copy-list))))
-                (cdr (car dst-msgs))))
+               (setq wl-summary-buffer-copy-list
+                     (wl-delete-associations (cdr (car dst-msgs))
+                                             wl-summary-buffer-copy-list)))
            (setq copy-failures
                  (+ copy-failures (length (cdr (car dst-msgs))))))
-         (setq executed (+ executed (length (cdr (car dst-msgs)))))
+         (setq copy-executed (+ copy-executed (length (cdr (car dst-msgs)))))
          (setq dst-msgs (cdr dst-msgs)))
-       ;; end cOpy 
+       ;; end cOpy
        (wl-summary-folder-info-update)
        (wl-summary-set-message-modified)
        (wl-summary-set-mark-modified)
@@ -3253,14 +3435,16 @@ 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
-      (wl-folder-confirm-existence fld ignore-error))
+      (if ignore-error
+         (ignore-errors (wl-folder-confirm-existence fld))
+       (wl-folder-confirm-existence fld)))
     fld))
 
 (defun wl-summary-print-destination (msg-num folder)
@@ -3278,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)
@@ -3292,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)
@@ -3308,8 +3493,8 @@ If optional argument DST is specified, put mark without asking
 destination folder.
 If optional argument NUMBER is specified, mark message specified by NUMBER.
 
-If folder is read-only, message should be copied. 
-See `wl-refile-policy-alist' for more details."  
+If folder is read-only, message should be copied.
+See `wl-refile-policy-alist' for more details."
   (interactive)
   (let ((policy (wl-get-assoc-list-value wl-refile-policy-alist
                                         wl-summary-buffer-folder-name)))
@@ -3318,29 +3503,28 @@ See `wl-refile-policy-alist' for more details."
               (call-interactively 'wl-summary-copy)
             (wl-summary-copy dst number)))
          (t
-          (wl-summary-refile-subr "refile" (interactive-p) dst number)))))
+          (wl-summary-refile-subr 'refile (interactive-p) dst number)))))
 
 (defun wl-summary-copy (&optional dst number)
-  "Put refile mark on current line message.
+  "Put copy mark on current line message.
 If optional argument DST is specified, put mark without asking
 destination folder.
 If optional argument NUMBER is specified, mark message specified by NUMBER."
   (interactive)
-  (wl-summary-refile-subr "copy" (interactive-p) dst number))
+  (wl-summary-refile-subr 'copy (interactive-p) dst number))
 
 (defun wl-summary-refile-subr (copy-or-refile interactive &optional dst number)
   (interactive)
   (let* ((buffer-num (wl-summary-message-number))
         (msg-num (or number buffer-num))
-        (msgid (and msg-num 
+        (msgid (and msg-num
                     (cdr (assq msg-num
                                (elmo-msgdb-get-number-alist
                                 wl-summary-buffer-msgdb)))))
         (entity (and msg-num
-                     (elmo-msgdb-overview-get-entity-by-number
-                      (elmo-msgdb-get-overview wl-summary-buffer-msgdb)
-                      msg-num)))
-        (variable 
+                     (elmo-msgdb-overview-get-entity
+                      msg-num wl-summary-buffer-msgdb)))
+        (variable
          (intern (format "wl-summary-buffer-%s-list" copy-or-refile)))
         folder mark already tmp-folder)
     (catch 'done
@@ -3359,39 +3543,41 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
              (error "Already marked as `%s'" mark))
          (throw 'done nil)))
       (setq folder (and msg-num
-                       (or dst (wl-summary-read-folder 
+                       (or dst (wl-summary-read-folder
                                 (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)
-              (not (string= folder
+      (if (and (eq (car (elmo-folder-get-spec
+                        (wl-folder-get-realname folder))) 'cache)
+              (not (string= folder
                             (setq tmp-folder
-                                  (concat "'cache/" 
+                                  (concat "'cache/"
                                           (elmo-cache-get-path-subr
                                            (elmo-msgid-to-cache msgid)))))))
-         (progn 
-           (setq folder tmp-folder)
-           (message "Force refile to %s." folder)))
+         (progn
+           (setq folder tmp-folder)
+           (message "Force refile to %s." folder)))
       (if (string= folder wl-summary-buffer-folder-name)
          (error "Same folder"))
-      (if (and
-          (not (elmo-folder-plugged-p folder))
-          (or (null msgid)
-              (not (elmo-cache-exists-p msgid))))
-         (error "Unplugged (no cache or msgid)"))
+      (unless (or (elmo-folder-plugged-p wl-summary-buffer-folder-name)
+                 (and (eq (elmo-folder-get-type wl-summary-buffer-folder-name) 'pipe)
+                      (elmo-folder-plugged-p
+                       (elmo-pipe-spec-dst (elmo-folder-get-spec wl-summary-buffer-folder-name))))
+                 (elmo-cache-exists-p msgid))
+       (error "Unplugged (no cache or msgid)"))
       (if (or (string= folder wl-queue-folder)
              (string= folder wl-draft-folder))
          (error "Don't %s messages to %s" copy-or-refile folder))
       ;; learn for refile.
-      (if (string= "refile" copy-or-refile)
+      (if (eq copy-or-refile 'refile)
          (wl-refile-learn entity folder))
       (wl-summary-unmark msg-num)
-      (set variable (append 
+      (set variable (append
                     (symbol-value variable)
                     (list (cons msg-num folder))))
       (when (or interactive
                (eq number buffer-num))
-       (wl-summary-mark-line (if (string= "refile" copy-or-refile)
+       (wl-summary-mark-line (if (eq copy-or-refile 'refile)
                                  "o" "O"))
        ;; print refile destination
        (wl-summary-print-destination msg-num folder))
@@ -3404,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))
@@ -3413,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))
@@ -3421,16 +3607,16 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       (wl-summary-prev)
     (wl-summary-next)))
 
-(defsubst wl-summary-no-auto-refile-message-p (msg mark-alist) 
+(defsubst wl-summary-no-auto-refile-message-p (msg mark-alist)
   (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
     (if (and (eq wl-summary-buffer-view 'thread)
-            open-all) 
+            open-all)
        (wl-thread-open-all))
     (let* ((spec wl-summary-buffer-folder-name)
           (overview (elmo-msgdb-get-overview
@@ -3443,12 +3629,13 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       (goto-line 1)
       (while (not (eobp))
        (setq number (wl-summary-message-number))
-       (when (and (not (wl-summary-no-auto-refile-message-p 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-by-number
-                          overview number)))
+                        (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)
@@ -3458,32 +3645,32 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
          (message "Marking...%d message(s)." count))
        (if (eq wl-summary-buffer-view 'thread)
            ;; process invisible children.
-           (if (not (wl-thread-entity-get-opened
-                     (setq thr-entity (wl-thread-get-entity number))))
-               (mapcar 
-                (function
-                 (lambda (x)
-                   (when (and (setq dst 
-                                    (wl-refile-guess-by-rule
-                                     (elmo-msgdb-overview-get-entity-by-number 
-                                      overview x)))
-                              (not (equal dst spec)))
-                     (if (wl-summary-refile dst x)
-                         (incf count))
-                     (message "Marking...%d message(s)." count))))
-                (elmo-delete-if
-                 (function (lambda (x)
-                             (wl-summary-no-auto-refile-message-p 
-                              x
-                              mark-alist)))
-                 (wl-thread-entity-get-descendant thr-entity)))))
+           (unless (wl-thread-entity-get-opened
+                    (setq thr-entity (wl-thread-get-entity number)))
+             (let ((messages
+                    (elmo-delete-if
+                     (function
+                      (lambda (x)
+                        (wl-summary-no-auto-refile-message-p
+                         x mark-alist)))
+                     (wl-thread-entity-get-descendant thr-entity))))
+               (while messages
+                 (when (and (setq dst
+                                  (wl-refile-guess-by-rule
+                                   (elmo-msgdb-overview-get-entity
+                                    (car messages) wl-summary-buffer-msgdb)))
+                            (not (equal dst spec)))
+                   (if (wl-summary-refile dst (car messages))
+                       (incf count))
+                   (message "Marking...%d message(s)." count))
+                 (setq messages (cdr messages))))))
        (forward-line))
       (if (eq count 0)
          (message "No message was marked.")
        (message "Marked %d message(s)." count)))))
 
 (defun wl-summary-unmark (&optional number)
-  "Unmark marks (temporary, refile, copy, delete)of current line. 
+  "Unmark marks (temporary, refile, copy, delete)of current line.
 If optional argument NUMBER is specified, unmark message specified by NUMBER."
   (interactive)
   (save-excursion
@@ -3498,7 +3685,7 @@ If optional argument NUMBER is specified, unmark message specified by NUMBER."
          (setq visible (wl-summary-jump-to-msg number))
        (setq visible t))
       ;; Delete mark on buffer.
-      (when (and visible 
+      (when (and visible
                 (looking-at "^ *\\([0-9]+\\)\\([^0-9]\\)"))
        (goto-char (match-end 2))
        (or number
@@ -3513,7 +3700,7 @@ If optional argument NUMBER is specified, unmark message specified by NUMBER."
        (if (or (string= cur-mark "o")
                (string= cur-mark "O"))
            (wl-summary-remove-destination))
-       (if wl-summary-highlight          
+       (if wl-summary-highlight
            (wl-highlight-summary-current-line nil nil score-mark))
        (set-buffer-modified-p nil))
       ;; Remove from temporary mark structure.
@@ -3568,7 +3755,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
   "Put copy mark on messages in the region specified by BEG and END."
   (interactive "r")
   (wl-summary-refile-region-subr "refile" beg end))
-  
+
 (defun wl-summary-copy-region (beg end)
   "Put copy mark on messages in the region specified by BEG and END."
   (interactive "r")
@@ -3580,36 +3767,34 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       (goto-char beg)
       ;; guess by first msg
       (let* ((msgid (cdr (assq (wl-summary-message-number)
-                               (elmo-msgdb-get-number-alist
-                                wl-summary-buffer-msgdb))))
+                              (elmo-msgdb-get-number-alist
+                               wl-summary-buffer-msgdb))))
             (function (intern (format "wl-summary-%s" copy-or-refile)))
             (entity (assoc msgid (elmo-msgdb-get-overview
                                   wl-summary-buffer-msgdb)))
             folder)
-       (if entity
-           (setq folder (wl-summary-read-folder (wl-refile-guess entity)
-                                                (format "for %s"
+       (if entity
+           (setq folder (wl-summary-read-folder (wl-refile-guess entity)
+                                                (format "for %s"
                                                         copy-or-refile))))
-       (narrow-to-region beg end)
-       (if (eq wl-summary-buffer-view 'thread)
-           (progn
-             (while (not (eobp))
-               (let* ((number (wl-summary-message-number))
-                      (entity (wl-thread-get-entity number))
-                      children)
-                 (if (wl-thread-entity-get-opened entity)
-                     ;; opened...refile line.
-                     (funcall function folder number)
-                   ;; closed
-                   (mapcar
-                    (function
-                     (lambda (x)
-                       (funcall function folder x)))
-                    (wl-thread-get-children-msgs number)))
-                 (forward-line 1))))
-         (while (not (eobp))
-           (funcall function folder (wl-summary-message-number))
-           (forward-line 1)))))))
+       (narrow-to-region beg end)
+       (if (eq wl-summary-buffer-view 'thread)
+           (progn
+             (while (not (eobp))
+               (let* ((number (wl-summary-message-number))
+                      (entity (wl-thread-get-entity number))
+                      children)
+                 (if (wl-thread-entity-get-opened entity)
+                     ;; opened...refile line.
+                     (funcall function folder number)
+                   ;; closed
+                   (setq children (wl-thread-get-children-msgs number))
+                   (while children
+                     (funcall function folder (pop children))))
+                 (forward-line 1))))
+         (while (not (eobp))
+           (funcall function folder (wl-summary-message-number))
+           (forward-line 1)))))))
 
 (defun wl-summary-unmark-region (beg end)
   (interactive "r")
@@ -3626,8 +3811,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                    ;; opened...unmark line.
                    (wl-summary-unmark)
                  ;; closed
-                 (mapcar
-                  'wl-summary-unmark
+                 (wl-summary-delete-marks-on-buffer
                   (wl-thread-get-children-msgs number))))
              (forward-line 1)))
        (while (not (eobp))
@@ -3644,14 +3828,15 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
            (while (not (eobp))
              (let* ((number (wl-summary-message-number))
                     (entity (wl-thread-get-entity number))
-                    (wl-summary-move-direction-downward t))
+                    (wl-summary-move-direction-downward t)
+                    children)
                (if (wl-thread-entity-get-opened entity)
                    ;; opened...delete line.
                    (funcall function number)
                  ;; closed
-                 (mapcar
-                  function
-                  (wl-thread-get-children-msgs number)))
+                 (setq children (wl-thread-get-children-msgs number))
+                 (while children
+                   (funcall function (pop children))))
                (forward-line 1))))
        (while (not (eobp))
          (funcall function (wl-summary-message-number))
@@ -3668,14 +3853,14 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 (defun wl-summary-target-mark-all ()
   (interactive)
   (wl-summary-target-mark-region (point-min) (point-max))
-  (setq wl-summary-buffer-target-mark-list 
-       (mapcar 'car 
+  (setq wl-summary-buffer-target-mark-list
+       (mapcar 'car
                (elmo-msgdb-get-number-alist wl-summary-buffer-msgdb))))
 
 (defun wl-summary-delete-all-mark (mark)
   (goto-char (point-min))
   (let ((case-fold-search nil))
-    (while (re-search-forward (format "^ *[0-9]+%s" 
+    (while (re-search-forward (format "^ *[0-9]+%s"
                                      (regexp-quote mark)) nil t)
       (wl-summary-unmark))
     (cond ((string= mark "*")
@@ -3707,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)))
@@ -3722,93 +3907,24 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 
 (defun wl-summary-pick (&optional from-list delete-marks)
   (interactive)
-  (save-excursion
-    (let* ((completion-ignore-case t)
-          (field (completing-read
-                  (format "Field name (%s): " wl-summary-pick-field-default)
-                  (mapcar 'list
-                          (append '("From" "Subject" "Date"
-                                    "To" "Cc" "Body" "Since" "Before")
-                                  elmo-msgdb-extra-fields))))
-          (field (if (string= field "")
-                     (setq field wl-summary-pick-field-default)
-                   field))
-          (value (if (string-match field "Since\\|Before")
-                     (completing-read "Value: "
-                                      (mapcar (function
-                                               (lambda (x)
-                                                 (list (format "%s" (car x)))))
-                                              elmo-date-descriptions))
-                   (read-from-minibuffer "Value: ")))
-          (overview (elmo-msgdb-get-overview wl-summary-buffer-msgdb))
-          (number-alist (elmo-msgdb-get-number-alist wl-summary-buffer-msgdb))
-          (elmo-search-mime-charset wl-search-mime-charset)
-          server-side-search
-          result get-func sum)
-      (if delete-marks
-         (let ((mlist wl-summary-buffer-target-mark-list))
-           (while mlist
-             (when (wl-summary-jump-to-msg (car mlist))
-               (wl-summary-unmark))
-             (setq mlist (cdr mlist)))
-           (setq wl-summary-buffer-target-mark-list nil)))
-      (setq field (downcase field))
-      (cond 
-       ((string-match field "from")
-       (setq get-func 'elmo-msgdb-overview-entity-get-from))
-       ((string-match field "subject")
-       (setq get-func 'elmo-msgdb-overview-entity-get-subject))
-       ((string-match field "date")
-       (setq get-func 'elmo-msgdb-overview-entity-get-date))
-       ((string-match field "to")
-       (setq get-func 'elmo-msgdb-overview-entity-get-to))
-       ((string-match field "cc")
-       (setq get-func 'elmo-msgdb-overview-entity-get-cc))
-       ((string-match field "since")
-       (setq server-side-search (vector 'date "since" value)))
-       ((string-match field "before")
-       (setq server-side-search (vector 'date "before" value)))
-       ((string-match field "body")
-       (setq server-side-search (vector 'match "body" value)))
-       ((member field elmo-msgdb-extra-fields)
-       (setq get-func
-             (lambda (entity)
-               (elmo-msgdb-overview-entity-get-extra-field entity field))))
-       (t
-       (error "Pick by %s is not supported" field)))
-      (unwind-protect
-         (if server-side-search
-             (progn
-               (message "Searching...")
-               (let ((elmo-mime-charset wl-summary-buffer-mime-charset))
-                 (setq result (elmo-search wl-summary-buffer-folder-name 
-                                           (list server-side-search))))
-               (if from-list
-                   (setq result (elmo-list-filter from-list result)))
-               (message "%d message(s) are picked." (length result)))
-           (setq sum 0)
-           (message "Searching...")
-           (while overview
-             (when (and (string-match value
-                                      (or 
-                                       (funcall get-func (car overview))
-                                       ""))
-                        (or (not from-list)
-                            (memq 
-                             (elmo-msgdb-overview-entity-get-number
-                              (car overview)) from-list)))
-               (setq result
-                     (append result
-                             (list
-                              (elmo-msgdb-overview-entity-get-number
-                               (car overview)))))
-               (message "Picked %d message(s)." (setq sum (+ sum 1))))
-             (setq overview (cdr overview)))
-           (message "%d message(s) are picked." sum))
-       (if (null result)
-           (message "No message was picked.")
-         (wl-summary-target-mark-msgs result))))))
-  
+  (let ((result (elmo-msgdb-search
+                wl-summary-buffer-folder-name
+                (elmo-read-search-condition wl-summary-pick-field-default)
+                wl-summary-buffer-msgdb)))
+    (if delete-marks
+      (let ((mlist wl-summary-buffer-target-mark-list))
+       (while mlist
+         (when (wl-summary-jump-to-msg (car mlist))
+           (wl-summary-unmark))
+         (setq mlist (cdr mlist)))
+       (setq wl-summary-buffer-target-mark-list nil)))
+    (if from-list
+       (setq result (elmo-list-filter from-list result)))
+    (message "%d message(s) are picked." (length result))
+    (if (null result)
+       (message "No message was picked.")
+      (wl-summary-target-mark-msgs result))))
+
 (defun wl-summary-unvirtual ()
   "Exit from current virtual folder."
   (interactive)
@@ -3820,26 +3936,17 @@ 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)
-    (let* ((completion-ignore-case t)
-          (field (completing-read (format "Field name (%s): " 
-                                          wl-summary-pick-field-default)
-                                  '(("From" . "From") 
-                                    ("Subject" . "Subject")
-                                    ("To" . "To")
-                                    ("Cc" . "Cc")
-                                    ("Body" . "Body")
-                                    ("Since" . "Since")
-                                    ("Before" . "Before"))))
-          (value (read-from-minibuffer "Value: ")))
-      (if (string= field "")
-         (setq field wl-summary-pick-field-default))
-      (wl-summary-goto-folder-subr (concat "/" (downcase field) "=" value "/" 
-                                          wl-summary-buffer-folder-name)
-                                  'update nil nil t))))
+    (wl-summary-goto-folder-subr (concat "/"
+                                        (elmo-read-search-condition
+                                         wl-summary-pick-field-default)
+                                        "/"
+                                        wl-summary-buffer-folder-name)
+                                'update nil nil t)))
 
 (defun wl-summary-delete-all-temp-marks ()
   (interactive)
@@ -3849,12 +3956,12 @@ 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)
     (setq wl-summary-buffer-copy-list nil)))
-    
+
 (defun wl-summary-delete-mark (number)
   "Delete temporary mark of the message specified by NUMBER."
   (cond
@@ -3866,7 +3973,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
          (delq number wl-summary-buffer-delete-list)))
    (t
     (let (pair)
-      (cond 
+      (cond
        ((setq pair (assq number wl-summary-buffer-copy-list))
        (setq wl-summary-buffer-copy-list
              (delq pair wl-summary-buffer-copy-list)))
@@ -3875,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)
@@ -3887,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))
@@ -3937,7 +4044,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                    (delete-region (match-beginning 1) (match-end 1)))
                  (goto-char (match-beginning 1))
                  (insert new-mark)
-                 (if wl-summary-highlight      
+                 (if wl-summary-highlight
                      (wl-highlight-summary-current-line))
                  (save-excursion
                    (goto-char pos)
@@ -3984,7 +4091,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
        ;; process invisible messages.
        (setq mlist wl-summary-buffer-target-mark-list)
        (while mlist
-         (set variable 
+         (set variable
               (append (symbol-value variable)
                       (list (cons (car mlist) folder))))
          (setq wl-summary-buffer-target-mark-list
@@ -4013,18 +4120,18 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
          (delete-region (match-beginning 1) (match-end 1))
          (insert " ")
          (setq number (wl-summary-mark-as-read t))
-         (if wl-summary-highlight      
+         (if wl-summary-highlight
              (wl-highlight-summary-current-line))
          (if number
              (setq wl-summary-buffer-target-mark-list
                    (delq number wl-summary-buffer-target-mark-list)))))
       (setq mlist wl-summary-buffer-target-mark-list)
       (while mlist
-       (wl-thread-msg-mark-as-read (car mlist))
+       (wl-summary-mark-as-read t nil nil (car mlist))
        (setq wl-summary-buffer-target-mark-list
              (delq (car mlist) wl-summary-buffer-target-mark-list))
        (setq mlist (cdr mlist)))
-      (wl-summary-count-unread 
+      (wl-summary-count-unread
        (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
       (wl-summary-update-modeline))))
 
@@ -4042,7 +4149,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
          (delete-region (match-beginning 1) (match-end 1))
          (insert " ")
          (setq number (wl-summary-mark-as-unread))
-         (if wl-summary-highlight      
+         (if wl-summary-highlight
              (wl-highlight-summary-current-line))
          (if number
              (setq wl-summary-buffer-target-mark-list
@@ -4050,11 +4157,11 @@ 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)))
-      (wl-summary-count-unread 
+      (wl-summary-count-unread
        (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
       (wl-summary-update-modeline))))
 
@@ -4072,7 +4179,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
          (delete-region (match-beginning 1) (match-end 1))
          (insert " ")
          (setq number (wl-summary-mark-as-important))
-         (if wl-summary-highlight      
+         (if wl-summary-highlight
              (wl-highlight-summary-current-line))
          (if number
              (setq wl-summary-buffer-target-mark-list
@@ -4084,7 +4191,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
        (setq wl-summary-buffer-target-mark-list
              (delq (car mlist) wl-summary-buffer-target-mark-list))
        (setq mlist (cdr mlist)))
-      (wl-summary-count-unread 
+      (wl-summary-count-unread
        (elmo-msgdb-get-mark-alist wl-summary-buffer-msgdb))
       (wl-summary-update-modeline))))
 
@@ -4110,11 +4217,11 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
   (interactive)
   (wl-summary-pick wl-summary-buffer-target-mark-list 'delete))
 
-(defun wl-summary-mark-as-read (&optional notcrosses 
+(defun wl-summary-mark-as-read (&optional notcrosses
                                          leave-server-side-mark-untouched
-                                         displayed 
+                                         displayed
                                          number
-                                         no-cache)
+                                         cached)
   (interactive)
   (save-excursion
     (let* (eol
@@ -4123,10 +4230,10 @@ 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 unread visible uncached new-mark)
-      (if number 
+          mark stat visible uncached new-mark marked)
+      (if number
          (progn
            (setq visible (wl-summary-jump-to-msg number))
            (setq mark (cadr (assq number mark-alist))))
@@ -4134,7 +4241,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       (beginning-of-line)
       (if (or (not visible)
              (looking-at
-              (format "^ *\\([0-9]+\\)[^0-9]\\(%s\\|%s\\|%s\\|%s\\).*$" 
+              (format "^ *\\([0-9]+\\)[^0-9]\\(%s\\|%s\\|%s\\|%s\\).*$"
                       (regexp-quote wl-summary-read-uncached-mark)
                       (regexp-quote wl-summary-unread-uncached-mark)
                       (regexp-quote wl-summary-unread-cached-mark)
@@ -4142,52 +4249,61 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
          (progn
            (setq mark (or mark (wl-match-buffer 2)))
            (when mark
-             (cond 
+             (cond
               ((string= mark wl-summary-new-mark) ; N
-               (setq wl-summary-buffer-new-count 
-                     (- wl-summary-buffer-new-count 1))
-               (setq uncached t)
-               (setq unread t))
+               (setq stat 'new)
+               (setq uncached t))
               ((string= mark wl-summary-unread-uncached-mark) ; U
-               (setq wl-summary-buffer-unread-count 
-                     (- wl-summary-buffer-unread-count 1))
-               (setq uncached t)
-               (setq unread t))
+               (setq stat 'unread)
+               (setq uncached t))
               ((string= mark wl-summary-unread-cached-mark)  ; !
-               (setq wl-summary-buffer-unread-count 
-                     (- wl-summary-buffer-unread-count 1))
-               (setq unread t))
+               (setq stat 'unread))
               (t
                ;; no need to mark server.
-               (setq leave-server-side-mark-untouched t)))
-             (wl-summary-update-modeline)
-             (wl-folder-update-unread 
-              folder
-              (+ wl-summary-buffer-unread-count 
-                 wl-summary-buffer-new-count)))
+               (setq leave-server-side-mark-untouched t))))
            (setq number (or number (string-to-int (wl-match-buffer 1))))
            ;; set server side mark...
-           (setq new-mark (if (and uncached no-cache) 
+           (setq new-mark (if (and uncached
+                                   (if (elmo-use-cache-p folder number)
+                                       (not (elmo-folder-local-p folder)))
+                                   (not cached))
                               wl-summary-read-uncached-mark
                             nil))
            (if (not leave-server-side-mark-untouched)
-               (elmo-mark-as-read folder
-                                  (list number) msgdb))
-           (when visible
-             (goto-char (match-end 2))
-             (delete-region (match-beginning 2) (match-end 2))
-             (insert (or new-mark " ")))
-           (setq mark-alist
-                 (elmo-msgdb-mark-set mark-alist number new-mark))
-           (elmo-msgdb-set-mark-alist msgdb mark-alist)
-           (wl-summary-set-mark-modified)
-           (if (and visible wl-summary-highlight)
-               (wl-highlight-summary-current-line nil nil t))
-           (if (not notcrosses)
-               (wl-summary-set-crosspost nil (and wl-summary-buffer-disp-msg
-                                                   (interactive-p))))))
+               (setq marked (elmo-mark-as-read folder
+                                               (list number) msgdb)))
+           (if (or leave-server-side-mark-untouched
+                   marked)
+               (progn
+                 (cond ((eq stat 'unread)
+                        (setq wl-summary-buffer-unread-count
+                              (1- wl-summary-buffer-unread-count)))
+                       ((eq stat 'new)
+                        (setq wl-summary-buffer-new-count
+                              (1- wl-summary-buffer-new-count))))
+                 (wl-summary-update-modeline)
+                 (wl-folder-update-unread
+                  folder
+                  (+ wl-summary-buffer-unread-count
+                     wl-summary-buffer-new-count))
+                 (when (or stat cached)
+                   (when visible
+                     (goto-char (match-end 2))
+                     (delete-region (match-beginning 2) (match-end 2))
+                     (insert (or new-mark " ")))
+                   (setq mark-alist
+                         (elmo-msgdb-mark-set mark-alist number new-mark))
+                   (elmo-msgdb-set-mark-alist msgdb mark-alist)
+                   (wl-summary-set-mark-modified))
+                 (if (and visible wl-summary-highlight)
+                     (wl-highlight-summary-current-line nil nil t))
+                 (if (not notcrosses)
+                     (wl-summary-set-crosspost nil
+                                               (and wl-summary-buffer-disp-msg
+                                                    (interactive-p)))))
+             (if mark (message "Warning: Changing mark failed.")))))
       (set-buffer-modified-p nil)
-      (if unread
+      (if stat
          (run-hooks 'wl-summary-unread-message-hook))
       number ;return value
       )))
@@ -4208,16 +4324,21 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
          (mark-alist (elmo-msgdb-get-mark-alist msgdb))
          (number-alist (elmo-msgdb-get-number-alist msgdb))
          message-id visible)
-      (if number 
+      (if number
          (progn
            (setq visible (wl-summary-jump-to-msg number))
            (setq mark (or mark (cadr (assq number mark-alist)))))
        (setq visible t))
-      (end-of-line)
-      (setq eol (point))
-      (if visible
+      (when visible
+       (if (null (wl-summary-message-number))
+           (progn
+             (message "No message.")
+             (setq visible nil))
+         (end-of-line)
+         (setq eol (point))
          (re-search-backward (concat "^" wl-summary-buffer-number-regexp
                                      "..../..") nil t)) ; set cursor line
+       )
       (beginning-of-line)
       (if (re-search-forward "^ *\\([0-9]+\\)[^0-9]\\([^0-9]\\)" eol t)
          (progn
@@ -4230,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 " "))
@@ -4253,7 +4377,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                  (elmo-force-cache-msg folder number message-id
                                        (elmo-msgdb-get-location msgdb))))
              (unless no-server-update
-               (elmo-msgdb-global-mark-set message-id 
+               (elmo-msgdb-global-mark-set message-id
                                            wl-summary-important-mark)))
            (elmo-msgdb-set-mark-alist msgdb mark-alist)
            (wl-summary-set-mark-modified)))
@@ -4264,7 +4388,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 
 (defsubst wl-summary-format-date (date-string)
   (condition-case nil
-      (let ((datevec (timezone-fix-time date-string nil 
+      (let ((datevec (timezone-fix-time date-string nil
                                        wl-summary-fix-timezone)))
        (format "%02d/%02d(%s)%02d:%02d"
                (aref datevec 1)
@@ -4276,12 +4400,12 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                (aref datevec 4)))
     (error "??/??(??)??:??")))
 
-(defun wl-summary-overview-create-summary-line (msg 
-                                               entity 
-                                               parent-entity 
+(defun wl-summary-overview-create-summary-line (msg
+                                               entity
+                                               parent-entity
                                                depth
                                                mark-alist
-                                               &optional 
+                                               &optional
                                                children-num
                                                temp-mark thr-entity
                                                subject-differ)
@@ -4292,20 +4416,22 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
        mark line
        (elmo-lang wl-summary-buffer-weekday-name-lang)
        (children-num (if children-num (int-to-string children-num)))
-       (thr-str ""))
-    (if thr-entity
-       (setq thr-str (wl-thread-make-indent-string thr-entity)))
+       (thr-str "")
+       linked)
+    (when thr-entity
+      (setq thr-str (wl-thread-make-indent-string thr-entity))
+      (setq linked (wl-thread-entity-get-linked thr-entity)))
     (if (string= thr-str "")
        (setq no-parent t)) ; no parent
-    (if (and wl-summary-width 
+    (if (and wl-summary-width
             wl-summary-indent-length-limit
             (< wl-summary-indent-length-limit
                (string-width thr-str)))
-       (setq thr-str (wl-set-string-width 
+       (setq thr-str (wl-set-string-width
                       wl-summary-indent-length-limit
                       thr-str)))
-    (setq from 
-         (wl-set-string-width 
+    (setq from
+         (wl-set-string-width
           (if children-num
               (- wl-from-width (length children-num) 2)
             wl-from-width)
@@ -4314,20 +4440,20 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                              (elmo-msgdb-overview-entity-get-from entity)))))
     (setq subject
          (elmo-delete-char ?\n
-                           (or (elmo-msgdb-overview-entity-get-subject 
+                           (or (elmo-msgdb-overview-entity-get-subject
                                 entity)
                                wl-summary-no-subject-message)))
-    (setq parent-raw-subject 
+    (setq parent-raw-subject
          (elmo-msgdb-overview-entity-get-subject parent-entity))
-    (setq parent-subject 
-         (if parent-raw-subject 
+    (setq parent-subject
+         (if parent-raw-subject
              (elmo-delete-char ?\n parent-raw-subject)))
     (setq mark (or (cadr (assq msg mark-alist)) " "))
-    (setq line 
-         (concat 
+    (setq line
+         (concat
           (setq before-indent
-                (format (concat "%" 
-                                (int-to-string 
+                (format (concat "%"
+                                (int-to-string
                                  wl-summary-buffer-number-column)
                                 "s%s%s%s %s")
                         msg
@@ -4336,20 +4462,28 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                         (wl-summary-format-date
                          (elmo-msgdb-overview-entity-get-date entity))
                         (if thr-str thr-str "")))
-          (format "[%s ] %s"
+          (format (if linked
+                      "<%s > %s"
+                    "[%s ] %s")
                   (if children-num
                       (concat "+" children-num ": " from)
                     (concat " " from))
-                  (if (or no-parent
-                          (null parent-subject)
-                          (not (wl-summary-subject-equal 
-                                subject parent-subject)))
-                      (wl-summary-subject-func-internal subject) ""))))
-    (if wl-summary-width (setq line 
-                              (wl-set-string-width 
+                  (progn
+                    (setq subject
+                          (if (or no-parent
+                                  (null parent-subject)
+                                  (not (wl-summary-subject-equal
+                                        subject parent-subject)))
+                              (wl-summary-subject-func-internal subject) ""))
+                    (if (and (not wl-summary-width)
+                             wl-subject-length-limit)
+                        (truncate-string subject wl-subject-length-limit)
+                      subject)))))
+    (if wl-summary-width (setq line
+                              (wl-set-string-width
                                (- wl-summary-width 1) line)))
     (if wl-summary-highlight
-       (wl-highlight-summary-line-string line 
+       (wl-highlight-summary-line-string line
                                          mark
                                          temp-mark
                                          thr-str))
@@ -4358,9 +4492,10 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 (defsubst wl-summary-buffer-number-column-detect (update)
   (let (end)
     (save-excursion
+      (goto-char (point-min))
       (setq wl-summary-buffer-number-column
            (or
-            (if (and update 
+            (if (and update
                      (setq end (if (re-search-forward "^ *[0-9]+[^0-9]" nil t)
                                    (point))))
                 (- end (progn (beginning-of-line) (point)) 1))
@@ -4369,125 +4504,103 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
             wl-summary-default-number-column))
       (setq wl-summary-buffer-number-regexp
            (wl-repeat-string "." wl-summary-buffer-number-column)))))
-       
+
 (defsubst wl-summary-proc-wday (wday-str year month mday)
   (save-match-data
     (if (string-match "\\([A-Z][a-z][a-z]\\).*" wday-str)
        (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-save-view-cache (&optional keep-current-buffer)
+(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)
+          (tmp-buffer (get-buffer-create " *wl-summary-save-view-cache*"))
+          (charset wl-summary-buffer-mime-charset))
       (if (file-directory-p dir)
          (); ok.
        (if (file-exists-p dir)
@@ -4498,27 +4611,13 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       (unwind-protect
          (progn
            (when (file-writable-p cache)
-             (if keep-current-buffer
-                 (progn
-                   (save-excursion
-                     (set-buffer tmp-buffer)
-                     (erase-buffer))
-                   (setq charset wl-summary-buffer-mime-charset)
-                   (copy-to-buffer tmp-buffer (point-min) (point-max))
-                   (save-excursion
-                     (set-buffer tmp-buffer)
-                     (widen)
-                     (encode-mime-charset-region 
-                      (point-min) (point-max) charset)
-                     (as-binary-output-file
-                      (write-region (point-min)
-                                    (point-max) cache nil 'no-msg))))
-               (let (buffer-read-only)
-                 (widen)
-                 (encode-mime-charset-region (point-min) (point-max)
-                                             wl-summary-buffer-mime-charset)
-                 (as-binary-output-file
-                  (write-region (point-min) (point-max) cache nil 'no-msg)))))
+             (copy-to-buffer tmp-buffer (point-min) (point-max))
+             (with-current-buffer tmp-buffer
+               (widen)
+               (encode-mime-charset-region
+                (point-min) (point-max) charset)
+               (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)
@@ -4532,7 +4631,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 (defsubst wl-summary-get-sync-range (folder)
   (intern (or (and
               (elmo-folder-plugged-p folder)
-              (wl-get-assoc-list-value 
+              (wl-get-assoc-list-value
                wl-folder-sync-range-alist
                folder))
              wl-default-sync-range)))
@@ -4541,11 +4640,11 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 (defun wl-summary-input-range (folder)
   "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"))
-       (default (or (wl-get-assoc-list-value 
+  (let ((input-range-list '("update" "all" "rescan" "first:" "last:"
+                           "no-sync" "rescan-noscore" "all-visible"))
+       (default (or (wl-get-assoc-list-value
                      wl-folder-sync-range-alist
-                     folder) 
+                     folder)
                     wl-default-sync-range))
        range)
     (setq range
@@ -4563,7 +4662,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
        (view-message-buffer (wl-message-get-buffer-create))
        (cur-buf (current-buffer))
        (summary-win (get-buffer-window (current-buffer))))
-    (cond 
+    (cond
      ((eq arg 'on)
       (setq wl-summary-buffer-disp-folder t)
       ;; hide your folder window
@@ -4593,7 +4692,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       (switch-to-buffer cur-buf))
      (t
       (if (setq fld-buf (get-buffer wl-folder-buffer-name))
-         (if (setq fld-win (get-buffer-window fld-buf))      
+         (if (setq fld-win (get-buffer-window fld-buf))
              (setq wl-summary-buffer-disp-folder nil)
            (setq wl-summary-buffer-disp-folder t)))
       (if (not wl-summary-buffer-disp-folder)
@@ -4615,40 +4714,39 @@ 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)
   (interactive)
   (let (fld-buf fld-win
        (view-message-buffer (wl-message-get-buffer-create))
        (cur-buf (current-buffer))
        summary-win)
-    (cond 
+    (cond
      ((eq arg 'on)
       (setq wl-summary-buffer-disp-msg t)
       ;; hide your folder window
@@ -4672,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
@@ -4683,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 ()
@@ -4709,7 +4807,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 (defun wl-summary-prev-page ()
   (interactive)
   (wl-message-prev-page))
-  
+
 (defsubst wl-summary-no-mime-p (folder)
   (wl-string-match-member folder wl-summary-no-mime-folder-list))
 
@@ -4725,7 +4823,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
       (setq cur-folder wl-message-buffer-cur-folder)
       (setq cur-number wl-message-buffer-cur-number))
     (if (and (not ignore-original)
-            (not 
+            (not
              (and (eq number (wl-message-original-buffer-number))
                   (string= folder (wl-message-original-buffer-folder)))))
        (progn
@@ -4802,8 +4900,7 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 
 (defun wl-summary-reply-with-citation (&optional arg)
   (interactive "P")
-  (unwind-protect
-      (wl-summary-reply arg t)
+  (when (wl-summary-reply arg t)
     (goto-char (point-max))
     (wl-draft-yank-original)
     (run-hooks 'wl-mail-setup-hook)))
@@ -4817,24 +4914,24 @@ 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)
       ;; for XEmacs!
       (if (and elmo-use-database
-              (setq errmsg
-                    (format 
+              (setq errmsg
+                    (format
                      "No message with id \"%s\" in the database." msgid))
-              (setq otherfld (elmo-database-msgid-get msgid)))
+              (setq otherfld (elmo-database-msgid-get msgid)))
          (if (cdr (wl-summary-jump-to-msg-internal
                    (car otherfld) (nth 1 otherfld) 'no-sync))
              t ; succeed.
            ;; Back to original.
            (wl-summary-jump-to-msg-internal
             wl-summary-buffer-folder-name original 'no-sync))
-       (cond ((eq wl-summary-search-via-nntp 'confirm)
+       (cond ((eq wl-summary-search-via-nntp 'confirm)
               (message "Search message in nntp server \"%s\" <y/n/s(elect)>?"
                        elmo-default-nntp-server)
               (setq schar (read-char))
@@ -4842,46 +4939,47 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
                      (wl-summary-jump-to-msg-by-message-id-via-nntp msgid))
                     ((eq schar ?s)
                      (wl-summary-jump-to-msg-by-message-id-via-nntp
-                      msgid 
+                      msgid
                       (read-from-minibuffer "NNTP Server: ")))
                     (t
                      (message errmsg)
                      nil)))
              (wl-summary-search-via-nntp
-              (wl-summary-jump-to-msg-by-message-id-via-nntp msgid))
-             (t
-              (message errmsg)
-              nil))))))
+              (wl-summary-jump-to-msg-by-message-id-via-nntp msgid))
+             (t
+              (message errmsg)
+              nil))))))
 
 (defun wl-summary-jump-to-msg-by-message-id-via-nntp (&optional id server-spec)
   (interactive)
   (let* ((msgid (elmo-string (or id (read-from-minibuffer "Message-ID: "))))
-        newsgroups folder ret
-        user server port ssl spec)
+        newsgroups folder ret
+        user server port type spec)
     (if server-spec
        (if (string-match "^-" server-spec)
            (setq spec (elmo-nntp-get-spec server-spec)
                  user (nth 2 spec)
                  server (nth 3 spec)
                  port (nth 4 spec)
-                 ssl (nth 5 spec))
+                 type (nth 5 spec))
          (setq server server-spec)))
     (when (setq ret (elmo-nntp-get-newsgroup-by-msgid
                     msgid
                     (or server elmo-default-nntp-server)
                     (or user elmo-default-nntp-user)
                     (or port elmo-default-nntp-port)
-                    (or ssl elmo-default-nntp-ssl)))
+                    (or type elmo-default-nntp-stream-type)))
       (setq newsgroups (wl-parse-newsgroups ret))
       (setq folder (concat "-" (car newsgroups)
-                          (elmo-nntp-folder-postfix user server port ssl)))
+                          (elmo-nntp-folder-postfix user server port type)))
       (catch 'found
        (while newsgroups
          (if (wl-folder-entity-exists-p (car newsgroups)
                                         wl-folder-newsgroups-hashtb)
              (throw 'found
                     (setq folder (concat "-" (car newsgroups)
-                                         (elmo-nntp-folder-postfix user server port ssl)))))
+                                         (elmo-nntp-folder-postfix
+                                          user server port type)))))
          (setq newsgroups (cdr newsgroups)))))
     (if ret
        (wl-summary-jump-to-msg-internal folder nil 'update msgid)
@@ -4892,24 +4990,24 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 (defun wl-summary-jump-to-msg-internal (folder msg scan-type &optional msgid)
   (let (wl-auto-select-first entity)
     (if (or (string= folder wl-summary-buffer-folder-name)
-           (y-or-n-p 
-            (format
-             "Message was found in the folder \"%s\". Jump to it? "
-             folder)))
-       (progn
-         (unwind-protect
-             (wl-summary-goto-folder-subr
-              folder scan-type nil nil t)
-           (if msgid
-               (setq msg
-                     (car (rassoc msgid
-                                  (elmo-msgdb-get-number-alist
-                                   wl-summary-buffer-msgdb)))))
+           (y-or-n-p
+            (format
+             "Message was found in the folder \"%s\". Jump to it? "
+             folder)))
+       (progn
+         (unwind-protect
+             (wl-summary-goto-folder-subr
+              folder scan-type nil nil t)
+           (if msgid
+               (setq msg
+                     (car (rassoc msgid
+                                  (elmo-msgdb-get-number-alist
+                                   wl-summary-buffer-msgdb)))))
            (setq entity (wl-folder-search-entity-by-name folder
                                                          wl-folder-entity
                                                          'folder))
            (if entity
-               (wl-folder-set-current-entity-id 
+               (wl-folder-set-current-entity-id
                 (wl-folder-get-entity-id entity))))
          (if (null msg)
              (message "Message was not found currently in this folder.")
@@ -4919,128 +5017,172 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 (defun wl-summary-jump-to-parent-message (arg)
   (interactive "P")
   (let ((cur-buf (current-buffer))
+       (number (wl-summary-message-number))
        (regexp "\\(<[^<>]*>\\)[ \t]*$")
        (i -1) ;; xxx
-       msg-id ref-list ref irt)
-    (wl-summary-set-message-buffer-or-redisplay)
-    (set-buffer (wl-message-get-original-buffer))
-    (message "Searching parent message...")
-    (setq ref (std11-field-body "References")
-         irt (std11-field-body "In-Reply-To"))
-    (cond
-     ((and arg (not (numberp arg)) ref (not (string= ref ""))
-          (string-match regexp ref))
-      ;; The first message of the thread.
-      (setq msg-id (wl-match-string 1 ref)))
-     ;; "In-Reply-To:" has only one msg-id.
-     ((and irt (not (string= irt ""))
-          (string-match regexp irt))
-      (setq msg-id (wl-match-string 1 irt)))
-     ((and (or (null arg) (numberp arg)) ref (not (string= ref ""))
-          (string-match regexp ref))
-      ;; "^" searching parent, "C-u 2 ^" looking for grandparent.
-      (while (string-match regexp ref)
-       (setq ref-list
-             (append (list
-                      (wl-match-string 1 ref))
-                     ref-list))
-       (setq ref (substring ref (match-end 0)))
-       (setq i (1+ i)))
-      (setq msg-id
-            (if (null arg) (nth 0 ref-list) ;; previous
-              (if (<= arg i) (nth (1- arg) ref-list)
-                (nth i ref-list))))))
-    (set-buffer cur-buf)
-    (cond ((null msg-id)
-          (message "No parent message!")
-          nil)
-         ((wl-summary-jump-to-msg-by-message-id msg-id)
-          (wl-summary-redisplay)
-          (message "Searching parent message...done.")
-          t)
-         (t ; failed.
-          (message "Parent message was not found.")
-          nil))))
+       msg-id msg-num ref-list ref irt)
+    (if (null number)
+       (message "No message.")
+      (when (eq wl-summary-buffer-view 'thread)
+       (cond ((and arg (not (numberp arg)))
+              (setq msg-num
+                    (wl-thread-entity-get-number
+                     (wl-thread-entity-get-top-entity
+                      (wl-thread-get-entity number)))))
+             ((and arg (numberp arg))
+              (setq i 0)
+              (setq msg-num number)
+              (while (< i arg)
+                (setq msg-num
+                      (wl-thread-entity-get-number
+                       (wl-thread-entity-get-parent-entity
+                        (wl-thread-get-entity msg-num))))
+                (setq i (1+ i))))
+             (t (setq msg-num
+                      (wl-thread-entity-get-number
+                       (wl-thread-entity-get-parent-entity
+                        (wl-thread-get-entity number)))))))
+      (when (null msg-num)
+       (wl-summary-set-message-buffer-or-redisplay)
+       (set-buffer (wl-message-get-original-buffer))
+       (message "Searching parent message...")
+       (setq ref (std11-field-body "References")
+             irt (std11-field-body "In-Reply-To"))
+       (cond
+        ((and arg (not (numberp arg)) ref (not (string= ref ""))
+              (string-match regexp ref))
+         ;; The first message of the thread.
+         (setq msg-id (wl-match-string 1 ref)))
+        ;; "In-Reply-To:" has only one msg-id.
+        ((and (null arg) irt (not (string= irt ""))
+              (string-match regexp irt))
+         (setq msg-id (wl-match-string 1 irt)))
+        ((and (or (null arg) (numberp arg)) ref (not (string= ref ""))
+              (string-match regexp ref))
+         ;; "^" searching parent, "C-u 2 ^" looking for grandparent.
+         (while (string-match regexp ref)
+           (setq ref-list
+                 (append (list
+                          (wl-match-string 1 ref))
+                         ref-list))
+           (setq ref (substring ref (match-end 0)))
+           (setq i (1+ i)))
+         (setq msg-id
+               (if (null arg) (nth 0 ref-list) ;; previous
+                 (if (<= arg i) (nth (1- arg) ref-list)
+                   (nth i ref-list)))))))
+      (set-buffer cur-buf)
+      (cond ((and (null msg-id) (null msg-num))
+            (message "No parent message!")
+            nil)
+           ((and msg-id (wl-summary-jump-to-msg-by-message-id msg-id))
+            (wl-summary-redisplay)
+            (message "Searching parent message...done")
+            t)
+           ((and msg-num (wl-summary-jump-to-msg msg-num))
+            (wl-summary-redisplay)
+            (message "Searching parent message...done")
+            t)
+           (t ; failed.
+            (message "Parent message was not found.")
+            nil)))))
 
 (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))
        (summary-buf (current-buffer))
        mes-buf)
-    (wl-summary-redisplay-internal folder number)
-    (wl-select-buffer (get-buffer (setq mes-buf (wl-current-message-buffer))))
-    (set-buffer mes-buf)
-    (goto-char (point-min))
-    (or wl-draft-use-frame
-       (split-window-vertically))
-    (other-window 1)
-    (when (setq mes-buf (wl-message-get-original-buffer))
-      (wl-draft-reply mes-buf (not arg) summary-buf)
-      (unless without-setup-hook
-       (run-hooks 'wl-mail-setup-hook)))))
+    (if number
+       (unwind-protect
+           (progn
+             (wl-summary-redisplay-internal folder number)
+             (wl-select-buffer
+              (get-buffer (setq mes-buf (wl-current-message-buffer))))
+             (set-buffer mes-buf)
+             (goto-char (point-min))
+             (or wl-draft-use-frame
+                 (split-window-vertically))
+             (other-window 1)
+             (when (setq mes-buf (wl-message-get-original-buffer))
+               (wl-draft-reply mes-buf arg summary-buf)
+               (unless without-setup-hook
+                 (run-hooks 'wl-mail-setup-hook)))
+             t)))))
 
 (defun wl-summary-write ()
   "Write a new draft from Summary."
   (interactive)
   (wl-draft nil nil nil nil nil
-           nil nil nil nil nil (current-buffer))
+           nil nil nil nil nil nil (current-buffer))
   (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))
        (summary-buf (current-buffer))
        (wl-draft-forward t)
        entity subject num)
-    (wl-summary-redisplay-internal folder number)
-    (wl-select-buffer (get-buffer wl-message-buf-name))
-    (or wl-draft-use-frame
-       (split-window-vertically))
-    (other-window 1)
-    ;; get original subject.
-    (if summary-buf
-       (save-excursion 
-         (set-buffer summary-buf)
-         (setq num (wl-summary-message-number))
-         (setq entity (assoc (cdr (assq num 
-                                        (elmo-msgdb-get-number-alist 
-                                         wl-summary-buffer-msgdb)))
-                             (elmo-msgdb-get-overview 
-                              wl-summary-buffer-msgdb)))
-         (and entity
-              (setq subject 
-                    (or (elmo-msgdb-overview-entity-get-subject entity) 
-                        "")))))
-    (wl-draft-forward subject summary-buf)
-    (unless without-setup-hook
-      (run-hooks 'wl-mail-setup-hook))))
+    (if (null number)
+       (message "No message.")
+      (wl-summary-redisplay-internal folder number)
+      (wl-select-buffer (get-buffer wl-message-buf-name))
+      (or wl-draft-use-frame
+         (split-window-vertically))
+      (other-window 1)
+      ;; get original subject.
+      (if summary-buf
+         (save-excursion
+           (set-buffer summary-buf)
+           (setq num (wl-summary-message-number))
+           (setq entity (assoc (cdr (assq num
+                                          (elmo-msgdb-get-number-alist
+                                           wl-summary-buffer-msgdb)))
+                               (elmo-msgdb-get-overview
+                                wl-summary-buffer-msgdb)))
+           (and entity
+                (setq subject
+                      (or (elmo-msgdb-overview-entity-get-subject entity)
+                          "")))))
+      (wl-draft-forward subject summary-buf)
+      (unless without-setup-hook
+       (run-hooks 'wl-mail-setup-hook)))))
 
 (defun wl-summary-click (e)
   (interactive "e")
@@ -5048,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))
@@ -5072,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))
@@ -5104,18 +5248,20 @@ Reply to author if invoked with argument."
          (if wl-summary-buffer-disp-msg
              (wl-summary-redisplay)))
       (if (or interactive (interactive-p))
-         (progn
+         (if wl-summary-buffer-prev-folder-func
+             (funcall wl-summary-buffer-prev-folder-func)
            (when wl-auto-select-next
              (setq next-entity (wl-summary-get-prev-folder))
              (if next-entity
                  (setq finfo (wl-folder-get-entity-info next-entity))))
-           (wl-ask-folder 
+           (wl-ask-folder
             '(lambda () (wl-summary-next-folder-or-exit next-entity))
             (format
              "No more messages. Type SPC to go to %s."
              (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))
@@ -5133,7 +5279,7 @@ Reply to author if invoked with argument."
                          wl-summary-buffer-number-regexp
                          skip-mark-regexp
                          (regexp-quote wl-summary-unread-cached-mark)
-                         (regexp-quote wl-summary-important-mark))))    
+                         (regexp-quote wl-summary-important-mark))))
     (unless (re-search-forward regex nil t)
       (forward-line 1)
       (setq goto-next t))
@@ -5142,18 +5288,20 @@ Reply to author if invoked with argument."
        (if wl-summary-buffer-disp-msg
            (wl-summary-redisplay))
       (if (or interactive (interactive-p))
-         (progn
+         (if wl-summary-buffer-next-folder-func
+             (funcall wl-summary-buffer-next-folder-func)
            (when wl-auto-select-next
              (setq next-entity (wl-summary-get-next-folder))
              (if next-entity
                  (setq finfo (wl-folder-get-entity-info next-entity))))
-           (wl-ask-folder 
+           (wl-ask-folder
             '(lambda () (wl-summary-next-folder-or-exit next-entity))
             (format
              "No more messages. Type SPC to go to %s."
              (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))
@@ -5162,20 +5310,22 @@ Reply to author if invoked with argument."
          (wl-summary-redisplay))
     (if (or interactive
            (interactive-p))
-       (let (next-entity finfo)
-         (when wl-auto-select-next
-           (progn
-             (setq next-entity (wl-summary-get-prev-unread-folder))
-             (if next-entity
-                 (setq finfo (wl-folder-get-entity-info next-entity)))))
-         (if (and skip-no-unread
-                  (eq wl-auto-select-next 'skip-no-unread))
-             (wl-summary-next-folder-or-exit next-entity t)
-           (wl-ask-folder 
-            '(lambda () (wl-summary-next-folder-or-exit next-entity t))
-            (format
-             "No more unread messages. Type SPC to go to %s."
-             (wl-summary-entity-info-msg next-entity finfo))))))))
+       (if wl-summary-buffer-prev-folder-func
+           (funcall wl-summary-buffer-prev-folder-func)
+         (let (next-entity finfo)
+           (when wl-auto-select-next
+             (progn
+               (setq next-entity (wl-summary-get-prev-unread-folder))
+               (if next-entity
+                   (setq finfo (wl-folder-get-entity-info next-entity)))))
+           (if (and skip-no-unread
+                    (eq wl-auto-select-next 'skip-no-unread))
+               (wl-summary-next-folder-or-exit next-entity t)
+             (wl-ask-folder
+              '(lambda () (wl-summary-next-folder-or-exit next-entity t))
+              (format
+               "No more unread messages. Type SPC to go to %s."
+               (wl-summary-entity-info-msg next-entity finfo)))))))))
 
 (defun wl-summary-get-prev-folder ()
   (let ((folder-buf (get-buffer wl-folder-buffer-name))
@@ -5218,24 +5368,26 @@ Reply to author if invoked with argument."
          (wl-summary-redisplay))
     (if (or interactive
            (interactive-p))
-       (let (next-entity finfo)
-         (when wl-auto-select-next
-           (setq next-entity (wl-summary-get-next-unread-folder))
+       (if wl-summary-buffer-next-folder-func
+           (funcall wl-summary-buffer-next-folder-func)
+         (let (next-entity finfo)
+           (when wl-auto-select-next
+             (setq next-entity (wl-summary-get-next-unread-folder)))
            (if next-entity
-               (setq finfo (wl-folder-get-entity-info next-entity))))
-         (if (and skip-no-unread
-                  (eq wl-auto-select-next 'skip-no-unread))
-             (wl-summary-next-folder-or-exit next-entity)
-           (wl-ask-folder 
-            '(lambda () (wl-summary-next-folder-or-exit next-entity))
-            (format
-             "No more unread messages. Type SPC to go to %s."
-             (wl-summary-entity-info-msg next-entity finfo))))))))
+               (setq finfo (wl-folder-get-entity-info next-entity)))
+           (if (and skip-no-unread
+                    (eq wl-auto-select-next 'skip-no-unread))
+               (wl-summary-next-folder-or-exit next-entity)
+             (wl-ask-folder
+              '(lambda () (wl-summary-next-folder-or-exit next-entity))
+              (format
+               "No more unread messages. Type SPC to go to %s."
+               (wl-summary-entity-info-msg next-entity finfo)))))))))
 
 (defun wl-summary-goto-last-displayed-msg ()
   (interactive)
   (unless wl-summary-buffer-last-displayed-msg
-    (setq wl-summary-buffer-last-displayed-msg 
+    (setq wl-summary-buffer-last-displayed-msg
          wl-summary-buffer-current-msg))
   (if wl-summary-buffer-last-displayed-msg
       (progn
@@ -5258,41 +5410,53 @@ Reply to author if invoked with argument."
         (num (or number (wl-summary-message-number)))
         (wl-mime-charset      wl-summary-buffer-mime-charset)
         (default-mime-charset wl-summary-buffer-mime-charset)
-        (wl-message-redisplay-func 
+        (wl-message-redisplay-func
          wl-summary-buffer-message-redisplay-func)
         fld-buf fld-win thr-entity)
     (if (and wl-thread-open-reading-thread
             (eq wl-summary-buffer-view 'thread)
-            (not (wl-thread-entity-get-opened 
-                  (setq thr-entity (wl-thread-get-entity 
+            (not (wl-thread-entity-get-opened
+                  (setq thr-entity (wl-thread-get-entity
                                     num))))
             (wl-thread-entity-get-children thr-entity))
        (wl-thread-force-open))
     (if num
        (progn
          (setq wl-summary-buffer-disp-msg t)
-         (setq wl-summary-buffer-last-displayed-msg 
+         (setq wl-summary-buffer-last-displayed-msg
                wl-summary-buffer-current-msg)
          ;; hide folder window
          (if (and (not wl-stay-folder-window)
                   (setq fld-buf (get-buffer wl-folder-buffer-name)))
              (if (setq fld-win (get-buffer-window fld-buf))
-                 (delete-window fld-win)))       
+                 (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
                                           nil
                                         ;; plugged, then leave server-mark.
-                                        (if (elmo-folder-plugged-p
-                                             wl-summary-buffer-folder-name)
+                                        (if (and
+                                             (not
+                                              (elmo-folder-local-p
+                                               wl-summary-buffer-folder-name))
+                                             (elmo-folder-plugged-p
+                                              wl-summary-buffer-folder-name))
                                             'leave))
-                                      t) ;; displayed
+                                      t ; displayed
+                                      nil
+                                      'cached ; cached by reading.
+                                      )
            )
          (setq wl-summary-buffer-current-msg num)
-         (if wl-summary-recenter
-             (recenter (/ (- (window-height) 2) 2)))
+         (when wl-summary-recenter
+           (recenter (/ (- (window-height) 2) 2))
+           (if (not wl-summary-width)
+               (wl-horizontal-recenter)))
          (wl-highlight-summary-displaying)
          (wl-cache-prefetch-next fld num (current-buffer))
          (run-hooks 'wl-summary-redisplay-hook))
@@ -5304,17 +5468,23 @@ Reply to author if invoked with argument."
         (fld (or folder wl-summary-buffer-folder-name))
         (num (or number (wl-summary-message-number)))
         (wl-mime-charset      wl-summary-buffer-mime-charset)
-        (default-mime-charset wl-summary-buffer-mime-charset)   
+        (default-mime-charset wl-summary-buffer-mime-charset)
         wl-break-pages)
     (if num
        (progn
          (setq wl-summary-buffer-disp-msg t)
+         (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)
-         (if wl-summary-recenter
-             (recenter (/ (- (window-height) 2) 2)))
+         (when wl-summary-recenter
+           (recenter (/ (- (window-height) 2) 2))
+           (if (not wl-summary-width)
+               (wl-horizontal-recenter)))
          (wl-highlight-summary-displaying)
          (run-hooks 'wl-summary-redisplay-hook))
       (message "No message to display.")
@@ -5327,15 +5497,27 @@ Reply to author if invoked with argument."
         (fld (or folder wl-summary-buffer-folder-name))
         (num (or number (wl-summary-message-number)))
         (wl-mime-charset      wl-summary-buffer-mime-charset)
-        (default-mime-charset wl-summary-buffer-mime-charset)   
+        (default-mime-charset wl-summary-buffer-mime-charset)
         (wl-message-redisplay-func wl-summary-buffer-message-redisplay-func))
     (if num
        (progn
-         (if (wl-message-redisplay fld num 'all-header msgdb); t if displayed.
+         (setq wl-summary-buffer-disp-msg t)
+         (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
+                                   ;; 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
+           (recenter (/ (- (window-height) 2) 2))
+           (if (not wl-summary-width)
+               (wl-horizontal-recenter)))
+         (wl-highlight-summary-displaying)
          (run-hooks 'wl-summary-redisplay-hook))
       (message "No message to display."))))
-        
+
 (defun wl-summary-jump-to-current-message ()
   (interactive)
   (let (message-buf message-win)
@@ -5350,71 +5532,87 @@ Reply to author if invoked with argument."
 (defun wl-summary-cancel-message ()
   "Cancel an article on news."
   (interactive)
-  (let ((summary-buf (current-buffer))
-       message-buf)
-    (wl-summary-set-message-buffer-or-redisplay)
-    (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"))
-    (when (yes-or-no-p "Do you really want to cancel this article? ")
-      (let (from newsgroups message-id distribution buf)
-       (save-excursion
-         (setq from (std11-field-body "from")
-               newsgroups (std11-field-body "newsgroups")
-               message-id (std11-field-body "message-id")
-               distribution (std11-field-body "distribution"))
-         ;; Make sure that this article was written by the user.
-         (unless (wl-address-user-mail-address-p 
-                  (wl-address-header-extract-address
-                   (car (wl-parse-addresses from))))
-           (error "This article is not yours"))
-         ;; Make control message.
-         (setq buf (set-buffer (get-buffer-create " *message cancel*")))
-         (setq wl-draft-buffer-cur-summary-buffer summary-buf)
-         (buffer-disable-undo (current-buffer))
-         (erase-buffer)
-         (insert "Newsgroups: " newsgroups "\n"
-                 "From: " (wl-address-header-extract-address
-                           wl-from) "\n"
-                           "Subject: cmsg cancel " message-id "\n"
-                           "Control: cancel " message-id "\n"
-                           (if distribution
-                               (concat "Distribution: " distribution "\n")
-                             "")
-                           mail-header-separator "\n"
-                           wl-summary-cancel-message)
-         (message "Canceling your message...")
-         (wl-draft-raw-send t t) ; kill when done, force-pre-hooks.
-         (message "Canceling your message...done"))))))
+  (if (null (wl-summary-message-number))
+      (message "No message.")
+    (let ((summary-buf (current-buffer))
+         message-buf)
+      (wl-summary-set-message-buffer-or-redisplay)
+      (if (setq message-buf (wl-message-get-original-buffer))
+         (set-buffer message-buf))
+      (unless (wl-message-news-p)
+       (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
+           (setq from (std11-field-body "from")
+                 newsgroups (std11-field-body "newsgroups")
+                 message-id (std11-field-body "message-id")
+                 distribution (std11-field-body "distribution"))
+           ;; Make sure that this article was written by the user.
+           (unless (wl-address-user-mail-address-p
+                    (wl-address-header-extract-address
+                     (car (wl-parse-addresses from))))
+             (error "This article is not yours"))
+           ;; Make control message.
+           (setq buf (set-buffer (get-buffer-create " *message cancel*")))
+           (setq wl-draft-buffer-cur-summary-buffer summary-buf)
+           (buffer-disable-undo (current-buffer))
+           (erase-buffer)
+           (insert "Newsgroups: " newsgroups "\n"
+                   "From: " (wl-address-header-extract-address
+                             wl-from) "\n"
+                             "Subject: cmsg cancel " message-id "\n"
+                             "Control: cancel " message-id "\n"
+                             (if distribution
+                                 (concat "Distribution: " distribution "\n")
+                               "")
+                             mail-header-separator "\n"
+                             wl-summary-cancel-message)
+           (message "Canceling your message...")
+           (wl-draft-raw-send t t) ; kill when done, force-pre-hooks.
+           (message "Canceling your message...done")))))))
 
 (defun wl-summary-supersedes-message ()
   "Supersede current message."
   (interactive)
   (let ((summary-buf (current-buffer))
-       (mmelmo-force-fetch-entire-message t)
-       message-buf from)
+       (mmelmo-force-fetch-entire-message t)
+       message-buf from)
     (wl-summary-set-message-buffer-or-redisplay)
     (if (setq message-buf (wl-message-get-original-buffer))
-       (set-buffer message-buf))
+       (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.
-      (unless (wl-address-user-mail-address-p 
+      (unless (wl-address-user-mail-address-p
               (wl-address-header-extract-address
                (car (wl-parse-addresses from))))
-       (error "This article is not yours"))
+       (error "This article is not yours"))
       (let* ((message-id (std11-field-body "message-id"))
-            (followup-to (std11-field-body "followup-to"))
-            (mail-default-headers
-             (concat mail-default-headers
-                     "Supersedes: " message-id "\n"
-                     (and followup-to
-                          (concat "Followup-To: " followup-to "\n")))))
-       (set-buffer (wl-message-get-original-buffer))
-       (wl-draft-edit-string (buffer-substring (point-min) (point-max)))))))
+            (followup-to (std11-field-body "followup-to"))
+            (mail-default-headers
+             (concat mail-default-headers
+                     "Supersedes: " message-id "\n"
+                     (and followup-to
+                          (concat "Followup-To: " followup-to "\n")))))
+       (set-buffer (wl-message-get-original-buffer))
+       (wl-draft-edit-string (buffer-substring (point-min) (point-max)))))))
 
 (defun wl-summary-save (&optional arg wl-save-dir)
   (interactive)
@@ -5432,11 +5630,11 @@ Reply to author if invoked with argument."
                         (null (file-exists-p filename))))
              (setq filename
                    (read-file-name "Save to file: " filename)))
-                                
+
          (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."))
@@ -5469,83 +5667,90 @@ Reply to author if invoked with argument."
 ;; mew-summary-pipe-message()
 (defun wl-summary-pipe-message (prefix command)
   "Send this message via pipe."
-  (interactive
-   (list current-prefix-arg
-        (read-string "Shell command on message: " wl-summary-shell-command-last)))
-  (if (y-or-n-p "Send this message to pipe? ")
-      (save-excursion
-       (wl-summary-set-message-buffer-or-redisplay)
-       (set-buffer (wl-message-get-original-buffer))
-       (if (string= command "")
-           (setq command wl-summary-shell-command-last))
-       (goto-char (point-min)) ; perhaps this line won't be necessary
-       (if prefix
-           (search-forward "\n\n"))
-       (shell-command-on-region (point) (point-max) command nil)
-       (setq wl-summary-shell-command-last command))))
+  (interactive (list current-prefix-arg nil))
+  (if (null (wl-summary-message-number))
+      (message "No message.")
+    (setq command (read-string "Shell command on message: "
+                              wl-summary-shell-command-last))
+    (if (y-or-n-p "Send this message to pipe? ")
+       (save-excursion
+         (wl-summary-set-message-buffer-or-redisplay)
+         (set-buffer (wl-message-get-original-buffer))
+         (if (string= command "")
+             (setq command wl-summary-shell-command-last))
+         (goto-char (point-min)) ; perhaps this line won't be necessary
+         (if prefix
+             (search-forward "\n\n"))
+         (shell-command-on-region (point) (point-max) command nil)
+         (setq wl-summary-shell-command-last command)))))
 
 (defun wl-summary-print-message (&optional arg)
   (interactive "P")
-  (save-excursion
-    (wl-summary-set-message-buffer-or-redisplay)
+  (if (null (wl-summary-message-number))
+      (message "No message.")
+    (save-excursion
+      (wl-summary-set-message-buffer-or-redisplay)
+      (if (or (not (interactive-p))
+             (y-or-n-p "Print ok? "))
+         (progn
+           (let* ((message-buffer (get-buffer wl-message-buf-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))
+             (set-buffer buffer)
+             (funcall wl-print-buffer-func)
+             (kill-buffer buffer)))
+       (message "")))))
+
+(defun wl-summary-print-message-with-ps-print (&optional filename)
+  (interactive)
+  (if (null (wl-summary-message-number))
+      (message "No message.")
+    (setq filename (ps-print-preprint current-prefix-arg))
     (if (or (not (interactive-p))
-           (y-or-n-p "Print ok?"))
-       (progn
-         (let* ((message-buffer (get-buffer wl-message-buf-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))
-           (set-buffer buffer)
-           (funcall wl-print-buffer-func)
-           (kill-buffer buffer)))
+           (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-redisplay-internal)
+           (let* ((message-buffer (get-buffer wl-message-buf-name))
+                  (buffer (generate-new-buffer " *print*"))
+                  (entity (progn
+                            (set-buffer summary-buffer)
+                            (assoc (cdr (assq
+                                         (wl-summary-message-number)
+                                         (elmo-msgdb-get-number-alist
+                                          wl-summary-buffer-msgdb)))
+                                   (elmo-msgdb-get-overview
+                                    wl-summary-buffer-msgdb))))
+                  (wl-ps-subject
+                   (and entity
+                        (or (elmo-msgdb-overview-entity-get-subject entity)
+                            "")))
+                  (wl-ps-from
+                   (and entity
+                        (or (elmo-msgdb-overview-entity-get-from entity) "")))
+                  (wl-ps-date
+                   (and entity
+                        (or (elmo-msgdb-overview-entity-get-date entity) ""))))
+             (run-hooks 'wl-ps-preprint-hook)
+             (set-buffer message-buffer)
+             (copy-to-buffer buffer (point-min) (point-max))
+             (set-buffer buffer)
+             (unwind-protect
+                 (let ((ps-left-header
+                        (list (concat "(" wl-ps-subject ")")
+                              (concat "(" wl-ps-from ")")))
+                       (ps-right-header
+                        (list "/pagenumberstring load"
+                              (concat "(" wl-ps-date ")"))))
+                   (run-hooks 'wl-ps-print-hook)
+                   (funcall wl-ps-print-buffer-func filename))
+               (kill-buffer buffer)))))
       (message ""))))
 
-(defun wl-summary-print-message-with-ps-print (&optional filename)
-  (interactive (list (ps-print-preprint current-prefix-arg)))
-  (if (or (not (interactive-p))
-         (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-redisplay-internal)
-         (let* ((message-buffer (get-buffer wl-message-buf-name))
-                (buffer (generate-new-buffer " *print*"))
-                (entity (progn
-                          (set-buffer summary-buffer)
-                          (assoc (cdr (assq 
-                                       (wl-summary-message-number)
-                                       (elmo-msgdb-get-number-alist 
-                                        wl-summary-buffer-msgdb)))
-                                 (elmo-msgdb-get-overview 
-                                  wl-summary-buffer-msgdb))))
-                (wl-ps-subject
-                 (and entity
-                      (or (elmo-msgdb-overview-entity-get-subject entity) 
-                          "")))
-                (wl-ps-from
-                 (and entity
-                      (or (elmo-msgdb-overview-entity-get-from entity) "")))
-                (wl-ps-date
-                 (and entity
-                      (or (elmo-msgdb-overview-entity-get-date entity) ""))))
-           (run-hooks 'wl-ps-preprint-hook)
-           (set-buffer message-buffer)
-           (copy-to-buffer buffer (point-min) (point-max))
-           (set-buffer buffer)
-           (unwind-protect
-               (let ((ps-left-header
-                      (list (concat "(" wl-ps-subject ")")
-                            (concat "(" wl-ps-from ")")))
-                     (ps-right-header 
-                      (list "/pagenumberstring load" 
-                            (concat "(" wl-ps-date ")"))))
-                 (run-hooks 'wl-ps-print-hook)
-                 (funcall wl-ps-print-buffer-func filename))
-             (kill-buffer buffer)))))
-    (message "")))
-  
 (if (featurep 'ps-print) ; ps-print is available.
     (fset 'wl-summary-print-message 'wl-summary-print-message-with-ps-print))
 
@@ -5555,7 +5760,7 @@ Reply to author if invoked with argument."
                 wl-summary-buffer-msgdb)))
     (wl-folder-set-folder-updated folder
                                  (list 0
-                                       (+ wl-summary-buffer-unread-count 
+                                       (+ wl-summary-buffer-unread-count
                                           wl-summary-buffer-new-count)
                                        (length num-db)))))
 
@@ -5588,8 +5793,8 @@ Reply to author if invoked with argument."
               (ng-list (wl-summary-get-newsgroups)) ;; for multi folder
               crosspost-folders)
          (when (setq crosspost-folders
-                     (elmo-delete-lists ng-list
-                                        (wl-parse-newsgroups newsgroups t)))
+                     (elmo-list-delete ng-list
+                                       (wl-parse-newsgroups newsgroups t)))
            (elmo-crosspost-message-set (cdr (assq number num-db)) ;;message-id
                                        crosspost-folders
                                        type) ;;not used
@@ -5605,7 +5810,7 @@ Reply to author if invoked with argument."
     flds))
 
 (defun wl-summary-update-crosspost ()
-  (let* ((msgdb wl-summary-buffer-msgdb) 
+  (let* ((msgdb wl-summary-buffer-msgdb)
         (number-alist (elmo-msgdb-get-number-alist msgdb))
         (mark-alist (elmo-msgdb-get-mark-alist msgdb))
         (spec-list (elmo-folder-get-primitive-spec-list
@@ -5627,7 +5832,7 @@ Reply to author if invoked with argument."
                (setq crossed (1+ crossed)))
            (if (wl-summary-jump-to-msg num)
                (wl-summary-mark-as-read t);; opened
-             (wl-thread-msg-mark-as-read num)));; closed
+             (wl-summary-mark-as-read t nil nil num)));; closed
          ;; delete if message does't exists.
          (elmo-crosspost-message-delete (caar alist) ngs)
          (setq wl-crosspost-alist-modified t))
@@ -5663,7 +5868,8 @@ Reply to author if invoked with argument."
   (setq wl-summary-buffer-msgdb
        (elmo-pack-number
         wl-summary-buffer-folder-name wl-summary-buffer-msgdb arg))
-  (wl-summary-rescan))
+  (let (wl-use-scoring)
+    (wl-summary-rescan)))
 
 (defun wl-summary-target-mark-uudecode ()
   (interactive)
@@ -5683,9 +5889,11 @@ Reply to author if invoked with argument."
        (set-buffer (setq orig-buf (wl-message-get-original-buffer)))
        (goto-char (point-min))
        (cond ((= i 1) ; first
-              (setq filename (wl-message-uu-substring 
-                              orig-buf tmp-buf t 
-                              (= i k))))
+              (if (setq filename (wl-message-uu-substring
+                                  orig-buf tmp-buf t
+                                  (= i k)))
+                  nil
+                (error "Can't find begin line")))
              ((< i k)
               (wl-message-uu-substring orig-buf tmp-buf))
              (t ; last
@@ -5706,7 +5914,7 @@ Reply to author if invoked with argument."
                                            wl-tmp-dir))
              (setq filename (expand-file-name filename decode-dir)))
            (if (file-exists-p filename)
-               (or (yes-or-no-p (format "File %s exists. Save anyway? " 
+               (or (yes-or-no-p (format "File %s exists. Save anyway? "
                                         filename))
                    (error "")))
            (elmo-bind-directory
@@ -5718,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
@@ -5737,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))
@@ -5751,9 +5959,9 @@ Reply to author if invoked with argument."
            (incf multi-num)
            (setcar pair (+ (* multi-num elmo-multi-divide-number)
                            (car pair))))
-         (elmo-msgdb-set-number-alist 
-          wl-summary-buffer-msgdb 
-          (nconc 
+         (elmo-msgdb-set-number-alist
+          wl-summary-buffer-msgdb
+          (nconc
            (elmo-msgdb-get-number-alist wl-summary-buffer-msgdb)
            (list (cons (car pair) nil))))
          (setq sum (+ sum (cdr pair)))
@@ -5761,28 +5969,19 @@ Reply to author if invoked with argument."
        (wl-summary-set-message-modified)
        (wl-folder-set-folder-updated wl-summary-buffer-folder-name
                                      (list 0
-                                           (+ wl-summary-buffer-unread-count 
+                                           (+ 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)
@@ -5801,13 +6000,13 @@ Reply to author if invoked with argument."
        (t
         wl-cache-prefetch-folder-list)))
 
-(defconst wl-cache-prefetch-idle-time 
+(defconst wl-cache-prefetch-idle-time
   (if (featurep 'lisp-float-type) (/ (float 1) (float 10)) 1))
 
 (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)))
@@ -5835,7 +6034,7 @@ Reply to author if invoked with argument."
                                      (elmo-msgdb-get-number-alist msgdb)))))
          (if (not (elmo-buffer-cache-hit (list folder next message-id)))
              (let* ((size (elmo-msgdb-overview-entity-get-size
-                           (assoc message-id 
+                           (assoc message-id
                                   (elmo-msgdb-get-overview msgdb)))))
                (when (or (elmo-local-file-p folder next)
                          (not (and (integerp size)
@@ -5845,10 +6044,32 @@ 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))))))))))
 
-(provide 'wl-summary)
+(defun wl-summary-save-current-message ()
+  "Save current message for `wl-summary-yank-saved-message'."
+  (interactive)
+  (let ((number (wl-summary-message-number)))
+    (setq wl-summary-buffer-saved-message number)
+    (and number (message "No: %s is saved." number))))
+
+(defun wl-summary-yank-saved-message ()
+  "Set current message as a parent of the saved message."
+  (interactive)
+  (if wl-summary-buffer-saved-message
+      (let ((number (wl-summary-message-number)))
+       (if (eq wl-summary-buffer-saved-message number)
+           (message "Cannot set itself as a parent.")
+         (save-excursion
+           (wl-thread-jump-to-msg wl-summary-buffer-saved-message)
+           (wl-thread-set-parent number)
+           (wl-summary-set-thread-modified))
+         (setq  wl-summary-buffer-saved-message nil)))
+    (message "There's no saved message.")))
+
+(require 'product)
+(product-provide (provide 'wl-summary) (require 'wl-version))
 
 ;;; wl-summary.el ends here