1 ;;; wl-folder.el -- Folder mode for Wanderlust.
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4 ;; Copyright (C) 1998,1999,2000 Masahiro MURATA <muse@ba2.so-net.ne.jp>
6 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
7 ;; Masahiro MURATA <muse@ba2.so-net.ne.jp>
8 ;; Keywords: mail, net news
10 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
39 (require 'easymenu) ; needed here.
49 (defvar wl-folder-buffer-name "Folder")
50 (defvar wl-folder-entity nil) ; desktop entity.
51 (defvar wl-folder-group-alist nil) ; opened or closed
52 (defvar wl-folder-entity-id nil) ; id
53 (defvar wl-folder-entity-hashtb nil)
54 (defvar wl-folder-entity-id-name-hashtb nil)
55 (defvar wl-folder-elmo-folder-hashtb nil) ; name => elmo folder structure
57 (defvar wl-folder-newsgroups-hashtb nil)
58 (defvar wl-folder-info-alist-modified nil)
59 (defvar wl-folder-completion-function nil)
61 (defvar wl-folder-mode-map nil)
63 (defvar wl-folder-buffer-disp-summary nil)
64 (defvar wl-folder-buffer-cur-entity-id nil)
65 (defvar wl-folder-buffer-cur-path nil)
66 (defvar wl-folder-buffer-cur-point nil)
68 (make-variable-buffer-local 'wl-folder-buffer-disp-summary)
69 (make-variable-buffer-local 'wl-folder-buffer-cur-entity-id)
70 (make-variable-buffer-local 'wl-folder-buffer-cur-path)
71 (make-variable-buffer-local 'wl-folder-buffer-cur-point)
73 (defconst wl-folder-entity-regexp "^\\([ ]*\\)\\(\\[[\\+-]\\]\\)?\\([^\\[].+\\):[-*0-9]+/[-*0-9]+/[-*0-9]+")
74 (defconst wl-folder-group-regexp "^\\([ ]*\\)\\[\\([\\+-]\\)\\]\\(.+\\):[-0-9-]+/[0-9-]+/[0-9-]+\n")
75 ;; 1:indent 2:opened 3:group-name
76 (defconst wl-folder-unsync-regexp ":[^0\\*][0-9]*/[0-9\\*-]+/[0-9\\*-]+$")
78 (defvar wl-folder-mode-menu-spec
80 ["Enter Current Folder" wl-folder-jump-to-current-entity t]
81 ["Prev Folder" wl-folder-prev-entity t]
82 ["Next Folder" wl-folder-next-entity t]
83 ["Check Current Folder" wl-folder-check-current-entity t]
84 ["Sync Current Folder" wl-folder-sync-current-entity t]
85 ; ["Drop Current Folder" wl-folder-drop-unsync-current-entity t]
86 ["Prefetch Current Folder" wl-folder-prefetch-current-entity t]
87 ["Mark as Read all Current Folder" wl-folder-mark-as-read-all-current-entity t]
88 ["Expire Current Folder" wl-folder-expire-current-entity t]
89 ["Empty trash" wl-folder-empty-trash t]
90 ["Flush queue" wl-folder-flush-queue t]
91 ["Open All" wl-folder-open-all t]
92 ["Open All Unread folder" wl-folder-open-all-unread-folder t]
93 ["Close All" wl-folder-close-all t]
95 ["Add folder" wl-fldmgr-add t]
96 ["Add group" wl-fldmgr-make-group t]
97 ["Copy" wl-fldmgr-copy t]
98 ["Cut" wl-fldmgr-cut t]
99 ["Paste" wl-fldmgr-yank t]
100 ["Set petname" wl-fldmgr-set-petname t]
101 ["Rename" wl-fldmgr-rename t]
102 ["Save" wl-fldmgr-save-folders t]
104 ["Unsubscribe" wl-fldmgr-unsubscribe t]
105 ["Display all" wl-fldmgr-access-display-all t])
107 ["Write a message" wl-draft t]
109 ["Toggle Plug Status" wl-toggle-plugged t]
110 ["Change Plug Status" wl-plugged-change t]
112 ["Save Current Status" wl-save t]
113 ["Update Satus" wl-status-update t]
118 (defun wl-folder-setup-mouse ()
119 (define-key wl-folder-mode-map 'button2 'wl-folder-click)
120 (define-key wl-folder-mode-map 'button4 'wl-folder-prev-entity)
121 (define-key wl-folder-mode-map 'button5 'wl-folder-next-entity)
122 (define-key wl-folder-mode-map [(shift button4)]
123 'wl-folder-prev-unread)
124 (define-key wl-folder-mode-map [(shift button5)]
125 'wl-folder-next-unread))
126 (defun wl-folder-setup-mouse ()
127 (define-key wl-folder-mode-map [mouse-2] 'wl-folder-click)
128 (define-key wl-folder-mode-map [mouse-4] 'wl-folder-prev-entity)
129 (define-key wl-folder-mode-map [mouse-5] 'wl-folder-next-entity)
130 (define-key wl-folder-mode-map [S-mouse-4] 'wl-folder-prev-unread)
131 (define-key wl-folder-mode-map [S-mouse-5] 'wl-folder-next-unread)))
133 (if wl-folder-mode-map
135 (setq wl-folder-mode-map (make-sparse-keymap))
136 (define-key wl-folder-mode-map " " 'wl-folder-jump-to-current-entity)
137 ; (define-key wl-folder-mode-map "\M- " 'wl-folder-open-close)
138 (define-key wl-folder-mode-map "/" 'wl-folder-open-close)
139 (define-key wl-folder-mode-map "\C-m" 'wl-folder-jump-to-current-entity)
140 (define-key wl-folder-mode-map "\M-\C-m" 'wl-folder-update-recursive-current-entity)
141 (define-key wl-folder-mode-map "rc" 'wl-folder-mark-as-read-all-region)
142 (define-key wl-folder-mode-map "c" 'wl-folder-mark-as-read-all-current-entity)
143 (define-key wl-folder-mode-map "g" 'wl-folder-goto-folder)
144 (define-key wl-folder-mode-map "j" 'wl-folder-jump-to-current-entity)
145 (define-key wl-folder-mode-map "w" 'wl-draft)
146 (define-key wl-folder-mode-map "W" 'wl-folder-write-current-folder)
147 (define-key wl-folder-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
148 (define-key wl-folder-mode-map "\C-c\C-a" 'wl-addrmgr)
149 (define-key wl-folder-mode-map "rS" 'wl-folder-sync-region)
150 (define-key wl-folder-mode-map "S" 'wl-folder-sync-current-entity)
151 (define-key wl-folder-mode-map "rs" 'wl-folder-check-region)
152 (define-key wl-folder-mode-map "s" 'wl-folder-check-current-entity)
153 (define-key wl-folder-mode-map "I" 'wl-folder-prefetch-current-entity)
154 ; (define-key wl-folder-mode-map "D" 'wl-folder-drop-unsync-current-entity)
155 (define-key wl-folder-mode-map "p" 'wl-folder-prev-entity)
156 (define-key wl-folder-mode-map "n" 'wl-folder-next-entity)
157 (define-key wl-folder-mode-map "v" 'wl-folder-toggle-disp-summary)
158 (define-key wl-folder-mode-map "P" 'wl-folder-prev-unread)
159 (define-key wl-folder-mode-map "N" 'wl-folder-next-unread)
160 (define-key wl-folder-mode-map "J" 'wl-folder-jump-folder)
161 (define-key wl-folder-mode-map "f" 'wl-folder-goto-first-unread-folder)
162 (define-key wl-folder-mode-map "o" 'wl-folder-open-all-unread-folder)
163 (define-key wl-folder-mode-map "[" 'wl-folder-open-all)
164 (define-key wl-folder-mode-map "]" 'wl-folder-close-all)
165 (define-key wl-folder-mode-map "e" 'wl-folder-expire-current-entity)
166 (define-key wl-folder-mode-map "E" 'wl-folder-empty-trash)
167 (define-key wl-folder-mode-map "F" 'wl-folder-flush-queue)
168 (define-key wl-folder-mode-map "q" 'wl-exit)
169 (define-key wl-folder-mode-map "z" 'wl-folder-suspend)
170 (define-key wl-folder-mode-map "\M-t" 'wl-toggle-plugged)
171 (define-key wl-folder-mode-map "\C-t" 'wl-plugged-change)
172 (define-key wl-folder-mode-map "<" 'beginning-of-buffer)
173 (define-key wl-folder-mode-map ">" 'end-of-buffer)
175 (define-key wl-folder-mode-map "m" 'wl-fldmgr-mode-map)
176 (define-key wl-folder-mode-map "*" 'wl-fldmgr-make-multi)
177 (define-key wl-folder-mode-map "+" 'wl-fldmgr-make-group)
178 (define-key wl-folder-mode-map "|" 'wl-fldmgr-make-filter)
179 (define-key wl-folder-mode-map "\M-c" 'wl-fldmgr-copy)
180 (define-key wl-folder-mode-map "\M-w" 'wl-fldmgr-copy-region)
181 (define-key wl-folder-mode-map "\C-k" 'wl-fldmgr-cut)
182 (define-key wl-folder-mode-map "\C-w" 'wl-fldmgr-cut-region)
183 (define-key wl-folder-mode-map "\C-y" 'wl-fldmgr-yank)
184 (define-key wl-folder-mode-map "R" 'wl-fldmgr-rename)
185 (define-key wl-folder-mode-map "u" 'wl-fldmgr-unsubscribe)
186 (define-key wl-folder-mode-map "ru" 'wl-fldmgr-unsubscribe-region)
187 (define-key wl-folder-mode-map "U" 'wl-fldmgr-unsubscribe-region)
188 (define-key wl-folder-mode-map "l" 'wl-fldmgr-access-display-normal)
189 (define-key wl-folder-mode-map "L" 'wl-fldmgr-access-display-all)
190 (define-key wl-folder-mode-map "Z" 'wl-status-update)
191 (define-key wl-folder-mode-map "\C-x\C-s" 'wl-save)
192 (define-key wl-folder-mode-map "\M-s" 'wl-save)
193 (define-key wl-folder-mode-map "\C-xk" 'wl-folder-mimic-kill-buffer)
194 (define-key wl-folder-mode-map "\M-\C-a"
195 'wl-folder-goto-top-of-current-folder)
196 (define-key wl-folder-mode-map "\M-\C-e"
197 'wl-folder-goto-bottom-of-current-folder)
199 (wl-folder-setup-mouse)
203 "Menu used in Folder mode."
204 wl-folder-mode-menu-spec))
206 (defmacro wl-folder-unread-regex (group)
207 (` (concat "^[ ]*.+:[0-9\\*-]+/[^0\\*][0-9]*/[0-9\\*-]+$"
212 (defmacro wl-folder-buffer-group-p ()
213 (` (save-excursion (beginning-of-line)
214 (looking-at wl-folder-group-regexp))))
216 (defmacro wl-folder-folder-name ()
219 (if (or (looking-at "^[ ]*\\[[\\+-]\\]\\(.+\\):[-0-9\\*-]+/[0-9\\*-]+/[0-9\\*-]+\n")
220 (looking-at "^[ ]*\\([^\\[].+\\):.*\n"))
221 (wl-match-buffer 1)))))
223 (defmacro wl-folder-entity-name ()
226 (if (looking-at "^[ ]*\\([^\\[].+\\):.*\n")
227 (wl-match-buffer 1)))))
229 (defun wl-folder-buffer-search-group (group)
232 "^\\([ \t]*\\)\\[[\\+-]\\]"
233 (regexp-quote group) ":[-0-9-]+/[0-9-]+/[0-9-]+") nil t))
235 (defun wl-folder-buffer-search-entity (folder &optional searchname)
236 (let ((search (or searchname (wl-folder-get-petname folder))))
240 (regexp-quote search) ":[-0-9\\*-]+/[0-9\\*-]+/[0-9\\*-]+") nil t)))
242 (defsubst wl-folder-get-folder-name-by-id (entity-id &optional hashtb)
243 (and (numberp entity-id)
244 (elmo-get-hash-val (format "#%d" entity-id)
245 (or hashtb wl-folder-entity-id-name-hashtb))))
247 (defsubst wl-folder-set-id-name (entity-id entity &optional hashtb)
248 (and (numberp entity-id)
249 (elmo-set-hash-val (format "#%d" entity-id)
250 entity (or hashtb wl-folder-entity-id-name-hashtb))))
252 (defmacro wl-folder-get-entity-id (entity)
253 (` (or (get-text-property 0
256 (, entity)))) ;; for nemacs
258 (defmacro wl-folder-get-entity-from-buffer (&optional getid)
259 (` (let ((id (get-text-property (point)
260 'wl-folder-entity-id)))
261 (if (not id) ;; for nemacs
262 (wl-folder-get-realname (wl-folder-folder-name))
265 (wl-folder-get-folder-name-by-id id))))))
267 (defmacro wl-folder-entity-exists-p (entity &optional hashtb)
268 (` (let ((sym (intern-soft (, entity)
269 (or (, hashtb) wl-folder-entity-hashtb))))
270 (and sym (boundp sym)))))
272 (defmacro wl-folder-clear-entity-info (entity &optional hashtb)
273 (` (let ((sym (intern-soft (, entity)
274 (or (, hashtb) wl-folder-entity-hashtb))))
278 (defmacro wl-folder-get-entity-info (entity &optional hashtb)
279 (` (elmo-get-hash-val (, entity) (or (, hashtb) wl-folder-entity-hashtb))))
281 (defmacro wl-folder-set-entity-info (entity value &optional hashtb)
282 (` (let* ((hashtb (or (, hashtb) wl-folder-entity-hashtb))
283 (info (wl-folder-get-entity-info (, entity) hashtb)))
284 (elmo-set-hash-val (, entity)
285 (if (< (length (, value)) 4)
286 (append (, value) (list (nth 3 info)))
290 (defun wl-folder-persistent-p (folder)
291 (or (and (wl-folder-search-entity-by-name folder wl-folder-entity
295 (let ((li wl-save-folder-list))
297 (if (string-match (car li) folder)
299 (setq li (cdr li)))))
301 (let ((li wl-no-save-folder-list))
303 (if (string-match (car li) folder)
305 (setq li (cdr li))))))))
307 ;;; ELMO folder structure with cache.
308 (defmacro wl-folder-get-elmo-folder (entity)
309 "Get elmo folder structure from entity."
310 (` (or (wl-folder-elmo-folder-cache-get (, entity))
311 (let* ((name (elmo-string (, entity)))
312 (folder (elmo-make-folder name)))
313 (wl-folder-elmo-folder-cache-put name folder)
316 (defmacro wl-folder-elmo-folder-cache-get (name &optional hashtb)
317 "Returns a elmo folder structure associated with NAME from HASHTB.
318 Default HASHTB is `wl-folder-elmo-folder-hashtb'."
319 (` (elmo-get-hash-val (, name)
320 (or (, hashtb) wl-folder-elmo-folder-hashtb))))
322 (defmacro wl-folder-elmo-folder-cache-put (name folder &optional hashtb)
323 "Get folder elmo folder structure on HASHTB for folder with NAME.
324 Default HASHTB is `wl-folder-elmo-folder-hashtb'."
325 (` (elmo-set-hash-val (, name) (, folder)
326 (or (, hashtb) wl-folder-elmo-folder-hashtb))))
328 (defun wl-folder-prev-entity ()
332 (defun wl-folder-next-entity ()
336 (defun wl-folder-prev-entity-skip-invalid (&optional hereto)
337 "move to previous entity. skip unsubscribed or removed entity."
341 (if (re-search-backward wl-folder-entity-regexp nil t)
343 (goto-char (point-min))))
345 (defun wl-folder-next-entity-skip-invalid (&optional hereto)
346 "Move to next entity. skip unsubscribed or removed entity."
351 (if (re-search-forward wl-folder-entity-regexp nil t)
353 (goto-char (point-max))))
355 (defun wl-folder-search-group-entity-by-name (name entity)
356 (wl-folder-search-entity-by-name name entity 'group))
358 (defun wl-folder-search-entity-by-name (name entity &optional type)
359 (let ((entities (list entity))
363 (setq entity (wl-pop entities))
366 (if (and (not (eq type 'folder))
367 (string= name (car entity)))
368 (throw 'done entity))
370 (wl-push entities entity-stack))
371 (setq entities (nth 2 entity)))
372 ((and (not (eq type 'group))
374 (if (string= name entity)
375 (throw 'done entity))))
377 (setq entities (wl-pop entity-stack)))))))
379 (defun wl-folder-search-entity-list-by-name (name entity &optional get-id)
380 (let ((entities (list entity))
381 entity-stack ret-val)
383 (setq entity (wl-pop entities))
387 (wl-push entities entity-stack))
388 (setq entities (nth 2 entity)))
390 (if (string= name entity)
391 (wl-append ret-val (if get-id
392 (list (wl-folder-get-entity-id entity))
395 (setq entities (wl-pop entity-stack))))
398 (defun wl-folder-get-prev-folder (id &optional unread)
399 (let ((name (if (stringp id)
401 (wl-folder-get-folder-name-by-id id)))
402 entity entity-stack last-entity finfo
403 (entities (list wl-folder-entity)))
406 (setq entity (wl-pop entities))
409 ;; (if (and (string= name (car entity))
410 ;; (eq id (wl-folder-get-entity-id (car entity))))
411 ;; (throw 'done last-entity))
413 (wl-push entities entity-stack))
414 (setq entities (nth 2 entity)))
416 (if (and (string= name entity)
417 ;; don't use eq, `id' is string on Nemacs.
418 (equal id (wl-folder-get-entity-id entity)))
419 (throw 'done last-entity))
421 (and (setq finfo (wl-folder-get-entity-info entity))
422 (and (nth 0 finfo)(nth 1 finfo))
423 (> (+ (nth 0 finfo)(nth 1 finfo)) 0)))
424 (setq last-entity entity))))
426 (setq entities (wl-pop entity-stack)))))))
428 (defun wl-folder-get-next-folder (id &optional unread)
429 (let ((name (if (stringp id)
431 (wl-folder-get-folder-name-by-id id)))
432 entity entity-stack found finfo
433 (entities (list wl-folder-entity)))
436 (setq entity (wl-pop entities))
439 ;;; (if (and (string= name (car entity))
440 ;;; (eq id (wl-folder-get-entity-id (car entity))))
443 (wl-push entities entity-stack))
444 (setq entities (nth 2 entity)))
447 (when (or (not unread)
448 (and (setq finfo (wl-folder-get-entity-info entity))
449 (and (nth 0 finfo)(nth 1 finfo))
450 (> (+ (nth 0 finfo)(nth 1 finfo)) 0)))
451 (throw 'done entity))
452 (if (and (string= name entity)
453 ;; don't use eq, `id' is string on Nemacs.
454 (equal id (wl-folder-get-entity-id entity)))
457 (setq entities (wl-pop entity-stack)))))))
459 (defun wl-folder-flush-queue ()
462 (let ((cur-buf (current-buffer))
463 (wl-auto-select-first nil)
466 (if elmo-enable-disconnected-operation
467 (elmo-dop-queue-flush 'force)) ; Try flushing all queue.
468 (if (not (elmo-folder-list-messages
469 (wl-folder-get-elmo-folder wl-queue-folder)))
470 (message "No sending queue exists.")
471 (if wl-stay-folder-window
472 (wl-folder-select-buffer
473 (wl-summary-get-buffer-create wl-queue-folder)))
474 (wl-summary-goto-folder-subr wl-queue-folder 'force-update nil)
476 (wl-draft-queue-flush)
477 (if (get-buffer-window cur-buf)
478 (select-window (get-buffer-window cur-buf)))
480 (if wl-stay-folder-window
481 (wl-folder-toggle-disp-summary 'off wl-queue-folder)
482 (switch-to-buffer cur-buf))))))
484 (defun wl-folder-empty-trash ()
487 (let ((cur-buf (current-buffer))
488 (wl-auto-select-first nil)
490 (if wl-stay-folder-window
491 (wl-folder-select-buffer
492 (wl-summary-get-buffer-create wl-trash-folder)))
493 (wl-summary-goto-folder-subr wl-trash-folder 'force-update nil nil t)
494 (setq trash-buf (current-buffer))
496 (setq emptied (wl-summary-delete-all-msgs))
498 (setq wl-thread-entities nil
499 wl-thread-entity-list nil)
500 (if wl-summary-cache-use (wl-summary-save-view-cache))
501 (elmo-folder-commit wl-summary-buffer-elmo-folder))
502 (if (get-buffer-window cur-buf)
503 (select-window (get-buffer-window cur-buf)))
506 (wl-folder-set-folder-updated wl-trash-folder '(0 0 0)))
507 (if wl-stay-folder-window
508 (wl-folder-toggle-disp-summary 'off wl-trash-folder)
509 (switch-to-buffer cur-buf))
511 (kill-buffer trash-buf)))))
513 (defun wl-folder-goto-top-of-current-folder (&optional arg)
514 "Move backward to the top of the current folder group.
515 Optional argument ARG is repeart count."
517 (if (re-search-backward
518 "^ *\\[[\\+-]\\]" nil t (if arg (prefix-numeric-value arg)))
520 (goto-char (point-min))))
522 (defun wl-folder-goto-bottom-of-current-folder (indent)
523 "Move forward to the bottom of the current folder group."
528 (if (looking-at "^ *")
529 (buffer-substring (match-beginning 0)(1- (match-end 0)))
533 (while (re-search-forward "^ *" nil t)
534 (if (<= (length (match-string 0))
538 (goto-char (point-max))))
540 (defsubst wl-folder-update-group (entity diffs &optional is-group)
542 (let ((path (wl-folder-get-path
544 (wl-folder-get-entity-id entity)
547 ;; delete itself from path
548 (setq path (delete (nth (- (length path) 1) path) path)))
549 (goto-char (point-min))
552 ;; goto the path line.
553 (if (or (eq (car path) 0) ; update desktop
554 (wl-folder-buffer-search-group
555 (wl-folder-get-petname
556 (if (stringp (car path))
558 (wl-folder-get-folder-name-by-id
561 (wl-folder-update-diff-line diffs)
563 (setq path (cdr path)))))))
565 (defun wl-folder-maybe-load-folder-list (entity)
566 (when (null (caddr entity))
568 (elmo-msgdb-flist-load (car entity)))
572 (wl-folder-entity-assign-id entity
573 wl-folder-entity-id-name-hashtb
575 (setq diffs (wl-fldmgr-add-entity-hashtb (list entity)))
576 (unless (equal diffs '(0 0 0))
577 (wl-folder-update-group (car entity) diffs t)))))))
579 (defsubst wl-folder-force-fetch-p (entity)
581 ((consp wl-force-fetch-folders)
582 (wl-string-match-member entity wl-force-fetch-folders))
584 wl-force-fetch-folders)))
586 (defun wl-folder-jump-to-current-entity (&optional arg)
587 "Enter the current folder. If optional ARG exists, update folder list."
590 (let (entity beg end indent opened fname err fld-name)
592 ((looking-at wl-folder-group-regexp)
594 (setq fname (wl-folder-get-realname (wl-match-buffer 3)))
595 (setq indent (wl-match-buffer 1))
596 (setq opened (wl-match-buffer 2))
597 (if (string= opened "+")
599 (setq entity (wl-folder-search-group-entity-by-name
604 (wl-folder-update-recursive-current-entity entity)
606 (setcdr (assoc (car entity) wl-folder-group-alist) t)
607 (if (eq 'access (cadr entity))
608 (wl-folder-maybe-load-folder-list entity))
609 ;(condition-case errobj
611 (if (or (wl-folder-force-fetch-p (car entity))
613 (eq 'access (cadr entity))
614 (null (caddr entity))))
615 (wl-folder-update-newest indent entity)
616 (wl-folder-insert-entity indent entity))
617 (wl-highlight-folder-path wl-folder-buffer-cur-path))
620 ; (setcdr (assoc fname wl-folder-group-alist) nil))
622 ; (elmo-display-error errobj t)
625 ; (setcdr (assoc fname wl-folder-group-alist) nil)))
627 (let ((buffer-read-only nil))
628 (delete-region (save-excursion (beginning-of-line)
630 (save-excursion (end-of-line)
636 (progn (wl-folder-goto-bottom-of-current-folder indent)
639 (setq entity (wl-folder-search-group-entity-by-name
642 (let ((buffer-read-only nil))
643 (delete-region beg end))
644 (setcdr (assoc (car entity) wl-folder-group-alist) nil)
645 (wl-folder-insert-entity indent entity) ; insert entity
647 (wl-highlight-folder-path wl-folder-buffer-cur-path)
648 ; (wl-delete-all-overlays)
649 ; (wl-highlight-folder-current-line)
651 ((setq fld-name (wl-folder-entity-name))
652 (wl-folder-set-current-entity-id
653 (get-text-property (point) 'wl-folder-entity-id))
654 (setq fld-name (wl-folder-get-folder-name-by-id
655 wl-folder-buffer-cur-entity-id))
656 (let ((summary-buf (wl-summary-get-buffer-create fld-name arg))
658 (if (or wl-stay-folder-window wl-summary-use-frame)
659 (wl-folder-select-buffer summary-buf)
661 (get-buffer-window summary-buf))
663 (wl-summary-goto-folder-subr fld-name
664 (wl-summary-get-sync-range
665 (wl-folder-get-elmo-folder fld-name))
667 (set-buffer-modified-p nil))
669 (defun wl-folder-close-entity (entity)
670 (let ((entities (list entity))
673 (setq entity (wl-pop entities))
676 (setcdr (assoc (car entity) wl-folder-group-alist) nil)
678 (wl-push entities entity-stack))
679 (setq entities (nth 2 entity))))
681 (setq entities (wl-pop entity-stack))))))
683 (defun wl-folder-update-recursive-current-entity (&optional entity)
685 (when (wl-folder-buffer-group-p)
687 ((string= (wl-match-buffer 2) "+")
691 (wl-folder-search-group-entity-by-name
692 (wl-folder-get-realname (wl-match-buffer 3))
694 (let ((inhibit-read-only t)
695 (entities (list entity))
696 entity-stack err indent)
697 (while (and entities (not err))
698 (setq entity (wl-pop entities))
701 (wl-folder-close-entity entity)
702 (setcdr (assoc (car entity) wl-folder-group-alist) t)
703 (unless (wl-folder-buffer-search-group
704 (wl-folder-get-petname (car entity)))
705 (error "%s: not found group" (car entity)))
706 (setq indent (wl-match-buffer 1))
707 (if (eq 'access (cadr entity))
708 (wl-folder-maybe-load-folder-list entity))
712 (condition-case errobj
713 (wl-folder-update-newest indent entity)
716 (setcdr (assoc (car entity) wl-folder-group-alist) nil))
718 (elmo-display-error errobj t)
721 (setcdr (assoc (car entity) wl-folder-group-alist) nil)))
723 (delete-region (save-excursion (beginning-of-line)
725 (save-excursion (end-of-line)
729 (wl-push entities entity-stack))
730 (setq entities (nth 2 entity))))
732 (setq entities (wl-pop entity-stack)))))
733 (set-buffer-modified-p nil)))
735 (wl-folder-jump-to-current-entity)))))
737 (defun wl-folder-no-auto-check-folder-p (folder)
740 (let ((li wl-auto-check-folder-list))
742 (if (string-match (car li) folder)
744 (setq li (cdr li)))))
747 (let ((li wl-auto-uncheck-folder-list))
749 (if (string-match (car li) folder)
750 (throw 'found t)) ; no check!
751 (setq li (cdr li))))))))
753 (defsubst wl-folder-add-folder-info (pre-value value)
755 (+ (or (nth 0 pre-value) 0) (or (nth 0 value) 0))
756 (+ (or (nth 1 pre-value) 0) (or (nth 1 value) 0))
757 (+ (or (nth 2 pre-value) 0) (or (nth 2 value) 0))))
759 (defun wl-folder-check-entity (entity &optional auto)
760 "Check unsync message number."
761 (let ((start-pos (point))
763 (run-hooks 'wl-folder-check-entity-pre-hook)
764 (if (and (consp entity) ;; group entity
765 wl-folder-check-async) ;; very fast
766 (setq ret-val (wl-folder-check-entity-async entity auto))
770 (let ((flist (if auto
772 'wl-folder-no-auto-check-folder-p
775 (wl-folder-check-entity-pre-hook nil)
776 (wl-folder-check-entity-hook nil)
780 (wl-folder-add-folder-info
782 (wl-folder-check-entity (car flist))))
783 (setq flist (cdr flist)))
784 ;(wl-folder-buffer-search-entity (car entity))
785 ;(wl-folder-update-line ret-val)
788 (message "Checking \"%s\"" entity)
789 (setq ret-val (wl-folder-check-one-entity
791 (goto-char start-pos)
794 (message "Uncheck(unplugged) \"%s\"" entity)))))
796 (message "Checking \"%s\" is done."
797 (if (consp entity) (car entity) entity)))
798 (run-hooks 'wl-folder-check-entity-hook)
801 (defun wl-folder-check-one-entity (entity)
802 (let* ((folder (wl-folder-get-elmo-folder entity))
803 (nums (condition-case err
804 (if (wl-string-match-member entity wl-strict-diff-folders)
805 (elmo-strict-folder-diff folder)
806 (elmo-folder-diff folder))
808 ;; maybe not exist folder.
809 (if (and (not (memq 'elmo-open-error
810 (get (car err) 'error-conditions)))
811 (not (elmo-folder-exists-p folder)))
812 (wl-folder-create-subr folder)
813 (signal (car err) (cdr err))))))
815 (if (and (eq wl-folder-notify-deleted 'sync)
817 (or (> 0 (car nums)) (> 0 (cdr nums))))
819 (wl-folder-sync-entity entity)
820 (setq nums (elmo-folder-diff folder)))
821 (unless wl-folder-notify-deleted
822 (setq unsync (if (and (car nums) (> 0 (car nums))) 0 (car nums)))
823 (setq nomif (if (and (car nums) (> 0 (cdr nums))) 0 (cdr nums)))
824 (setq nums (cons unsync nomif)))
825 (setq unread (or ;; If server diff, All unreads are
827 (if (elmo-folder-use-flag-p folder)
829 (elmo-folder-get-info-unread folder)
830 (wl-summary-count-unread (elmo-msgdb-mark-load
831 (elmo-folder-msgdb-path
833 (setq unread (min unread (- (or (cdr nums) 0) (or (car nums) 0))))
834 (wl-folder-entity-hashtb-set wl-folder-entity-hashtb entity
838 (get-buffer wl-folder-buffer-name)))
839 (setq wl-folder-info-alist-modified t)
841 (list (if wl-folder-notify-deleted
843 (max (or (car nums) 0))) unread (cdr nums))))
845 (defun wl-folder-check-entity-async (entity &optional auto)
846 (let ((elmo-nntp-groups-async t)
849 'wl-folder-no-auto-check-folder-p
850 (wl-folder-get-entity-list entity))
851 (wl-folder-get-entity-list entity)))
852 (nntp-connection-keys nil)
853 name folder folder-list
859 (setq folder (wl-folder-get-elmo-folder (car elist)))
860 (if (not (elmo-folder-plugged-p folder))
861 (message "Uncheck \"%s\"" (car elist))
863 (elmo-folder-get-primitive-list folder))
864 (cond ((elmo-folder-contains-type folder 'nntp)
865 (wl-append async-folder-list (list folder))
867 (when (eq (elmo-folder-type-internal (car folder-list))
871 (elmo-net-folder-server-internal
873 (setq server (elmo-net-folder-server-internal
875 (message "Checking on \"%s\"" server))
876 (setq nntp-connection-keys
877 (elmo-nntp-get-folders-info-prepare
879 nntp-connection-keys)))
880 (setq folder-list (cdr folder-list))))
882 (wl-append sync-folder-list (list folder)))))
883 (setq elist (cdr elist)))
884 ;; check local entity at first
885 (while (setq folder (pop sync-folder-list))
886 (if (not (elmo-folder-plugged-p folder))
887 (message "Uncheck \"%s\"" (elmo-folder-name-internal folder))
888 (message "Checking \"%s\"" (elmo-folder-name-internal folder))
890 (wl-folder-add-folder-info
892 (wl-folder-check-one-entity (elmo-folder-name-internal
896 ;; check network entity at last
897 (when async-folder-list
898 (elmo-nntp-get-folders-info nntp-connection-keys)
899 (while (setq folder (pop async-folder-list))
900 (if (not (elmo-folder-plugged-p folder))
901 (message "Uncheck \"%s\"" (elmo-folder-name-internal folder))
902 (message "Checking \"%s\"" (elmo-folder-name-internal folder))
904 (wl-folder-add-folder-info
906 (wl-folder-check-one-entity (elmo-folder-name-internal
913 (defun wl-folder-resume-entity-hashtb-by-finfo (entity-hashtb info-alist)
914 "Resume unread info for entity alist."
917 (setq info (nth 1 (car info-alist)))
918 (wl-folder-set-entity-info (caar info-alist)
919 (list (nth 2 info)(nth 3 info)(nth 1 info))
921 (setq info-alist (cdr info-alist)))))
923 (defun wl-folder-move-path (path)
924 (let ((fp (if (consp path)
927 (wl-folder-get-path wl-folder-entity path))))
928 (goto-char (point-min))
931 (when (equal (car fp)
932 (wl-folder-get-entity-from-buffer t))
934 (setq wl-folder-buffer-cur-point (point)))
936 (and wl-folder-buffer-cur-point
937 (goto-char wl-folder-buffer-cur-point))))
939 (defun wl-folder-set-current-entity-id (entity-id)
940 (let ((buf (get-buffer wl-folder-buffer-name)))
944 (setq wl-folder-buffer-cur-entity-id entity-id)
945 (setq wl-folder-buffer-cur-path (wl-folder-get-path wl-folder-entity
947 (wl-highlight-folder-path wl-folder-buffer-cur-path)
948 (and wl-folder-move-cur-folder
949 wl-folder-buffer-cur-point
950 (goto-char wl-folder-buffer-cur-point))))
951 (if (eq (current-buffer) buf)
952 (and wl-folder-move-cur-folder
953 wl-folder-buffer-cur-point
954 (goto-char wl-folder-buffer-cur-point)))))
956 (defun wl-folder-check-current-entity ()
957 "Check folder at position.
958 If current line is group folder, check all sub entries."
960 (let* ((entity-name (wl-folder-get-entity-from-buffer))
961 (group (wl-folder-buffer-group-p))
962 (desktop (string= entity-name wl-folder-desktop-name)))
964 (wl-folder-check-entity
966 (wl-folder-search-group-entity-by-name entity-name
971 (defun wl-folder-sync-entity (entity &optional unread-only)
972 "Synchronize the msgdb of ENTITY."
975 (let ((flist (nth 2 entity)))
977 (wl-folder-sync-entity (car flist) unread-only)
978 (setq flist (cdr flist)))))
980 (let* ((folder (wl-folder-get-elmo-folder entity))
981 (nums (wl-folder-get-entity-info entity))
982 (wl-summary-highlight (if (or (wl-summary-sticky-p folder)
983 (wl-summary-always-sticky-folder-p
985 wl-summary-highlight))
986 wl-auto-select-first new unread)
987 (setq new (or (car nums) 0))
988 (setq unread (or (cadr nums) 0))
989 (if (or (not unread-only)
990 (or (< 0 new) (< 0 unread)))
991 (let ((wl-summary-buffer-name (concat
992 wl-summary-buffer-name
993 (symbol-name this-command)))
994 (wl-summary-use-frame nil)
995 (wl-summary-always-sticky-folder-list nil))
996 (save-window-excursion
998 (wl-summary-goto-folder-subr entity
999 (wl-summary-get-sync-range
1002 (wl-summary-exit)))))))))
1004 (defun wl-folder-sync-current-entity (&optional unread-only)
1005 "Synchronize the folder at position.
1006 If current line is group folder, check all subfolders."
1009 (let ((entity-name (wl-folder-get-entity-from-buffer))
1010 (group (wl-folder-buffer-group-p)))
1011 (when (and entity-name
1012 (y-or-n-p (format "Sync %s?" entity-name)))
1013 (wl-folder-sync-entity
1015 (wl-folder-search-group-entity-by-name entity-name
1019 (message "Syncing %s is done!" entity-name)))))
1021 (defun wl-folder-mark-as-read-all-entity (entity)
1022 "Mark as read all messages in the ENTITY."
1025 (let ((flist (nth 2 entity)))
1027 (wl-folder-mark-as-read-all-entity (car flist))
1028 (setq flist (cdr flist)))))
1030 (let* ((nums (wl-folder-get-entity-info entity))
1031 (folder (wl-folder-get-elmo-folder entity))
1032 (wl-summary-highlight (if (or (wl-summary-sticky-p folder)
1033 (wl-summary-always-sticky-folder-p
1035 wl-summary-highlight))
1036 wl-auto-select-first new unread)
1037 (setq new (or (car nums) 0))
1038 (setq unread (or (cadr nums) 0))
1039 (if (or (< 0 new) (< 0 unread))
1040 (save-window-excursion
1042 (let ((wl-summary-buffer-name (concat
1043 wl-summary-buffer-name
1044 (symbol-name this-command)))
1045 (wl-summary-use-frame nil)
1046 (wl-summary-always-sticky-folder-list nil))
1047 (wl-summary-goto-folder-subr entity
1048 (wl-summary-get-sync-range folder)
1050 (wl-summary-mark-as-read-all)
1051 (wl-summary-exit))))
1054 (defun wl-folder-mark-as-read-all-current-entity ()
1055 "Mark as read all messages in the folder at position.
1056 If current line is group folder, all subfolders are marked."
1059 (let ((entity-name (wl-folder-get-entity-from-buffer))
1060 (group (wl-folder-buffer-group-p))
1062 (when (and entity-name
1063 (y-or-n-p (format "Mark all messages in %s as read?" entity-name)))
1064 (wl-folder-mark-as-read-all-entity
1066 (wl-folder-search-group-entity-by-name entity-name
1069 (message "All messages in %s are marked!" entity-name)))))
1071 (defun wl-folder-check-region (beg end)
1080 (let ((inhibit-read-only t)
1082 (while (< (point) end)
1083 ;; normal folder entity
1084 (if (looking-at "^[\t ]*\\([^\\[]+\\):\\(.*\\)\n")
1086 (setq entity (wl-folder-get-entity-from-buffer))
1087 (if (not (elmo-folder-plugged-p (wl-folder-get-elmo-folder
1089 (message "Uncheck %s" entity)
1090 (message "Checking %s" entity)
1091 (wl-folder-check-one-entity entity)
1096 (defun wl-folder-sync-region (beg end)
1105 (while (< (point) end)
1106 ;; normal folder entity
1107 (if (looking-at "^[\t ]*\\([^\\[]+\\):\\(.*\\)\n")
1109 (let ((inhibit-read-only t)
1111 (setq entity (wl-folder-get-entity-from-buffer))
1112 (wl-folder-sync-entity entity)
1113 (message "Syncing %s is done!" entity)
1118 (defun wl-folder-mark-as-read-all-region (beg end)
1127 (while (< (point) end)
1128 ;; normal folder entity
1129 (if (looking-at "^[\t ]*\\([^\\[]+\\):\\(.*\\)\n")
1131 (let ((inhibit-read-only t)
1133 (setq entity (wl-folder-get-entity-from-buffer))
1134 (wl-folder-mark-as-read-all-entity entity)
1135 (message "All messages in %s are marked!" entity)
1140 (defsubst wl-create-access-init-load-p (folder)
1141 (let ((no-load-regexp (when (and
1142 (not wl-folder-init-load-access-folders)
1143 wl-folder-init-no-load-access-folders)
1144 (mapconcat 'identity
1145 wl-folder-init-no-load-access-folders
1147 (load-regexp (and wl-folder-init-load-access-folders
1148 (mapconcat 'identity
1149 wl-folder-init-load-access-folders
1151 (cond (load-regexp (string-match load-regexp folder))
1152 (t (not (and no-load-regexp
1153 (string-match no-load-regexp folder)))))))
1155 (defun wl-create-access-folder-entity (name)
1157 (when (wl-create-access-init-load-p name)
1158 (setq flists (elmo-msgdb-flist-load name)) ; load flist.
1159 (setq flist (car flists))
1161 (when (consp (car flist))
1162 (setcdr (cdar flist)
1163 (wl-create-access-folder-entity (caar flist))))
1164 (setq flist (cdr flist)))
1167 (defun wl-create-folder-entity-from-buffer ()
1168 "Create folder entity recursively."
1170 ((looking-at "^[ \t]*$") ; blank line
1171 (goto-char (+ 1(match-end 0)))
1173 ((looking-at "^#.*$") ; comment
1174 (goto-char (+ 1 (match-end 0)))
1176 ((looking-at "^[\t ]*\\(.+\\)[\t ]*{[\t ]*$") ; group definition
1177 (let (name entity flist)
1178 (setq name (wl-match-buffer 1))
1179 (goto-char (+ 1 (match-end 0)))
1180 (while (setq entity (wl-create-folder-entity-from-buffer))
1181 (unless (eq entity 'ignore)
1182 (wl-append flist (list entity))))
1183 (if (looking-at "^[\t ]*}[\t ]*$") ; end of group
1185 (goto-char (+ 1 (match-end 0)))
1186 (if (wl-string-assoc name wl-folder-petname-alist)
1187 (error "%s already defined as petname" name))
1188 (list name 'group flist))
1189 (error "Syntax error in folder definition"))))
1190 ((looking-at "^[\t ]*\\([^\t \n]+\\)[\t ]*/$") ; access it!
1192 (setq name (wl-match-buffer 1))
1193 (goto-char (+ 1 (match-end 0)))
1194 ; (condition-case ()
1196 ; (setq flist (elmo-list-folders name)))
1197 ; (error (message "Access to folder %s failed." name)))
1198 ;; (setq flist (elmo-msgdb-flist-load name)) ; load flist.
1199 ;; (setq unsublist (nth 1 flist))
1200 ;; (setq flist (car flist))
1201 ;; (list name 'access flist unsublist)))
1202 (append (list name 'access) (wl-create-access-folder-entity name))))
1203 ;((looking-at "^[\t ]*\\([^\t \n}]+\\)[\t ]*\\(\"[^\"]*\"\\)?[\t ]*$") ; normal folder entity
1204 ((looking-at "^[\t ]*=[ \t]+\\([^\n]+\\)$"); petname definition
1205 (goto-char (+ 1 (match-end 0)))
1206 (let ((rest (elmo-match-buffer 1))
1208 (when (string-match "\\(\"[^\"]*\"\\)[\t ]*$" rest)
1209 (setq petname (elmo-delete-char ?\" (elmo-match-string 1 rest)))
1210 (setq rest (substring rest 0 (match-beginning 0))))
1211 (when (string-match "^[\t ]*\\(.*[^\t ]+\\)[\t ]+$" rest)
1212 (wl-folder-append-petname (elmo-match-string 1 rest)
1215 ((looking-at "^[ \t]*}[ \t]*$") ; end of group
1217 ((looking-at "^.*$") ; normal folder entity
1218 (goto-char (+ 1 (match-end 0)))
1219 (let ((rest (elmo-match-buffer 0))
1221 (if (string-match "\\(\"[^\"]*\"\\)[\t ]*$" rest)
1223 (setq petname (elmo-delete-char ?\" (elmo-match-string 1 rest)))
1224 (setq rest (substring rest 0 (match-beginning 0)))
1225 (when (string-match "^[\t ]*\\(.*[^\t ]+\\)[\t ]+$" rest)
1226 (wl-folder-append-petname
1227 (setq realname (elmo-match-string 1 rest))
1230 (if (string-match "^[\t ]*\\(.+\\)$" rest)
1231 (elmo-match-string 1 rest)
1234 (defun wl-folder-create-folder-entity ()
1235 "Create folder entries."
1236 (let ((tmp-buf (get-buffer-create " *wl-folder-tmp*"))
1240 (with-current-buffer tmp-buf
1242 (insert-file-contents wl-folders-file)
1243 (goto-char (point-min))
1244 (while (and (not (eobp))
1245 (setq entity (wl-create-folder-entity-from-buffer)))
1246 (unless (eq entity 'ignore)
1247 (wl-append ret-val (list entity)))))
1248 (kill-buffer tmp-buf))
1250 (setq ret-val (list wl-folder-desktop-name 'group ret-val))))
1252 (defun wl-folder-entity-assign-id (entity &optional hashtb on-noid)
1253 (let ((hashtb (or hashtb
1254 (setq wl-folder-entity-id-name-hashtb
1255 (elmo-make-hash wl-folder-entity-id))))
1256 (entities (list entity))
1259 (setq entity (wl-pop entities))
1262 (when (not (and on-noid
1263 (get-text-property 0
1264 'wl-folder-entity-id
1266 (put-text-property 0 (length (car entity))
1267 'wl-folder-entity-id
1270 (wl-folder-set-id-name wl-folder-entity-id
1271 (car entity) hashtb))
1273 (wl-push entities entity-stack))
1274 (setq entities (nth 2 entity)))
1276 (when (not (and on-noid
1277 (get-text-property 0
1278 'wl-folder-entity-id
1280 (put-text-property 0 (length entity)
1281 'wl-folder-entity-id
1284 (wl-folder-set-id-name wl-folder-entity-id
1286 (setq wl-folder-entity-id (+ 1 wl-folder-entity-id))
1288 (setq entities (wl-pop entity-stack))))))
1290 (defun wl-folder-click (e)
1295 (wl-folder-jump-to-current-entity)))
1297 (defun wl-folder-select-buffer (buffer)
1298 (let ((gbw (get-buffer-window buffer))
1301 (progn (select-window gbw)
1303 (unless wl-summary-use-frame
1306 (split-window-horizontally wl-folder-window-width)
1310 (if wl-summary-use-frame
1311 (switch-to-buffer-other-frame buffer)
1312 (switch-to-buffer buffer))
1315 (defun wl-folder-toggle-disp-summary (&optional arg folder)
1317 (if (or (and folder (assoc folder wl-folder-group-alist))
1318 (and (interactive-p) (wl-folder-buffer-group-p)))
1319 (error "This command is not available on Group"))
1321 (let (wl-auto-select-first
1322 (wl-stay-folder-window t))
1325 (setq wl-folder-buffer-disp-summary t))
1327 (setq wl-folder-buffer-disp-summary nil)
1328 ;; hide wl-summary window.
1329 (let ((cur-buf (current-buffer))
1330 (summary-buffer (wl-summary-get-buffer folder)))
1331 (wl-folder-select-buffer summary-buffer)
1333 (select-window (get-buffer-window cur-buf))))
1335 (setq wl-folder-buffer-disp-summary
1336 (not wl-folder-buffer-disp-summary))
1337 (let ((cur-buf (current-buffer))
1339 (when (looking-at "^[ ]*\\([^\\[].+\\):.*\n")
1340 (setq folder-name (wl-folder-get-entity-from-buffer))
1341 (if wl-folder-buffer-disp-summary
1343 (wl-folder-select-buffer
1344 (wl-summary-get-buffer-create folder-name))
1346 (wl-summary-goto-folder-subr folder-name 'no-sync nil)
1347 (select-window (get-buffer-window cur-buf))))
1348 (wl-folder-select-buffer (wl-summary-get-buffer folder-name))
1350 (select-window (get-buffer-window cur-buf)))))))))
1352 (defun wl-folder-prev-unsync ()
1353 "Move cursor to the previous unsync folder."
1356 (setq start-point (point))
1358 (if (re-search-backward wl-folder-unsync-regexp nil t)
1360 (goto-char start-point)
1361 (message "No more unsync folder"))))
1363 (defun wl-folder-next-unsync (&optional plugged)
1364 "Move cursor to the next unsync."
1366 (let (start-point entity)
1367 (setq start-point (point))
1370 (while (re-search-forward wl-folder-unsync-regexp nil t)
1371 (if (or (wl-folder-buffer-group-p)
1374 (wl-folder-get-realname
1375 (wl-folder-folder-name)))
1376 (elmo-folder-plugged-p entity))
1379 (goto-char start-point)
1380 (message "No more unsync folder"))))
1382 (defun wl-folder-prev-unread (&optional group)
1383 "Move cursor to the previous unread folder."
1386 (setq start-point (point))
1388 (if (re-search-backward (wl-folder-unread-regex group) nil t)
1391 (wl-folder-folder-name))
1392 (goto-char start-point)
1393 (message "No more unread folder")
1396 (defun wl-folder-next-unread (&optional group)
1397 "Move cursor to the next unread folder."
1400 (setq start-point (point))
1402 (if (re-search-forward (wl-folder-unread-regex group) nil t)
1405 (wl-folder-folder-name))
1406 (goto-char start-point)
1407 (message "No more unread folder")
1410 (defun wl-folder-mode ()
1411 "Major mode for Wanderlust Folder.
1412 See Info under Wanderlust for full documentation.
1415 \\{wl-folder-mode-map}
1417 Entering Folder mode calls the value of `wl-folder-mode-hook'."
1419 (setq major-mode 'wl-folder-mode)
1420 (setq mode-name "Folder")
1421 (use-local-map wl-folder-mode-map)
1422 (setq buffer-read-only t)
1423 (setq inhibit-read-only nil)
1424 (setq truncate-lines t)
1425 (setq wl-folder-buffer-cur-entity-id nil
1426 wl-folder-buffer-cur-path nil
1427 wl-folder-buffer-cur-point nil)
1428 (wl-mode-line-buffer-identification)
1429 (easy-menu-add wl-folder-mode-menu)
1430 ;; This hook may contain the functions `wl-folder-init-icons' and
1431 ;; `wl-setup-folder' for reasons of system internal to accord
1432 ;; facilities for the Emacs variants.
1433 (run-hooks 'wl-folder-mode-hook))
1435 (defun wl-folder-append-petname (realname petname)
1437 ;; check group name.
1438 (if (wl-folder-search-group-entity-by-name petname wl-folder-entity)
1439 (error "%s already defined as group name" petname))
1440 (when (setq pentry (wl-string-assoc realname wl-folder-petname-alist))
1441 (setq wl-folder-petname-alist
1442 (delete pentry wl-folder-petname-alist)))
1443 (wl-append wl-folder-petname-alist
1444 (list (cons realname petname)))))
1446 (defun wl-folder (&optional arg)
1448 (let (initialize folder-buf)
1449 (if (setq folder-buf (get-buffer wl-folder-buffer-name))
1450 (if wl-folder-use-frame
1452 (save-selected-window
1453 (dolist (frame (visible-frame-list))
1454 (select-frame frame)
1455 (if (get-buffer-window folder-buf)
1456 (setq select-frame frame))))
1458 (select-frame select-frame)
1459 (switch-to-buffer folder-buf)))
1460 (switch-to-buffer folder-buf))
1461 (if wl-folder-use-frame
1462 (switch-to-buffer-other-frame
1463 (get-buffer-create wl-folder-buffer-name))
1464 (switch-to-buffer (get-buffer-create wl-folder-buffer-name)))
1465 (set-buffer wl-folder-buffer-name)
1468 (setq wl-folder-entity-id 0)
1469 (wl-folder-entity-assign-id wl-folder-entity)
1470 (setq wl-folder-entity-hashtb
1471 (wl-folder-create-entity-hashtb wl-folder-entity))
1472 (setq wl-folder-elmo-folder-hashtb (elmo-make-hash wl-folder-entity-id))
1473 (setq wl-folder-group-alist
1474 (wl-folder-create-group-alist wl-folder-entity))
1475 (setq wl-folder-newsgroups-hashtb
1476 (wl-folder-create-newsgroups-hashtb wl-folder-entity))
1477 (wl-folder-init-info-hashtb)
1478 (let ((inhibit-read-only t)
1479 (buffer-read-only nil))
1481 (setcdr (assoc (car wl-folder-entity) wl-folder-group-alist) t)
1483 (wl-folder-insert-entity " " wl-folder-entity)))
1485 (set-buffer-modified-p nil)
1486 (setq initialize t))
1489 (defun wl-folder-auto-check ()
1490 "Check and update folders in `wl-auto-check-folder-name'."
1492 (when (get-buffer wl-folder-buffer-name)
1493 (switch-to-buffer wl-folder-buffer-name)
1495 ((eq wl-auto-check-folder-name 'none))
1496 ((or (consp wl-auto-check-folder-name)
1497 (stringp wl-auto-check-folder-name))
1498 (let ((folder-list (if (consp wl-auto-check-folder-name)
1499 wl-auto-check-folder-name
1500 (list wl-auto-check-folder-name)))
1503 (if (setq entity (wl-folder-search-entity-by-name
1506 (wl-folder-check-entity entity 'auto))
1507 (setq folder-list (cdr folder-list)))))
1509 (wl-folder-check-entity wl-folder-entity 'auto)))))
1511 (defun wl-folder-set-folder-updated (name value)
1514 (if (setq buf (get-buffer wl-folder-buffer-name))
1515 (wl-folder-entity-hashtb-set
1516 wl-folder-entity-hashtb name value buf))
1517 (setq wl-folder-info-alist-modified t))))
1519 (defun wl-folder-calc-finfo (entity)
1520 ;; calcurate finfo without inserting.
1521 (let ((entities (list entity))
1523 new unread all nums)
1525 (setq entity (wl-pop entities))
1529 (wl-push entities entity-stack))
1530 (setq entities (nth 2 entity)))
1532 (setq nums (wl-folder-get-entity-info entity))
1533 (setq new (+ (or new 0) (or (nth 0 nums) 0)))
1534 (setq unread (+ (or unread 0)
1535 (or (and (nth 0 nums)(nth 1 nums)
1536 (+ (nth 0 nums)(nth 1 nums))) 0)))
1537 (setq all (+ (or all 0) (or (nth 2 nums) 0)))))
1539 (setq entities (wl-pop entity-stack))))
1540 (list new unread all)))
1542 (defsubst wl-folder-make-save-access-list (list)
1543 (mapcar '(lambda (x)
1546 (list (elmo-string (car x)) 'access))
1551 (defun wl-folder-update-newest (indent entity)
1552 (let (ret-val new unread all)
1555 (let ((inhibit-read-only t)
1556 (buffer-read-only nil)
1557 (flist (nth 2 entity))
1558 (as-opened (cdr (assoc (car entity) wl-folder-group-alist)))
1563 (let (update-flist flist-unsub new-flist removed group-name-end)
1564 (when (and (eq (cadr entity) 'access)
1565 (elmo-folder-plugged-p
1566 (wl-folder-get-elmo-folder (car entity))))
1567 (message "Fetching folder entries...")
1568 (when (setq new-flist
1569 (elmo-folder-list-subfolders
1570 (wl-folder-get-elmo-folder (car entity))
1573 wl-folder-hierarchy-access-folders)))
1575 (wl-folder-update-access-group entity new-flist))
1576 (setq flist (nth 1 update-flist))
1577 (when (car update-flist) ;; diff
1578 (setq flist-unsub (nth 2 update-flist))
1579 (setq removed (nth 3 update-flist))
1580 (elmo-msgdb-flist-save
1583 (wl-folder-make-save-access-list flist)
1584 (wl-folder-make-save-access-list flist-unsub)))
1585 (wl-folder-entity-assign-id
1587 wl-folder-entity-id-name-hashtb
1589 (setq wl-folder-entity-hashtb
1590 (wl-folder-create-entity-hashtb
1592 wl-folder-entity-hashtb
1594 (setq wl-folder-newsgroups-hashtb
1596 (wl-folder-create-newsgroups-hashtb
1598 wl-folder-newsgroups-hashtb))))
1599 (message "Fetching folder entries...done"))
1600 (wl-folder-insert-entity indent entity))))))))
1602 (defun wl-folder-insert-entity (indent entity &optional onlygroup)
1603 (let (ret-val new unread all)
1606 (let ((inhibit-read-only t)
1607 (buffer-read-only nil)
1608 (flist (nth 2 entity))
1609 (as-opened (cdr (assoc (car entity) wl-folder-group-alist)))
1612 ;;; (insert indent "[" (if as-opened "-" "+") "]" (car entity) "\n")
1613 ;;; (save-excursion (forward-line -1)
1614 ;;; (wl-highlight-folder-current-line))
1618 (let (update-flist flist-unsub new-flist removed group-name-end)
1619 ;;; (when (and (eq (cadr entity) 'access)
1621 ;;; (message "fetching folder entries...")
1622 ;;; (when (setq new-flist
1623 ;;; (elmo-list-folders
1624 ;;; (elmo-string (car entity))
1625 ;;; (wl-string-member
1627 ;;; wl-folder-hierarchy-access-folders)
1629 ;;; (setq update-flist
1630 ;;; (wl-folder-update-access-group entity new-flist))
1631 ;;; (setq flist (nth 1 update-flist))
1632 ;;; (when (car update-flist) ;; diff
1633 ;;; (setq flist-unsub (nth 2 update-flist))
1634 ;;; (setq removed (nth 3 update-flist))
1635 ;;; (elmo-msgdb-flist-save
1638 ;;; (wl-folder-make-save-access-list flist)
1639 ;;; (wl-folder-make-save-access-list flist-unsub)))
1641 ;;; ;; reconstruct wl-folder-entity-id-name-hashtb and
1642 ;;; ;; wl-folder-entity-hashtb
1644 ;;; (wl-folder-entity-assign-id
1646 ;;; wl-folder-entity-id-name-hashtb
1648 ;;; (setq wl-folder-entity-hashtb
1649 ;;; (wl-folder-create-entity-hashtb
1651 ;;; wl-folder-entity-hashtb
1653 ;;; (setq wl-folder-newsgroups-hashtb
1655 ;;; (wl-folder-create-newsgroups-hashtb
1657 ;;; wl-folder-newsgroups-hashtb))))
1658 ;;; (message "fetching folder entries...done"))
1659 (insert indent "[" (if as-opened "-" "+") "]"
1660 (wl-folder-get-petname (car entity)))
1661 (setq group-name-end (point))
1663 (put-text-property beg (point) 'wl-folder-entity-id
1664 (get-text-property 0 'wl-folder-entity-id
1670 wl-folder-removed-mark
1671 (if (listp (car removed))
1672 (concat "[+]" (caar removed))
1675 (save-excursion (forward-line -1)
1676 (wl-highlight-folder-current-line))
1677 (setq removed (cdr removed)))
1678 (remove-text-properties beg (point) '(wl-folder-entity-id)))
1679 (let* ((len (length flist))
1684 (wl-folder-insert-entity
1685 (concat indent " ") (car flist)))
1686 (setq new (+ (or new 0) (or (nth 0 ret-val) 0)))
1687 (setq unread (+ (or unread 0) (or (nth 1 ret-val) 0)))
1688 (setq all (+ (or all 0) (or (nth 2 ret-val) 0)))
1690 (> len elmo-display-progress-threshold))
1692 (elmo-display-progress
1693 'wl-folder-insert-entity "Inserting group %s..."
1694 (/ (* i 100) len) (car entity)))
1695 (setq flist (cdr flist))))
1697 (goto-char group-name-end)
1698 (delete-region (point) (save-excursion (end-of-line)
1700 (insert (format ":%d/%d/%d" (or new 0)
1701 (or unread 0) (or all 0)))
1702 (setq ret-val (list new unread all))
1703 (wl-highlight-folder-current-line ret-val)))
1704 (setq ret-val (wl-folder-calc-finfo entity))
1705 (insert indent "[" (if as-opened "-" "+") "]"
1706 (wl-folder-get-petname (car entity))
1708 (or (nth 0 ret-val) 0)
1709 (or (nth 1 ret-val) 0)
1710 (or (nth 2 ret-val) 0))
1712 (put-text-property beg (point) 'wl-folder-entity-id
1713 (get-text-property 0 'wl-folder-entity-id
1715 (save-excursion (forward-line -1)
1716 (wl-highlight-folder-current-line ret-val)))))
1718 (let* ((inhibit-read-only t)
1719 (buffer-read-only nil)
1720 (nums (wl-folder-get-entity-info entity))
1723 (insert indent (wl-folder-get-petname entity)
1724 (format ":%s/%s/%s\n"
1725 (or (setq new (nth 0 nums)) "*")
1726 (or (setq unread (and (nth 0 nums)(nth 1 nums)
1727 (+ (nth 0 nums)(nth 1 nums))))
1729 (or (setq all (nth 2 nums)) "*")))
1730 (put-text-property beg (point) 'wl-folder-entity-id
1731 (get-text-property 0 'wl-folder-entity-id entity))
1732 (save-excursion (forward-line -1)
1733 (wl-highlight-folder-current-line nums))
1734 (setq ret-val (list new unread all)))))
1735 (set-buffer-modified-p nil)
1738 (defun wl-folder-check-all ()
1740 (wl-folder-check-entity wl-folder-entity))
1742 (defun wl-folder-entity-hashtb-set (entity-hashtb name value buffer)
1749 (setq cur-val (wl-folder-get-entity-info name entity-hashtb))
1750 (setq new-diff (- (or (nth 0 value) 0) (or (nth 0 cur-val) 0)))
1753 (- (or (nth 1 value) 0) (or (nth 1 cur-val) 0))))
1754 (setq all-diff (- (or (nth 2 value) 0) (or (nth 2 cur-val) 0)))
1755 (setq diffs (list new-diff unread-diff all-diff))
1756 (unless (and (nth 0 cur-val)
1757 (equal diffs '(0 0 0)))
1758 (wl-folder-set-entity-info name value entity-hashtb)
1760 (with-current-buffer buffer
1762 (setq entity-list (wl-folder-search-entity-list-by-name
1763 name wl-folder-entity))
1765 (wl-folder-update-group (car entity-list) diffs)
1766 (setq entity-list (cdr entity-list)))
1767 (goto-char (point-min))
1768 (while (wl-folder-buffer-search-entity name)
1769 (wl-folder-update-line value))))))))
1771 (defun wl-folder-update-unread (folder unread)
1772 ; (save-window-excursion
1773 (let ((buf (get-buffer wl-folder-buffer-name))
1776 ;;(fld (elmo-string folder))
1777 value newvalue entity-list)
1778 ;;; Update folder-info
1779 ;;; (elmo-folder-set-info-hashtb fld nil nil nil unread)
1780 (setq cur-unread (or (nth 1 (wl-folder-get-entity-info folder)) 0))
1781 (setq unread-diff (- (or unread 0) cur-unread))
1782 (setq value (wl-folder-get-entity-info folder))
1783 (setq newvalue (list (nth 0 value)
1786 (wl-folder-set-entity-info folder newvalue)
1787 (setq wl-folder-info-alist-modified t)
1789 (not (eq unread-diff 0)))
1791 (with-current-buffer buf
1793 (setq entity-list (wl-folder-search-entity-list-by-name
1794 folder wl-folder-entity))
1796 (wl-folder-update-group (car entity-list) (list 0
1799 (setq entity-list (cdr entity-list)))
1800 (goto-char (point-min))
1801 (while (wl-folder-buffer-search-entity folder)
1802 (wl-folder-update-line newvalue))))))));)
1804 (defun wl-folder-create-entity-hashtb (entity &optional hashtb reconst)
1805 (let ((hashtb (or hashtb (elmo-make-hash wl-folder-entity-id)))
1806 (entities (list entity))
1809 (setq entity (wl-pop entities))
1813 (wl-push entities entity-stack))
1814 (setq entities (nth 2 entity)))
1816 (when (not (and reconst
1817 (wl-folder-get-entity-info entity)))
1818 (wl-folder-set-entity-info entity
1822 (setq entities (wl-pop entity-stack))))
1825 ;; Unsync number is reserved.
1826 ;;(defun wl-folder-reconstruct-entity-hashtb (entity &optional hashtb id-name)
1827 ;; (let* ((hashtb (or hashtb (elmo-make-hash wl-folder-entity-id)))
1828 ;; (entities (list entity))
1831 ;; (setq entity (wl-pop entities))
1835 ;; (wl-folder-set-id-name (wl-folder-get-entity-id (car entity))
1838 ;; (wl-push entities entity-stack))
1839 ;; (setq entities (nth 2 entity))
1841 ;; ((stringp entity)
1842 ;; (wl-folder-set-entity-info entity
1843 ;; (wl-folder-get-entity-info entity)
1846 ;; (wl-folder-set-id-name (wl-folder-get-entity-id entity)
1849 ;; (setq entities (wl-pop entity-stack))))
1852 (defun wl-folder-create-newsgroups-from-nntp-access (entity)
1853 (let ((flist (nth 2 entity))
1858 ((consp (car flist))
1859 (wl-folder-create-newsgroups-from-nntp-access (car flist)))
1862 (elmo-nntp-folder-group-internal
1863 (wl-folder-get-elmo-folder (car flist)))))))
1864 (setq flist (cdr flist)))
1867 (defun wl-folder-create-newsgroups-hashtb (entity &optional is-list info)
1868 "Create NNTP group hashtable for ENTITY."
1869 (let ((entities (if is-list entity (list entity)))
1870 entity-stack folder-list newsgroups newsgroup make-hashtb)
1871 (and info (message "Creating newsgroups..."))
1873 (setq entity (wl-pop entities))
1876 (if (eq (nth 1 entity) 'access)
1877 (when (eq (elmo-folder-type-internal
1878 (elmo-make-folder (car entity))) 'nntp)
1879 (wl-append newsgroups
1880 (wl-folder-create-newsgroups-from-nntp-access entity))
1881 (setq make-hashtb t))
1883 (wl-push entities entity-stack))
1884 (setq entities (nth 2 entity))))
1886 (setq folder-list (elmo-folder-get-primitive-list
1887 (elmo-make-folder entity)))
1889 (when (and (eq (elmo-folder-type-internal (car folder-list))
1891 (setq newsgroup (elmo-nntp-folder-group-internal
1892 (car folder-list))))
1893 (wl-append newsgroups (list (elmo-string newsgroup))))
1894 (setq folder-list (cdr folder-list)))))
1896 (setq entities (wl-pop entity-stack))))
1897 (and info (message "Creating newsgroups...done"))
1898 (if (or newsgroups make-hashtb)
1899 (elmo-setup-subscribed-newsgroups newsgroups))))
1901 (defun wl-folder-get-path (entity target-id &optional string)
1902 (let ((entities (list entity))
1903 entity-stack result-path)
1907 (setq entity (wl-pop entities))
1910 (if (and (or (not string) (string= string (car entity)))
1911 ;; don't use eq, `id' is string on Nemacs.
1912 (equal target-id (wl-folder-get-entity-id (car entity))))
1914 (wl-push target-id result-path))
1915 (wl-push (wl-folder-get-entity-id (car entity)) result-path))
1916 (wl-push entities entity-stack)
1917 (setq entities (nth 2 entity)))
1919 (if (and (or (not string) (string= string entity))
1920 ;; don't use eq, `id' is string on Nemacs.
1921 (equal target-id (wl-folder-get-entity-id entity)))
1923 (wl-push target-id result-path)))))
1925 (while (and entity-stack
1927 (setq result-path (cdr result-path))
1928 (setq entities (wl-pop entity-stack)))))))))
1930 (defun wl-folder-create-group-alist (entity)
1932 (let ((flist (nth 2 entity))
1933 (cur-alist (list (cons (car entity) nil)))
1936 (if (consp (car flist))
1937 (wl-append append-alist
1938 (wl-folder-create-group-alist (car flist))))
1939 (setq flist (cdr flist)))
1940 (append cur-alist append-alist))))
1942 (defun wl-folder-init-info-hashtb ()
1943 (let ((info-alist (and wl-folder-info-save
1944 (elmo-msgdb-finfo-load))))
1945 (elmo-folder-info-make-hashtb
1947 wl-folder-entity-hashtb)))
1948 ;;; (wl-folder-resume-entity-hashtb-by-finfo
1949 ;;; wl-folder-entity-hashtb
1952 (defun wl-folder-cleanup-variables ()
1953 (setq wl-folder-entity nil
1954 wl-folder-entity-hashtb nil
1955 wl-folder-entity-id-name-hashtb nil
1956 wl-folder-group-alist nil
1957 wl-folder-petname-alist nil
1958 wl-folder-newsgroups-hashtb nil
1959 wl-fldmgr-cut-entity-list nil
1960 wl-fldmgr-modified nil
1961 wl-fldmgr-modified-access-list nil
1965 (defun wl-make-plugged-alist ()
1966 (let ((entity-list (wl-folder-get-entity-list wl-folder-entity))
1967 (add (not wl-reset-plugged-alist)))
1969 (elmo-folder-set-plugged
1970 (wl-folder-get-elmo-folder (car entity-list)) wl-plugged add)
1971 (setq entity-list (cdr entity-list)))
1972 ;; smtp posting server
1973 (when wl-smtp-posting-server
1974 (elmo-set-plugged wl-plugged
1975 wl-smtp-posting-server ; server
1976 (or (and (boundp 'smtp-service) smtp-service)
1978 wl-smtp-connection-type
1979 nil nil "smtp" add))
1980 ;; nntp posting server
1981 (when wl-nntp-posting-server
1982 (elmo-set-plugged wl-plugged
1983 wl-nntp-posting-server
1984 wl-nntp-posting-stream-type
1985 wl-nntp-posting-port
1986 nil nil "nntp" add))
1987 (run-hooks 'wl-make-plugged-hook)))
1989 (defvar wl-folder-init-function 'wl-local-folder-init)
1991 (defun wl-folder-init ()
1992 "Return top-level folder entity."
1996 (funcall wl-folder-init-function)))
1998 (defun wl-local-folder-init ()
1999 "Initialize local folder."
2000 (message "Initializing folder...")
2001 (setq wl-folder-entity (wl-folder-create-folder-entity))
2002 (message "Initializing folder...done"))
2004 (defun wl-folder-get-realname (petname)
2008 wl-folder-petname-alist))
2011 (defun wl-folder-get-petname (name)
2015 wl-folder-petname-alist))
2018 (defun wl-folder-get-entity-with-petname ()
2019 (let ((alist wl-folder-petname-alist)
2020 (hashtb (copy-sequence wl-folder-entity-hashtb)))
2022 (wl-folder-set-entity-info (cdar alist) nil hashtb)
2023 (setq alist (cdr alist)))
2026 (defun wl-folder-get-newsgroups (folder)
2027 "Return Newsgroups field value string for FOLDER newsgroup.
2028 If FOLDER is multi, return comma separated string (cross post)."
2029 (let ((flist (elmo-folder-get-primitive-list
2030 (wl-folder-get-elmo-folder folder))) ; multi
2032 (while (setq fld (car flist))
2034 (cond ((eq 'nntp (elmo-folder-type-internal fld))
2035 (elmo-nntp-folder-group-internal fld))
2036 ((eq 'localnews (elmo-folder-type-internal fld))
2037 (elmo-replace-in-string
2038 (elmo-nntp-folder-group-internal fld)
2041 (setq newsgroups (if (stringp newsgroups)
2042 (concat newsgroups "," ret)
2044 (setq flist (cdr flist)))
2045 (list nil nil newsgroups)))
2047 (defun wl-folder-guess-mailing-list-by-refile-rule (entity)
2048 "Return ML address guess by FOLDER.
2049 Use `wl-subscribed-mailing-list' and `wl-refile-rule-alist'."
2051 (elmo-folder-get-primitive-list
2052 (wl-folder-get-elmo-folder entity)))
2054 (while (setq fld (car flist))
2056 (wl-folder-guess-mailing-list-by-refile-rule-subr
2057 (elmo-folder-name-internal fld)))
2058 (setq mlist (if (stringp mlist)
2059 (concat mlist ", " ret)
2061 (setq flist (cdr flist)))
2063 (list mlist nil nil))))
2065 (defun wl-folder-guess-mailing-list-by-refile-rule-subr (entity)
2066 (unless (memq (elmo-folder-type entity)
2068 (let ((rules wl-refile-rule-alist)
2071 (if (or (and (stringp (car (car rules)))
2072 (string-match "[Tt]o" (car (car rules))))
2073 (and (listp (car (car rules)))
2074 (elmo-string-matched-member "to" (car (car rules))
2076 (setq toalist (append toalist (cdr (car rules)))))
2077 (setq rules (cdr rules)))
2078 (setq tokey (car (rassoc entity toalist)))
2079 ;;; (setq histkey (car (rassoc folder wl-refile-alist)))
2080 ;; case-ignore search `wl-subscribed-mailing-list'
2082 (elmo-string-matched-member tokey wl-subscribed-mailing-list t)))))
2084 (defun wl-folder-guess-mailing-list-by-folder-name (entity)
2085 "Return ML address guess by FOLDER name's last hierarchy.
2086 Use `wl-subscribed-mailing-list'."
2088 (elmo-folder-get-primitive-list
2089 (wl-folder-get-elmo-folder entity)))
2091 (while (setq fld (car flist))
2093 (wl-folder-guess-mailing-list-by-folder-name-subr
2094 (elmo-folder-name-internal fld)))
2095 (setq mlist (if (stringp mlist)
2096 (concat mlist ", " ret)
2098 (setq flist (cdr flist)))
2100 (list mlist nil nil))))
2102 (defun wl-folder-guess-mailing-list-by-folder-name-subr (entity)
2103 (when (memq (elmo-folder-type entity)
2104 '(localdir imap4 maildir))
2105 (let (key foldername)
2106 ;; Get foldername and Remove folder type symbol.
2107 (setq foldername (substring entity 1))
2108 (if (string-match "@" foldername)
2109 (setq foldername (substring foldername 0 (match-beginning 0))))
2110 (when (string-match "[^\\./]+$" foldername)
2111 (setq key (regexp-quote
2112 (concat (substring foldername (match-beginning 0)) "@")))
2113 (elmo-string-matched-member
2114 key wl-subscribed-mailing-list 'case-ignore)))))
2116 (defun wl-folder-update-diff-line (diffs)
2117 (let ((inhibit-read-only t)
2118 (buffer-read-only nil)
2120 cur-unread new-unread
2125 (setq id (get-text-property (point) 'wl-folder-entity-id))
2126 (when (looking-at "^[ ]*\\(.*\\):\\([0-9\\*-]*\\)/\\([0-9\\*-]*\\)/\\([0-9\\*]*\\)")
2127 ;;(looking-at "^[ ]*\\([^\\[].+\\):\\([0-9\\*-]*/[0-9\\*-]*/[0-9\\*]*\\)")
2128 (setq cur-new (string-to-int
2129 (wl-match-buffer 2)))
2130 (setq cur-unread (string-to-int
2131 (wl-match-buffer 3)))
2132 (setq cur-all (string-to-int
2133 (wl-match-buffer 4)))
2134 (delete-region (match-beginning 2)
2136 (goto-char (match-beginning 2))
2137 (insert (format "%s/%s/%s"
2138 (setq new-new (+ cur-new (nth 0 diffs)))
2139 (setq new-unread (+ cur-unread (nth 1 diffs)))
2140 (setq new-all (+ cur-all (nth 2 diffs)))))
2141 (put-text-property (match-beginning 2) (point)
2142 'wl-folder-entity-id id)
2143 (if wl-use-highlight-mouse-line
2144 (put-text-property (match-beginning 2) (point)
2145 'mouse-face 'highlight))
2146 (wl-highlight-folder-group-line (list new-new new-unread new-all))
2147 (setq buffer-read-only t)
2148 (set-buffer-modified-p nil)))))
2150 (defun wl-folder-update-line (nums &optional is-group)
2151 (let ((inhibit-read-only t)
2152 (buffer-read-only nil)
2156 (setq id (get-text-property (point) 'wl-folder-entity-id))
2157 (if (looking-at "^[ ]*\\(.*\\):\\([0-9\\*-]*/[0-9\\*-]*/[0-9\\*]*\\)")
2158 ;;; (looking-at "^[ ]*\\([^\\[].+\\):\\([0-9\\*-]*/[0-9\\*-]*/[0-9\\*]*\\)")
2160 (delete-region (match-beginning 2)
2162 (goto-char (match-beginning 2))
2163 (insert (format "%s/%s/%s"
2164 (or (nth 0 nums) "*")
2165 (or (and (nth 0 nums)(nth 1 nums)
2166 (+ (nth 0 nums)(nth 1 nums)))
2168 (or (nth 2 nums) "*")))
2169 (put-text-property (match-beginning 2) (point)
2170 'wl-folder-entity-id id)
2172 ;; update only colors
2173 (wl-highlight-folder-group-line nums)
2174 (wl-highlight-folder-current-line nums))
2176 (set-buffer-modified-p nil))))))
2178 (defun wl-folder-goto-folder (&optional arg)
2180 (wl-folder-goto-folder-subr nil arg))
2182 (defun wl-folder-goto-folder-subr (&optional folder sticky)
2184 (let (summary-buf fld-name entity id error-selecting)
2185 ;;; (setq fld-name (wl-folder-get-entity-from-buffer))
2186 ;;; (if (or (null fld-name)
2187 ;;; (assoc fld-name wl-folder-group-alist))
2188 (setq fld-name wl-default-folder)
2189 (setq fld-name (or folder
2190 (wl-summary-read-folder fld-name)))
2191 (if (and (setq entity
2192 (wl-folder-search-entity-by-name fld-name
2195 (setq id (wl-folder-get-entity-id entity)))
2196 (wl-folder-set-current-entity-id id))
2197 (setq summary-buf (wl-summary-get-buffer-create fld-name sticky))
2198 (if (or wl-stay-folder-window wl-summary-use-frame)
2199 (wl-folder-select-buffer summary-buf)
2200 (if (and summary-buf
2201 (get-buffer-window summary-buf))
2203 (wl-summary-goto-folder-subr fld-name
2204 (wl-summary-get-sync-range
2205 (wl-folder-get-elmo-folder fld-name))
2208 (defun wl-folder-suspend ()
2210 (run-hooks 'wl-folder-suspend-hook)
2211 (wl-folder-info-save)
2212 (elmo-crosspost-message-alist-save)
2214 ;(if (fboundp 'mmelmo-cleanup-entity-buffers)
2215 ;(mmelmo-cleanup-entity-buffers))
2216 (bury-buffer wl-folder-buffer-name)
2217 (delete-windows-on wl-folder-buffer-name t))
2219 (defun wl-folder-info-save ()
2220 (when (and wl-folder-info-save
2221 wl-folder-info-alist-modified)
2222 (let ((entities (list wl-folder-entity))
2223 entity entity-stack info-alist info)
2225 (setq entity (wl-pop entities))
2229 (wl-push entities entity-stack))
2230 (setq entities (nth 2 entity)))
2232 (when (and (setq info (elmo-folder-get-info
2233 (wl-folder-get-elmo-folder entity)))
2234 (not (equal info '(nil))))
2236 (wl-append info-alist (list (list (elmo-string entity)
2237 (list (nth 3 info) ;; max
2238 (nth 2 info) ;; length
2240 (nth 1 info)) ;; unread
2243 (setq entities (wl-pop entity-stack))))
2244 (elmo-msgdb-finfo-save info-alist)
2245 (setq wl-folder-info-alist-modified nil))))
2247 (defun wl-folder-goto-first-unread-folder (&optional arg)
2249 (let ((entities (list wl-folder-entity))
2250 entity entity-stack ret-val
2255 (setq entity (wl-pop entities))
2259 (wl-push entities entity-stack))
2260 (setq entities (nth 2 entity)))
2262 (if (and (setq finfo (wl-folder-get-entity-info entity))
2263 (and (nth 0 finfo)(nth 1 finfo))
2264 (> (+ (nth 0 finfo)(nth 1 finfo)) 0))
2265 (throw 'done entity))
2266 (wl-append ret-val (list entity))))
2268 (setq entities (wl-pop entity-stack))))))
2272 (wl-folder-jump-folder first-entity)
2274 (wl-folder-goto-folder-subr first-entity))
2275 (message "No unread folder"))))
2277 (defun wl-folder-jump-folder (&optional fld-name noopen)
2280 (setq fld-name (wl-summary-read-folder wl-default-folder)))
2281 (goto-char (point-min))
2283 (wl-folder-open-folder fld-name))
2284 (and (wl-folder-buffer-search-entity fld-name)
2285 (beginning-of-line)))
2287 (defun wl-folder-get-entity-list (entity)
2288 (let ((entities (list entity))
2289 entity-stack ret-val)
2291 (setq entity (wl-pop entities))
2295 (wl-push entities entity-stack))
2296 (setq entities (nth 2 entity)))
2298 (wl-append ret-val (list entity))))
2300 (setq entities (wl-pop entity-stack))))
2303 (defun wl-folder-open-unread-folder (entity)
2305 (let ((alist (wl-folder-get-entity-list entity))
2307 finfo path-list path id)
2309 (when (and (setq finfo (wl-folder-get-entity-info (car alist)))
2310 (nth 0 finfo) (nth 1 finfo)
2311 (> (+ (nth 0 finfo)(nth 1 finfo)) 0))
2312 (setq unread (+ unread (+ (nth 0 finfo)(nth 1 finfo))))
2313 (setq id (wl-folder-get-entity-id (car alist)))
2314 (setq path (delete id (wl-folder-get-path
2318 (if (not (member path path-list))
2319 (wl-append path-list (list path))))
2320 (setq alist (cdr alist)))
2322 (wl-folder-open-folder-sub (car path-list))
2323 (setq path-list (cdr path-list)))
2324 (message "%s unread folder"
2325 (if (> unread 0) unread "No")))))
2327 (defun wl-folder-open-unread-current-entity ()
2329 (let ((entity-name (wl-folder-get-entity-from-buffer))
2330 (group (wl-folder-buffer-group-p)))
2332 (wl-folder-open-unread-folder
2334 (wl-folder-search-group-entity-by-name entity-name
2338 (defun wl-folder-open-only-unread-folder ()
2341 (wl-folder-prev-entity-skip-invalid t)
2342 (wl-folder-get-entity-from-buffer t))))
2343 (wl-folder-open-all-unread-folder)
2345 (goto-char (point-max))
2346 (while (and (re-search-backward
2347 "^[ ]*\\[[-]\\].+:0/0/[0-9-]+" nil t)
2349 (wl-folder-jump-to-current-entity) ;; close it
2351 (wl-folder-move-path id)
2354 (defun wl-folder-open-all-unread-folder (&optional arg)
2357 (wl-folder-prev-entity-skip-invalid t)
2358 (wl-folder-get-entity-from-buffer t))))
2359 (wl-folder-open-unread-folder wl-folder-entity)
2361 (wl-folder-move-path id)
2362 (goto-char (point-min))
2363 (wl-folder-next-unread t))))
2365 (defun wl-folder-open-folder (&optional fld-name)
2368 (setq fld-name (wl-summary-read-folder wl-default-folder)))
2369 (let* ((id (wl-folder-get-entity-id
2370 (wl-folder-search-entity-by-name fld-name wl-folder-entity
2372 (path (and id (wl-folder-get-path wl-folder-entity id))))
2374 (wl-folder-open-folder-sub path))))
2376 (defun wl-folder-open-folder-sub (path)
2377 (let ((inhibit-read-only t)
2378 (buffer-read-only nil)
2382 (goto-char (point-min))
2384 (wl-folder-buffer-search-group
2385 (wl-folder-get-petname
2386 (if (stringp (car path))
2388 (wl-folder-get-folder-name-by-id
2391 (setq path (cdr path))
2392 (if (and (looking-at wl-folder-group-regexp)
2393 (string= "+" (wl-match-buffer 2)));; closed group
2395 (setq indent (wl-match-buffer 1))
2396 (setq name (wl-folder-get-realname (wl-match-buffer 3)))
2397 (setq entity (wl-folder-search-group-entity-by-name
2401 (setcdr (assoc (car entity) wl-folder-group-alist) t)
2402 (if (eq 'access (cadr entity))
2403 (wl-folder-maybe-load-folder-list entity))
2404 (wl-folder-insert-entity indent entity)
2405 (delete-region (save-excursion (beginning-of-line)
2407 (save-excursion (end-of-line)
2409 (set-buffer-modified-p nil))))
2411 (defun wl-folder-open-all-pre ()
2412 (let ((entities (list wl-folder-entity))
2413 entity entity-stack group-entry)
2415 (setq entity (wl-pop entities))
2418 (unless (or (not (setq group-entry
2419 (assoc (car entity) wl-folder-group-alist)))
2421 (setcdr group-entry t)
2422 (when (eq 'access (cadr entity))
2423 (wl-folder-maybe-load-folder-list entity)))
2425 (wl-push entities entity-stack))
2426 (setq entities (nth 2 entity))))
2428 (setq entities (wl-pop entity-stack))))))
2430 (defun wl-folder-open-all (&optional refresh)
2432 (let* ((inhibit-read-only t)
2433 (buffer-read-only nil)
2434 (len (length wl-folder-group-alist))
2439 (wl-folder-prev-entity-skip-invalid t)
2440 (wl-folder-get-entity-from-buffer t)))
2441 (alist wl-folder-group-alist))
2443 (setcdr (pop alist) t))
2445 (wl-folder-insert-entity " " wl-folder-entity)
2446 (wl-folder-move-path id))
2447 (message "Opening all folders...")
2448 (wl-folder-open-all-pre)
2450 (goto-char (point-min))
2451 (while (re-search-forward
2452 "^\\([ ]*\\)\\[\\([+]\\)\\]\\(.+\\):[-0-9-]+/[0-9-]+/[0-9-]+\n"
2454 (setq indent (wl-match-buffer 1))
2455 (setq name (wl-folder-get-realname (wl-match-buffer 3)))
2456 (setq entity (wl-folder-search-group-entity-by-name
2460 (setcdr (assoc (car entity) wl-folder-group-alist) t)
2462 (wl-folder-insert-entity indent entity)
2463 (delete-region (save-excursion (beginning-of-line)
2465 (save-excursion (end-of-line)
2467 (when (> len elmo-display-progress-threshold)
2469 (if (or (zerop (% i 5)) (= i len))
2470 (elmo-display-progress
2471 'wl-folder-open-all "Opening all folders..."
2472 (/ (* i 100) len)))))
2473 (when (> len elmo-display-progress-threshold)
2474 (elmo-display-progress
2475 'wl-folder-open-all "Opening all folders..." 100))))
2476 (message "Opening all folders...done")
2477 (set-buffer-modified-p nil)))
2479 (defun wl-folder-close-all ()
2481 (let ((inhibit-read-only t)
2482 (buffer-read-only nil)
2483 (alist wl-folder-group-alist)
2485 (wl-folder-prev-entity-skip-invalid t)
2486 (wl-folder-get-entity-from-buffer t))))
2488 (setcdr (car alist) nil)
2489 (setq alist (cdr alist)))
2490 (setcdr (assoc (car wl-folder-entity) wl-folder-group-alist) t)
2492 (wl-folder-insert-entity " " wl-folder-entity)
2493 (wl-folder-move-path id)
2495 (set-buffer-modified-p nil)))
2497 (defun wl-folder-open-close ()
2498 "Open or close parent entity."
2502 (if (wl-folder-buffer-group-p)
2503 ;; if group (whether opend or closed.)
2504 (wl-folder-jump-to-current-entity)
2507 (setq indent (save-excursion
2508 (re-search-forward "\\([ ]*\\)." nil t)
2509 (wl-match-buffer 1)))
2510 (while (looking-at indent)
2512 (wl-folder-jump-to-current-entity))))
2514 (defsubst wl-folder-access-subscribe-p (group folder)
2515 (let (subscr regexp match)
2516 (if (setq subscr (wl-get-assoc-list-value
2517 wl-folder-access-subscribe-alist
2520 (setq regexp (mapconcat 'identity (cdr subscr) "\\|"))
2521 (setq match (string-match regexp folder))
2527 (defun wl-folder-update-access-group (entity new-flist)
2528 (let* ((flist (nth 2 entity))
2529 (unsubscribes (nth 3 entity))
2530 (len (+ (length flist) (length unsubscribes)))
2532 diff new-unsubscribes removes
2533 subscribed-list folder group entry)
2534 ;; check subscribed groups
2537 ((listp (car flist)) ;; group
2538 (setq group (elmo-string (caar flist)))
2540 ((assoc group new-flist) ;; found in new-flist
2541 (setq new-flist (delete (assoc group new-flist)
2543 (if (wl-folder-access-subscribe-p (car entity) group)
2544 (wl-append subscribed-list (list (car flist)))
2545 (wl-append new-unsubscribes (list (car flist)))
2548 (setq wl-folder-group-alist
2549 (delete (wl-string-assoc group wl-folder-group-alist)
2550 wl-folder-group-alist))
2551 (wl-append removes (list (list group))))))
2553 (setq folder (elmo-string (car flist)))
2555 ((member folder new-flist) ;; found in new-flist
2556 (setq new-flist (delete folder new-flist))
2557 (if (wl-folder-access-subscribe-p (car entity) folder)
2558 (wl-append subscribed-list (list (car flist)))
2559 (wl-append new-unsubscribes (list folder))
2562 (wl-append removes (list folder))))))
2563 (when (> len elmo-display-progress-threshold)
2565 (if (or (zerop (% i 10)) (= i len))
2566 (elmo-display-progress
2567 'wl-folder-update-access-group "Updating access group..."
2568 (/ (* i 100) len))))
2569 (setq flist (cdr flist)))
2570 ;; check unsubscribed groups
2573 ((listp (car unsubscribes))
2574 (when (setq entry (assoc (caar unsubscribes) new-flist))
2575 (setq new-flist (delete entry new-flist))
2576 (wl-append new-unsubscribes (list (car unsubscribes)))))
2578 (when (member (car unsubscribes) new-flist)
2579 (setq new-flist (delete (car unsubscribes) new-flist))
2580 (wl-append new-unsubscribes (list (car unsubscribes))))))
2581 (when (> len elmo-display-progress-threshold)
2583 (if (or (zerop (% i 10)) (= i len))
2584 (elmo-display-progress
2585 'wl-folder-update-access-group "Updating access group..."
2586 (/ (* i 100) len))))
2587 (setq unsubscribes (cdr unsubscribes)))
2589 (if (or new-flist removes)
2592 (mapcar '(lambda (x)
2593 (cond ((consp x) (list (car x) 'access))
2597 (let ((new-list new-flist))
2599 (if (not (wl-folder-access-subscribe-p
2601 (if (listp (car new-list))
2606 (wl-append new-unsubscribes (list (car new-list)))
2607 (setq new-flist (delete (car new-list) new-flist)))
2609 ((listp (car new-list))
2610 ;; check group exists
2611 (if (wl-string-assoc (caar new-list) wl-folder-group-alist)
2613 (message "%s: group already exists." (caar new-list))
2615 (wl-append new-unsubscribes (list (car new-list)))
2616 (setq new-flist (delete (car new-list) new-flist)))
2617 (wl-append wl-folder-group-alist
2618 (list (cons (caar new-list) nil)))))))
2619 (setq new-list (cdr new-list))))
2621 (message "%d new folder(s)." (length new-flist))
2622 (message "Updating access group...done"))
2623 (wl-append new-flist subscribed-list) ;; new is first
2624 (run-hooks 'wl-folder-update-access-group-hook)
2625 (setcdr (cdr entity) (list new-flist new-unsubscribes))
2626 (list diff new-flist new-unsubscribes removes)))
2628 (defun wl-folder-prefetch-entity (entity)
2629 "Prefetch all new messages in the ENTITY."
2632 (let ((flist (nth 2 entity))
2637 (setq result (wl-folder-prefetch-entity (car flist)))
2638 (setq sum-done (+ sum-done (car result)))
2639 (setq sum-all (+ sum-all (cdr result)))
2640 (setq flist (cdr flist)))
2641 (message "Prefetched %d/%d message(s) in \"%s\"."
2643 (wl-folder-get-petname (car entity)))
2644 (cons sum-done sum-all)))
2646 (let* ((folder (wl-folder-get-elmo-folder entity))
2647 (nums (wl-folder-get-entity-info entity))
2648 (wl-summary-highlight (if (or (wl-summary-sticky-p folder)
2649 (wl-summary-always-sticky-folder-p
2651 wl-summary-highlight))
2652 wl-summary-exit-next-move
2653 wl-auto-select-first ret-val
2655 (setq count (or (car nums) 0))
2656 (setq count (+ count (wl-folder-count-incorporates folder)))
2657 (if (or (null (car nums)) ; unknown
2659 (save-window-excursion
2661 (let ((wl-summary-buffer-name (concat
2662 wl-summary-buffer-name
2663 (symbol-name this-command)))
2664 (wl-summary-use-frame nil)
2665 (wl-summary-always-sticky-folder-list nil))
2666 (wl-summary-goto-folder-subr entity
2667 (wl-summary-get-sync-range
2670 (setq ret-val (wl-summary-incorporate))
2675 (defun wl-folder-count-incorporates (folder)
2676 (let ((marks (elmo-msgdb-mark-load
2677 (elmo-folder-msgdb-path folder)))
2680 (if (member (cadr (car marks))
2681 wl-summary-incorporate-marks)
2683 (setq marks (cdr marks)))
2686 (defun wl-folder-prefetch-current-entity (&optional no-check)
2687 "Prefetch all uncached messages in the folder at position.
2688 If current line is group folder, all subfolders are prefetched."
2691 (let ((entity-name (wl-folder-get-entity-from-buffer))
2692 (group (wl-folder-buffer-group-p))
2693 wl-folder-check-entity-hook
2698 (wl-folder-search-group-entity-by-name entity-name
2702 (wl-folder-check-entity entity))
2703 (wl-folder-prefetch-entity entity)))))
2705 ;(defun wl-folder-drop-unsync-entity (entity)
2706 ; "Drop all unsync messages in the ENTITY."
2709 ; (let ((flist (nth 2 entity)))
2711 ; (wl-folder-drop-unsync-entity (car flist))
2712 ; (setq flist (cdr flist)))))
2714 ; (let ((nums (wl-folder-get-entity-info entity))
2715 ; wl-summary-highlight wl-auto-select-first new)
2716 ; (setq new (or (car nums) 0))
2718 ; (save-window-excursion
2720 ; (let ((wl-summary-buffer-name (concat
2721 ; wl-summary-buffer-name
2722 ; (symbol-name this-command))))
2723 ; (wl-summary-goto-folder-subr entity 'no-sync nil)
2724 ; (wl-summary-drop-unsync)
2725 ; (wl-summary-exit)))))))))
2727 ;(defun wl-folder-drop-unsync-current-entity (&optional force-check)
2728 ; "Drop all unsync messages in the folder at position.
2729 ;If current line is group folder, all subfolders are dropped.
2730 ;If optional arg exists, don't check any folders."
2733 ; (let ((entity-name (wl-folder-get-entity-from-buffer))
2734 ; (group (wl-folder-buffer-group-p))
2735 ; wl-folder-check-entity-hook
2736 ; summary-buf entity)
2737 ; (when (and entity-name
2739 ; "Drop all unsync messages in %s?" entity-name)))
2742 ; (wl-folder-search-group-entity-by-name entity-name
2745 ; (if (null force-check)
2746 ; (wl-folder-check-entity entity))
2747 ; (wl-folder-drop-unsync-entity entity)
2748 ; (message "All unsync messages in %s are dropped!" entity-name)))))
2750 (defun wl-folder-write-current-folder ()
2751 "Write message to current folder's newsgroup or mailing-list.
2752 Call `wl-summary-write-current-folder' with current folder name."
2754 (unless (wl-folder-buffer-group-p)
2755 (wl-summary-write-current-folder
2756 (wl-folder-get-realname (wl-folder-entity-name)))))
2758 (defun wl-folder-mimic-kill-buffer ()
2759 "Kill the current (Folder) buffer with query."
2761 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
2763 wl-interactive-exit)
2764 (if (or (not bufname)
2765 (string-equal bufname "")
2766 (string-equal bufname (buffer-name)))
2768 (kill-buffer bufname))))
2770 (defun wl-folder-create-subr (folder)
2771 (if (not (elmo-folder-creatable-p folder))
2772 (error "Folder %s is not found" (elmo-folder-name-internal folder))
2774 (format "Folder %s does not exist, create it?"
2775 (elmo-folder-name-internal folder)))
2777 (setq wl-folder-entity-hashtb
2778 (wl-folder-create-entity-hashtb
2779 (elmo-folder-name-internal folder)
2780 wl-folder-entity-hashtb))
2781 (unless (elmo-folder-create folder)
2782 (error "Create folder failed")))
2783 (error "Folder %s is not created" (elmo-folder-name-internal folder)))))
2785 (defun wl-folder-confirm-existence (folder &optional force)
2787 (unless (elmo-folder-exists-p folder)
2788 (wl-folder-create-subr folder))
2789 (unless (or (wl-folder-entity-exists-p (elmo-folder-name-internal folder))
2790 (file-exists-p (elmo-folder-msgdb-path folder))
2791 (elmo-folder-exists-p folder))
2792 (wl-folder-create-subr folder))))
2795 (product-provide (provide 'wl-folder) (require 'wl-version))
2797 ;;; wl-folder.el ends here