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 (defcustom wl-folder-init-hook nil
50 "A hook called after folder initialization is finished."
54 (defvar wl-folder-buffer-name "Folder")
55 (defvar wl-folder-entity nil) ; desktop entity.
56 (defvar wl-folder-group-alist nil) ; opened or closed
57 (defvar wl-folder-entity-id nil) ; id
58 (defvar wl-folder-entity-hashtb nil)
59 (defvar wl-folder-entity-id-name-hashtb nil)
60 (defvar wl-folder-elmo-folder-hashtb nil) ; name => elmo folder structure
62 (defvar wl-folder-newsgroups-hashtb nil)
63 (defvar wl-folder-info-alist-modified nil)
64 (defvar wl-folder-completion-function nil)
66 (defvar wl-folder-mode-map nil)
68 (defvar wl-folder-buffer-disp-summary nil)
69 (defvar wl-folder-buffer-cur-entity-id nil)
70 (defvar wl-folder-buffer-cur-path nil)
71 (defvar wl-folder-buffer-cur-point nil)
73 (make-variable-buffer-local 'wl-folder-buffer-disp-summary)
74 (make-variable-buffer-local 'wl-folder-buffer-cur-entity-id)
75 (make-variable-buffer-local 'wl-folder-buffer-cur-path)
76 (make-variable-buffer-local 'wl-folder-buffer-cur-point)
78 (defconst wl-folder-entity-regexp "^\\([ ]*\\)\\(\\[[\\+-]\\]\\)?\\([^\\[].+\\):[-*0-9]+/[-*0-9]+/[-*0-9]+")
79 (defconst wl-folder-group-regexp "^\\([ ]*\\)\\[\\([\\+-]\\)\\]\\(.+\\):[-0-9-]+/[0-9-]+/[0-9-]+\n")
80 ;; 1:indent 2:opened 3:group-name
81 (defconst wl-folder-unsync-regexp ":[^0\\*][0-9]*/[0-9\\*-]+/[0-9\\*-]+$")
83 (defvar wl-folder-mode-menu-spec
85 ["Enter Current Folder" wl-folder-jump-to-current-entity t]
86 ["Prev Folder" wl-folder-prev-entity t]
87 ["Next Folder" wl-folder-next-entity t]
88 ["Check Current Folder" wl-folder-check-current-entity t]
89 ["Sync Current Folder" wl-folder-sync-current-entity t]
90 ; ["Drop Current Folder" wl-folder-drop-unsync-current-entity t]
91 ["Prefetch Current Folder" wl-folder-prefetch-current-entity t]
92 ["Mark as Read all Current Folder" wl-folder-mark-as-read-all-current-entity t]
93 ["Expire Current Folder" wl-folder-expire-current-entity t]
94 ["Empty trash" wl-folder-empty-trash t]
95 ["Flush queue" wl-folder-flush-queue t]
96 ["Open All" wl-folder-open-all t]
97 ["Open All Unread folder" wl-folder-open-all-unread-folder t]
98 ["Close All" wl-folder-close-all t]
100 ["Add folder" wl-fldmgr-add t]
101 ["Add group" wl-fldmgr-make-group t]
102 ["Copy" wl-fldmgr-copy t]
103 ["Cut" wl-fldmgr-cut t]
104 ["Paste" wl-fldmgr-yank t]
105 ["Set petname" wl-fldmgr-set-petname t]
106 ["Rename" wl-fldmgr-rename t]
107 ["Save" wl-fldmgr-save-folders t]
109 ["Unsubscribe" wl-fldmgr-unsubscribe t]
110 ["Display all" wl-fldmgr-access-display-all t])
112 ["Write a message" wl-draft t]
114 ["Toggle Plug Status" wl-toggle-plugged t]
115 ["Change Plug Status" wl-plugged-change t]
117 ["Save Current Status" wl-save t]
118 ["Update Satus" wl-status-update t]
123 (defun wl-folder-setup-mouse ()
124 (define-key wl-folder-mode-map 'button2 'wl-folder-click)
125 (define-key wl-folder-mode-map 'button4 'wl-folder-prev-entity)
126 (define-key wl-folder-mode-map 'button5 'wl-folder-next-entity)
127 (define-key wl-folder-mode-map [(shift button4)]
128 'wl-folder-prev-unread)
129 (define-key wl-folder-mode-map [(shift button5)]
130 'wl-folder-next-unread))
131 (defun wl-folder-setup-mouse ()
132 (define-key wl-folder-mode-map [mouse-2] 'wl-folder-click)
133 (define-key wl-folder-mode-map [mouse-4] 'wl-folder-prev-entity)
134 (define-key wl-folder-mode-map [mouse-5] 'wl-folder-next-entity)
135 (define-key wl-folder-mode-map [S-mouse-4] 'wl-folder-prev-unread)
136 (define-key wl-folder-mode-map [S-mouse-5] 'wl-folder-next-unread)))
138 (if wl-folder-mode-map
140 (setq wl-folder-mode-map (make-sparse-keymap))
141 (define-key wl-folder-mode-map " " 'wl-folder-jump-to-current-entity)
142 ; (define-key wl-folder-mode-map "\M- " 'wl-folder-open-close)
143 (define-key wl-folder-mode-map "/" 'wl-folder-open-close)
144 (define-key wl-folder-mode-map "\C-m" 'wl-folder-jump-to-current-entity)
145 (define-key wl-folder-mode-map "\M-\C-m" 'wl-folder-update-recursive-current-entity)
146 (define-key wl-folder-mode-map "rc" 'wl-folder-mark-as-read-all-region)
147 (define-key wl-folder-mode-map "c" 'wl-folder-mark-as-read-all-current-entity)
148 (define-key wl-folder-mode-map "g" 'wl-folder-goto-folder)
149 (define-key wl-folder-mode-map "j" 'wl-folder-jump-to-current-entity)
150 (define-key wl-folder-mode-map "w" 'wl-draft)
151 (define-key wl-folder-mode-map "W" 'wl-folder-write-current-folder)
152 (define-key wl-folder-mode-map "\C-c\C-o" 'wl-jump-to-draft-buffer)
153 (define-key wl-folder-mode-map "\C-c\C-a" 'wl-addrmgr)
154 (define-key wl-folder-mode-map "rS" 'wl-folder-sync-region)
155 (define-key wl-folder-mode-map "S" 'wl-folder-sync-current-entity)
156 (define-key wl-folder-mode-map "rs" 'wl-folder-check-region)
157 (define-key wl-folder-mode-map "s" 'wl-folder-check-current-entity)
158 (define-key wl-folder-mode-map "I" 'wl-folder-prefetch-current-entity)
159 ; (define-key wl-folder-mode-map "D" 'wl-folder-drop-unsync-current-entity)
160 (define-key wl-folder-mode-map "p" 'wl-folder-prev-entity)
161 (define-key wl-folder-mode-map "n" 'wl-folder-next-entity)
162 (define-key wl-folder-mode-map "v" 'wl-folder-toggle-disp-summary)
163 (define-key wl-folder-mode-map "P" 'wl-folder-prev-unread)
164 (define-key wl-folder-mode-map "N" 'wl-folder-next-unread)
165 (define-key wl-folder-mode-map "J" 'wl-folder-jump-folder)
166 (define-key wl-folder-mode-map "f" 'wl-folder-goto-first-unread-folder)
167 (define-key wl-folder-mode-map "o" 'wl-folder-open-all-unread-folder)
168 (define-key wl-folder-mode-map "[" 'wl-folder-open-all)
169 (define-key wl-folder-mode-map "]" 'wl-folder-close-all)
170 (define-key wl-folder-mode-map "e" 'wl-folder-expire-current-entity)
171 (define-key wl-folder-mode-map "E" 'wl-folder-empty-trash)
172 (define-key wl-folder-mode-map "F" 'wl-folder-flush-queue)
173 (define-key wl-folder-mode-map "q" 'wl-exit)
174 (define-key wl-folder-mode-map "z" 'wl-folder-suspend)
175 (define-key wl-folder-mode-map "\M-t" 'wl-toggle-plugged)
176 (define-key wl-folder-mode-map "\C-t" 'wl-plugged-change)
177 (define-key wl-folder-mode-map "<" 'beginning-of-buffer)
178 (define-key wl-folder-mode-map ">" 'end-of-buffer)
180 (define-key wl-folder-mode-map "m" 'wl-fldmgr-mode-map)
181 (define-key wl-folder-mode-map "*" 'wl-fldmgr-make-multi)
182 (define-key wl-folder-mode-map "+" 'wl-fldmgr-make-group)
183 (define-key wl-folder-mode-map "|" 'wl-fldmgr-make-filter)
184 (define-key wl-folder-mode-map "\M-c" 'wl-fldmgr-copy)
185 (define-key wl-folder-mode-map "\M-w" 'wl-fldmgr-copy-region)
186 (define-key wl-folder-mode-map "\C-k" 'wl-fldmgr-cut)
187 (define-key wl-folder-mode-map "\C-w" 'wl-fldmgr-cut-region)
188 (define-key wl-folder-mode-map "\C-y" 'wl-fldmgr-yank)
189 (define-key wl-folder-mode-map "R" 'wl-fldmgr-rename)
190 (define-key wl-folder-mode-map "u" 'wl-fldmgr-unsubscribe)
191 (define-key wl-folder-mode-map "ru" 'wl-fldmgr-unsubscribe-region)
192 (define-key wl-folder-mode-map "U" 'wl-fldmgr-unsubscribe-region)
193 (define-key wl-folder-mode-map "l" 'wl-fldmgr-access-display-normal)
194 (define-key wl-folder-mode-map "L" 'wl-fldmgr-access-display-all)
195 (define-key wl-folder-mode-map "Z" 'wl-status-update)
196 (define-key wl-folder-mode-map "\C-x\C-s" 'wl-save)
197 (define-key wl-folder-mode-map "\M-s" 'wl-save)
198 (define-key wl-folder-mode-map "\C-xk" 'wl-folder-mimic-kill-buffer)
199 (define-key wl-folder-mode-map "\M-\C-a"
200 'wl-folder-goto-top-of-current-folder)
201 (define-key wl-folder-mode-map "\M-\C-e"
202 'wl-folder-goto-bottom-of-current-folder)
204 (wl-folder-setup-mouse)
208 "Menu used in Folder mode."
209 wl-folder-mode-menu-spec))
211 (defmacro wl-folder-unread-regex (group)
212 (` (concat "^[ ]*.+:[0-9\\*-]+/[^0\\*][0-9]*/[0-9\\*-]+$"
217 (defmacro wl-folder-buffer-group-p ()
218 (` (save-excursion (beginning-of-line)
219 (looking-at wl-folder-group-regexp))))
221 (defmacro wl-folder-folder-name ()
224 (if (or (looking-at "^[ ]*\\[[\\+-]\\]\\(.+\\):[-0-9\\*-]+/[0-9\\*-]+/[0-9\\*-]+\n")
225 (looking-at "^[ ]*\\([^\\[].+\\):.*\n"))
226 (wl-match-buffer 1)))))
228 (defmacro wl-folder-entity-name ()
231 (if (looking-at "^[ ]*\\([^\\[].+\\):.*\n")
232 (wl-match-buffer 1)))))
234 (defun wl-folder-buffer-search-group (group)
237 "^\\([ \t]*\\)\\[[\\+-]\\]"
238 (regexp-quote group) ":[-0-9-]+/[0-9-]+/[0-9-]+") nil t))
240 (defun wl-folder-buffer-search-entity (folder &optional searchname)
241 (let ((search (or searchname (wl-folder-get-petname folder))))
245 (regexp-quote search) ":[-0-9\\*-]+/[0-9\\*-]+/[0-9\\*-]+") nil t)))
247 (defsubst wl-folder-get-folder-name-by-id (entity-id &optional hashtb)
248 (and (numberp entity-id)
249 (elmo-get-hash-val (format "#%d" entity-id)
250 (or hashtb wl-folder-entity-id-name-hashtb))))
252 (defsubst wl-folder-set-id-name (entity-id entity &optional hashtb)
253 (and (numberp entity-id)
254 (elmo-set-hash-val (format "#%d" entity-id)
255 entity (or hashtb wl-folder-entity-id-name-hashtb))))
257 (defmacro wl-folder-get-entity-id (entity)
258 `(get-text-property 0 'wl-folder-entity-id ,entity))
260 (defmacro wl-folder-get-entity-from-buffer (&optional getid)
261 `(let ((id (get-text-property (point)
262 'wl-folder-entity-id)))
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 &optional no-cache)
309 "Get elmo folder structure from entity."
311 (elmo-make-folder (elmo-string (, entity)))
312 (or (wl-folder-elmo-folder-cache-get (, entity))
313 (let* ((name (elmo-string (, entity)))
314 (folder (elmo-make-folder name)))
315 (wl-folder-elmo-folder-cache-put name folder)
318 (defmacro wl-folder-elmo-folder-cache-get (name &optional hashtb)
319 "Returns a elmo folder structure associated with NAME from HASHTB.
320 Default HASHTB is `wl-folder-elmo-folder-hashtb'."
321 (` (elmo-get-hash-val (, name)
322 (or (, hashtb) wl-folder-elmo-folder-hashtb))))
324 (defmacro wl-folder-elmo-folder-cache-put (name folder &optional hashtb)
325 "Get folder elmo folder structure on HASHTB for folder with NAME.
326 Default HASHTB is `wl-folder-elmo-folder-hashtb'."
327 (` (elmo-set-hash-val (, name) (, folder)
328 (or (, hashtb) wl-folder-elmo-folder-hashtb))))
330 (defun wl-folder-prev-entity ()
334 (defun wl-folder-next-entity ()
338 (defun wl-folder-prev-entity-skip-invalid (&optional hereto)
339 "move to previous entity. skip unsubscribed or removed entity."
343 (if (re-search-backward wl-folder-entity-regexp nil t)
345 (goto-char (point-min))))
347 (defun wl-folder-next-entity-skip-invalid (&optional hereto)
348 "Move to next entity. skip unsubscribed or removed entity."
353 (if (re-search-forward wl-folder-entity-regexp nil t)
355 (goto-char (point-max))))
357 (defun wl-folder-search-group-entity-by-name (name entity)
358 (wl-folder-search-entity-by-name name entity 'group))
360 (defun wl-folder-search-entity-by-name (name entity &optional type)
361 (let ((entities (list entity))
365 (setq entity (wl-pop entities))
368 (if (and (not (eq type 'folder))
369 (string= name (car entity)))
370 (throw 'done entity))
372 (wl-push entities entity-stack))
373 (setq entities (nth 2 entity)))
374 ((and (not (eq type 'group))
376 (if (string= name entity)
377 (throw 'done entity))))
379 (setq entities (wl-pop entity-stack)))))))
381 (defun wl-folder-search-entity-list-by-name (name entity &optional get-id)
382 (let ((entities (list entity))
383 entity-stack ret-val)
385 (setq entity (wl-pop entities))
389 (wl-push entities entity-stack))
390 (setq entities (nth 2 entity)))
392 (if (string= name entity)
393 (wl-append ret-val (if get-id
394 (list (wl-folder-get-entity-id entity))
397 (setq entities (wl-pop entity-stack))))
400 (defun wl-folder-get-prev-folder (id &optional unread)
401 (let ((name (if (stringp id)
403 (wl-folder-get-folder-name-by-id id)))
404 entity entity-stack last-entity finfo
405 (entities (list wl-folder-entity)))
408 (setq entity (wl-pop entities))
411 ;; (if (and (string= name (car entity))
412 ;; (eq id (wl-folder-get-entity-id (car entity))))
413 ;; (throw 'done last-entity))
415 (wl-push entities entity-stack))
416 (setq entities (nth 2 entity)))
418 (if (and (string= name entity)
419 ;; don't use eq, `id' is string on Nemacs.
420 (equal id (wl-folder-get-entity-id entity)))
421 (throw 'done last-entity))
423 (and (setq finfo (wl-folder-get-entity-info entity))
424 (and (nth 0 finfo)(nth 1 finfo))
425 (> (+ (nth 0 finfo)(nth 1 finfo)) 0)))
426 (setq last-entity entity))))
428 (setq entities (wl-pop entity-stack)))))))
430 (defun wl-folder-get-next-folder (id &optional unread)
431 (let ((name (if (stringp id)
433 (wl-folder-get-folder-name-by-id id)))
434 entity entity-stack found finfo
435 (entities (list wl-folder-entity)))
438 (setq entity (wl-pop entities))
441 ;;; (if (and (string= name (car entity))
442 ;;; (eq id (wl-folder-get-entity-id (car entity))))
445 (wl-push entities entity-stack))
446 (setq entities (nth 2 entity)))
449 (when (or (not unread)
450 (and (setq finfo (wl-folder-get-entity-info entity))
451 (and (nth 0 finfo)(nth 1 finfo))
452 (> (+ (nth 0 finfo)(nth 1 finfo)) 0)))
453 (throw 'done entity))
454 (if (and (string= name entity)
455 ;; don't use eq, `id' is string on Nemacs.
456 (equal id (wl-folder-get-entity-id entity)))
459 (setq entities (wl-pop entity-stack)))))))
461 (defun wl-folder-flush-queue ()
464 (let ((cur-buf (current-buffer))
465 (wl-auto-select-first nil)
468 (if elmo-enable-disconnected-operation
469 (elmo-dop-queue-flush 'force)) ; Try flushing all queue.
470 (if (not (elmo-folder-list-messages
471 (wl-folder-get-elmo-folder wl-queue-folder)))
472 (message "No sending queue exists.")
473 (if wl-stay-folder-window
474 (wl-folder-select-buffer
475 (wl-summary-get-buffer-create wl-queue-folder)))
476 (wl-summary-goto-folder-subr wl-queue-folder 'force-update nil)
478 (wl-draft-queue-flush)
479 (if (get-buffer-window cur-buf)
480 (select-window (get-buffer-window cur-buf)))
482 (if wl-stay-folder-window
483 (wl-folder-toggle-disp-summary 'off wl-queue-folder)
484 (switch-to-buffer cur-buf))))))
486 (defun wl-folder-empty-trash ()
489 (let ((cur-buf (current-buffer))
490 (wl-auto-select-first nil)
492 (if wl-stay-folder-window
493 (wl-folder-select-buffer
494 (wl-summary-get-buffer-create wl-trash-folder)))
495 (wl-summary-goto-folder-subr wl-trash-folder 'force-update nil nil t)
496 (setq trash-buf (current-buffer))
498 (setq emptied (wl-summary-delete-all-msgs))
500 (setq wl-thread-entities nil
501 wl-thread-entity-list nil)
502 (if wl-summary-cache-use (wl-summary-save-view-cache))
503 (elmo-folder-commit wl-summary-buffer-elmo-folder))
504 (if (get-buffer-window cur-buf)
505 (select-window (get-buffer-window cur-buf)))
508 (wl-folder-set-folder-updated wl-trash-folder '(0 0 0)))
509 (if wl-stay-folder-window
510 (wl-folder-toggle-disp-summary 'off wl-trash-folder)
511 (switch-to-buffer cur-buf))
513 (kill-buffer trash-buf)))))
515 (defun wl-folder-goto-top-of-current-folder (&optional arg)
516 "Move backward to the top of the current folder group.
517 Optional argument ARG is repeart count."
519 (if (re-search-backward
520 "^ *\\[[\\+-]\\]" nil t (if arg (prefix-numeric-value arg)))
522 (goto-char (point-min))))
524 (defun wl-folder-goto-bottom-of-current-folder (indent)
525 "Move forward to the bottom of the current folder group."
530 (if (looking-at "^ *")
531 (buffer-substring (match-beginning 0)(1- (match-end 0)))
535 (while (re-search-forward "^ *" nil t)
536 (if (<= (length (match-string 0))
540 (goto-char (point-max))))
542 (defsubst wl-folder-update-group (entity diffs &optional is-group)
544 (let ((path (wl-folder-get-path
546 (wl-folder-get-entity-id entity)
549 ;; delete itself from path
550 (setq path (delete (nth (- (length path) 1) path) path)))
551 (goto-char (point-min))
554 ;; goto the path line.
555 (if (or (eq (car path) 0) ; update desktop
556 (wl-folder-buffer-search-group
557 (wl-folder-get-petname
558 (if (stringp (car path))
560 (wl-folder-get-folder-name-by-id
563 (wl-folder-update-diff-line diffs)
565 (setq path (cdr path)))))))
567 (defun wl-folder-maybe-load-folder-list (entity)
568 (when (null (caddr entity))
570 (elmo-msgdb-flist-load (car entity)))
574 (wl-folder-entity-assign-id entity
575 wl-folder-entity-id-name-hashtb
577 (setq diffs (wl-fldmgr-add-entity-hashtb (list entity)))
578 (unless (equal diffs '(0 0 0))
579 (wl-folder-update-group (car entity) diffs t)))))))
581 (defsubst wl-folder-force-fetch-p (entity)
583 ((consp wl-force-fetch-folders)
584 (wl-string-match-member entity wl-force-fetch-folders))
586 wl-force-fetch-folders)))
588 (defun wl-folder-jump-to-current-entity (&optional arg)
589 "Enter the current folder. If optional ARG exists, update folder list."
592 (let (entity beg end indent opened fname err fld-name)
594 ((looking-at wl-folder-group-regexp)
596 (setq fname (wl-folder-get-realname (wl-match-buffer 3)))
597 (setq indent (wl-match-buffer 1))
598 (setq opened (wl-match-buffer 2))
599 (if (string= opened "+")
601 (setq entity (wl-folder-search-group-entity-by-name
606 (wl-folder-update-recursive-current-entity entity)
608 (setcdr (assoc (car entity) wl-folder-group-alist) t)
609 (if (eq 'access (cadr entity))
610 (wl-folder-maybe-load-folder-list entity))
611 ;(condition-case errobj
613 (if (or (wl-folder-force-fetch-p (car entity))
615 (eq 'access (cadr entity))
616 (null (caddr entity))))
617 (wl-folder-update-newest indent entity)
618 (wl-folder-insert-entity indent entity))
619 (wl-highlight-folder-path wl-folder-buffer-cur-path))
622 ; (setcdr (assoc fname wl-folder-group-alist) nil))
624 ; (elmo-display-error errobj t)
627 ; (setcdr (assoc fname wl-folder-group-alist) nil)))
629 (let ((buffer-read-only nil))
630 (delete-region (save-excursion (beginning-of-line)
632 (save-excursion (end-of-line)
638 (progn (wl-folder-goto-bottom-of-current-folder indent)
641 (setq entity (wl-folder-search-group-entity-by-name
644 (let ((buffer-read-only nil))
645 (delete-region beg end))
646 (setcdr (assoc (car entity) wl-folder-group-alist) nil)
647 (wl-folder-insert-entity indent entity) ; insert entity
649 (wl-highlight-folder-path wl-folder-buffer-cur-path)
650 ; (wl-delete-all-overlays)
651 ; (wl-highlight-folder-current-line)
653 ((setq fld-name (wl-folder-entity-name))
654 (wl-folder-set-current-entity-id
655 (get-text-property (point) 'wl-folder-entity-id))
656 (setq fld-name (wl-folder-get-folder-name-by-id
657 wl-folder-buffer-cur-entity-id))
658 (let ((summary-buf (wl-summary-get-buffer-create fld-name arg))
660 (if (or wl-stay-folder-window wl-summary-use-frame)
661 (wl-folder-select-buffer summary-buf)
663 (get-buffer-window summary-buf))
665 (wl-summary-goto-folder-subr fld-name
666 (wl-summary-get-sync-range
667 (wl-folder-get-elmo-folder fld-name))
669 (set-buffer-modified-p nil))
671 (defun wl-folder-close-entity (entity)
672 (let ((entities (list entity))
675 (setq entity (wl-pop entities))
678 (setcdr (assoc (car entity) wl-folder-group-alist) nil)
680 (wl-push entities entity-stack))
681 (setq entities (nth 2 entity))))
683 (setq entities (wl-pop entity-stack))))))
685 (defun wl-folder-update-recursive-current-entity (&optional entity)
687 (when (wl-folder-buffer-group-p)
689 ((string= (wl-match-buffer 2) "+")
693 (wl-folder-search-group-entity-by-name
694 (wl-folder-get-realname (wl-match-buffer 3))
696 (let ((inhibit-read-only t)
697 (entities (list entity))
698 entity-stack err indent)
699 (while (and entities (not err))
700 (setq entity (wl-pop entities))
703 (wl-folder-close-entity entity)
704 (setcdr (assoc (car entity) wl-folder-group-alist) t)
705 (unless (wl-folder-buffer-search-group
706 (wl-folder-get-petname (car entity)))
707 (error "%s: not found group" (car entity)))
708 (setq indent (wl-match-buffer 1))
709 (if (eq 'access (cadr entity))
710 (wl-folder-maybe-load-folder-list entity))
714 (condition-case errobj
715 (wl-folder-update-newest indent entity)
718 (setcdr (assoc (car entity) wl-folder-group-alist) nil))
720 (elmo-display-error errobj t)
723 (setcdr (assoc (car entity) wl-folder-group-alist) nil)))
725 (delete-region (save-excursion (beginning-of-line)
727 (save-excursion (end-of-line)
731 (wl-push entities entity-stack))
732 (setq entities (nth 2 entity))))
734 (setq entities (wl-pop entity-stack)))))
735 (set-buffer-modified-p nil)))
737 (wl-folder-jump-to-current-entity)))))
739 (defun wl-folder-no-auto-check-folder-p (folder)
742 (let ((li wl-auto-check-folder-list))
744 (if (string-match (car li) folder)
746 (setq li (cdr li)))))
749 (let ((li wl-auto-uncheck-folder-list))
751 (if (string-match (car li) folder)
752 (throw 'found t)) ; no check!
753 (setq li (cdr li))))))))
755 (defsubst wl-folder-add-folder-info (pre-value value)
757 (+ (or (nth 0 pre-value) 0) (or (nth 0 value) 0))
758 (+ (or (nth 1 pre-value) 0) (or (nth 1 value) 0))
759 (+ (or (nth 2 pre-value) 0) (or (nth 2 value) 0))))
761 (defun wl-folder-check-entity (entity &optional auto)
762 "Check unsync message number."
763 (let ((start-pos (point))
765 (run-hooks 'wl-folder-check-entity-pre-hook)
766 (if (and (consp entity) ;; group entity
767 wl-folder-check-async) ;; very fast
768 (setq ret-val (wl-folder-check-entity-async entity auto))
772 (let ((flist (if auto
774 'wl-folder-no-auto-check-folder-p
777 (wl-folder-check-entity-pre-hook nil)
778 (wl-folder-check-entity-hook nil)
782 (wl-folder-add-folder-info
784 (wl-folder-check-entity (car flist))))
785 (setq flist (cdr flist)))
786 ;(wl-folder-buffer-search-entity (car entity))
787 ;(wl-folder-update-line ret-val)
790 (message "Checking \"%s\"" entity)
791 (setq ret-val (wl-folder-check-one-entity
793 (goto-char start-pos)
796 (message "Uncheck(unplugged) \"%s\"" entity)))))
798 (message "Checking \"%s\" is done."
799 (if (consp entity) (car entity) entity)))
800 (run-hooks 'wl-folder-check-entity-hook)
803 (defun wl-folder-check-one-entity (entity &optional biff)
804 (let* ((folder (wl-folder-get-elmo-folder entity biff))
805 (nums (condition-case err
807 (if biff (elmo-folder-set-biff-internal folder t))
808 (if (wl-string-match-member entity wl-strict-diff-folders)
809 (elmo-strict-folder-diff folder)
810 (elmo-folder-diff folder)))
812 ;; maybe not exist folder.
813 (if (and (not (memq 'elmo-open-error
814 (get (car err) 'error-conditions)))
815 (not (elmo-folder-exists-p folder)))
816 (wl-folder-create-subr folder)
817 (signal (car err) (cdr err))))))
818 (new (elmo-diff-new nums))
819 (nums (cons (elmo-diff-unread nums) (elmo-diff-all nums)))
821 (if (and (eq wl-folder-notify-deleted 'sync)
823 (or (> 0 (car nums)) (> 0 (cdr nums))))
825 (wl-folder-sync-entity entity)
826 (setq nums (elmo-folder-diff folder)))
827 (unless wl-folder-notify-deleted
828 (setq unsync (if (car nums)
831 (setq nomif (if (cdr nums)
834 (setq nums (cons unsync nomif)))
835 (setq unread (or ;; If server diff, All unreads are
837 (if (elmo-folder-use-flag-p folder)
839 (elmo-folder-get-info-unread folder)
840 (wl-summary-count-unread (elmo-msgdb-mark-load
841 (elmo-folder-msgdb-path
843 (when new (setq unread (- unread new)))
844 (wl-folder-entity-hashtb-set wl-folder-entity-hashtb entity
845 (list (or new (car nums))
848 (get-buffer wl-folder-buffer-name)))
849 (setq wl-folder-info-alist-modified t)
851 (list (if wl-folder-notify-deleted
852 (or new (car nums) 0)
853 (max 0 (or new (car nums) 0)))
857 (defun wl-folder-check-entity-async (entity &optional auto)
858 (let ((elmo-nntp-groups-async t)
861 'wl-folder-no-auto-check-folder-p
862 (wl-folder-get-entity-list entity))
863 (wl-folder-get-entity-list entity)))
864 (nntp-connection-keys nil)
865 name folder folder-list
871 (setq folder (wl-folder-get-elmo-folder (car elist)))
872 (if (not (elmo-folder-plugged-p folder))
873 (message "Uncheck \"%s\"" (car elist))
875 (elmo-folder-get-primitive-list folder))
876 (cond ((elmo-folder-contains-type folder 'nntp)
877 (wl-append async-folder-list (list folder))
879 (when (eq (elmo-folder-type-internal (car folder-list))
883 (elmo-net-folder-server-internal
885 (setq server (elmo-net-folder-server-internal
887 (message "Checking on \"%s\"" server))
888 (setq nntp-connection-keys
889 (elmo-nntp-get-folders-info-prepare
891 nntp-connection-keys)))
892 (setq folder-list (cdr folder-list))))
894 (wl-append sync-folder-list (list folder)))))
895 (setq elist (cdr elist)))
896 ;; check local entity at first
897 (while (setq folder (pop sync-folder-list))
898 (if (not (elmo-folder-plugged-p folder))
899 (message "Uncheck \"%s\"" (elmo-folder-name-internal folder))
900 (message "Checking \"%s\"" (elmo-folder-name-internal folder))
902 (wl-folder-add-folder-info
904 (wl-folder-check-one-entity (elmo-folder-name-internal
908 ;; check network entity at last
909 (when async-folder-list
910 (elmo-nntp-get-folders-info nntp-connection-keys)
911 (while (setq folder (pop async-folder-list))
912 (if (not (elmo-folder-plugged-p folder))
913 (message "Uncheck \"%s\"" (elmo-folder-name-internal folder))
914 (message "Checking \"%s\"" (elmo-folder-name-internal folder))
916 (wl-folder-add-folder-info
918 (wl-folder-check-one-entity (elmo-folder-name-internal
925 (defun wl-folder-resume-entity-hashtb-by-finfo (entity-hashtb info-alist)
926 "Resume unread info for entity alist."
929 (setq info (nth 1 (car info-alist)))
930 (wl-folder-set-entity-info (caar info-alist)
931 (list (nth 2 info)(nth 3 info)(nth 1 info))
933 (setq info-alist (cdr info-alist)))))
935 (defun wl-folder-move-path (path)
936 (let ((fp (if (consp path)
939 (wl-folder-get-path wl-folder-entity path))))
940 (goto-char (point-min))
943 (when (equal (car fp)
944 (wl-folder-get-entity-from-buffer t))
946 (setq wl-folder-buffer-cur-point (point)))
948 (and wl-folder-buffer-cur-point
949 (goto-char wl-folder-buffer-cur-point))))
951 (defun wl-folder-set-current-entity-id (entity-id)
952 (let ((buf (get-buffer wl-folder-buffer-name)))
956 (setq wl-folder-buffer-cur-entity-id entity-id)
957 (setq wl-folder-buffer-cur-path (wl-folder-get-path wl-folder-entity
959 (wl-highlight-folder-path wl-folder-buffer-cur-path)
960 (and wl-folder-move-cur-folder
961 wl-folder-buffer-cur-point
962 (goto-char wl-folder-buffer-cur-point))))
963 (if (eq (current-buffer) buf)
964 (and wl-folder-move-cur-folder
965 wl-folder-buffer-cur-point
966 (goto-char wl-folder-buffer-cur-point)))))
968 (defun wl-folder-check-current-entity ()
969 "Check folder at position.
970 If current line is group folder, check all sub entries."
972 (let* ((entity-name (wl-folder-get-entity-from-buffer))
973 (group (wl-folder-buffer-group-p))
974 (desktop (string= entity-name wl-folder-desktop-name)))
976 (wl-folder-check-entity
978 (wl-folder-search-group-entity-by-name entity-name
983 (defun wl-folder-sync-entity (entity &optional unread-only)
984 "Synchronize the msgdb of ENTITY."
987 (let ((flist (nth 2 entity)))
989 (wl-folder-sync-entity (car flist) unread-only)
990 (setq flist (cdr flist)))))
992 (let* ((folder (wl-folder-get-elmo-folder entity))
993 (nums (wl-folder-get-entity-info entity))
994 (wl-summary-highlight (if (or (wl-summary-sticky-p folder)
995 (wl-summary-always-sticky-folder-p
997 wl-summary-highlight))
998 wl-auto-select-first new unread)
999 (setq new (or (car nums) 0))
1000 (setq unread (or (cadr nums) 0))
1001 (if (or (not unread-only)
1002 (or (< 0 new) (< 0 unread)))
1003 (let ((wl-summary-buffer-name (concat
1004 wl-summary-buffer-name
1005 (symbol-name this-command)))
1006 (wl-summary-use-frame nil)
1007 (wl-summary-always-sticky-folder-list nil))
1008 (save-window-excursion
1010 (wl-summary-goto-folder-subr entity
1011 (wl-summary-get-sync-range
1014 (wl-summary-exit)))))))))
1016 (defun wl-folder-sync-current-entity (&optional unread-only)
1017 "Synchronize the folder at position.
1018 If current line is group folder, check all subfolders."
1021 (let ((entity-name (wl-folder-get-entity-from-buffer))
1022 (group (wl-folder-buffer-group-p)))
1023 (when (and entity-name
1024 (y-or-n-p (format "Sync %s? " entity-name)))
1025 (wl-folder-sync-entity
1027 (wl-folder-search-group-entity-by-name entity-name
1031 (message "Syncing %s is done!" entity-name)))))
1033 (defun wl-folder-mark-as-read-all-entity (entity)
1034 "Mark as read all messages in the ENTITY."
1037 (let ((flist (nth 2 entity)))
1039 (wl-folder-mark-as-read-all-entity (car flist))
1040 (setq flist (cdr flist)))))
1042 (let* ((nums (wl-folder-get-entity-info entity))
1043 (folder (wl-folder-get-elmo-folder entity))
1044 (wl-summary-highlight (if (or (wl-summary-sticky-p folder)
1045 (wl-summary-always-sticky-folder-p
1047 wl-summary-highlight))
1048 wl-auto-select-first new unread)
1049 (setq new (or (car nums) 0))
1050 (setq unread (or (cadr nums) 0))
1051 (if (or (< 0 new) (< 0 unread))
1052 (save-window-excursion
1054 (let ((wl-summary-buffer-name (concat
1055 wl-summary-buffer-name
1056 (symbol-name this-command)))
1057 (wl-summary-use-frame nil)
1058 (wl-summary-always-sticky-folder-list nil))
1059 (wl-summary-goto-folder-subr entity
1060 (wl-summary-get-sync-range folder)
1062 (wl-summary-mark-as-read-all)
1063 (wl-summary-exit))))
1066 (defun wl-folder-mark-as-read-all-current-entity ()
1067 "Mark as read all messages in the folder at position.
1068 If current line is group folder, all subfolders are marked."
1071 (let ((entity-name (wl-folder-get-entity-from-buffer))
1072 (group (wl-folder-buffer-group-p))
1074 (when (and entity-name
1075 (y-or-n-p (format "Mark all messages in %s as read? " entity-name)))
1076 (wl-folder-mark-as-read-all-entity
1078 (wl-folder-search-group-entity-by-name entity-name
1081 (message "All messages in %s are marked!" entity-name)))))
1083 (defun wl-folder-check-region (beg end)
1092 (let ((inhibit-read-only t)
1094 (while (< (point) end)
1095 ;; normal folder entity
1096 (if (looking-at "^[\t ]*\\([^\\[]+\\):\\(.*\\)\n")
1098 (setq entity (wl-folder-get-entity-from-buffer))
1099 (if (not (elmo-folder-plugged-p (wl-folder-get-elmo-folder
1101 (message "Uncheck %s" entity)
1102 (message "Checking %s" entity)
1103 (wl-folder-check-one-entity entity)
1108 (defun wl-folder-sync-region (beg end)
1117 (while (< (point) end)
1118 ;; normal folder entity
1119 (if (looking-at "^[\t ]*\\([^\\[]+\\):\\(.*\\)\n")
1121 (let ((inhibit-read-only t)
1123 (setq entity (wl-folder-get-entity-from-buffer))
1124 (wl-folder-sync-entity entity)
1125 (message "Syncing %s is done!" entity)
1130 (defun wl-folder-mark-as-read-all-region (beg end)
1139 (while (< (point) end)
1140 ;; normal folder entity
1141 (if (looking-at "^[\t ]*\\([^\\[]+\\):\\(.*\\)\n")
1143 (let ((inhibit-read-only t)
1145 (setq entity (wl-folder-get-entity-from-buffer))
1146 (wl-folder-mark-as-read-all-entity entity)
1147 (message "All messages in %s are marked!" entity)
1152 (defsubst wl-create-access-init-load-p (folder)
1153 (let ((no-load-regexp (when (and
1154 (not wl-folder-init-load-access-folders)
1155 wl-folder-init-no-load-access-folders)
1156 (mapconcat 'identity
1157 wl-folder-init-no-load-access-folders
1159 (load-regexp (and wl-folder-init-load-access-folders
1160 (mapconcat 'identity
1161 wl-folder-init-load-access-folders
1163 (cond (load-regexp (string-match load-regexp folder))
1164 (t (not (and no-load-regexp
1165 (string-match no-load-regexp folder)))))))
1167 (defun wl-create-access-folder-entity (name)
1169 (when (wl-create-access-init-load-p name)
1170 (setq flists (elmo-msgdb-flist-load name)) ; load flist.
1171 (setq flist (car flists))
1173 (when (consp (car flist))
1174 (setcdr (cdar flist)
1175 (wl-create-access-folder-entity (caar flist))))
1176 (setq flist (cdr flist)))
1179 (defun wl-create-folder-entity-from-buffer ()
1180 "Create folder entity recursively."
1182 ((looking-at "^[ \t]*$") ; blank line
1183 (goto-char (+ 1(match-end 0)))
1185 ((looking-at "^#.*$") ; comment
1186 (goto-char (+ 1 (match-end 0)))
1188 ((looking-at "^[\t ]*\\(.+\\)[\t ]*{[\t ]*$") ; group definition
1189 (let (name entity flist)
1190 (setq name (wl-match-buffer 1))
1191 (goto-char (+ 1 (match-end 0)))
1192 (while (setq entity (wl-create-folder-entity-from-buffer))
1193 (unless (eq entity 'ignore)
1194 (wl-append flist (list entity))))
1195 (if (looking-at "^[\t ]*}[\t ]*$") ; end of group
1197 (goto-char (+ 1 (match-end 0)))
1198 (if (wl-string-assoc name wl-folder-petname-alist)
1199 (error "%s already defined as petname" name))
1200 (list name 'group flist))
1201 (error "Syntax error in folder definition"))))
1202 ((looking-at "^[\t ]*\\([^\t \n]+\\)[\t ]*/$") ; access it!
1204 (setq name (wl-match-buffer 1))
1205 (goto-char (+ 1 (match-end 0)))
1206 ; (condition-case ()
1208 ; (setq flist (elmo-list-folders name)))
1209 ; (error (message "Access to folder %s failed." name)))
1210 ;; (setq flist (elmo-msgdb-flist-load name)) ; load flist.
1211 ;; (setq unsublist (nth 1 flist))
1212 ;; (setq flist (car flist))
1213 ;; (list name 'access flist unsublist)))
1214 (append (list name 'access) (wl-create-access-folder-entity name))))
1215 ;((looking-at "^[\t ]*\\([^\t \n}]+\\)[\t ]*\\(\"[^\"]*\"\\)?[\t ]*$") ; normal folder entity
1216 ((looking-at "^[\t ]*=[ \t]+\\([^\n]+\\)$"); petname definition
1217 (goto-char (+ 1 (match-end 0)))
1218 (let ((rest (elmo-match-buffer 1))
1220 (when (string-match "\\(\"[^\"]*\"\\)[\t ]*$" rest)
1221 (setq petname (elmo-delete-char ?\" (elmo-match-string 1 rest)))
1222 (setq rest (substring rest 0 (match-beginning 0))))
1223 (when (string-match "^[\t ]*\\(.*[^\t ]+\\)[\t ]+$" rest)
1224 (wl-folder-append-petname (elmo-match-string 1 rest)
1227 ((looking-at "^[ \t]*}[ \t]*$") ; end of group
1229 ((looking-at "^.*$") ; normal folder entity
1230 (goto-char (+ 1 (match-end 0)))
1231 (let ((rest (elmo-match-buffer 0))
1233 (if (string-match "\\(\"[^\"]*\"\\)[\t ]*$" rest)
1235 (setq petname (elmo-delete-char ?\" (elmo-match-string 1 rest)))
1236 (setq rest (substring rest 0 (match-beginning 0)))
1237 (when (string-match "^[\t ]*\\(.*[^\t ]+\\)[\t ]+$" rest)
1238 (wl-folder-append-petname
1239 (setq realname (elmo-match-string 1 rest))
1242 (if (string-match "^[\t ]*\\(.+\\)$" rest)
1243 (elmo-match-string 1 rest)
1246 (defun wl-folder-create-folder-entity ()
1247 "Create folder entries."
1248 (let ((tmp-buf (get-buffer-create " *wl-folder-tmp*"))
1252 (with-current-buffer tmp-buf
1254 (insert-file-contents wl-folders-file)
1255 (goto-char (point-min))
1256 (while (and (not (eobp))
1257 (setq entity (wl-create-folder-entity-from-buffer)))
1258 (unless (eq entity 'ignore)
1259 (wl-append ret-val (list entity)))))
1260 (kill-buffer tmp-buf))
1262 (setq ret-val (list wl-folder-desktop-name 'group ret-val))))
1264 (defun wl-folder-entity-assign-id (entity &optional hashtb on-noid)
1265 (let ((hashtb (or hashtb
1266 (setq wl-folder-entity-id-name-hashtb
1267 (elmo-make-hash wl-folder-entity-id))))
1268 (entities (list entity))
1271 (setq entity (wl-pop entities))
1274 (when (not (and on-noid
1275 (get-text-property 0
1276 'wl-folder-entity-id
1278 (put-text-property 0 (length (car entity))
1279 'wl-folder-entity-id
1282 (wl-folder-set-id-name wl-folder-entity-id
1283 (car entity) hashtb))
1285 (wl-push entities entity-stack))
1286 (setq entities (nth 2 entity)))
1288 (when (not (and on-noid
1289 (get-text-property 0
1290 'wl-folder-entity-id
1292 (put-text-property 0 (length entity)
1293 'wl-folder-entity-id
1296 (wl-folder-set-id-name wl-folder-entity-id
1298 (setq wl-folder-entity-id (+ 1 wl-folder-entity-id))
1300 (setq entities (wl-pop entity-stack))))))
1302 (defun wl-folder-click (e)
1307 (wl-folder-jump-to-current-entity)))
1309 (defun wl-folder-select-buffer (buffer)
1310 (let ((gbw (get-buffer-window buffer))
1313 (progn (select-window gbw)
1315 (unless wl-summary-use-frame
1318 (split-window-horizontally wl-folder-window-width)
1322 (if wl-summary-use-frame
1323 (switch-to-buffer-other-frame buffer)
1324 (switch-to-buffer buffer))
1327 (defun wl-folder-toggle-disp-summary (&optional arg folder)
1329 (if (or (and folder (assoc folder wl-folder-group-alist))
1330 (and (interactive-p) (wl-folder-buffer-group-p)))
1331 (error "This command is not available on Group"))
1333 (let (wl-auto-select-first
1334 (wl-stay-folder-window t))
1337 (setq wl-folder-buffer-disp-summary t))
1339 (setq wl-folder-buffer-disp-summary nil)
1340 ;; hide wl-summary window.
1341 (let ((cur-buf (current-buffer))
1342 (summary-buffer (wl-summary-get-buffer folder)))
1343 (wl-folder-select-buffer summary-buffer)
1345 (select-window (get-buffer-window cur-buf))))
1347 (setq wl-folder-buffer-disp-summary
1348 (not wl-folder-buffer-disp-summary))
1349 (let ((cur-buf (current-buffer))
1351 (when (looking-at "^[ ]*\\([^\\[].+\\):.*\n")
1352 (setq folder-name (wl-folder-get-entity-from-buffer))
1353 (if wl-folder-buffer-disp-summary
1355 (wl-folder-select-buffer
1356 (wl-summary-get-buffer-create folder-name))
1358 (wl-summary-goto-folder-subr folder-name 'no-sync nil)
1359 (select-window (get-buffer-window cur-buf))))
1360 (wl-folder-select-buffer (wl-summary-get-buffer folder-name))
1362 (select-window (get-buffer-window cur-buf)))))))))
1364 (defun wl-folder-prev-unsync ()
1365 "Move cursor to the previous unsync folder."
1368 (setq start-point (point))
1370 (if (re-search-backward wl-folder-unsync-regexp nil t)
1372 (goto-char start-point)
1373 (message "No more unsync folder"))))
1375 (defun wl-folder-next-unsync (&optional plugged)
1376 "Move cursor to the next unsync."
1378 (let (start-point entity)
1379 (setq start-point (point))
1382 (while (re-search-forward wl-folder-unsync-regexp nil t)
1383 (if (or (wl-folder-buffer-group-p)
1386 (wl-folder-get-realname
1387 (wl-folder-folder-name)))
1388 (elmo-folder-plugged-p entity))
1391 (goto-char start-point)
1392 (message "No more unsync folder"))))
1394 (defun wl-folder-prev-unread (&optional group)
1395 "Move cursor to the previous unread folder."
1398 (setq start-point (point))
1400 (if (re-search-backward (wl-folder-unread-regex group) nil t)
1403 (wl-folder-folder-name))
1404 (goto-char start-point)
1405 (message "No more unread folder")
1408 (defun wl-folder-next-unread (&optional group)
1409 "Move cursor to the next unread folder."
1412 (setq start-point (point))
1414 (if (re-search-forward (wl-folder-unread-regex group) nil t)
1417 (wl-folder-folder-name))
1418 (goto-char start-point)
1419 (message "No more unread folder")
1422 (defun wl-folder-mode ()
1423 "Major mode for Wanderlust Folder.
1424 See Info under Wanderlust for full documentation.
1427 \\{wl-folder-mode-map}
1429 Entering Folder mode calls the value of `wl-folder-mode-hook'."
1431 (setq major-mode 'wl-folder-mode)
1432 (setq mode-name "Folder")
1433 (use-local-map wl-folder-mode-map)
1434 (setq buffer-read-only t)
1435 (setq inhibit-read-only nil)
1436 (setq truncate-lines t)
1437 (setq wl-folder-buffer-cur-entity-id nil
1438 wl-folder-buffer-cur-path nil
1439 wl-folder-buffer-cur-point nil)
1440 (wl-mode-line-buffer-identification)
1441 (easy-menu-add wl-folder-mode-menu)
1442 ;; This hook may contain the functions `wl-folder-init-icons' and
1443 ;; `wl-setup-folder' for reasons of system internal to accord
1444 ;; facilities for the Emacs variants.
1445 (run-hooks 'wl-folder-mode-hook))
1447 (defun wl-folder-append-petname (realname petname)
1449 ;; check group name.
1450 (if (wl-folder-search-group-entity-by-name petname wl-folder-entity)
1451 (error "%s already defined as group name" petname))
1452 (when (setq pentry (wl-string-assoc realname wl-folder-petname-alist))
1453 (setq wl-folder-petname-alist
1454 (delete pentry wl-folder-petname-alist)))
1455 (wl-append wl-folder-petname-alist
1456 (list (cons realname petname)))))
1458 (defun wl-folder (&optional arg)
1460 (let (initialize folder-buf)
1461 (if (setq folder-buf (get-buffer wl-folder-buffer-name))
1462 (if wl-folder-use-frame
1464 (save-selected-window
1465 (dolist (frame (visible-frame-list))
1466 (select-frame frame)
1467 (if (get-buffer-window folder-buf)
1468 (setq select-frame frame))))
1470 (select-frame select-frame)
1471 (switch-to-buffer folder-buf)))
1472 (switch-to-buffer folder-buf))
1473 (if wl-folder-use-frame
1474 (switch-to-buffer-other-frame
1475 (get-buffer-create wl-folder-buffer-name))
1476 (switch-to-buffer (get-buffer-create wl-folder-buffer-name)))
1477 (set-buffer wl-folder-buffer-name)
1480 (setq wl-folder-entity-id 0)
1481 (wl-folder-entity-assign-id wl-folder-entity)
1482 (setq wl-folder-entity-hashtb
1483 (wl-folder-create-entity-hashtb wl-folder-entity))
1484 (setq wl-folder-elmo-folder-hashtb (elmo-make-hash wl-folder-entity-id))
1485 (setq wl-folder-group-alist
1486 (wl-folder-create-group-alist wl-folder-entity))
1487 (setq wl-folder-newsgroups-hashtb
1488 (wl-folder-create-newsgroups-hashtb wl-folder-entity))
1489 (wl-folder-init-info-hashtb)
1490 (let ((inhibit-read-only t)
1491 (buffer-read-only nil))
1493 (setcdr (assoc (car wl-folder-entity) wl-folder-group-alist) t)
1495 (wl-folder-insert-entity " " wl-folder-entity)))
1497 (set-buffer-modified-p nil)
1498 (setq initialize t))
1501 (defun wl-folder-auto-check ()
1502 "Check and update folders in `wl-auto-check-folder-name'."
1504 (when (get-buffer wl-folder-buffer-name)
1505 (switch-to-buffer wl-folder-buffer-name)
1507 ((eq wl-auto-check-folder-name 'none))
1508 ((or (consp wl-auto-check-folder-name)
1509 (stringp wl-auto-check-folder-name))
1510 (let ((folder-list (if (consp wl-auto-check-folder-name)
1511 wl-auto-check-folder-name
1512 (list wl-auto-check-folder-name)))
1515 (if (setq entity (wl-folder-search-entity-by-name
1518 (wl-folder-check-entity entity 'auto))
1519 (setq folder-list (cdr folder-list)))))
1521 (wl-folder-check-entity wl-folder-entity 'auto)))))
1523 (defun wl-folder-set-folder-updated (name value)
1526 (if (setq buf (get-buffer wl-folder-buffer-name))
1527 (wl-folder-entity-hashtb-set
1528 wl-folder-entity-hashtb name value buf))
1529 (setq wl-folder-info-alist-modified t))))
1531 (defun wl-folder-calc-finfo (entity)
1532 ;; calcurate finfo without inserting.
1533 (let ((entities (list entity))
1535 new unread all nums)
1537 (setq entity (wl-pop entities))
1541 (wl-push entities entity-stack))
1542 (setq entities (nth 2 entity)))
1544 (setq nums (wl-folder-get-entity-info entity))
1545 (setq new (+ (or new 0) (or (nth 0 nums) 0)))
1546 (setq unread (+ (or unread 0)
1547 (or (and (nth 0 nums)(nth 1 nums)
1548 (+ (nth 0 nums)(nth 1 nums))) 0)))
1549 (setq all (+ (or all 0) (or (nth 2 nums) 0)))))
1551 (setq entities (wl-pop entity-stack))))
1552 (list new unread all)))
1554 (defsubst wl-folder-make-save-access-list (list)
1555 (mapcar '(lambda (x)
1558 (list (elmo-string (car x)) 'access))
1563 (defun wl-folder-update-newest (indent entity)
1564 (let (ret-val new unread all)
1567 (let ((inhibit-read-only t)
1568 (buffer-read-only nil)
1569 (flist (nth 2 entity))
1570 (as-opened (cdr (assoc (car entity) wl-folder-group-alist)))
1575 (let (update-flist flist-unsub new-flist removed group-name-end)
1576 (when (and (eq (cadr entity) 'access)
1577 (elmo-folder-plugged-p
1578 (wl-folder-get-elmo-folder (car entity))))
1579 (message "Fetching folder entries...")
1580 (when (setq new-flist
1581 (elmo-folder-list-subfolders
1582 (wl-folder-get-elmo-folder (car entity))
1585 wl-folder-hierarchy-access-folders)))
1587 (wl-folder-update-access-group entity new-flist))
1588 (setq flist (nth 1 update-flist))
1589 (when (car update-flist) ;; diff
1590 (setq flist-unsub (nth 2 update-flist))
1591 (setq removed (nth 3 update-flist))
1592 (elmo-msgdb-flist-save
1595 (wl-folder-make-save-access-list flist)
1596 (wl-folder-make-save-access-list flist-unsub)))
1597 (wl-folder-entity-assign-id
1599 wl-folder-entity-id-name-hashtb
1601 (setq wl-folder-entity-hashtb
1602 (wl-folder-create-entity-hashtb
1604 wl-folder-entity-hashtb
1606 (setq wl-folder-newsgroups-hashtb
1608 (wl-folder-create-newsgroups-hashtb
1610 wl-folder-newsgroups-hashtb))))
1611 (message "Fetching folder entries...done"))
1612 (wl-folder-insert-entity indent entity))))))))
1614 (defun wl-folder-insert-entity (indent entity &optional onlygroup)
1615 (let (ret-val new unread all)
1618 (let ((inhibit-read-only t)
1619 (buffer-read-only nil)
1620 (flist (nth 2 entity))
1621 (as-opened (cdr (assoc (car entity) wl-folder-group-alist)))
1624 ;;; (insert indent "[" (if as-opened "-" "+") "]" (car entity) "\n")
1625 ;;; (save-excursion (forward-line -1)
1626 ;;; (wl-highlight-folder-current-line))
1630 (let (update-flist flist-unsub new-flist removed group-name-end)
1631 ;;; (when (and (eq (cadr entity) 'access)
1633 ;;; (message "fetching folder entries...")
1634 ;;; (when (setq new-flist
1635 ;;; (elmo-list-folders
1636 ;;; (elmo-string (car entity))
1637 ;;; (wl-string-member
1639 ;;; wl-folder-hierarchy-access-folders)
1641 ;;; (setq update-flist
1642 ;;; (wl-folder-update-access-group entity new-flist))
1643 ;;; (setq flist (nth 1 update-flist))
1644 ;;; (when (car update-flist) ;; diff
1645 ;;; (setq flist-unsub (nth 2 update-flist))
1646 ;;; (setq removed (nth 3 update-flist))
1647 ;;; (elmo-msgdb-flist-save
1650 ;;; (wl-folder-make-save-access-list flist)
1651 ;;; (wl-folder-make-save-access-list flist-unsub)))
1653 ;;; ;; reconstruct wl-folder-entity-id-name-hashtb and
1654 ;;; ;; wl-folder-entity-hashtb
1656 ;;; (wl-folder-entity-assign-id
1658 ;;; wl-folder-entity-id-name-hashtb
1660 ;;; (setq wl-folder-entity-hashtb
1661 ;;; (wl-folder-create-entity-hashtb
1663 ;;; wl-folder-entity-hashtb
1665 ;;; (setq wl-folder-newsgroups-hashtb
1667 ;;; (wl-folder-create-newsgroups-hashtb
1669 ;;; wl-folder-newsgroups-hashtb))))
1670 ;;; (message "fetching folder entries...done"))
1671 (insert indent "[" (if as-opened "-" "+") "]"
1672 (wl-folder-get-petname (car entity)))
1673 (setq group-name-end (point))
1675 (put-text-property beg (point) 'wl-folder-entity-id
1676 (get-text-property 0 'wl-folder-entity-id
1682 wl-folder-removed-mark
1683 (if (listp (car removed))
1684 (concat "[+]" (caar removed))
1687 (save-excursion (forward-line -1)
1688 (wl-highlight-folder-current-line))
1689 (setq removed (cdr removed)))
1690 (remove-text-properties beg (point) '(wl-folder-entity-id)))
1691 (let* ((len (length flist))
1696 (wl-folder-insert-entity
1697 (concat indent " ") (car flist)))
1698 (setq new (+ (or new 0) (or (nth 0 ret-val) 0)))
1699 (setq unread (+ (or unread 0) (or (nth 1 ret-val) 0)))
1700 (setq all (+ (or all 0) (or (nth 2 ret-val) 0)))
1702 (> len elmo-display-progress-threshold))
1704 (elmo-display-progress
1705 'wl-folder-insert-entity "Inserting group %s..."
1706 (/ (* i 100) len) (car entity)))
1707 (setq flist (cdr flist))))
1709 (goto-char group-name-end)
1710 (delete-region (point) (save-excursion (end-of-line)
1712 (insert (format ":%d/%d/%d" (or new 0)
1713 (or unread 0) (or all 0)))
1714 (setq ret-val (list new unread all))
1715 (wl-highlight-folder-current-line ret-val)))
1716 (setq ret-val (wl-folder-calc-finfo entity))
1717 (insert indent "[" (if as-opened "-" "+") "]"
1718 (wl-folder-get-petname (car entity))
1720 (or (nth 0 ret-val) 0)
1721 (or (nth 1 ret-val) 0)
1722 (or (nth 2 ret-val) 0))
1724 (put-text-property beg (point) 'wl-folder-entity-id
1725 (get-text-property 0 'wl-folder-entity-id
1727 (save-excursion (forward-line -1)
1728 (wl-highlight-folder-current-line ret-val)))))
1730 (let* ((inhibit-read-only t)
1731 (buffer-read-only nil)
1732 (nums (wl-folder-get-entity-info entity))
1735 (insert indent (wl-folder-get-petname entity)
1736 (format ":%s/%s/%s\n"
1737 (or (setq new (nth 0 nums)) "*")
1738 (or (setq unread (and (nth 0 nums)(nth 1 nums)
1739 (+ (nth 0 nums)(nth 1 nums))))
1741 (or (setq all (nth 2 nums)) "*")))
1742 (put-text-property beg (point) 'wl-folder-entity-id
1743 (get-text-property 0 'wl-folder-entity-id entity))
1744 (save-excursion (forward-line -1)
1745 (wl-highlight-folder-current-line nums))
1746 (setq ret-val (list new unread all)))))
1747 (set-buffer-modified-p nil)
1750 (defun wl-folder-check-all ()
1752 (wl-folder-check-entity wl-folder-entity))
1754 (defun wl-folder-entity-hashtb-set (entity-hashtb name value buffer)
1761 (setq cur-val (wl-folder-get-entity-info name entity-hashtb))
1762 (setq new-diff (- (or (nth 0 value) 0) (or (nth 0 cur-val) 0)))
1765 (- (or (nth 1 value) 0) (or (nth 1 cur-val) 0))))
1766 (setq all-diff (- (or (nth 2 value) 0) (or (nth 2 cur-val) 0)))
1767 (setq diffs (list new-diff unread-diff all-diff))
1768 (unless (and (nth 0 cur-val)
1769 (equal diffs '(0 0 0)))
1770 (wl-folder-set-entity-info name value entity-hashtb)
1772 (with-current-buffer buffer
1774 (setq entity-list (wl-folder-search-entity-list-by-name
1775 name wl-folder-entity))
1777 (wl-folder-update-group (car entity-list) diffs)
1778 (setq entity-list (cdr entity-list)))
1779 (goto-char (point-min))
1780 (while (wl-folder-buffer-search-entity name)
1781 (wl-folder-update-line value))))))))
1783 (defun wl-folder-update-unread (folder unread)
1784 ; (save-window-excursion
1785 (let ((buf (get-buffer wl-folder-buffer-name))
1788 ;;(fld (elmo-string folder))
1789 value newvalue entity-list)
1790 ;;; Update folder-info
1791 ;;; (elmo-folder-set-info-hashtb fld nil nil nil unread)
1792 (setq cur-unread (or (nth 1 (wl-folder-get-entity-info folder)) 0))
1793 (setq unread-diff (- (or unread 0) cur-unread))
1794 (setq value (wl-folder-get-entity-info folder))
1795 (setq newvalue (list (nth 0 value)
1798 (wl-folder-set-entity-info folder newvalue)
1799 (setq wl-folder-info-alist-modified t)
1801 (not (eq unread-diff 0)))
1803 (with-current-buffer buf
1805 (setq entity-list (wl-folder-search-entity-list-by-name
1806 folder wl-folder-entity))
1808 (wl-folder-update-group (car entity-list) (list 0
1811 (setq entity-list (cdr entity-list)))
1812 (goto-char (point-min))
1813 (while (wl-folder-buffer-search-entity folder)
1814 (wl-folder-update-line newvalue))))))));)
1816 (defun wl-folder-create-entity-hashtb (entity &optional hashtb reconst)
1817 (let ((hashtb (or hashtb (elmo-make-hash wl-folder-entity-id)))
1818 (entities (list entity))
1821 (setq entity (wl-pop entities))
1825 (wl-push entities entity-stack))
1826 (setq entities (nth 2 entity)))
1828 (when (not (and reconst
1829 (wl-folder-get-entity-info entity)))
1830 (wl-folder-set-entity-info entity
1834 (setq entities (wl-pop entity-stack))))
1837 ;; Unsync number is reserved.
1838 ;;(defun wl-folder-reconstruct-entity-hashtb (entity &optional hashtb id-name)
1839 ;; (let* ((hashtb (or hashtb (elmo-make-hash wl-folder-entity-id)))
1840 ;; (entities (list entity))
1843 ;; (setq entity (wl-pop entities))
1847 ;; (wl-folder-set-id-name (wl-folder-get-entity-id (car entity))
1850 ;; (wl-push entities entity-stack))
1851 ;; (setq entities (nth 2 entity))
1853 ;; ((stringp entity)
1854 ;; (wl-folder-set-entity-info entity
1855 ;; (wl-folder-get-entity-info entity)
1858 ;; (wl-folder-set-id-name (wl-folder-get-entity-id entity)
1861 ;; (setq entities (wl-pop entity-stack))))
1864 (defun wl-folder-create-newsgroups-from-nntp-access (entity)
1865 (let ((flist (nth 2 entity))
1870 ((consp (car flist))
1871 (wl-folder-create-newsgroups-from-nntp-access (car flist)))
1874 (elmo-nntp-folder-group-internal
1875 (wl-folder-get-elmo-folder (car flist)))))))
1876 (setq flist (cdr flist)))
1879 (defun wl-folder-create-newsgroups-hashtb (entity &optional is-list info)
1880 "Create NNTP group hashtable for ENTITY."
1881 (let ((entities (if is-list entity (list entity)))
1882 entity-stack folder-list newsgroups newsgroup make-hashtb)
1883 (and info (message "Creating newsgroups..."))
1885 (setq entity (wl-pop entities))
1888 (if (eq (nth 1 entity) 'access)
1889 (when (eq (elmo-folder-type-internal
1890 (elmo-make-folder (car entity))) 'nntp)
1891 (wl-append newsgroups
1892 (wl-folder-create-newsgroups-from-nntp-access entity))
1893 (setq make-hashtb t))
1895 (wl-push entities entity-stack))
1896 (setq entities (nth 2 entity))))
1898 (setq folder-list (elmo-folder-get-primitive-list
1899 (elmo-make-folder entity)))
1901 (when (and (eq (elmo-folder-type-internal (car folder-list))
1903 (setq newsgroup (elmo-nntp-folder-group-internal
1904 (car folder-list))))
1905 (wl-append newsgroups (list (elmo-string newsgroup))))
1906 (setq folder-list (cdr folder-list)))))
1908 (setq entities (wl-pop entity-stack))))
1909 (and info (message "Creating newsgroups...done"))
1910 (if (or newsgroups make-hashtb)
1911 (elmo-setup-subscribed-newsgroups newsgroups))))
1913 (defun wl-folder-get-path (entity target-id &optional string)
1914 (let ((entities (list entity))
1915 entity-stack result-path)
1919 (setq entity (wl-pop entities))
1922 (if (and (or (not string) (string= string (car entity)))
1923 ;; don't use eq, `id' is string on Nemacs.
1924 (equal target-id (wl-folder-get-entity-id (car entity))))
1926 (wl-push target-id result-path))
1927 (wl-push (wl-folder-get-entity-id (car entity)) result-path))
1928 (wl-push entities entity-stack)
1929 (setq entities (nth 2 entity)))
1931 (if (and (or (not string) (string= string entity))
1932 ;; don't use eq, `id' is string on Nemacs.
1933 (equal target-id (wl-folder-get-entity-id entity)))
1935 (wl-push target-id result-path)))))
1937 (while (and entity-stack
1939 (setq result-path (cdr result-path))
1940 (setq entities (wl-pop entity-stack)))))))))
1942 (defun wl-folder-create-group-alist (entity)
1944 (let ((flist (nth 2 entity))
1945 (cur-alist (list (cons (car entity) nil)))
1948 (if (consp (car flist))
1949 (wl-append append-alist
1950 (wl-folder-create-group-alist (car flist))))
1951 (setq flist (cdr flist)))
1952 (append cur-alist append-alist))))
1954 (defun wl-folder-init-info-hashtb ()
1955 (let ((info-alist (and wl-folder-info-save
1956 (elmo-msgdb-finfo-load))))
1957 (elmo-folder-info-make-hashtb
1959 wl-folder-entity-hashtb)))
1960 ;;; (wl-folder-resume-entity-hashtb-by-finfo
1961 ;;; wl-folder-entity-hashtb
1964 (defun wl-folder-cleanup-variables ()
1965 (setq wl-folder-entity nil
1966 wl-folder-entity-hashtb nil
1967 wl-folder-entity-id-name-hashtb nil
1968 wl-folder-group-alist nil
1969 wl-folder-petname-alist nil
1970 wl-folder-newsgroups-hashtb nil
1971 wl-fldmgr-cut-entity-list nil
1972 wl-fldmgr-modified nil
1973 wl-fldmgr-modified-access-list nil
1977 (defun wl-make-plugged-alist ()
1978 (let ((entity-list (wl-folder-get-entity-list wl-folder-entity))
1979 (add (not wl-reset-plugged-alist)))
1981 (elmo-folder-set-plugged
1982 (wl-folder-get-elmo-folder (car entity-list)) wl-plugged add)
1983 (setq entity-list (cdr entity-list)))
1984 ;; smtp posting server
1985 (when wl-smtp-posting-server
1986 (elmo-set-plugged wl-plugged
1987 wl-smtp-posting-server ; server
1988 (or (and (boundp 'smtp-service) smtp-service)
1990 wl-smtp-connection-type
1991 nil nil "smtp" add))
1992 ;; nntp posting server
1993 (when wl-nntp-posting-server
1994 (elmo-set-plugged wl-plugged
1995 wl-nntp-posting-server
1996 wl-nntp-posting-stream-type
1997 wl-nntp-posting-port
1998 nil nil "nntp" add))
1999 (run-hooks 'wl-make-plugged-hook)))
2001 (defvar wl-folder-init-function 'wl-local-folder-init)
2003 (defun wl-folder-init ()
2004 "Return top-level folder entity."
2008 (funcall wl-folder-init-function))
2009 (run-hooks 'wl-folder-init-hook))
2011 (defun wl-local-folder-init ()
2012 "Initialize local folder."
2013 (message "Initializing folder...")
2014 (setq wl-folder-entity (wl-folder-create-folder-entity))
2015 (message "Initializing folder...done"))
2017 (defun wl-folder-get-realname (petname)
2021 wl-folder-petname-alist))
2024 (defun wl-folder-get-petname (name)
2028 wl-folder-petname-alist))
2031 (defun wl-folder-get-entity-with-petname ()
2032 (let ((alist wl-folder-petname-alist)
2033 (hashtb (copy-sequence wl-folder-entity-hashtb)))
2035 (wl-folder-set-entity-info (cdar alist) nil hashtb)
2036 (setq alist (cdr alist)))
2039 (defun wl-folder-get-newsgroups (folder)
2040 "Return Newsgroups field value string for FOLDER newsgroup.
2041 If FOLDER is multi, return comma separated string (cross post)."
2042 (let ((nlist (elmo-folder-newsgroups
2043 (wl-folder-get-elmo-folder folder))))
2045 (list nil nil (mapconcat 'identity nlist ","))
2048 (defun wl-folder-guess-mailing-list-by-refile-rule (entity)
2049 "Return ML address guess by FOLDER.
2050 Use `wl-subscribed-mailing-list' and `wl-refile-rule-alist'."
2052 (elmo-folder-get-primitive-list
2053 (wl-folder-get-elmo-folder entity)))
2055 (while (setq fld (car flist))
2056 (setq mladdr (wl-folder-guess-mailing-list-by-refile-rule-subr
2057 (elmo-folder-name-internal fld)))
2059 (setq to (if (stringp to)
2060 (concat to ", " mladdr)
2062 (setq flist (cdr flist)))
2067 (defun wl-folder-guess-mailing-list-by-refile-rule-subr (entity)
2068 (unless (memq (elmo-folder-type entity)
2070 (let ((rules wl-refile-rule-alist)
2073 (if (or (and (stringp (car (car rules)))
2074 (string-match "[Tt]o" (car (car rules))))
2075 (and (listp (car (car rules)))
2076 (elmo-string-matched-member "to" (car (car rules))
2078 (setq toalist (append toalist (cdr (car rules)))))
2079 (setq rules (cdr rules)))
2080 (setq tokey (car (rassoc entity toalist)))
2081 ;;; (setq histkey (car (rassoc folder wl-refile-alist)))
2082 ;; case-ignore search `wl-subscribed-mailing-list'
2084 (elmo-string-matched-member tokey wl-subscribed-mailing-list t)))))
2086 (defun wl-folder-guess-mailing-list-by-folder-name (entity)
2087 "Return ML address guess by FOLDER name's last hierarchy.
2088 Use `wl-subscribed-mailing-list'."
2090 (elmo-folder-get-primitive-list
2091 (wl-folder-get-elmo-folder entity)))
2093 (while (setq fld (car flist))
2094 (setq mladdr (wl-folder-guess-mailing-list-by-folder-name-subr
2095 (elmo-folder-name-internal fld)))
2097 (setq to (if (stringp to)
2098 (concat to ", " mladdr)
2100 (setq flist (cdr flist)))
2105 (defun wl-folder-guess-mailing-list-by-folder-name-subr (entity)
2106 (when (memq (elmo-folder-type entity)
2107 '(localdir imap4 maildir))
2108 (let (key foldername)
2109 ;; Get foldername and Remove folder type symbol.
2110 (setq foldername (substring entity 1))
2111 (if (string-match "@" foldername)
2112 (setq foldername (substring foldername 0 (match-beginning 0))))
2113 (when (string-match "[^\\./]+$" foldername)
2114 (setq key (regexp-quote
2115 (concat (substring foldername (match-beginning 0)) "@")))
2116 (elmo-string-matched-member
2117 key wl-subscribed-mailing-list 'case-ignore)))))
2119 (defun wl-folder-update-diff-line (diffs)
2120 (let ((inhibit-read-only t)
2121 (buffer-read-only nil)
2123 cur-unread new-unread
2128 (setq id (get-text-property (point) 'wl-folder-entity-id))
2129 (when (looking-at "^[ ]*\\(.*\\):\\([0-9\\*-]*\\)/\\([0-9\\*-]*\\)/\\([0-9\\*]*\\)")
2130 ;;(looking-at "^[ ]*\\([^\\[].+\\):\\([0-9\\*-]*/[0-9\\*-]*/[0-9\\*]*\\)")
2131 (setq cur-new (string-to-int
2132 (wl-match-buffer 2)))
2133 (setq cur-unread (string-to-int
2134 (wl-match-buffer 3)))
2135 (setq cur-all (string-to-int
2136 (wl-match-buffer 4)))
2137 (delete-region (match-beginning 2)
2139 (goto-char (match-beginning 2))
2140 (insert (format "%s/%s/%s"
2141 (setq new-new (+ cur-new (nth 0 diffs)))
2142 (setq new-unread (+ cur-unread (nth 1 diffs)))
2143 (setq new-all (+ cur-all (nth 2 diffs)))))
2144 (put-text-property (match-beginning 2) (point)
2145 'wl-folder-entity-id id)
2146 (if wl-use-highlight-mouse-line
2147 (put-text-property (match-beginning 2) (point)
2148 'mouse-face 'highlight))
2149 (wl-highlight-folder-group-line (list new-new new-unread new-all))
2150 (setq buffer-read-only t)
2151 (set-buffer-modified-p nil)))))
2153 (defun wl-folder-update-line (nums &optional is-group)
2154 (let ((inhibit-read-only t)
2155 (buffer-read-only nil)
2159 (setq id (get-text-property (point) 'wl-folder-entity-id))
2160 (if (looking-at "^[ ]*\\(.*\\):\\([0-9\\*-]*/[0-9\\*-]*/[0-9\\*]*\\)")
2161 ;;; (looking-at "^[ ]*\\([^\\[].+\\):\\([0-9\\*-]*/[0-9\\*-]*/[0-9\\*]*\\)")
2163 (delete-region (match-beginning 2)
2165 (goto-char (match-beginning 2))
2166 (insert (format "%s/%s/%s"
2167 (or (nth 0 nums) "*")
2168 (or (and (nth 0 nums)(nth 1 nums)
2169 (+ (nth 0 nums)(nth 1 nums)))
2171 (or (nth 2 nums) "*")))
2172 (put-text-property (match-beginning 2) (point)
2173 'wl-folder-entity-id id)
2175 ;; update only colors
2176 (wl-highlight-folder-group-line nums)
2177 (wl-highlight-folder-current-line nums))
2179 (set-buffer-modified-p nil))))))
2181 (defun wl-folder-goto-folder (&optional arg)
2183 (wl-folder-goto-folder-subr nil arg))
2185 (defun wl-folder-goto-folder-subr (&optional folder sticky)
2187 (let (summary-buf fld-name entity id error-selecting)
2188 ;;; (setq fld-name (wl-folder-get-entity-from-buffer))
2189 ;;; (if (or (null fld-name)
2190 ;;; (assoc fld-name wl-folder-group-alist))
2191 (setq fld-name wl-default-folder)
2192 (setq fld-name (or folder
2193 (wl-summary-read-folder fld-name)))
2194 (if (and (setq entity
2195 (wl-folder-search-entity-by-name fld-name
2198 (setq id (wl-folder-get-entity-id entity)))
2199 (wl-folder-set-current-entity-id id))
2200 (setq summary-buf (wl-summary-get-buffer-create fld-name sticky))
2201 (if (or wl-stay-folder-window wl-summary-use-frame)
2202 (wl-folder-select-buffer summary-buf)
2203 (if (and summary-buf
2204 (get-buffer-window summary-buf))
2206 (wl-summary-goto-folder-subr fld-name
2207 (wl-summary-get-sync-range
2208 (wl-folder-get-elmo-folder fld-name))
2211 (defun wl-folder-suspend ()
2213 (run-hooks 'wl-folder-suspend-hook)
2214 (wl-folder-info-save)
2215 (elmo-crosspost-message-alist-save)
2217 ;(if (fboundp 'mmelmo-cleanup-entity-buffers)
2218 ;(mmelmo-cleanup-entity-buffers))
2219 (bury-buffer wl-folder-buffer-name)
2220 (delete-windows-on wl-folder-buffer-name t))
2222 (defun wl-folder-info-save ()
2223 (when (and wl-folder-info-save
2224 wl-folder-info-alist-modified)
2225 (let ((entities (list wl-folder-entity))
2226 entity entity-stack info-alist info)
2228 (setq entity (wl-pop entities))
2232 (wl-push entities entity-stack))
2233 (setq entities (nth 2 entity)))
2235 (when (and (setq info (elmo-folder-get-info
2236 (wl-folder-get-elmo-folder entity)))
2237 (not (equal info '(nil))))
2239 (wl-append info-alist (list (list (elmo-string entity)
2240 (list (nth 3 info) ;; max
2241 (nth 2 info) ;; length
2243 (nth 1 info)) ;; unread
2246 (setq entities (wl-pop entity-stack))))
2247 (elmo-msgdb-finfo-save info-alist)
2248 (setq wl-folder-info-alist-modified nil))))
2250 (defun wl-folder-goto-first-unread-folder (&optional arg)
2252 (let ((entities (list wl-folder-entity))
2253 entity entity-stack ret-val
2258 (setq entity (wl-pop entities))
2262 (wl-push entities entity-stack))
2263 (setq entities (nth 2 entity)))
2265 (if (and (setq finfo (wl-folder-get-entity-info entity))
2266 (and (nth 0 finfo)(nth 1 finfo))
2267 (> (+ (nth 0 finfo)(nth 1 finfo)) 0))
2268 (throw 'done entity))
2269 (wl-append ret-val (list entity))))
2271 (setq entities (wl-pop entity-stack))))))
2275 (wl-folder-jump-folder first-entity)
2277 (wl-folder-goto-folder-subr first-entity))
2278 (message "No unread folder"))))
2280 (defun wl-folder-jump-folder (&optional fld-name noopen)
2283 (setq fld-name (wl-summary-read-folder wl-default-folder)))
2284 (goto-char (point-min))
2286 (wl-folder-open-folder fld-name))
2287 (and (wl-folder-buffer-search-entity fld-name)
2288 (beginning-of-line)))
2290 (defun wl-folder-get-entity-list (entity)
2291 (let ((entities (list entity))
2292 entity-stack ret-val)
2294 (setq entity (wl-pop entities))
2298 (wl-push entities entity-stack))
2299 (setq entities (nth 2 entity)))
2301 (wl-append ret-val (list entity))))
2303 (setq entities (wl-pop entity-stack))))
2306 (defun wl-folder-open-unread-folder (entity)
2308 (let ((alist (wl-folder-get-entity-list entity))
2310 finfo path-list path id)
2312 (when (and (setq finfo (wl-folder-get-entity-info (car alist)))
2313 (nth 0 finfo) (nth 1 finfo)
2314 (> (+ (nth 0 finfo)(nth 1 finfo)) 0))
2315 (setq unread (+ unread (+ (nth 0 finfo)(nth 1 finfo))))
2316 (setq id (wl-folder-get-entity-id (car alist)))
2317 (setq path (delete id (wl-folder-get-path
2321 (if (not (member path path-list))
2322 (wl-append path-list (list path))))
2323 (setq alist (cdr alist)))
2325 (wl-folder-open-folder-sub (car path-list))
2326 (setq path-list (cdr path-list)))
2327 (message "%s unread folder"
2328 (if (> unread 0) unread "No")))))
2330 (defun wl-folder-open-unread-current-entity ()
2332 (let ((entity-name (wl-folder-get-entity-from-buffer))
2333 (group (wl-folder-buffer-group-p)))
2335 (wl-folder-open-unread-folder
2337 (wl-folder-search-group-entity-by-name entity-name
2341 (defun wl-folder-open-only-unread-folder ()
2344 (wl-folder-prev-entity-skip-invalid t)
2345 (wl-folder-get-entity-from-buffer t))))
2346 (wl-folder-open-all-unread-folder)
2348 (goto-char (point-max))
2349 (while (and (re-search-backward
2350 "^[ ]*\\[[-]\\].+:0/0/[0-9-]+" nil t)
2352 (wl-folder-jump-to-current-entity) ;; close it
2354 (wl-folder-move-path id)
2357 (defun wl-folder-open-all-unread-folder (&optional arg)
2360 (wl-folder-prev-entity-skip-invalid t)
2361 (wl-folder-get-entity-from-buffer t))))
2362 (wl-folder-open-unread-folder wl-folder-entity)
2364 (wl-folder-move-path id)
2365 (goto-char (point-min))
2366 (wl-folder-next-unread t))))
2368 (defun wl-folder-open-folder (&optional fld-name)
2371 (setq fld-name (wl-summary-read-folder wl-default-folder)))
2372 (let* ((id (wl-folder-get-entity-id
2373 (wl-folder-search-entity-by-name fld-name wl-folder-entity
2375 (path (and id (wl-folder-get-path wl-folder-entity id))))
2377 (wl-folder-open-folder-sub path))))
2379 (defun wl-folder-open-folder-sub (path)
2380 (let ((inhibit-read-only t)
2381 (buffer-read-only nil)
2385 (goto-char (point-min))
2387 (wl-folder-buffer-search-group
2388 (wl-folder-get-petname
2389 (if (stringp (car path))
2391 (wl-folder-get-folder-name-by-id
2394 (setq path (cdr path))
2395 (if (and (looking-at wl-folder-group-regexp)
2396 (string= "+" (wl-match-buffer 2)));; closed group
2398 (setq indent (wl-match-buffer 1))
2399 (setq name (wl-folder-get-realname (wl-match-buffer 3)))
2400 (setq entity (wl-folder-search-group-entity-by-name
2404 (setcdr (assoc (car entity) wl-folder-group-alist) t)
2405 (if (eq 'access (cadr entity))
2406 (wl-folder-maybe-load-folder-list entity))
2407 (wl-folder-insert-entity indent entity)
2408 (delete-region (save-excursion (beginning-of-line)
2410 (save-excursion (end-of-line)
2412 (set-buffer-modified-p nil))))
2414 (defun wl-folder-open-all-pre ()
2415 (let ((entities (list wl-folder-entity))
2416 entity entity-stack group-entry)
2418 (setq entity (wl-pop entities))
2421 (unless (or (not (setq group-entry
2422 (assoc (car entity) wl-folder-group-alist)))
2424 (setcdr group-entry t)
2425 (when (eq 'access (cadr entity))
2426 (wl-folder-maybe-load-folder-list entity)))
2428 (wl-push entities entity-stack))
2429 (setq entities (nth 2 entity))))
2431 (setq entities (wl-pop entity-stack))))))
2433 (defun wl-folder-open-all (&optional refresh)
2435 (let* ((inhibit-read-only t)
2436 (buffer-read-only nil)
2437 (len (length wl-folder-group-alist))
2442 (wl-folder-prev-entity-skip-invalid t)
2443 (wl-folder-get-entity-from-buffer t)))
2444 (alist wl-folder-group-alist))
2446 (setcdr (pop alist) t))
2448 (wl-folder-insert-entity " " wl-folder-entity)
2449 (wl-folder-move-path id))
2450 (message "Opening all folders...")
2451 (wl-folder-open-all-pre)
2453 (goto-char (point-min))
2454 (while (re-search-forward
2455 "^\\([ ]*\\)\\[\\([+]\\)\\]\\(.+\\):[-0-9-]+/[0-9-]+/[0-9-]+\n"
2457 (setq indent (wl-match-buffer 1))
2458 (setq name (wl-folder-get-realname (wl-match-buffer 3)))
2459 (setq entity (wl-folder-search-group-entity-by-name
2463 (setcdr (assoc (car entity) wl-folder-group-alist) t)
2465 (wl-folder-insert-entity indent entity)
2466 (delete-region (save-excursion (beginning-of-line)
2468 (save-excursion (end-of-line)
2470 (when (> len elmo-display-progress-threshold)
2472 (if (or (zerop (% i 5)) (= i len))
2473 (elmo-display-progress
2474 'wl-folder-open-all "Opening all folders..."
2475 (/ (* i 100) len)))))
2476 (when (> len elmo-display-progress-threshold)
2477 (elmo-display-progress
2478 'wl-folder-open-all "Opening all folders..." 100))))
2479 (message "Opening all folders...done")
2480 (set-buffer-modified-p nil)))
2482 (defun wl-folder-close-all ()
2484 (let ((inhibit-read-only t)
2485 (buffer-read-only nil)
2486 (alist wl-folder-group-alist)
2488 (wl-folder-prev-entity-skip-invalid t)
2489 (wl-folder-get-entity-from-buffer t))))
2491 (setcdr (car alist) nil)
2492 (setq alist (cdr alist)))
2493 (setcdr (assoc (car wl-folder-entity) wl-folder-group-alist) t)
2495 (wl-folder-insert-entity " " wl-folder-entity)
2496 (wl-folder-move-path id)
2498 (set-buffer-modified-p nil)))
2500 (defun wl-folder-open-close ()
2501 "Open or close parent entity."
2505 (if (wl-folder-buffer-group-p)
2506 ;; if group (whether opend or closed.)
2507 (wl-folder-jump-to-current-entity)
2510 (setq indent (save-excursion
2511 (re-search-forward "\\([ ]*\\)." nil t)
2512 (wl-match-buffer 1)))
2513 (while (looking-at indent)
2515 (wl-folder-jump-to-current-entity))))
2517 (defsubst wl-folder-access-subscribe-p (group folder)
2518 (let (subscr regexp match)
2519 (if (setq subscr (wl-get-assoc-list-value
2520 wl-folder-access-subscribe-alist
2523 (setq regexp (mapconcat 'identity (cdr subscr) "\\|"))
2524 (setq match (string-match regexp folder))
2530 (defun wl-folder-update-access-group (entity new-flist)
2531 (let* ((flist (nth 2 entity))
2532 (unsubscribes (nth 3 entity))
2533 (len (+ (length flist) (length unsubscribes)))
2535 diff new-unsubscribes removes
2536 subscribed-list folder group entry)
2537 ;; check subscribed groups
2540 ((listp (car flist)) ;; group
2541 (setq group (elmo-string (caar flist)))
2543 ((assoc group new-flist) ;; found in new-flist
2544 (setq new-flist (delete (assoc group new-flist)
2546 (if (wl-folder-access-subscribe-p (car entity) group)
2547 (wl-append subscribed-list (list (car flist)))
2548 (wl-append new-unsubscribes (list (car flist)))
2551 (setq wl-folder-group-alist
2552 (delete (wl-string-assoc group wl-folder-group-alist)
2553 wl-folder-group-alist))
2554 (wl-append removes (list (list group))))))
2556 (setq folder (elmo-string (car flist)))
2558 ((member folder new-flist) ;; found in new-flist
2559 (setq new-flist (delete folder new-flist))
2560 (if (wl-folder-access-subscribe-p (car entity) folder)
2561 (wl-append subscribed-list (list (car flist)))
2562 (wl-append new-unsubscribes (list folder))
2565 (wl-append removes (list folder))))))
2566 (when (> len elmo-display-progress-threshold)
2568 (if (or (zerop (% i 10)) (= i len))
2569 (elmo-display-progress
2570 'wl-folder-update-access-group "Updating access group..."
2571 (/ (* i 100) len))))
2572 (setq flist (cdr flist)))
2573 ;; check unsubscribed groups
2576 ((listp (car unsubscribes))
2577 (when (setq entry (assoc (caar unsubscribes) new-flist))
2578 (setq new-flist (delete entry new-flist))
2579 (wl-append new-unsubscribes (list (car unsubscribes)))))
2581 (when (member (car unsubscribes) new-flist)
2582 (setq new-flist (delete (car unsubscribes) new-flist))
2583 (wl-append new-unsubscribes (list (car unsubscribes))))))
2584 (when (> len elmo-display-progress-threshold)
2586 (if (or (zerop (% i 10)) (= i len))
2587 (elmo-display-progress
2588 'wl-folder-update-access-group "Updating access group..."
2589 (/ (* i 100) len))))
2590 (setq unsubscribes (cdr unsubscribes)))
2592 (if (or new-flist removes)
2595 (mapcar '(lambda (x)
2596 (cond ((consp x) (list (car x) 'access))
2600 (let ((new-list new-flist))
2602 (if (not (wl-folder-access-subscribe-p
2604 (if (listp (car new-list))
2609 (wl-append new-unsubscribes (list (car new-list)))
2610 (setq new-flist (delete (car new-list) new-flist)))
2612 ((listp (car new-list))
2613 ;; check group exists
2614 (if (wl-string-assoc (caar new-list) wl-folder-group-alist)
2616 (message "%s: group already exists." (caar new-list))
2618 (wl-append new-unsubscribes (list (car new-list)))
2619 (setq new-flist (delete (car new-list) new-flist)))
2620 (wl-append wl-folder-group-alist
2621 (list (cons (caar new-list) nil)))))))
2622 (setq new-list (cdr new-list))))
2624 (message "%d new folder(s)." (length new-flist))
2625 (message "Updating access group...done"))
2626 (wl-append new-flist subscribed-list) ;; new is first
2627 (run-hooks 'wl-folder-update-access-group-hook)
2628 (setcdr (cdr entity) (list new-flist new-unsubscribes))
2629 (list diff new-flist new-unsubscribes removes)))
2631 (defun wl-folder-prefetch-entity (entity)
2632 "Prefetch all new messages in the ENTITY."
2635 (let ((flist (nth 2 entity))
2640 (setq result (wl-folder-prefetch-entity (car flist)))
2641 (setq sum-done (+ sum-done (car result)))
2642 (setq sum-all (+ sum-all (cdr result)))
2643 (setq flist (cdr flist)))
2644 (message "Prefetched %d/%d message(s) in \"%s\"."
2646 (wl-folder-get-petname (car entity)))
2647 (cons sum-done sum-all)))
2649 (let* ((folder (wl-folder-get-elmo-folder entity))
2650 (nums (wl-folder-get-entity-info entity))
2651 (wl-summary-highlight (if (or (wl-summary-sticky-p folder)
2652 (wl-summary-always-sticky-folder-p
2654 wl-summary-highlight))
2655 wl-summary-exit-next-move
2656 wl-auto-select-first ret-val
2658 (setq count (or (car nums) 0))
2659 (setq count (+ count (wl-folder-count-incorporates folder)))
2660 (if (or (null (car nums)) ; unknown
2662 (save-window-excursion
2664 (let ((wl-summary-buffer-name (concat
2665 wl-summary-buffer-name
2666 (symbol-name this-command)))
2667 (wl-summary-use-frame nil)
2668 (wl-summary-always-sticky-folder-list nil))
2669 (wl-summary-goto-folder-subr entity
2670 (wl-summary-get-sync-range
2673 (setq ret-val (wl-summary-incorporate))
2678 (defun wl-folder-count-incorporates (folder)
2679 (let ((marks (elmo-msgdb-mark-load
2680 (elmo-folder-msgdb-path folder)))
2683 (if (member (cadr (car marks))
2684 wl-summary-incorporate-marks)
2686 (setq marks (cdr marks)))
2689 (defun wl-folder-prefetch-current-entity (&optional no-check)
2690 "Prefetch all uncached messages in the folder at position.
2691 If current line is group folder, all subfolders are prefetched."
2694 (let ((entity-name (wl-folder-get-entity-from-buffer))
2695 (group (wl-folder-buffer-group-p))
2696 wl-folder-check-entity-hook
2701 (wl-folder-search-group-entity-by-name entity-name
2705 (wl-folder-check-entity entity))
2706 (wl-folder-prefetch-entity entity)))))
2708 ;(defun wl-folder-drop-unsync-entity (entity)
2709 ; "Drop all unsync messages in the ENTITY."
2712 ; (let ((flist (nth 2 entity)))
2714 ; (wl-folder-drop-unsync-entity (car flist))
2715 ; (setq flist (cdr flist)))))
2717 ; (let ((nums (wl-folder-get-entity-info entity))
2718 ; wl-summary-highlight wl-auto-select-first new)
2719 ; (setq new (or (car nums) 0))
2721 ; (save-window-excursion
2723 ; (let ((wl-summary-buffer-name (concat
2724 ; wl-summary-buffer-name
2725 ; (symbol-name this-command))))
2726 ; (wl-summary-goto-folder-subr entity 'no-sync nil)
2727 ; (wl-summary-drop-unsync)
2728 ; (wl-summary-exit)))))))))
2730 ;(defun wl-folder-drop-unsync-current-entity (&optional force-check)
2731 ; "Drop all unsync messages in the folder at position.
2732 ;If current line is group folder, all subfolders are dropped.
2733 ;If optional arg exists, don't check any folders."
2736 ; (let ((entity-name (wl-folder-get-entity-from-buffer))
2737 ; (group (wl-folder-buffer-group-p))
2738 ; wl-folder-check-entity-hook
2739 ; summary-buf entity)
2740 ; (when (and entity-name
2742 ; "Drop all unsync messages in %s? " entity-name)))
2745 ; (wl-folder-search-group-entity-by-name entity-name
2748 ; (if (null force-check)
2749 ; (wl-folder-check-entity entity))
2750 ; (wl-folder-drop-unsync-entity entity)
2751 ; (message "All unsync messages in %s are dropped!" entity-name)))))
2753 (defun wl-folder-write-current-folder ()
2754 "Write message to current folder's newsgroup or mailing-list.
2755 Call `wl-summary-write-current-folder' with current folder name."
2757 (unless (wl-folder-buffer-group-p)
2758 (wl-summary-write-current-folder
2759 (wl-folder-get-realname (wl-folder-entity-name)))))
2761 (defun wl-folder-mimic-kill-buffer ()
2762 "Kill the current (Folder) buffer with query."
2764 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
2766 wl-interactive-exit)
2767 (if (or (not bufname)
2768 (string-equal bufname "")
2769 (string-equal bufname (buffer-name)))
2771 (kill-buffer bufname))))
2773 (defun wl-folder-create-subr (folder)
2774 (if (y-or-n-p (format "Folder %s does not exist, create it? "
2775 (elmo-folder-name-internal folder)))
2778 (setq wl-folder-entity-hashtb
2779 (wl-folder-create-entity-hashtb
2780 (elmo-folder-name-internal folder)
2781 wl-folder-entity-hashtb))
2782 (unless (elmo-folder-create folder)
2783 (error "Create folder failed")))
2784 (error "Folder %s is not created" (elmo-folder-name-internal folder))))
2786 (defun wl-folder-confirm-existence (folder &optional force)
2788 (unless (elmo-folder-exists-p folder)
2789 (wl-folder-create-subr folder))
2790 (unless (or (wl-folder-entity-exists-p (elmo-folder-name-internal folder))
2791 (file-exists-p (elmo-folder-msgdb-path folder))
2792 (elmo-folder-exists-p folder))
2793 (wl-folder-create-subr folder))))
2796 (product-provide (provide 'wl-folder) (require 'wl-version))
2798 ;;; wl-folder.el ends here