* wl-vars.el (wl-folder-use-frame): New user option.
[elisp/wanderlust.git] / wl / wl-folder.el
index cdc3dde..7afc18d 100644 (file)
@@ -1,7 +1,7 @@
 ;;; wl-folder.el -- Folder mode for Wanderlust.
 
-;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
-;;                          Masahiro MURATA <muse@ba2.so-net.ne.jp>
+;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
+;; Copyright (C) 1998,1999,2000 Masahiro MURATA <muse@ba2.so-net.ne.jp>
 
 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
 ;;     Masahiro MURATA <muse@ba2.so-net.ne.jp>
   (define-key wl-folder-mode-map "g"    'wl-folder-goto-folder)
   (define-key wl-folder-mode-map "j"    'wl-folder-jump-to-current-entity)
   (define-key wl-folder-mode-map "w"    'wl-draft)
-  (define-key wl-folder-mode-map "W"    'wl-folder-write-current-newsgroup)
+  (define-key wl-folder-mode-map "W"    'wl-folder-write-current-folder)
   (define-key wl-folder-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
   (define-key wl-folder-mode-map "rS"   'wl-folder-sync-region)
   (define-key wl-folder-mode-map "S"    'wl-folder-sync-current-entity)
@@ -840,7 +840,7 @@ Optional argument ARG is repeart count."
                                             (elmo-msgdb-expand-path entity))
                                            entity)))
                                         (cdr nums))
-                                  (current-buffer)))
+                                  (get-buffer wl-folder-buffer-name)))
     (setq wl-folder-info-alist-modified t)
     (sit-for 0)
     (list (if wl-folder-notify-deleted
@@ -981,12 +981,17 @@ If current line is group folder, check all sub entries."
       (setq unread (or (cadr nums) 0))
       (if (or (not unread-only)
              (or (< 0 new) (< 0 unread)))
-         (save-window-excursion
-           (save-excursion
-             (wl-summary-goto-folder-subr entity
-                                          (wl-summary-get-sync-range entity)
-                                          nil nil nil t)
-             (wl-summary-exit))))))))
+         (let ((wl-summary-buffer-name (concat
+                                        wl-summary-buffer-name
+                                        (symbol-name this-command)))
+               (wl-message-buf-name (concat wl-message-buf-name
+                                            (symbol-name this-command))))
+           (save-window-excursion
+             (save-excursion
+               (wl-summary-goto-folder-subr entity
+                                            (wl-summary-get-sync-range entity)
+                                            nil nil nil t)
+               (wl-summary-exit)))))))))
 
 (defun wl-folder-sync-current-entity (&optional unread-only)
   "Synchronize the folder at position.
@@ -1023,13 +1028,18 @@ If current line is group folder, check all subfolders."
       (setq new (or (car nums) 0))
       (setq unread (or (cadr nums) 0))
       (if (or (< 0 new) (< 0 unread))
-       (save-window-excursion
-         (save-excursion
-           (wl-summary-goto-folder-subr entity
-                                        (wl-summary-get-sync-range entity)
-                                        nil)
-           (wl-summary-mark-as-read-all)
-           (wl-summary-exit)))
+         (let ((wl-summary-buffer-name (concat
+                                        wl-summary-buffer-name
+                                        (symbol-name this-command)))
+               (wl-message-buf-name (concat wl-message-buf-name
+                                            (symbol-name this-command))))
+           (save-window-excursion
+             (save-excursion
+               (wl-summary-goto-folder-subr entity
+                                          (wl-summary-get-sync-range entity)
+                                          nil)
+               (wl-summary-mark-as-read-all)
+               (wl-summary-exit))))
        (sit-for 0))))))
 
 (defun wl-folder-mark-as-read-all-current-entity ()
@@ -1276,19 +1286,21 @@ If current line is group folder, all subfolders are marked."
 
 (defun wl-folder-select-buffer (buffer)
   (let ((gbw (get-buffer-window buffer))
-       ret-val)
+       exists)
     (if gbw
        (progn (select-window gbw)
-              (setq ret-val t))
-      (condition-case ()
-         (unwind-protect
-             (split-window-horizontally wl-folder-window-width)
-           (other-window 1))
-       (error nil)))
+              (setq exists t))
+      (unless wl-folder-use-frame
+       (condition-case ()
+           (unwind-protect
+               (split-window-horizontally wl-folder-window-width)
+             (other-window 1))
+         (error nil))))
     (set-buffer buffer)
-    (switch-to-buffer buffer)
-    ret-val
-    ))
+    (if wl-folder-use-frame
+       (switch-to-buffer-other-frame buffer)
+      (switch-to-buffer buffer))
+    exists))
 
 (defun wl-folder-toggle-disp-summary (&optional arg folder)
   (interactive)
@@ -1386,7 +1398,7 @@ If current line is group folder, all subfolders are marked."
 
 (defun wl-folder-mode ()
   "Major mode for Wanderlust Folder.
-See info under Wanderlust for full documentation.
+See Info under Wanderlust for full documentation.
 
 Special commands:
 \\{wl-folder-mode-map}
@@ -1952,9 +1964,6 @@ Entering Folder mode calls the value of `wl-folder-mode-hook'."
                        wl-nntp-posting-server
                        elmo-default-nntp-port
                        nil nil "nntp" add))
-    ;; This hook may contain the functions `wl-plugged-init-icons' and
-    ;; `wl-biff-init-icons' for reasons of system internal to accord
-    ;; facilities for the Emacs variants.
     (run-hooks 'wl-make-plugged-hook)))
 
 (defvar wl-folder-init-func 'wl-local-folder-init)
@@ -2005,6 +2014,72 @@ Entering Folder mode calls the value of `wl-folder-mode-hook'."
       (setq alist (cdr alist)))
     hashtb))
 
+(defun wl-folder-get-newsgroups (folder)
+  "Return Newsgroups field value string for FOLDER newsgroup.
+If FOLDER is multi, return comma separated string (cross post)."
+  (let ((flist (elmo-folder-get-primitive-folder-list folder)) ; multi
+       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)) "/" "\\."))))
+         ;; append newsgroup
+         (setq newsgroups (if (stringp newsgroups)
+                              (concat newsgroups "," ret)
+                            ret)))
+      (setq flist (cdr flist)))
+    (list nil nil newsgroups)))
+
+(defun wl-folder-guess-mailing-list-by-refile-rule (folder)
+  "Return ML address guess by FOLDER.
+Use `wl-subscribed-mailing-list' and `wl-refile-rule-alist'.
+Don't care multi."
+  (setq folder (car (elmo-folder-get-primitive-folder-list folder)))
+  (unless (memq (elmo-folder-get-type folder)
+               '(localnews nntp))
+    (let ((rules wl-refile-rule-alist)
+         mladdress tokey toalist histkey)
+      (while rules
+       (if (or (and (stringp (car (car rules)))
+                    (string-match "[Tt]o" (car (car rules))))
+               (and (listp (car (car rules)))
+                    (elmo-string-matched-member "to" (car (car rules))
+                                                'case-ignore)))
+           (setq toalist (append toalist (cdr (car rules)))))
+       (setq rules (cdr rules)))
+      (setq tokey (car (rassoc folder toalist)))
+;;;     (setq histkey (car (rassoc folder wl-refile-alist)))
+      ;; case-ignore search `wl-subscribed-mailing-list'
+      (if (stringp tokey)
+         (list
+          (elmo-string-matched-member tokey wl-subscribed-mailing-list t)
+          nil nil)
+       nil))))
+
+(defun wl-folder-guess-mailing-list-by-folder-name (folder)
+  "Return ML address guess by FOLDER name's last hierarchy.
+Use `wl-subscribed-mailing-list'."
+  (setq folder (car (elmo-folder-get-primitive-folder-list folder)))
+  (when (memq (elmo-folder-get-type folder)
+             '(localdir imap4 maildir))
+    (let (key mladdress)
+      (setq folder                     ; make folder name simple
+           (if (eq 'imap4 (elmo-folder-get-type folder))
+               (elmo-imap4-spec-mailbox (elmo-imap4-get-spec folder))
+             (substring folder 1)))
+      (when (string-match "[^\\./]+$" folder) ; last hierarchy
+       (setq key (regexp-quote
+                  (concat (substring folder (match-beginning 0)) "@")))
+       (setq mladdress
+             (elmo-string-matched-member
+              key wl-subscribed-mailing-list 'case-ignore))
+       (if (stringp mladdress)
+           (list mladdress nil nil)
+         nil)))))
+
 (defun wl-folder-update-diff-line (diffs)
   (let ((inhibit-read-only t)
        (buffer-read-only nil)
@@ -2549,14 +2624,19 @@ Entering Folder mode calls the value of `wl-folder-mode-hook'."
       (setq count (+ count (wl-folder-count-incorporates entity)))
       (if (or (null (car nums)) ; unknown
              (< 0 count))
-         (save-window-excursion
-           (save-excursion
-             (wl-summary-goto-folder-subr entity
-                                          (wl-summary-get-sync-range entity)
-                                          nil)
-             (setq ret-val (wl-summary-incorporate))
-             (wl-summary-exit)
-             ret-val))
+         (let ((wl-summary-buffer-name (concat
+                                        wl-summary-buffer-name
+                                        (symbol-name this-command)))
+               (wl-message-buf-name (concat wl-message-buf-name
+                                            (symbol-name this-command))))
+           (save-window-excursion
+             (save-excursion
+               (wl-summary-goto-folder-subr entity
+                                            (wl-summary-get-sync-range entity)
+                                            nil)
+               (setq ret-val (wl-summary-incorporate))
+               (wl-summary-exit)
+               ret-val)))
        (cons 0 0))))))
 
 (defun wl-folder-count-incorporates (folder)
@@ -2601,11 +2681,16 @@ If current line is group folder, all subfolders are prefetched."
          wl-summary-highlight wl-auto-select-first new)
       (setq new (or (car nums) 0))
       (if (< 0 new)
-         (save-window-excursion
-           (save-excursion
-             (wl-summary-goto-folder-subr entity 'no-sync nil)
-             (wl-summary-drop-unsync)
-             (wl-summary-exit))))))))
+         (let ((wl-summary-buffer-name (concat
+                                        wl-summary-buffer-name
+                                        (symbol-name this-command)))
+               (wl-message-buf-name (concat wl-message-buf-name
+                                            (symbol-name this-command))))
+           (save-window-excursion
+             (save-excursion
+               (wl-summary-goto-folder-subr entity 'no-sync nil)
+               (wl-summary-drop-unsync)
+               (wl-summary-exit)))))))))
 
 (defun wl-folder-drop-unsync-current-entity (&optional force-check)
   "Drop all unsync messages in the folder at position.
@@ -2630,10 +2715,13 @@ If optional arg exists, don't check any folders."
        (wl-folder-drop-unsync-entity entity)
        (message "All unsync messages in %s are dropped!" entity-name)))))
 
-(defun wl-folder-write-current-newsgroup ()
-  ""
+(defun wl-folder-write-current-folder ()
+  "Write message to current folder's newsgroup or mailing-list.
+Call `wl-summary-write-current-folder' with current folder name."
   (interactive)
-  (wl-summary-write-current-newsgroup (wl-folder-entity-name)))
+  (unless (wl-folder-buffer-group-p)
+    (wl-summary-write-current-folder
+     (wl-folder-get-realname (wl-folder-entity-name)))))
 
 (defun wl-folder-mimic-kill-buffer ()
   "Kill the current (Folder) buffer with query."