* bbdb-wl.el (bbdb-wl-get-addresses-1): New function.
[elisp/wanderlust.git] / wl / wl-summary.el
index 97ed58c..b79ad6f 100644 (file)
     (if (eq major-mode 'wl-summary-mode)
        (setq wl-summary-buffer-new-count new
              wl-summary-buffer-unread-count unread))
-    (+ new unread)))
+    (cons new unread)))
 
 (defun wl-summary-message-string (&optional use-cache)
   "Return full body string of current message.
@@ -595,8 +595,8 @@ If ARG is non-nil, Supersedes message"
       (wl-summary-supersedes-message)
     (if (string= (wl-summary-buffer-folder-name) wl-draft-folder)
        (if (wl-summary-message-number)
-           (unwind-protect
-               (wl-draft-reedit (wl-summary-message-number))
+           (progn
+             (wl-draft-reedit (wl-summary-message-number))
              (if (wl-message-news-p)
                  (mail-position-on-field "Newsgroups")
                (mail-position-on-field "To"))
@@ -996,7 +996,7 @@ Entering Folder mode calls the value of `wl-summary-mode-hook'."
 
 ;; a subroutine for wl-summary-exit/wl-save-status
 ;; Note that folder is not commited here.
-(defun wl-summary-save-view (&optional sticky)
+(defun wl-summary-save-view ()
   ;; already in summary buffer.
   (when wl-summary-buffer-persistent
     ;; save the current summary buffer view.
@@ -1026,12 +1026,11 @@ Entering Folder mode calls the value of `wl-summary-mode-hook'."
       (unwind-protect
          ;; save summary status
          (progn
-           (if (or force-exit
-                   (not sticky))
+           (wl-summary-save-view)
+           (if (or force-exit (not sticky))
                (elmo-folder-close wl-summary-buffer-elmo-folder)
              (elmo-folder-commit wl-summary-buffer-elmo-folder)
              (elmo-folder-check wl-summary-buffer-elmo-folder))
-           (wl-summary-save-view sticky)
            (if wl-use-scoring (wl-score-save)))
        ;; for sticky summary
        (wl-delete-all-overlays)
@@ -1117,12 +1116,15 @@ Entering Folder mode calls the value of `wl-summary-mode-hook'."
                 wl-use-scoring)
             (wl-summary-rescan)
             (and msg (wl-summary-jump-to-msg msg))))
+         ((string= range "cache-status")
+          (let ((msg (wl-summary-message-number)))
+            (wl-summary-resume-cache-status)
+            (and msg (wl-summary-jump-to-msg msg))))
          ((or (string-match "last:" range)
               (string-match "first:" range))
-          (wl-summary-goto-folder-subr
-           (wl-folder-get-elmo-folder (concat "/" range "/"
-                                              (elmo-folder-name-internal
-                                               folder)))
+          (wl-summary-goto-folder-subr (concat "/" range "/"
+                                               (elmo-folder-name-internal
+                                                folder))
            'force-update nil nil t))
          (t
           (wl-summary-sync-update unset-cursor
@@ -1162,8 +1164,8 @@ Entering Folder mode calls the value of `wl-summary-mode-hook'."
   ;; returns nil if there's no change.
   (if (elmo-get-hash-val (downcase the-email) wl-address-petname-hash)
       (let (char)
-       (message (format "'%s' already exists. (e)dit/(d)elete/(c)ancel?"
-                        the-email))
+       (message "'%s' already exists. (e)dit/(d)elete/(c)ancel?"
+                the-email)
        (while (not (or (eq (setq char (read-char)) ?\r)
                        (eq char ?\n)
                        (eq char ? )
@@ -1269,68 +1271,69 @@ If ARG is non-nil, checking is omitted."
           (size (elmo-msgdb-overview-entity-get-size ov))
           (inhibit-read-only t)
           (buffer-read-only nil)
+          (file-cached (elmo-file-cache-exists-p message-id))
           (force-read (and size
                            (or (null wl-prefetch-threshold)
                                (< size wl-prefetch-threshold))))
           mark new-mark)
-      (if (or arg
-             (null (elmo-file-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-summary-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
-                       ;; online
+      (unwind-protect
+         (progn
+           (when (and (or arg (not file-cached))
+                      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-summary-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
+                   ;; online
+                   (if (or arg (not file-cached))
                        (elmo-message-encache
                         wl-summary-buffer-elmo-folder
-                        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)
-                              ((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))))))))
+                        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)
+                          ((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
@@ -2170,9 +2173,10 @@ If ARG is non-nil, checking is omitted."
       (wl-folder-set-folder-updated
        (elmo-folder-name-internal folder)
        (list 0
-            (wl-summary-count-unread
-             (elmo-msgdb-get-mark-alist
-              (elmo-folder-msgdb folder)))
+            (let ((pair (wl-summary-count-unread
+                         (elmo-msgdb-get-mark-alist
+                          (elmo-folder-msgdb folder)))))
+              (+ (car pair) (cdr pair)))
             (elmo-folder-messages folder)))
       (wl-summary-update-modeline)
       (wl-summary-buffer-number-column-detect t)
@@ -2474,11 +2478,13 @@ If ARG, without confirm."
 
 (defsubst wl-summary-open-folder (folder)
   ;; Select folder
-  (unwind-protect
-      (elmo-folder-open folder 'load-msgdb)
-    ;; For compatibility
-    (setq wl-summary-buffer-msgdb (elmo-folder-msgdb folder))
-    (setq wl-summary-buffer-folder-name (elmo-folder-name-internal folder))))
+  (let ((elmo-mime-charset wl-summary-buffer-mime-charset))
+    (unwind-protect
+       (elmo-folder-open folder 'load-msgdb)
+      ;; For compatibility
+      (setq wl-summary-buffer-msgdb (elmo-folder-msgdb folder))
+      (setq wl-summary-buffer-folder-name (elmo-folder-name-internal
+                                          folder)))))
 
 (defun wl-summary-goto-folder-subr (&optional name scan-type other-window
                                              sticky interactive scoring)
@@ -2494,14 +2500,13 @@ If ARG, without confirm."
        (setq name wl-default-folder))
     (setq folder (wl-folder-get-elmo-folder name))
     (when (and (not (string=
-                    (and cur-fld
-                         (elmo-folder-name-internal cur-fld))
+                    (and cur-fld (elmo-folder-name-internal cur-fld))
                     (elmo-folder-name-internal folder))) ; folder is moved.
               (eq major-mode 'wl-summary-mode)) ; called in summary.
       (setq wl-summary-last-visited-folder (wl-summary-buffer-folder-name))
       (run-hooks 'wl-summary-exit-pre-hook)
       (wl-summary-cleanup-temp-marks (wl-summary-sticky-p))
-      (wl-summary-save-view 'keep) ; keep current buffer, anyway.
+      (wl-summary-save-view)
       (elmo-folder-commit wl-summary-buffer-elmo-folder))
     (setq buf (wl-summary-get-buffer-create (elmo-folder-name-internal folder)
                                            sticky))
@@ -2596,6 +2601,11 @@ If ARG, without confirm."
                       ;; wl-auto-select-first is non-nil and
                       ;; unreadp is non-nil but not important
                       (setq retval 'disp-msg))
+                     ((and wl-auto-prefetch-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 'prefetch-msg))
                      ((not (wl-summary-auto-select-msg-p unreadp))
                       ;; unreadp is nil or important
                       (setq retval 'more-next))))
@@ -2621,6 +2631,13 @@ If ARG, without confirm."
                (wl-highlight-summary (point-min) (point-max))))
          (if (eq retval 'disp-msg)
              (wl-summary-redisplay))
+         (if (eq retval 'prefetch-msg)
+             (wl-message-buffer-prefetch
+              folder
+              (wl-summary-message-number)
+              wl-message-buffer-prefetch-depth
+              (current-buffer)
+              wl-summary-buffer-mime-charset))
          (if mes (message "%s" mes))
          (if (and interactive wl-summary-recenter)
              (recenter (/ (- (window-height) 2) 2))))))
@@ -3284,7 +3301,6 @@ If optional argument NUMBER is specified, mark message specified by 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
@@ -3671,10 +3687,12 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
 
 (defun wl-summary-pick (&optional from-list delete-marks)
   (interactive)
-  (let ((result (elmo-msgdb-search
-                wl-summary-buffer-elmo-folder
-                (elmo-read-search-condition wl-summary-pick-field-default)
-                (wl-summary-buffer-msgdb))))
+  (let* ((condition (car (elmo-parse-search-condition
+                         (elmo-read-search-condition
+                          wl-summary-pick-field-default))))
+        (result (elmo-folder-search wl-summary-buffer-elmo-folder
+                                    condition
+                                    from-list)))
     (if delete-marks
       (let ((mlist wl-summary-buffer-target-mark-list))
        (while mlist
@@ -3682,12 +3700,11 @@ If optional argument NUMBER is specified, mark message specified by NUMBER."
            (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))))
+    (if result
+       (progn
+         (wl-summary-target-mark-msgs result)
+         (message "%d message(s) are picked." (length result)))
+      (message "No message was picked."))))
 
 (defun wl-summary-unvirtual ()
   "Exit from current virtual folder."
@@ -3966,7 +3983,8 @@ If ARG, exit virtual folder."
   (save-excursion
     (goto-char (point-min))
     (let ((wl-save-dir
-          (wl-read-directory-name "Save to directory: " wl-tmp-dir))
+          (wl-read-directory-name "Save to directory: "
+                                  wl-temporary-file-directory))
          (regexp (concat "^" wl-summary-buffer-number-regexp "\\(\\*\\)"))
          number mlist)
       (if (null (file-exists-p wl-save-dir))
@@ -4413,6 +4431,7 @@ If ARG, exit virtual 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:"
+                           "cache-status"
                            "no-sync" "rescan-noscore" "all-visible"))
        (default (or (wl-get-assoc-list-value
                      wl-folder-sync-range-alist
@@ -5214,7 +5233,9 @@ Use function list is `wl-summary-write-current-folder-functions'."
            (if (not wl-summary-indent-length-limit)
                (wl-horizontal-recenter)))
          (wl-highlight-summary-displaying)
-         (wl-message-buffer-prefetch-next folder num (current-buffer)
+         (wl-message-buffer-prefetch-next folder num
+                                          wl-message-buffer-prefetch-depth
+                                          (current-buffer)
                                           wl-summary-buffer-mime-charset)
          (run-hooks 'wl-summary-redisplay-hook))
       (message "No message to display."))))
@@ -5361,7 +5382,7 @@ Use function list is `wl-summary-write-current-folder-functions'."
                      "Supersedes: " message-id "\n"
                      (and followup-to
                           (concat "Followup-To: " followup-to "\n")))))
-    (if message-buf (set-buffer message-buf))
+       (if message-buf (set-buffer message-buf))
        (wl-draft-edit-string (buffer-substring (point-min) (point-max)))))))
 
 (defun wl-summary-save (&optional arg wl-save-dir)
@@ -5369,7 +5390,7 @@ Use function list is `wl-summary-write-current-folder-functions'."
   (let ((filename)
        (num (wl-summary-message-number)))
     (if (null wl-save-dir)
-       (setq wl-save-dir wl-tmp-dir))
+       (setq wl-save-dir wl-temporary-file-directory))
     (if num
        (save-excursion
          (setq filename (expand-file-name
@@ -5396,7 +5417,8 @@ Use function list is `wl-summary-write-current-folder-functions'."
       (narrow-to-region beg end)
       (goto-char (point-min))
       (let ((wl-save-dir
-            (wl-read-directory-name "Save to directory: " wl-tmp-dir)))
+            (wl-read-directory-name "Save to directory: "
+                                    wl-temporary-file-directory)))
        (if (null (file-exists-p wl-save-dir))
            (make-directory wl-save-dir))
        (if (eq wl-summary-buffer-view 'thread)
@@ -5553,15 +5575,15 @@ Use function list is `wl-summary-write-current-folder-functions'."
       (set-buffer tmp-buf)
       (message "Exec %s..." wl-prog-uudecode)
       (unwind-protect
-         (let ((decode-dir wl-tmp-dir))
+         (let ((decode-dir wl-temporary-file-directory))
            (if (not wl-prog-uudecode-no-stdout-option)
                (setq filename (read-file-name "Save to file: "
                                               (expand-file-name
                                                (elmo-safe-filename filename)
-                                               wl-tmp-dir)))
+                                               wl-temporary-file-directory)))
              (setq decode-dir
                    (wl-read-directory-name "Save to directory: "
-                                           wl-tmp-dir))
+                                           wl-temporary-file-directory))
              (setq filename (expand-file-name filename decode-dir)))
            (if (file-exists-p filename)
                (or (yes-or-no-p (format "File %s exists. Save anyway? "