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
)
65 (defvar wl-folder-mode-map nil
)
67 (defvar wl-folder-buffer-disp-summary nil
)
68 (defvar wl-folder-buffer-cur-entity-id nil
)
69 (defvar wl-folder-buffer-last-visited-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-last-visited-entity-id
)
76 (make-variable-buffer-local 'wl-folder-buffer-cur-path
)
77 (make-variable-buffer-local 'wl-folder-buffer-cur-point
)
79 (defconst wl-folder-entity-regexp
"^\\([ ]*\\)\\(\\[[\\+-]\\]\\)?\\([^\\[].+\\):[-*0-9]+/[-*0-9]+/[-*0-9]+")
80 (defconst wl-folder-group-regexp
"^\\([ ]*\\)\\[\\([\\+-]\\)\\]\\(.+\\):[0-9-]+/[0-9-]+/[0-9-]+\n")
81 ;; 1:indent 2:opened 3:group-name
82 (defconst wl-folder-unsync-regexp
":[^0\\*][0-9]*/[0-9\\*-]+/[0-9\\*-]+$")
84 (defvar wl-folder-mode-menu-spec
86 ["Enter Current Folder" wl-folder-jump-to-current-entity t
]
87 ["Prev Folder" wl-folder-prev-entity t
]
88 ["Next Folder" wl-folder-next-entity t
]
89 ["Check Current Folder" wl-folder-check-current-entity t
]
90 ["Sync Current Folder" wl-folder-sync-current-entity t
]
91 ; ["Drop Current Folder" wl-folder-drop-unsync-current-entity t]
92 ["Prefetch Current Folder" wl-folder-prefetch-current-entity t
]
94 ["Mark as Read all Current Folder" wl-folder-mark-as-read-all-current-entity t
]
95 ["Expire Current Folder" wl-folder-expire-current-entity t
]
97 ["Go to Draft Folder" wl-folder-goto-draft-folder t
]
98 ["Empty trash" wl-folder-empty-trash t
]
99 ["Flush queue" wl-folder-flush-queue t
]
101 ["Open All" wl-folder-open-all t
]
102 ["Open All Unread folder" wl-folder-open-all-unread-folder t
]
103 ["Close All" wl-folder-close-all t
]
105 ["Add folder" wl-fldmgr-add t
]
106 ["Add group" wl-fldmgr-make-group t
]
107 ["Copy" wl-fldmgr-copy t
]
108 ["Cut" wl-fldmgr-cut t
]
109 ["Paste" wl-fldmgr-yank t
]
110 ["Set petname" wl-fldmgr-set-petname t
]
111 ["Rename" wl-fldmgr-rename t
]
112 ["Save" wl-fldmgr-save-folders t
]
114 ["Unsubscribe" wl-fldmgr-unsubscribe t
]
115 ["Display all" wl-fldmgr-access-display-all t
])
117 ["Write a message" wl-draft t
]
118 ["Write for current folder" wl-folder-write-current-folder t
]
120 ["Wanderlust NEWS" wl-news t
]
122 ["Toggle Plug Status" wl-toggle-plugged t
]
123 ["Change Plug Status" wl-plugged-change t
]
125 ["Save Current Status" wl-save t
]
126 ["Update Status" wl-status-update t
]
131 (defun wl-folder-setup-mouse ()
132 (define-key wl-folder-mode-map
'button2
'wl-folder-click
)
133 (define-key wl-folder-mode-map
'button4
'wl-folder-prev-entity
)
134 (define-key wl-folder-mode-map
'button5
'wl-folder-next-entity
)
135 (define-key wl-folder-mode-map
[(shift button4
)]
136 'wl-folder-prev-unread
)
137 (define-key wl-folder-mode-map
[(shift button5
)]
138 'wl-folder-next-unread
))
139 (defun wl-folder-setup-mouse ()
140 (define-key wl-folder-mode-map
[mouse-2
] 'wl-folder-click
)
141 (define-key wl-folder-mode-map
[mouse-4
] 'wl-folder-prev-entity
)
142 (define-key wl-folder-mode-map
[mouse-5
] 'wl-folder-next-entity
)
143 (define-key wl-folder-mode-map
[S-mouse-4
] 'wl-folder-prev-unread
)
144 (define-key wl-folder-mode-map
[S-mouse-5
] 'wl-folder-next-unread
)))
146 (if wl-folder-mode-map
148 (setq wl-folder-mode-map
(make-sparse-keymap))
149 (define-key wl-folder-mode-map
" " 'wl-folder-jump-to-current-entity
)
150 ; (define-key wl-folder-mode-map "\M- " 'wl-folder-open-close)
151 (define-key wl-folder-mode-map
"/" 'wl-folder-open-close
)
152 (define-key wl-folder-mode-map
"\C-m" 'wl-folder-jump-to-current-entity
)
153 (define-key wl-folder-mode-map
[(shift return
)] 'wl-folder-jump-to-current-entity-with-arg
)
154 (define-key wl-folder-mode-map
"\M-\C-m" 'wl-folder-update-recursive-current-entity
)
155 (define-key wl-folder-mode-map
"rc" 'wl-folder-mark-as-read-all-region
)
156 (define-key wl-folder-mode-map
"c" 'wl-folder-mark-as-read-all-current-entity
)
157 (define-key wl-folder-mode-map
"g" 'wl-folder-goto-folder
)
158 (define-key wl-folder-mode-map
"G" 'wl-folder-goto-folder-sticky
)
159 (define-key wl-folder-mode-map
"j" 'wl-folder-jump-to-current-entity
)
160 (define-key wl-folder-mode-map
"\C-i" 'wl-folder-revisit-last-visited-folder
)
161 (define-key wl-folder-mode-map
"w" 'wl-draft
)
162 (define-key wl-folder-mode-map
"W" 'wl-folder-write-current-folder
)
163 (define-key wl-folder-mode-map
"\C-c\C-o" 'wl-jump-to-draft-buffer
)
164 (define-key wl-folder-mode-map
"\C-c\C-a" 'wl-addrmgr
)
165 (define-key wl-folder-mode-map
"\C-c\C-p" 'wl-folder-jump-to-previous-summary
)
166 (define-key wl-folder-mode-map
"\C-c\C-n" 'wl-folder-jump-to-next-summary
)
167 (define-key wl-folder-mode-map
"rS" 'wl-folder-sync-region
)
168 (define-key wl-folder-mode-map
"S" 'wl-folder-sync-current-entity
)
169 (define-key wl-folder-mode-map
"rs" 'wl-folder-check-region
)
170 (define-key wl-folder-mode-map
"s" 'wl-folder-check-current-entity
)
171 (define-key wl-folder-mode-map
"I" 'wl-folder-prefetch-current-entity
)
172 ; (define-key wl-folder-mode-map "D" 'wl-folder-drop-unsync-current-entity)
173 (define-key wl-folder-mode-map
"p" 'wl-folder-prev-entity
)
174 (define-key wl-folder-mode-map
"n" 'wl-folder-next-entity
)
175 (define-key wl-folder-mode-map
"v" 'wl-folder-toggle-disp-summary
)
176 (define-key wl-folder-mode-map
"P" 'wl-folder-prev-unread
)
177 (define-key wl-folder-mode-map
"N" 'wl-folder-next-unread
)
178 (define-key wl-folder-mode-map
"J" 'wl-folder-jump-folder
)
179 (define-key wl-folder-mode-map
"f" 'wl-folder-goto-first-unread-folder
)
180 (define-key wl-folder-mode-map
"o" 'wl-folder-open-all-unread-folder
)
181 (define-key wl-folder-mode-map
"[" 'wl-folder-open-all
)
182 (define-key wl-folder-mode-map
"]" 'wl-folder-close-all
)
183 (define-key wl-folder-mode-map
"e" 'wl-folder-expire-current-entity
)
184 (define-key wl-folder-mode-map
"E" 'wl-folder-empty-trash
)
185 (define-key wl-folder-mode-map
"F" 'wl-folder-flush-queue
)
186 (define-key wl-folder-mode-map
"V" 'wl-folder-virtual
)
187 (define-key wl-folder-mode-map
"?" 'wl-folder-pick
)
188 (define-key wl-folder-mode-map
"q" 'wl-exit
)
189 (define-key wl-folder-mode-map
"z" 'wl-folder-suspend
)
190 (define-key wl-folder-mode-map
"x" 'wl-execute-temp-marks
)
191 (define-key wl-folder-mode-map
"\M-t" 'wl-toggle-plugged
)
192 (define-key wl-folder-mode-map
"\C-t" 'wl-plugged-change
)
193 (define-key wl-folder-mode-map
"<" 'beginning-of-buffer
)
194 (define-key wl-folder-mode-map
">" 'end-of-buffer
)
196 (define-key wl-folder-mode-map
"m" 'wl-fldmgr-mode-map
)
197 (define-key wl-folder-mode-map
"*" 'wl-fldmgr-make-multi
)
198 (define-key wl-folder-mode-map
"+" 'wl-fldmgr-make-group
)
199 (define-key wl-folder-mode-map
"|" 'wl-fldmgr-make-filter
)
200 (define-key wl-folder-mode-map
"\M-c" 'wl-fldmgr-copy
)
201 (define-key wl-folder-mode-map
"\M-w" 'wl-fldmgr-copy-region
)
202 (define-key wl-folder-mode-map
"\C-k" 'wl-fldmgr-cut
)
203 (define-key wl-folder-mode-map
"\C-w" 'wl-fldmgr-cut-region
)
204 (define-key wl-folder-mode-map
"\C-y" 'wl-fldmgr-yank
)
205 (define-key wl-folder-mode-map
"R" 'wl-fldmgr-rename
)
206 (define-key wl-folder-mode-map
"u" 'wl-fldmgr-unsubscribe
)
207 (define-key wl-folder-mode-map
"ru" 'wl-fldmgr-unsubscribe-region
)
208 (define-key wl-folder-mode-map
"U" 'wl-fldmgr-unsubscribe-region
)
209 (define-key wl-folder-mode-map
"l" 'wl-fldmgr-access-display-normal
)
210 (define-key wl-folder-mode-map
"L" 'wl-fldmgr-access-display-all
)
211 (define-key wl-folder-mode-map
"Z" 'wl-status-update
)
212 (define-key wl-folder-mode-map
"\C-x\C-s" 'wl-save
)
213 (define-key wl-folder-mode-map
"\M-s" 'wl-save
)
214 (define-key wl-folder-mode-map
"\C-xk" 'wl-folder-mimic-kill-buffer
)
215 (define-key wl-folder-mode-map
"\M-\C-a"
216 'wl-folder-goto-top-of-current-folder
)
217 (define-key wl-folder-mode-map
"\M-\C-e"
218 'wl-folder-goto-bottom-of-current-folder
)
220 (wl-folder-setup-mouse)
224 "Menu used in Folder mode."
225 wl-folder-mode-menu-spec
))
227 (defmacro wl-folder-unread-regex
(group)
228 `(concat "^[ ]*.+:[0-9\\*-]+/[^0\\*][0-9]*/[0-9\\*-]+$"
233 (defmacro wl-folder-buffer-group-p
()
234 '(get-text-property (point) 'wl-folder-is-group
))
236 (defun wl-folder-buffer-search-group (group)
237 (let ((prev-point (point))
238 (group-regexp (concat
239 "^\\([ \t]*\\)\\[[\\+-]\\]"
240 (regexp-quote group
) ":[-0-9-]+/[0-9-]+/[0-9-]+")))
242 (while (re-search-forward group-regexp nil t
)
243 (if (wl-folder-buffer-group-p)
244 (throw 'found
(point)))))
246 (goto-char prev-point
)
249 (defun wl-folder-buffer-search-entity (folder &optional searchname
)
250 (let ((search (or searchname
(wl-folder-get-petname folder
)))
258 (regexp-quote search
) ":[-0-9\\*-]+/[0-9\\*-]+/[0-9\\*-]+")
260 (when (string= (wl-folder-get-entity-from-buffer) folder
)
261 (throw 'found result
))))))
263 (defsubst wl-folder-get-folder-name-by-id
(entity-id &optional hashtb
)
264 (and (numberp entity-id
)
265 (elmo-get-hash-val (format "#%d" entity-id
)
266 (or hashtb wl-folder-entity-id-name-hashtb
))))
268 (defsubst wl-folder-set-id-name
(entity-id entity
&optional hashtb
)
269 (and (numberp entity-id
)
270 (elmo-set-hash-val (format "#%d" entity-id
)
271 entity
(or hashtb wl-folder-entity-id-name-hashtb
))))
273 (defmacro wl-folder-get-entity-id
(entity)
274 `(get-text-property 0 'wl-folder-entity-id
,entity
))
276 (defmacro wl-folder-get-entity-from-buffer
(&optional getid
)
277 `(let ((id (get-text-property (point)
278 'wl-folder-entity-id
)))
281 (wl-folder-get-folder-name-by-id id
))))
283 (defmacro wl-folder-entity-exists-p
(entity &optional hashtb
)
284 `(let ((sym (intern-soft ,entity
(or ,hashtb wl-folder-entity-hashtb
))))
285 (and sym
(boundp sym
))))
287 (defmacro wl-folder-clear-entity-info
(entity &optional hashtb
)
288 `(elmo-clear-hash-val ,entity
(or ,hashtb wl-folder-entity-hashtb
)))
290 (defmacro wl-folder-get-entity-info
(entity &optional hashtb
)
291 `(elmo-get-hash-val ,entity
(or ,hashtb wl-folder-entity-hashtb
)))
293 (defmacro wl-folder-set-entity-info
(entity value
&optional hashtb
)
294 `(let* ((hashtb (or ,hashtb wl-folder-entity-hashtb
))
295 (info (wl-folder-get-entity-info ,entity hashtb
)))
296 (elmo-set-hash-val (elmo-string ,entity
)
297 (if (< (length ,value
) 4)
298 (append ,value
(list (nth 3 info
)))
302 (defun wl-folder-persistent-p (folder)
303 (or (and (wl-folder-search-entity-by-name folder wl-folder-entity
307 (let ((li wl-save-folder-list
))
309 (if (string-match (car li
) folder
)
311 (setq li
(cdr li
)))))
313 (let ((li wl-no-save-folder-list
))
315 (if (string-match (car li
) folder
)
317 (setq li
(cdr li
))))))))
319 ;;; ELMO folder structure with cache.
320 (defmacro wl-folder-elmo-folder-cache-get
(name &optional hashtb
)
321 "Returns a elmo folder structure associated with NAME from HASHTB.
322 Default HASHTB is `wl-folder-elmo-folder-hashtb'."
323 `(elmo-get-hash-val ,name
324 (or ,hashtb wl-folder-elmo-folder-hashtb
)))
326 (defmacro wl-folder-elmo-folder-cache-put
(name folder
&optional hashtb
)
327 "Get folder elmo folder structure on HASHTB for folder with NAME.
328 Default HASHTB is `wl-folder-elmo-folder-hashtb'."
329 `(elmo-set-hash-val ,name
,folder
330 (or ,hashtb wl-folder-elmo-folder-hashtb
)))
332 (defun wl-draft-get-folder ()
333 "A function to obtain `opened' draft elmo folder structure."
334 (if (and wl-draft-folder-internal
335 (string= (elmo-folder-name-internal wl-draft-folder-internal
)
337 wl-draft-folder-internal
338 (setq wl-draft-folder-internal
(wl-folder-make-elmo-folder
340 (wl-folder-confirm-existence wl-draft-folder-internal
)
341 (elmo-folder-open wl-draft-folder-internal
'load-msgdb
)
342 wl-draft-folder-internal
))
344 (defun wl-folder-mime-charset (folder-name)
345 (or (wl-get-assoc-list-value wl-folder-mime-charset-alist folder-name
)
348 (defun wl-folder-make-elmo-folder (folder-name)
349 (elmo-make-folder folder-name nil
(wl-folder-mime-charset folder-name
)))
351 (defsubst wl-folder-get-elmo-folder
(entity &optional no-cache
)
352 "Get elmo folder structure from ENTITY."
353 (let ((name (elmo-string entity
)))
355 (wl-folder-make-elmo-folder name
)
356 (if (string= name wl-draft-folder
)
357 (wl-draft-get-folder)
358 (or (wl-folder-elmo-folder-cache-get name
)
359 (let ((folder (wl-folder-make-elmo-folder name
)))
360 (wl-folder-elmo-folder-cache-put name folder
)
363 (defsubst wl-folder-put-folder-property
(beg end id is-group
&optional object
)
364 (put-text-property beg end
'wl-folder-entity-id id object
)
365 (put-text-property beg end
'wl-folder-is-group is-group object
))
367 (defun wl-folder-prev-entity ()
371 (defun wl-folder-next-entity ()
375 (defun wl-folder-prev-entity-skip-invalid (&optional hereto
)
376 "Move to previous entity. skip unsubscribed or removed entity."
380 (if (re-search-backward wl-folder-entity-regexp nil t
)
382 (goto-char (point-min))))
384 (defun wl-folder-next-entity-skip-invalid (&optional hereto
)
385 "Move to next entity. skip unsubscribed or removed entity."
390 (if (re-search-forward wl-folder-entity-regexp nil t
)
392 (goto-char (point-max))))
394 (defun wl-folder-search-group-entity-by-name (name entity
)
395 (wl-folder-search-entity-by-name name entity
'group
))
397 (defun wl-folder-search-entity-by-name (name entity
&optional type
)
398 (let ((entities (list entity
))
402 (setq entity
(wl-pop entities
))
405 (if (and (not (eq type
'folder
))
406 (string= name
(car entity
)))
407 (throw 'done entity
))
409 (wl-push entities entity-stack
))
410 (setq entities
(nth 2 entity
)))
411 ((and (not (eq type
'group
))
413 (if (string= name entity
)
414 (throw 'done entity
))))
416 (setq entities
(wl-pop entity-stack
)))))))
418 (defun wl-folder-search-entity-list-by-name (name entity
&optional get-id
)
419 (let ((entities (list entity
))
420 entity-stack ret-val
)
422 (setq entity
(wl-pop entities
))
426 (wl-push entities entity-stack
))
427 (setq entities
(nth 2 entity
)))
429 (if (string= name entity
)
430 (wl-append ret-val
(if get-id
431 (list (wl-folder-get-entity-id entity
))
434 (setq entities
(wl-pop entity-stack
))))
437 (defun wl-folder-get-prev-folder (id &optional unread
)
438 (let ((name (if (stringp id
)
440 (wl-folder-get-folder-name-by-id id
)))
441 entity entity-stack last-entity finfo
442 (entities (list wl-folder-entity
)))
445 (setq entity
(wl-pop entities
))
448 ;; (if (and (string= name (car entity))
449 ;; (eq id (wl-folder-get-entity-id (car entity))))
450 ;; (throw 'done last-entity))
452 (wl-push entities entity-stack
))
453 (setq entities
(nth 2 entity
)))
455 (if (and (string= name entity
)
456 (eq id
(wl-folder-get-entity-id entity
)))
457 (throw 'done last-entity
))
459 (and (setq finfo
(wl-folder-get-entity-info entity
))
460 (and (nth 0 finfo
)(nth 1 finfo
))
461 (> (+ (nth 0 finfo
)(nth 1 finfo
)) 0)))
462 (setq last-entity entity
))))
464 (setq entities
(wl-pop entity-stack
)))))))
466 (defun wl-folder-get-next-folder (id &optional unread
)
467 (let ((name (if (stringp id
)
469 (wl-folder-get-folder-name-by-id id
)))
470 entity entity-stack found finfo
471 (entities (list wl-folder-entity
)))
474 (setq entity
(wl-pop entities
))
477 ;;; (if (and (string= name (car entity))
478 ;;; (eq id (wl-folder-get-entity-id (car entity))))
481 (wl-push entities entity-stack
))
482 (setq entities
(nth 2 entity
)))
485 (when (or (not unread
)
486 (and (setq finfo
(wl-folder-get-entity-info entity
))
487 (and (nth 0 finfo
)(nth 1 finfo
))
488 (> (+ (nth 0 finfo
)(nth 1 finfo
)) 0)))
489 (throw 'done entity
))
490 (if (and (string= name entity
)
491 (eq id
(wl-folder-get-entity-id entity
)))
494 (setq entities
(wl-pop entity-stack
)))))))
496 (defun wl-folder-flush-queue ()
499 (let ((cur-buf (current-buffer))
500 (wl-auto-select-first nil
)
503 (if elmo-enable-disconnected-operation
504 (elmo-dop-queue-flush))
505 (if (not (elmo-folder-list-messages
506 (wl-folder-get-elmo-folder wl-queue-folder
)))
507 (message "No sending queue exists.")
508 (if wl-stay-folder-window
509 (wl-folder-select-buffer
510 (wl-summary-get-buffer-create wl-queue-folder
)))
511 (wl-summary-goto-folder-subr wl-queue-folder
'force-update nil
)
513 (wl-draft-queue-flush)
514 (if (get-buffer-window cur-buf
)
515 (select-window (get-buffer-window cur-buf
)))
517 (if wl-stay-folder-window
518 (wl-folder-toggle-disp-summary 'off wl-queue-folder
)
519 (switch-to-buffer cur-buf
))))))
521 (defun wl-folder-set-persistent-mark (folder number flag
)
522 "Set a persistent mark which corresponds to the specified flag on message."
523 (let ((buffer (wl-summary-get-buffer folder
)))
525 (with-current-buffer buffer
526 (wl-summary-set-persistent-mark flag number
))
527 ;; Parent buffer does not exist.
528 (let ((elmo-folder (wl-folder-get-elmo-folder folder
)))
529 (elmo-folder-open elmo-folder
'load-msgdb
)
530 (elmo-folder-set-flag elmo-folder
(list wl-draft-parent-number
) flag
)
531 (elmo-folder-close elmo-folder
)))))
533 (defun wl-folder-empty-trash ()
536 (let ((cur-buf (current-buffer))
537 (wl-auto-select-first nil
)
539 (wl-summary-goto-folder-subr wl-trash-folder
'force-update
)
540 (setq trash-buf
(wl-summary-get-buffer-create wl-trash-folder
))
541 (if wl-stay-folder-window
542 (wl-folder-select-buffer trash-buf
)
543 (switch-to-buffer trash-buf
))
545 (setq emptied
(wl-summary-delete-all-msgs))
547 (setq wl-thread-entities nil
548 wl-thread-entity-list nil
)
549 (if wl-summary-cache-use
(wl-summary-save-view-cache))
550 (elmo-folder-commit wl-summary-buffer-elmo-folder
))
551 (if (get-buffer-window cur-buf
)
552 (select-window (get-buffer-window cur-buf
)))
555 (wl-folder-set-folder-updated wl-trash-folder
'(0 0 0)))
556 (if wl-stay-folder-window
557 (wl-folder-toggle-disp-summary 'off wl-trash-folder
)
558 (switch-to-buffer cur-buf
))
560 (kill-buffer trash-buf
)))))
562 (defun wl-folder-goto-top-of-current-folder (&optional arg
)
563 "Move backward to the top of the current folder group.
564 Optional argument ARG is repeart count."
566 (if (re-search-backward
567 "^ *\\[[\\+-]\\]" nil t
(if arg
(prefix-numeric-value arg
)))
569 (goto-char (point-min))))
571 (defun wl-folder-goto-bottom-of-current-folder (indent)
572 "Move forward to the bottom of the current folder group."
577 (if (looking-at "^ *")
578 (buffer-substring (match-beginning 0)(1- (match-end 0)))
582 (while (re-search-forward "^ *" nil t
)
583 (if (<= (length (match-string 0))
587 (goto-char (point-max))))
589 (defun wl-folder-update-group (entity diffs
&optional is-group
)
591 (let ((path (wl-folder-get-path
593 (wl-folder-get-entity-id entity
)
596 ;; delete itself from path
597 (setq path
(delete (nth (- (length path
) 1) path
) path
)))
598 (goto-char (point-min))
601 ;; goto the path line.
602 (if (or (eq (car path
) 0) ; update desktop
603 (wl-folder-buffer-search-group
604 (wl-folder-get-petname
605 (if (stringp (car path
))
607 (wl-folder-get-folder-name-by-id
610 (wl-folder-update-diff-line diffs
)
612 (setq path
(cdr path
)))))))
614 (defun wl-folder-maybe-load-folder-list (entity)
615 (when (null (caddr entity
))
617 (elmo-msgdb-flist-load (car entity
)))
621 (wl-folder-entity-assign-id entity
622 wl-folder-entity-id-name-hashtb
624 (setq diffs
(wl-fldmgr-add-entity-hashtb (list entity
)))
625 (unless (equal diffs
'(0 0 0))
626 (wl-folder-update-group (car entity
) diffs t
)))))))
628 (defsubst wl-folder-force-fetch-p
(entity)
630 ((consp wl-force-fetch-folders
)
631 (wl-string-match-member entity wl-force-fetch-folders
))
633 wl-force-fetch-folders
)))
635 (defun wl-folder-jump-to-current-entity-with-arg ()
637 (wl-folder-jump-to-current-entity t
))
639 (defun wl-folder-jump-to-current-entity (&optional arg
)
640 "Enter the current folder. If optional ARG exists, update folder list."
642 (let ((fld-name (wl-folder-get-entity-from-buffer))
643 entity beg end indent opened err
)
647 (if (and (wl-folder-buffer-group-p)
648 (looking-at wl-folder-group-regexp
))
651 (setq indent
(wl-match-buffer 1))
652 (setq opened
(wl-match-buffer 2))
653 (if (string= opened
"+")
655 (setq entity
(wl-folder-search-group-entity-by-name
660 (wl-folder-update-recursive-current-entity entity
)
662 (setcdr (assoc (car entity
) wl-folder-group-alist
) t
)
663 (if (eq 'access
(cadr entity
))
664 (wl-folder-maybe-load-folder-list entity
))
665 ;(condition-case errobj
667 (if (or (wl-folder-force-fetch-p (car entity
))
669 (eq 'access
(cadr entity
))
670 (null (caddr entity
))))
671 (wl-folder-update-newest indent entity
)
672 (wl-folder-insert-entity indent entity
))
673 (wl-highlight-folder-path wl-folder-buffer-cur-path
))
676 ; (setcdr (assoc fld-name wl-folder-group-alist) nil))
678 ; (elmo-display-error errobj t)
681 ; (setcdr (assoc fld-name wl-folder-group-alist) nil)))
683 (let ((buffer-read-only nil
))
684 (delete-region (save-excursion (beginning-of-line)
686 (save-excursion (end-of-line)
692 (progn (wl-folder-goto-bottom-of-current-folder indent
)
695 (setq entity
(wl-folder-search-group-entity-by-name
698 (let ((buffer-read-only nil
))
699 (delete-region beg end
))
700 (setcdr (assoc (car entity
) wl-folder-group-alist
) nil
)
701 (wl-folder-insert-entity indent entity
) ; insert entity
703 (wl-highlight-folder-path wl-folder-buffer-cur-path
)
704 ; (wl-delete-all-overlays)
705 ; (wl-highlight-folder-current-line)
708 (wl-folder-set-current-entity-id
709 (get-text-property (point) 'wl-folder-entity-id
))
710 (setq fld-name
(wl-folder-get-folder-name-by-id
711 wl-folder-buffer-cur-entity-id
))
712 (let ((summary-buf (wl-summary-get-buffer-create fld-name arg
))
714 (if (or wl-stay-folder-window wl-summary-use-frame
)
715 (wl-folder-select-buffer summary-buf
)
717 (get-buffer-window summary-buf
))
719 (wl-summary-goto-folder-subr fld-name
720 (wl-summary-get-sync-range
721 (wl-folder-get-elmo-folder fld-name
))
723 (set-buffer-modified-p nil
))
725 (defun wl-folder-close-entity (entity)
726 (let ((entities (list entity
))
729 (setq entity
(wl-pop entities
))
732 (setcdr (assoc (car entity
) wl-folder-group-alist
) nil
)
734 (wl-push entities entity-stack
))
735 (setq entities
(nth 2 entity
))))
737 (setq entities
(wl-pop entity-stack
))))))
739 (defun wl-folder-update-recursive-current-entity (&optional entity
)
742 (when (and (wl-folder-buffer-group-p)
743 (looking-at wl-folder-group-regexp
))
745 ((string= (wl-match-buffer 2) "+")
749 (wl-folder-search-group-entity-by-name
750 (wl-folder-get-entity-from-buffer)
752 (let ((inhibit-read-only t
)
753 (entities (list entity
))
754 entity-stack err indent
)
755 (while (and entities
(not err
))
756 (setq entity
(wl-pop entities
))
759 (wl-folder-close-entity entity
)
760 (setcdr (assoc (car entity
) wl-folder-group-alist
) t
)
761 (unless (wl-folder-buffer-search-group
762 (wl-folder-get-petname (car entity
)))
763 (error "%s: not found group" (car entity
)))
764 (setq indent
(wl-match-buffer 1))
765 (if (eq 'access
(cadr entity
))
766 (wl-folder-maybe-load-folder-list entity
))
770 (condition-case errobj
771 (wl-folder-update-newest indent entity
)
774 (setcdr (assoc (car entity
) wl-folder-group-alist
) nil
))
776 (elmo-display-error errobj t
)
779 (setcdr (assoc (car entity
) wl-folder-group-alist
) nil
)))
781 (delete-region (save-excursion (beginning-of-line)
783 (save-excursion (end-of-line)
787 (wl-push entities entity-stack
))
788 (setq entities
(nth 2 entity
))))
790 (setq entities
(wl-pop entity-stack
)))))
791 (set-buffer-modified-p nil
)))
793 (wl-folder-jump-to-current-entity)))))
795 (defun wl-folder-no-auto-check-folder-p (folder)
798 (let ((li wl-auto-check-folder-list
))
800 (if (string-match (car li
) folder
)
802 (setq li
(cdr li
)))))
805 (let ((li wl-auto-uncheck-folder-list
))
807 (if (string-match (car li
) folder
)
808 (throw 'found t
)) ; no check!
809 (setq li
(cdr li
))))))))
811 (defsubst wl-folder-add-folder-info
(pre-value value
)
813 (+ (or (nth 0 pre-value
) 0) (or (nth 0 value
) 0))
814 (+ (or (nth 1 pre-value
) 0) (or (nth 1 value
) 0))
815 (+ (or (nth 2 pre-value
) 0) (or (nth 2 value
) 0))))
817 (defun wl-folder-check-entity (entity &optional auto
)
818 "Check unsync message number."
819 (let ((start-pos (point))
821 (run-hooks 'wl-folder-check-entity-pre-hook
)
822 (if (and (consp entity
) ;; group entity
823 wl-folder-check-async
) ;; very fast
824 (setq ret-val
(wl-folder-check-entity-async entity auto
))
828 (let ((flist (if auto
830 'wl-folder-no-auto-check-folder-p
833 (wl-folder-check-entity-pre-hook nil
)
834 (wl-folder-check-entity-hook nil
)
838 (wl-folder-add-folder-info
840 (wl-folder-check-entity (car flist
))))
841 (setq flist
(cdr flist
)))
842 ;(wl-folder-buffer-search-entity (car entity))
843 ;(wl-folder-update-line ret-val)
846 (message "Checking \"%s\"" entity
)
847 (setq ret-val
(wl-folder-check-one-entity
849 (goto-char start-pos
)
852 (message "Uncheck(unplugged) \"%s\"" entity
)))))
854 (message "Checking \"%s\" is done"
855 (if (consp entity
) (car entity
) entity
)))
856 (run-hooks 'wl-folder-check-entity-hook
)
859 (defun wl-folder-check-one-entity (entity &optional biff
)
860 (let* ((folder (wl-folder-get-elmo-folder entity biff
))
861 (nums (condition-case err
863 (if biff
(elmo-folder-set-biff-internal folder t
))
864 (if (wl-string-match-member entity wl-strict-diff-folders
)
865 (elmo-strict-folder-diff folder
)
866 (elmo-folder-diff folder
)))
868 (signal (car err
) (cdr err
)))
870 ;; maybe not exist folder.
871 (if (not (elmo-folder-exists-p folder
))
872 (wl-folder-create-subr folder
)
873 (signal (car err
) (cdr err
))))))
874 (new (elmo-diff-new nums
))
875 (unread (elmo-diff-unread nums
))
876 (all (elmo-diff-all nums
)))
877 (if (and (eq wl-folder-notify-deleted
'sync
)
878 (or (and new
(> 0 new
))
879 (and unread
(> 0 unread
))
880 (and all
(> 0 all
))))
882 (wl-folder-sync-entity entity
)
883 (setq nums
(elmo-folder-diff folder
)
884 new
(elmo-diff-new nums
)
885 unread
(elmo-diff-unread nums
)
886 all
(elmo-diff-all nums
)))
887 (unless wl-folder-notify-deleted
888 (setq new
(and new
(max 0 new
))
889 unread
(and unread
(max 0 unread
))
890 all
(and all
(max 0 all
))))
891 (setq unread
(if unread
892 (- unread
(or new
0))
893 (or (elmo-folder-get-info-unread folder
)
894 (cdr (assq 'unread
(elmo-folder-count-flags folder
)))
896 (wl-folder-entity-hashtb-set wl-folder-entity-hashtb entity
897 (list new unread all
)
898 (get-buffer wl-folder-buffer-name
)))
899 (setq wl-folder-info-alist-modified t
)
901 (list new unread all
)))
903 (defun wl-folder-check-entity-async (entity &optional auto
)
904 (let ((elmo-nntp-groups-async t
)
907 'wl-folder-no-auto-check-folder-p
908 (wl-folder-get-entity-list entity
))
909 (wl-folder-get-entity-list entity
)))
910 (nntp-connection-keys nil
)
911 name folder folder-list
917 (setq folder
(wl-folder-get-elmo-folder (car elist
)))
918 (if (not (elmo-folder-plugged-p folder
))
919 (message "Uncheck \"%s\"" (car elist
))
921 (elmo-folder-get-primitive-list folder
))
922 (cond ((elmo-folder-contains-type folder
'nntp
)
923 (wl-append async-folder-list
(list folder
))
925 (when (eq (elmo-folder-type-internal (car folder-list
))
929 (elmo-net-folder-server-internal
931 (setq server
(elmo-net-folder-server-internal
933 (message "Checking on \"%s\"" server
))
934 (setq nntp-connection-keys
935 (elmo-nntp-get-folders-info-prepare
937 nntp-connection-keys
)))
938 (setq folder-list
(cdr folder-list
))))
940 (wl-append sync-folder-list
(list folder
)))))
941 (setq elist
(cdr elist
)))
942 ;; check local entity at first
943 (while (setq folder
(pop sync-folder-list
))
944 (if (not (elmo-folder-plugged-p folder
))
945 (message "Uncheck \"%s\"" (elmo-folder-name-internal folder
))
946 (message "Checking \"%s\"" (elmo-folder-name-internal folder
))
948 (wl-folder-add-folder-info
950 (wl-folder-check-one-entity (elmo-folder-name-internal
954 ;; check network entity at last
955 (when async-folder-list
956 (elmo-nntp-get-folders-info nntp-connection-keys
)
957 (while (setq folder
(pop async-folder-list
))
958 (if (not (elmo-folder-plugged-p folder
))
959 (message "Uncheck \"%s\"" (elmo-folder-name-internal folder
))
960 (message "Checking \"%s\"" (elmo-folder-name-internal folder
))
962 (wl-folder-add-folder-info
964 (wl-folder-check-one-entity (elmo-folder-name-internal
971 (defun wl-folder-resume-entity-hashtb-by-finfo (entity-hashtb info-alist
)
972 "Resume unread info for entity alist."
975 (setq info
(nth 1 (car info-alist
)))
976 (wl-folder-set-entity-info (caar info-alist
)
977 (list (nth 2 info
)(nth 3 info
)(nth 1 info
))
979 (setq info-alist
(cdr info-alist
)))))
981 (defun wl-folder-move-path (path)
982 (let ((fp (if (consp path
)
985 (wl-folder-get-path wl-folder-entity path
))))
986 (goto-char (point-min))
989 (when (equal (car fp
)
990 (wl-folder-get-entity-from-buffer t
))
992 (setq wl-folder-buffer-cur-point
(point)))
994 (and wl-folder-buffer-cur-point
995 (goto-char wl-folder-buffer-cur-point
))))
997 (defun wl-folder-set-current-entity-id (entity-id)
998 (let* ((buf (get-buffer wl-folder-buffer-name
))
999 (buf-win (get-buffer-window buf
)))
1001 (save-current-buffer
1002 (save-selected-window
1004 (select-window buf-win
)
1006 (when (and wl-folder-buffer-cur-entity-id
1007 (not (eq wl-folder-buffer-cur-entity-id entity-id
)))
1008 (setq wl-folder-buffer-last-visited-entity-id wl-folder-buffer-cur-entity-id
))
1009 (setq wl-folder-buffer-cur-entity-id entity-id
)
1010 (setq wl-folder-buffer-cur-path
1011 (wl-folder-get-path wl-folder-entity entity-id
))
1012 (wl-highlight-folder-path wl-folder-buffer-cur-path
)
1013 (and wl-folder-move-cur-folder
1014 wl-folder-buffer-cur-point
1015 (goto-char wl-folder-buffer-cur-point
)))))))
1017 (defun wl-folder-check-current-entity ()
1018 "Check folder at position.
1019 If current line is group folder, check all sub entries."
1021 (let* ((entity-name (wl-folder-get-entity-from-buffer))
1022 (group (wl-folder-buffer-group-p))
1023 (desktop (string= entity-name wl-folder-desktop-name
)))
1025 (wl-folder-check-entity
1027 (wl-folder-search-group-entity-by-name entity-name
1032 (defun wl-folder-sync-entity (entity &optional unread-only
)
1033 "Synchronize the msgdb of ENTITY."
1036 (let ((flist (nth 2 entity
)))
1038 (wl-folder-sync-entity (car flist
) unread-only
)
1039 (setq flist
(cdr flist
)))))
1041 (let* ((folder (wl-folder-get-elmo-folder entity
))
1042 (nums (wl-folder-get-entity-info entity
))
1043 (new (or (car nums
) 0))
1044 (unread (or (cadr nums
) 0)))
1045 (when (or (not unread-only
)
1046 (or (> new
0) (> unread
0)))
1047 (let ((summary (wl-summary-get-buffer entity
))
1048 (range (wl-summary-get-sync-range folder
)))
1050 (save-selected-window
1051 (with-current-buffer summary
1052 (let ((win (get-buffer-window summary t
)))
1054 (select-window win
)))
1055 (wl-summary-sync 'unset-cursor range
)
1056 (wl-summary-save-status)))
1057 (elmo-folder-open folder
'load-msgdb
)
1060 (elmo-folder-synchronize folder nil
(eq range
'all
))
1061 (wl-folder-set-folder-updated
1065 (or (cdr (assq 'unread
(elmo-folder-count-flags folder
)))
1067 (elmo-folder-length folder
))))
1068 (elmo-folder-close folder
)))))))))
1070 (defun wl-folder-sync-current-entity (&optional unread-only
)
1071 "Synchronize the folder at position.
1072 If current line is group folder, check all subfolders."
1075 (let ((entity-name (wl-folder-get-entity-from-buffer))
1076 (group (wl-folder-buffer-group-p)))
1077 (when (and entity-name
1078 (y-or-n-p (format "Sync %s? " entity-name
)))
1079 (wl-folder-sync-entity
1081 (wl-folder-search-group-entity-by-name entity-name
1085 (message "Syncing %s is done!" entity-name
)))))
1087 (defun wl-folder-mark-as-read-all-entity (entity)
1088 "Mark as read all messages in the ENTITY."
1091 (let ((flist (nth 2 entity
)))
1093 (wl-folder-mark-as-read-all-entity (car flist
))
1094 (setq flist
(cdr flist
)))))
1096 (let* ((folder (wl-folder-get-elmo-folder entity
))
1097 (nums (wl-folder-get-entity-info entity
))
1098 (new (or (car nums
) 0))
1099 (unread (or (cadr nums
) 0)))
1100 (when (or (> new
0) (> unread
0))
1101 (let ((summary (wl-summary-get-buffer entity
))
1102 (range (wl-summary-get-sync-range folder
)))
1104 (save-selected-window
1105 (with-current-buffer summary
1106 (let ((win (get-buffer-window summary t
)))
1108 (select-window win
)))
1109 (wl-summary-sync 'unset-cursor range
)
1110 (wl-summary-mark-as-read-all)
1111 (wl-summary-save-status)))
1112 (elmo-folder-open folder
'load-msgdb
)
1115 (elmo-folder-synchronize folder nil
(eq range
'all
))
1116 (elmo-folder-unset-flag
1118 (elmo-folder-list-flagged folder
'unread
'in-msgdb
)
1120 (wl-folder-set-folder-updated
1122 (list 0 0 (elmo-folder-length folder
))))
1123 (elmo-folder-close folder
)))))))))
1125 (defun wl-folder-mark-as-read-all-current-entity ()
1126 "Mark as read all messages in the folder at position.
1127 If current line is group folder, all subfolders are marked."
1130 (let ((entity-name (wl-folder-get-entity-from-buffer))
1131 (group (wl-folder-buffer-group-p))
1133 (when (and entity-name
1134 (y-or-n-p (format "Mark all messages in %s as read? "
1136 (wl-folder-mark-as-read-all-entity
1138 (wl-folder-search-group-entity-by-name entity-name
1141 (message "All messages in %s are marked!" entity-name
)))))
1143 (defun wl-folder-check-region (beg end
)
1152 (let ((inhibit-read-only t
)
1154 (while (< (point) end
)
1155 ;; normal folder entity
1156 (if (looking-at "^[\t ]*\\([^\\[]+\\):\\(.*\\)\n")
1158 (setq entity
(wl-folder-get-entity-from-buffer))
1159 (if (not (elmo-folder-plugged-p (wl-folder-get-elmo-folder
1161 (message "Uncheck %s" entity
)
1162 (message "Checking %s" entity
)
1163 (wl-folder-check-one-entity entity
)
1168 (defun wl-folder-sync-region (beg end
)
1177 (while (< (point) end
)
1178 ;; normal folder entity
1179 (if (looking-at "^[\t ]*\\([^\\[]+\\):\\(.*\\)\n")
1181 (let ((inhibit-read-only t
)
1183 (setq entity
(wl-folder-get-entity-from-buffer))
1184 (wl-folder-sync-entity entity
)
1185 (message "Syncing %s is done!" entity
)
1190 (defun wl-folder-mark-as-read-all-region (beg end
)
1199 (while (< (point) end
)
1200 ;; normal folder entity
1201 (if (looking-at "^[\t ]*\\([^\\[]+\\):\\(.*\\)\n")
1203 (let ((inhibit-read-only t
)
1205 (setq entity
(wl-folder-get-entity-from-buffer))
1206 (wl-folder-mark-as-read-all-entity entity
)
1207 (message "All messages in %s are marked!" entity
)
1212 (defsubst wl-create-access-init-load-p
(folder)
1213 (let ((no-load-regexp (when (and
1214 (not wl-folder-init-load-access-folders
)
1215 wl-folder-init-no-load-access-folders
)
1216 (mapconcat 'identity
1217 wl-folder-init-no-load-access-folders
1219 (load-regexp (and wl-folder-init-load-access-folders
1220 (mapconcat 'identity
1221 wl-folder-init-load-access-folders
1223 (cond (load-regexp (string-match load-regexp folder
))
1224 (t (not (and no-load-regexp
1225 (string-match no-load-regexp folder
)))))))
1227 (defun wl-create-access-folder-entity (name)
1229 (when (wl-create-access-init-load-p name
)
1230 (setq flists
(elmo-msgdb-flist-load name
)) ; load flist.
1231 (setq flist
(car flists
))
1233 (when (consp (car flist
))
1234 (setcdr (cdar flist
)
1235 (wl-create-access-folder-entity (caar flist
))))
1236 (setq flist
(cdr flist
)))
1239 (defun wl-create-folder-entity-from-buffer ()
1240 "Create folder entity recursively."
1242 ((looking-at "^[ \t]*$") ; blank line
1243 (goto-char (+ 1(match-end 0)))
1245 ((looking-at "^#.*$") ; comment
1246 (goto-char (+ 1 (match-end 0)))
1248 ((looking-at "^[\t ]*\\(.+\\)[\t ]*{[\t ]*$") ; group definition
1249 (let (name entity flist
)
1250 (setq name
(wl-match-buffer 1))
1251 (goto-char (+ 1 (match-end 0)))
1252 (while (setq entity
(wl-create-folder-entity-from-buffer))
1253 (unless (eq entity
'ignore
)
1254 (wl-append flist
(list entity
))))
1255 (if (looking-at "^[\t ]*}[\t ]*$") ; end of group
1257 (goto-char (+ 1 (match-end 0)))
1258 (if (wl-string-assoc name wl-folder-petname-alist
)
1259 (error "%s already defined as petname" name
))
1260 (list name
'group flist
))
1261 (error "Syntax error in folder definition"))))
1262 ((looking-at "^[\t ]*\\([^\t \n]+\\)[\t ]*/$") ; access it!
1264 (setq name
(wl-match-buffer 1))
1265 (goto-char (+ 1 (match-end 0)))
1266 ; (condition-case ()
1268 ; (setq flist (elmo-list-folders name)))
1269 ; (error (message "Access to folder %s failed." name)))
1270 ;; (setq flist (elmo-msgdb-flist-load name)) ; load flist.
1271 ;; (setq unsublist (nth 1 flist))
1272 ;; (setq flist (car flist))
1273 ;; (list name 'access flist unsublist)))
1274 (append (list name
'access
) (wl-create-access-folder-entity name
))))
1275 ;((looking-at "^[\t ]*\\([^\t \n}]+\\)[\t ]*\\(\"[^\"]*\"\\)?[\t ]*$") ; normal folder entity
1276 ((looking-at "^[\t ]*=[ \t]+\\([^\n]+\\)$"); petname definition
1277 (goto-char (+ 1 (match-end 0)))
1278 (let ((rest (elmo-match-buffer 1))
1280 (when (string-match "\\(\"[^\"]*\"\\)[\t ]*$" rest
)
1281 (setq petname
(elmo-delete-char ?
\" (elmo-match-string 1 rest
)))
1282 (setq rest
(substring rest
0 (match-beginning 0))))
1283 (when (string-match "^[\t ]*\\(.*[^\t ]+\\)[\t ]+$" rest
)
1284 (wl-folder-append-petname (elmo-match-string 1 rest
)
1287 ((looking-at "^[ \t]*}[ \t]*$") ; end of group
1289 ((looking-at "^.*$") ; normal folder entity
1290 (goto-char (+ 1 (match-end 0)))
1291 (let ((rest (elmo-match-buffer 0))
1293 (if (string-match "\\(\"[^\"]*\"\\)[\t ]*$" rest
)
1295 (setq petname
(elmo-delete-char ?
\" (elmo-match-string 1 rest
)))
1296 (setq rest
(substring rest
0 (match-beginning 0)))
1297 (when (string-match "^[\t ]*\\(.*[^\t ]+\\)[\t ]+$" rest
)
1298 (wl-folder-append-petname
1299 (setq realname
(elmo-match-string 1 rest
))
1302 (if (string-match "^[\t ]*\\(.+\\)$" rest
)
1303 (elmo-match-string 1 rest
)
1306 (defun wl-folder-create-folder-entity ()
1307 "Create folder entries."
1308 (let ((tmp-buf (get-buffer-create " *wl-folder-tmp*"))
1312 (with-current-buffer tmp-buf
1314 (insert-file-contents wl-folders-file
)
1315 (goto-char (point-min))
1316 (while (and (not (eobp))
1317 (setq entity
(wl-create-folder-entity-from-buffer)))
1318 (unless (eq entity
'ignore
)
1319 (wl-append ret-val
(list entity
)))))
1320 (kill-buffer tmp-buf
))
1322 (setq ret-val
(list wl-folder-desktop-name
'group ret-val
))))
1324 (defun wl-folder-entity-assign-id (entity &optional hashtb on-noid
)
1325 (let ((hashtb (or hashtb
1326 (setq wl-folder-entity-id-name-hashtb
1327 (elmo-make-hash wl-folder-entity-id
))))
1328 (entities (list entity
))
1331 (setq entity
(wl-pop entities
))
1334 (when (not (and on-noid
1335 (get-text-property 0
1336 'wl-folder-entity-id
1338 (wl-folder-put-folder-property
1339 0 (length (car entity
))
1343 (wl-folder-set-id-name wl-folder-entity-id
1344 (car entity
) hashtb
)
1345 (setq wl-folder-entity-id
(+ 1 wl-folder-entity-id
)))
1347 (wl-push entities entity-stack
))
1348 (setq entities
(nth 2 entity
)))
1350 (when (not (and on-noid
1351 (get-text-property 0
1352 'wl-folder-entity-id
1354 (wl-folder-put-folder-property
1359 (wl-folder-set-id-name wl-folder-entity-id
1361 (setq wl-folder-entity-id
(+ 1 wl-folder-entity-id
)))))
1363 (setq entities
(wl-pop entity-stack
))))))
1365 (defun wl-folder-click (e)
1370 (wl-folder-jump-to-current-entity)))
1372 (defun wl-folder-select-buffer (buffer)
1373 (let ((gbw (get-buffer-window buffer
))
1376 (progn (select-window gbw
)
1378 (unless wl-summary-use-frame
1381 (split-window-horizontally wl-folder-window-width
)
1385 (if wl-summary-use-frame
1386 (switch-to-buffer-other-frame buffer
)
1387 (switch-to-buffer buffer
))
1390 (defun wl-folder-toggle-disp-summary (&optional arg folder
)
1392 (if (or (and folder
(assoc folder wl-folder-group-alist
))
1393 (and (interactive-p) (wl-folder-buffer-group-p)))
1394 (error "This command is not available on Group"))
1396 (let (wl-auto-select-first
1397 (wl-stay-folder-window t
))
1400 (setq wl-folder-buffer-disp-summary t
))
1402 (setq wl-folder-buffer-disp-summary nil
)
1403 ;; hide wl-summary window.
1404 (let ((cur-buf (current-buffer))
1405 (summary-buffer (wl-summary-get-buffer folder
)))
1406 (when summary-buffer
1407 (wl-folder-select-buffer summary-buffer
)
1409 (select-window (get-buffer-window cur-buf
))))
1411 (setq wl-folder-buffer-disp-summary
1412 (not wl-folder-buffer-disp-summary
))
1413 (let ((cur-buf (current-buffer))
1415 (when (looking-at "^[ ]*\\([^\\[].+\\):.*\n")
1416 (setq folder-name
(wl-folder-get-entity-from-buffer))
1417 (if wl-folder-buffer-disp-summary
1419 (wl-folder-select-buffer
1420 (wl-summary-get-buffer-create folder-name
))
1422 (wl-summary-goto-folder-subr folder-name
'no-sync nil
)
1423 (select-window (get-buffer-window cur-buf
))))
1424 (let ((summary-buffer (wl-summary-get-buffer folder-name
)))
1425 (when summary-buffer
1426 (wl-folder-select-buffer summary-buffer
)
1428 (select-window (get-buffer-window cur-buf
))))))))))
1430 (defun wl-folder-prev-unsync ()
1431 "Move cursor to the previous unsync folder."
1434 (setq start-point
(point))
1436 (if (re-search-backward wl-folder-unsync-regexp nil t
)
1438 (goto-char start-point
)
1439 (message "No more unsync folder"))))
1441 (defun wl-folder-next-unsync (&optional plugged
)
1442 "Move cursor to the next unsync."
1444 (let (start-point entity
)
1445 (setq start-point
(point))
1448 (while (re-search-forward wl-folder-unsync-regexp nil t
)
1449 (if (or (wl-folder-buffer-group-p)
1452 (wl-folder-get-entity-from-buffer))
1453 (elmo-folder-plugged-p entity
))
1456 (goto-char start-point
)
1457 (message "No more unsync folder"))))
1459 (defun wl-folder-prev-unread (&optional group
)
1460 "Move cursor to the previous unread folder."
1463 (setq start-point
(point))
1465 (if (re-search-backward (wl-folder-unread-regex group
) nil t
)
1468 (wl-folder-get-entity-from-buffer))
1469 (goto-char start-point
)
1470 (message "No more unread folder")
1473 (defun wl-folder-next-unread (&optional group
)
1474 "Move cursor to the next unread folder."
1477 (setq start-point
(point))
1479 (if (re-search-forward (wl-folder-unread-regex group
) nil t
)
1482 (wl-folder-get-entity-from-buffer))
1483 (goto-char start-point
)
1484 (message "No more unread folder")
1487 (defun wl-folder-mode ()
1488 "Major mode for Wanderlust Folder.
1489 See Info under Wanderlust for full documentation.
1492 \\{wl-folder-mode-map}
1494 Entering Folder mode calls the value of `wl-folder-mode-hook'."
1496 (setq major-mode
'wl-folder-mode
)
1497 (setq mode-name
"Folder")
1498 (use-local-map wl-folder-mode-map
)
1499 (setq buffer-read-only t
)
1500 (setq inhibit-read-only nil
)
1501 (setq truncate-lines t
)
1502 (setq wl-folder-buffer-cur-entity-id nil
1503 wl-folder-buffer-cur-path nil
1504 wl-folder-buffer-cur-point nil
)
1505 (wl-mode-line-buffer-identification)
1506 (easy-menu-add wl-folder-mode-menu
)
1507 ;; This hook may contain the functions `wl-folder-init-icons' and
1508 ;; `wl-setup-folder' for reasons of system internal to accord
1509 ;; facilities for the Emacs variants.
1510 (run-hooks 'wl-folder-mode-hook
))
1512 (defun wl-folder-append-petname (realname petname
)
1513 (let ((pentry (wl-string-assoc realname wl-folder-petname-alist
)))
1515 (setq wl-folder-petname-alist
1516 (delete pentry wl-folder-petname-alist
))))
1517 (wl-append wl-folder-petname-alist
1518 (list (cons realname petname
))))
1521 (let (initialize folder-buf
)
1522 (if (setq folder-buf
(get-buffer wl-folder-buffer-name
))
1523 (if wl-folder-use-frame
1525 (save-selected-window
1526 (dolist (frame (visible-frame-list))
1527 (select-frame frame
)
1528 (if (get-buffer-window folder-buf
)
1529 (setq select-frame frame
))))
1531 (select-frame select-frame
)
1532 (switch-to-buffer folder-buf
)))
1533 (switch-to-buffer folder-buf
))
1534 (if wl-folder-use-frame
1536 (switch-to-buffer-other-frame
1537 (get-buffer-create wl-folder-buffer-name
))
1538 (let ((frame (selected-frame)))
1539 (setq wl-delete-startup-frame-function
1541 (setq wl-delete-startup-frame-function nil
)
1542 (let ((frame ,frame
))
1543 (if (eq (selected-frame) frame
)
1544 (delete-frame frame
)))))))
1545 (switch-to-buffer (get-buffer-create wl-folder-buffer-name
)))
1546 (set-buffer wl-folder-buffer-name
)
1549 (unless wl-folder-entity
1551 (setq wl-folder-entity-id
0)
1552 (wl-folder-entity-assign-id wl-folder-entity
)
1553 (setq wl-folder-entity-hashtb
1554 (wl-folder-create-entity-hashtb wl-folder-entity
))
1555 (setq wl-folder-elmo-folder-hashtb
(elmo-make-hash wl-folder-entity-id
))
1556 (setq wl-folder-group-alist
1557 (wl-folder-create-group-alist wl-folder-entity
))
1558 (setq wl-folder-newsgroups-hashtb
1559 (wl-folder-create-newsgroups-hashtb wl-folder-entity
))
1560 (wl-folder-init-info-hashtb)
1561 (let ((inhibit-read-only t
)
1562 (buffer-read-only nil
))
1564 (setcdr (assoc (car wl-folder-entity
) wl-folder-group-alist
) t
)
1566 (wl-folder-insert-entity " " wl-folder-entity
)))
1568 (set-buffer-modified-p nil
)
1569 (setq initialize t
))
1572 (defun wl-folder-auto-check ()
1573 "Check and update folders in `wl-auto-check-folder-name'."
1575 (when (get-buffer wl-folder-buffer-name
)
1576 (switch-to-buffer wl-folder-buffer-name
)
1578 ((eq wl-auto-check-folder-name
'none
))
1579 ((or (consp wl-auto-check-folder-name
)
1580 (stringp wl-auto-check-folder-name
))
1581 (let ((folder-list (if (consp wl-auto-check-folder-name
)
1582 wl-auto-check-folder-name
1583 (list wl-auto-check-folder-name
)))
1586 (if (setq entity
(wl-folder-search-entity-by-name
1589 (wl-folder-check-entity entity
'auto
))
1590 (setq folder-list
(cdr folder-list
)))))
1592 (wl-folder-check-entity wl-folder-entity
'auto
)))))
1594 (defun wl-folder-set-folder-updated (name value
)
1596 (let ((buf (get-buffer wl-folder-buffer-name
)))
1598 (wl-folder-entity-hashtb-set
1599 wl-folder-entity-hashtb name value buf
))
1600 (setq wl-folder-info-alist-modified t
))))
1602 (defun wl-folder-calc-finfo (entity)
1603 ;; calcurate finfo without inserting.
1604 (let ((entities (list entity
))
1606 new unread all nums
)
1608 (setq entity
(wl-pop entities
))
1612 (wl-push entities entity-stack
))
1613 (setq entities
(nth 2 entity
)))
1615 (setq nums
(wl-folder-get-entity-info entity
))
1616 (setq new
(+ (or new
0) (or (nth 0 nums
) 0)))
1617 (setq unread
(+ (or unread
0)
1618 (or (and (nth 0 nums
)(nth 1 nums
)
1619 (+ (nth 0 nums
)(nth 1 nums
))) 0)))
1620 (setq all
(+ (or all
0) (or (nth 2 nums
) 0)))))
1622 (setq entities
(wl-pop entity-stack
))))
1623 (list new unread all
)))
1625 (defsubst wl-folder-make-save-access-list
(list)
1626 (mapcar '(lambda (x)
1629 (list (elmo-string (car x
)) 'access
))
1634 (defun wl-folder-update-newest (indent entity
)
1635 (let (ret-val new unread all
)
1638 (let ((inhibit-read-only t
)
1639 (buffer-read-only nil
)
1640 (flist (nth 2 entity
))
1641 (as-opened (cdr (assoc (car entity
) wl-folder-group-alist
)))
1646 (let (update-flist flist-unsub new-flist removed group-name-end
)
1647 (when (and (eq (cadr entity
) 'access
)
1648 (elmo-folder-plugged-p
1649 (wl-folder-get-elmo-folder (car entity
))))
1650 (message "Fetching folder entries...")
1651 (when (setq new-flist
1652 (elmo-folder-list-subfolders
1653 (wl-folder-get-elmo-folder (car entity
))
1654 (wl-string-match-member
1656 wl-folder-hierarchy-access-folders
)))
1658 (wl-folder-update-access-group entity new-flist
))
1659 (setq flist
(nth 1 update-flist
))
1660 (when (car update-flist
) ;; diff
1661 (setq flist-unsub
(nth 2 update-flist
))
1662 (setq removed
(nth 3 update-flist
))
1663 (elmo-msgdb-flist-save
1666 (wl-folder-make-save-access-list flist
)
1667 (wl-folder-make-save-access-list flist-unsub
)))
1668 (wl-folder-entity-assign-id
1670 wl-folder-entity-id-name-hashtb
1672 (setq wl-folder-entity-hashtb
1673 (wl-folder-create-entity-hashtb
1675 wl-folder-entity-hashtb
1677 (setq wl-folder-newsgroups-hashtb
1679 (wl-folder-create-newsgroups-hashtb
1681 wl-folder-newsgroups-hashtb
))))
1682 (message "Fetching folder entries...done"))
1683 (wl-folder-insert-entity indent entity
))))))))
1685 (defun wl-folder-insert-entity (indent entity
&optional onlygroup
)
1686 (let (ret-val new unread all
)
1689 (let ((inhibit-read-only t
)
1690 (buffer-read-only nil
)
1691 (flist (nth 2 entity
))
1692 (as-opened (cdr (assoc (car entity
) wl-folder-group-alist
)))
1695 ;;; (insert indent "[" (if as-opened "-" "+") "]" (car entity) "\n")
1696 ;;; (save-excursion (forward-line -1)
1697 ;;; (wl-highlight-folder-current-line))
1701 (let (update-flist flist-unsub new-flist removed group-name-end
)
1702 ;;; (when (and (eq (cadr entity) 'access)
1704 ;;; (message "fetching folder entries...")
1705 ;;; (when (setq new-flist
1706 ;;; (elmo-list-folders
1707 ;;; (elmo-string (car entity))
1708 ;;; (wl-string-member
1710 ;;; wl-folder-hierarchy-access-folders)
1712 ;;; (setq update-flist
1713 ;;; (wl-folder-update-access-group entity new-flist))
1714 ;;; (setq flist (nth 1 update-flist))
1715 ;;; (when (car update-flist) ;; diff
1716 ;;; (setq flist-unsub (nth 2 update-flist))
1717 ;;; (setq removed (nth 3 update-flist))
1718 ;;; (elmo-msgdb-flist-save
1721 ;;; (wl-folder-make-save-access-list flist)
1722 ;;; (wl-folder-make-save-access-list flist-unsub)))
1724 ;;; ;; reconstruct wl-folder-entity-id-name-hashtb and
1725 ;;; ;; wl-folder-entity-hashtb
1727 ;;; (wl-folder-entity-assign-id
1729 ;;; wl-folder-entity-id-name-hashtb
1731 ;;; (setq wl-folder-entity-hashtb
1732 ;;; (wl-folder-create-entity-hashtb
1734 ;;; wl-folder-entity-hashtb
1736 ;;; (setq wl-folder-newsgroups-hashtb
1738 ;;; (wl-folder-create-newsgroups-hashtb
1740 ;;; wl-folder-newsgroups-hashtb))))
1741 ;;; (message "fetching folder entries...done"))
1742 (insert indent
"[" (if as-opened
"-" "+") "]"
1743 (if (eq (cadr entity
) 'access
)
1744 (wl-folder-get-petname (car entity
))
1746 (setq group-name-end
(point))
1748 (wl-folder-put-folder-property
1750 (get-text-property 0 'wl-folder-entity-id
(car entity
))
1756 wl-folder-removed-mark
1757 (if (listp (car removed
))
1758 (concat "[+]" (caar removed
))
1761 (save-excursion (forward-line -
1)
1762 (wl-highlight-folder-current-line))
1763 (setq removed
(cdr removed
)))
1764 (remove-text-properties beg
(point) '(wl-folder-entity-id)))
1765 (elmo-with-progress-display
1766 (wl-folder-insert-entity (length flist
))
1767 (format "Inserting group %s" (car entity
))
1770 (wl-folder-insert-entity
1771 (concat indent
" ") (car flist
)))
1772 (setq new
(+ (or new
0) (or (nth 0 ret-val
) 0)))
1773 (setq unread
(+ (or unread
0) (or (nth 1 ret-val
) 0)))
1774 (setq all
(+ (or all
0) (or (nth 2 ret-val
) 0)))
1775 (elmo-progress-notify 'wl-folder-insert-entity
)
1776 (setq flist
(cdr flist
))))
1778 (goto-char group-name-end
)
1779 (delete-region (point) (save-excursion (end-of-line)
1781 (insert (format ":%d/%d/%d" (or new
0)
1782 (or unread
0) (or all
0)))
1783 (setq ret-val
(list new unread all
))
1784 (wl-highlight-folder-current-line ret-val
)))
1785 (setq ret-val
(wl-folder-calc-finfo entity
))
1786 (insert indent
"[" (if as-opened
"-" "+") "]"
1787 (if (eq (cadr entity
) 'access
)
1788 (wl-folder-get-petname (car entity
))
1791 (or (nth 0 ret-val
) 0)
1792 (or (nth 1 ret-val
) 0)
1793 (or (nth 2 ret-val
) 0))
1795 (wl-folder-put-folder-property
1797 (get-text-property 0 'wl-folder-entity-id
(car entity
))
1799 (save-excursion (forward-line -
1)
1800 (wl-highlight-folder-current-line ret-val
)))))
1802 (let* ((inhibit-read-only t
)
1803 (buffer-read-only nil
)
1804 (nums (wl-folder-get-entity-info entity
))
1807 (insert indent
(wl-folder-get-petname entity
)
1808 (format ":%s/%s/%s\n"
1809 (or (setq new
(nth 0 nums
)) "*")
1810 (or (setq unread
(and (nth 0 nums
)(nth 1 nums
)
1811 (+ (nth 0 nums
)(nth 1 nums
))))
1813 (or (setq all
(nth 2 nums
)) "*")))
1814 (wl-folder-put-folder-property
1816 (get-text-property 0 'wl-folder-entity-id entity
)
1818 (save-excursion (forward-line -
1)
1819 (wl-highlight-folder-current-line nums
))
1820 (setq ret-val
(list new unread all
)))))
1821 (set-buffer-modified-p nil
)
1824 (defun wl-folder-check-all ()
1826 (wl-folder-check-entity wl-folder-entity
))
1828 (defun wl-folder-entity-hashtb-set (entity-hashtb name value buffer
)
1829 (let ((cur-val (wl-folder-get-entity-info name entity-hashtb
))
1834 (setq new-diff
(- (or (nth 0 value
) 0) (or (nth 0 cur-val
) 0)))
1837 (- (or (nth 1 value
) 0) (or (nth 1 cur-val
) 0))))
1838 (setq all-diff
(- (or (nth 2 value
) 0) (or (nth 2 cur-val
) 0)))
1839 (setq diffs
(list new-diff unread-diff all-diff
))
1840 (unless (and (nth 0 cur-val
)
1841 (equal diffs
'(0 0 0)))
1842 (wl-folder-set-entity-info name value entity-hashtb
)
1844 (with-current-buffer buffer
1846 (let ((entity-list (wl-folder-search-entity-list-by-name
1847 name wl-folder-entity
)))
1849 (wl-folder-update-group (car entity-list
) diffs
)
1850 (setq entity-list
(cdr entity-list
))))
1851 (goto-char (point-min))
1852 (while (wl-folder-buffer-search-entity name
)
1853 (wl-folder-update-line value
))))))))
1855 (defun wl-folder-update-unread (folder unread
)
1856 (let ((buf (get-buffer wl-folder-buffer-name
))
1857 (value (wl-folder-get-entity-info folder
))
1861 ;;; Update folder-info
1862 ;;; (elmo-folder-set-info-hashtb fld nil nil nil unread)
1863 (setq cur-unread
(or (nth 1 value
) 0))
1864 (setq unread-diff
(- (or unread
0) cur-unread
))
1865 (setq newvalue
(list (nth 0 value
)
1868 (wl-folder-set-entity-info folder newvalue
)
1869 (setq wl-folder-info-alist-modified t
)
1871 (not (eq unread-diff
0)))
1873 (with-current-buffer buf
1875 (let ((entity-list (wl-folder-search-entity-list-by-name
1876 folder wl-folder-entity
)))
1878 (wl-folder-update-group (car entity-list
) (list 0
1881 (setq entity-list
(cdr entity-list
))))
1882 (goto-char (point-min))
1883 (while (wl-folder-buffer-search-entity folder
)
1884 (wl-folder-update-line newvalue
))))))))
1886 (defun wl-folder-create-entity-hashtb (entity &optional hashtb reconst
)
1887 (let ((hashtb (or hashtb
(elmo-make-hash wl-folder-entity-id
)))
1888 (entities (list entity
))
1891 (setq entity
(wl-pop entities
))
1895 (wl-push entities entity-stack
))
1896 (setq entities
(nth 2 entity
)))
1898 (when (not (and reconst
1899 (wl-folder-get-entity-info entity
)))
1900 (wl-folder-set-entity-info entity
1904 (setq entities
(wl-pop entity-stack
))))
1907 ;; Unsync number is reserved.
1908 ;;(defun wl-folder-reconstruct-entity-hashtb (entity &optional hashtb id-name)
1909 ;; (let* ((hashtb (or hashtb (elmo-make-hash wl-folder-entity-id)))
1910 ;; (entities (list entity))
1913 ;; (setq entity (wl-pop entities))
1917 ;; (wl-folder-set-id-name (wl-folder-get-entity-id (car entity))
1920 ;; (wl-push entities entity-stack))
1921 ;; (setq entities (nth 2 entity))
1923 ;; ((stringp entity)
1924 ;; (wl-folder-set-entity-info entity
1925 ;; (wl-folder-get-entity-info entity)
1928 ;; (wl-folder-set-id-name (wl-folder-get-entity-id entity)
1931 ;; (setq entities (wl-pop entity-stack))))
1934 (defun wl-folder-create-newsgroups-from-nntp-access (entity)
1935 (let ((flist (nth 2 entity
))
1940 ((consp (car flist
))
1941 (wl-folder-create-newsgroups-from-nntp-access (car flist
)))
1944 (elmo-nntp-folder-group-internal
1945 (wl-folder-get-elmo-folder (car flist
)))))))
1946 (setq flist
(cdr flist
)))
1949 (defun wl-folder-create-newsgroups-hashtb (entity &optional is-list info
)
1950 "Create NNTP group hashtable for ENTITY."
1951 (let ((entities (if is-list entity
(list entity
)))
1952 entity-stack folder-list newsgroups newsgroup make-hashtb
)
1953 (and info
(message "Creating newsgroups..."))
1955 (setq entity
(wl-pop entities
))
1958 (if (eq (nth 1 entity
) 'access
)
1959 (when (eq (elmo-folder-type-internal
1960 (elmo-make-folder (car entity
))) 'nntp
)
1961 (wl-append newsgroups
1962 (wl-folder-create-newsgroups-from-nntp-access entity
))
1963 (setq make-hashtb t
))
1965 (wl-push entities entity-stack
))
1966 (setq entities
(nth 2 entity
))))
1968 (setq folder-list
(elmo-folder-get-primitive-list
1969 (elmo-make-folder entity
)))
1971 (when (and (eq (elmo-folder-type-internal (car folder-list
))
1973 (setq newsgroup
(elmo-nntp-folder-group-internal
1974 (car folder-list
))))
1975 (wl-append newsgroups
(list (elmo-string newsgroup
))))
1976 (setq folder-list
(cdr folder-list
)))))
1978 (setq entities
(wl-pop entity-stack
))))
1979 (and info
(message "Creating newsgroups...done"))
1980 (if (or newsgroups make-hashtb
)
1981 (elmo-setup-subscribed-newsgroups newsgroups
))))
1983 (defun wl-folder-get-path (entity target-id
&optional string
)
1984 (let ((entities (list entity
))
1985 entity-stack result-path
)
1989 (setq entity
(wl-pop entities
))
1992 (if (and (or (not string
) (string= string
(car entity
)))
1993 (eq target-id
(wl-folder-get-entity-id (car entity
))))
1995 (wl-push target-id result-path
))
1996 (wl-push (wl-folder-get-entity-id (car entity
)) result-path
))
1997 (wl-push entities entity-stack
)
1998 (setq entities
(nth 2 entity
)))
2000 (if (and (or (not string
) (string= string entity
))
2001 (eq target-id
(wl-folder-get-entity-id entity
)))
2003 (wl-push target-id result-path
)))))
2005 (while (and entity-stack
2007 (setq result-path
(cdr result-path
))
2008 (setq entities
(wl-pop entity-stack
)))))))))
2010 (defun wl-folder-create-group-alist (entity)
2012 (let ((flist (nth 2 entity
))
2013 (cur-alist (list (cons (car entity
) nil
)))
2016 (if (consp (car flist
))
2017 (wl-append append-alist
2018 (wl-folder-create-group-alist (car flist
))))
2019 (setq flist
(cdr flist
)))
2020 (append cur-alist append-alist
))))
2022 (defun wl-folder-init-info-hashtb ()
2023 (let ((info-alist (and wl-folder-info-save
2024 (elmo-msgdb-finfo-load))))
2025 (elmo-folder-info-make-hashtb
2027 wl-folder-entity-hashtb
)))
2028 ;;; (wl-folder-resume-entity-hashtb-by-finfo
2029 ;;; wl-folder-entity-hashtb
2032 (defun wl-folder-cleanup-variables ()
2033 (setq wl-folder-entity nil
2034 wl-folder-entity-hashtb nil
2035 wl-folder-entity-id-name-hashtb nil
2036 wl-folder-group-alist nil
2037 wl-folder-petname-alist nil
2038 wl-folder-newsgroups-hashtb nil
2039 wl-fldmgr-cut-entity-list nil
2040 wl-fldmgr-modified nil
2041 wl-fldmgr-modified-access-list nil
2045 (defun wl-make-plugged-alist ()
2046 (let ((entity-list (wl-folder-get-entity-list wl-folder-entity
))
2047 (add (not wl-reset-plugged-alist
)))
2049 (elmo-folder-set-plugged
2050 (wl-folder-get-elmo-folder (car entity-list
)) wl-plugged add
)
2051 (setq entity-list
(cdr entity-list
)))
2052 ;; smtp posting server
2053 (when wl-smtp-posting-server
2054 (elmo-set-plugged wl-plugged
2055 wl-smtp-posting-server
; server
2056 (or wl-smtp-posting-port
2057 (and (boundp 'smtp-service
) smtp-service
)
2059 wl-smtp-connection-type
2060 nil nil
"smtp" add
))
2061 ;; nntp posting server
2062 (when wl-nntp-posting-server
2063 (elmo-set-plugged wl-plugged
2064 wl-nntp-posting-server
2065 wl-nntp-posting-port
2066 wl-nntp-posting-stream-type
2067 nil nil
"nntp" add
))
2068 (run-hooks 'wl-make-plugged-hook
)))
2070 (defvar wl-folder-init-function
'wl-local-folder-init
)
2072 (defun wl-folder-init ()
2073 "Return top-level folder entity."
2077 (funcall wl-folder-init-function
))
2078 (run-hooks 'wl-folder-init-hook
))
2080 (defun wl-local-folder-init ()
2081 "Initialize local folder."
2082 (message "Initializing folder...")
2083 (setq wl-folder-entity
(wl-folder-create-folder-entity))
2084 (message "Initializing folder...done"))
2086 (defun wl-folder-get-realname (petname)
2090 wl-folder-petname-alist
))
2093 (defun wl-folder-get-petname (name)
2097 wl-folder-petname-alist
))
2100 (defun wl-folder-get-entity-with-petname ()
2101 (let ((alist wl-folder-petname-alist
)
2102 (hashtb (copy-sequence wl-folder-entity-hashtb
)))
2104 (wl-folder-set-entity-info (cdar alist
) nil hashtb
)
2105 (setq alist
(cdr alist
)))
2108 (defun wl-folder-get-newsgroups (folder)
2109 "Return Newsgroups field value string for FOLDER newsgroup.
2110 If FOLDER is multi, return comma separated string (cross post)."
2111 (let ((nlist (elmo-folder-newsgroups
2112 (wl-folder-get-elmo-folder folder
))))
2114 (list nil nil
(mapconcat 'identity nlist
","))
2117 (defun wl-folder-guess-mailing-list-by-refile-rule (entity)
2118 "Return ML address guess by ENTITY.
2119 Use `wl-subscribed-mailing-list' and `wl-refile-rule-alist'."
2121 (elmo-folder-get-primitive-list
2122 (wl-folder-get-elmo-folder entity
)))
2124 (while (setq fld
(car flist
))
2125 (setq mladdr
(wl-folder-guess-mailing-list-by-refile-rule-subr
2126 (elmo-folder-name-internal fld
)))
2128 (setq to
(if (stringp to
)
2129 (concat to
", " mladdr
)
2131 (setq flist
(cdr flist
)))
2136 (defun wl-folder-guess-mailing-list-by-refile-rule-subr (entity)
2137 (unless (memq (elmo-folder-type entity
)
2139 (let ((rules wl-refile-rule-alist
)
2142 (if (or (and (stringp (car (car rules
)))
2143 (string-match "[Tt]o" (car (car rules
))))
2144 (and (listp (car (car rules
)))
2145 (elmo-string-matched-member "to" (car (car rules
))
2147 (setq toalist
(append toalist
(cdr (car rules
)))))
2148 (setq rules
(cdr rules
)))
2149 (setq tokey
(car (rassoc entity toalist
)))
2150 ;;; (setq histkey (car (rassoc folder wl-refile-alist)))
2151 ;; case-ignore search `wl-subscribed-mailing-list'
2153 (elmo-string-matched-member tokey wl-subscribed-mailing-list t
)))))
2155 (defun wl-folder-guess-mailing-list-by-folder-name (entity)
2156 "Return ML address guess by ENTITY name's last hierarchy.
2157 Use `wl-subscribed-mailing-list'."
2159 (elmo-folder-get-primitive-list
2160 (wl-folder-get-elmo-folder entity
)))
2162 (while (setq fld
(car flist
))
2163 (setq mladdr
(wl-folder-guess-mailing-list-by-folder-name-subr
2164 (elmo-folder-name-internal fld
)))
2166 (setq to
(if (stringp to
)
2167 (concat to
", " mladdr
)
2169 (setq flist
(cdr flist
)))
2174 (defun wl-folder-guess-mailing-list-by-folder-name-subr (entity)
2175 (when (memq (elmo-folder-type entity
)
2176 '(localdir imap4 maildir
))
2177 (let (key foldername
)
2178 ;; Get foldername and Remove folder type symbol.
2179 (setq foldername
(substring entity
1))
2180 (if (string-match "@" foldername
)
2181 (setq foldername
(substring foldername
0 (match-beginning 0))))
2182 (when (string-match "[^\\./]+$" foldername
)
2183 (setq key
(regexp-quote
2184 (concat (substring foldername
(match-beginning 0)) "@")))
2185 (elmo-string-matched-member
2186 key wl-subscribed-mailing-list
'case-ignore
)))))
2188 (defun wl-folder-update-diff-line (diffs)
2189 (let ((inhibit-read-only t
)
2190 (buffer-read-only nil
)
2192 cur-unread new-unread
2197 (setq id
(get-text-property (point) 'wl-folder-entity-id
))
2198 (setq is-group
(get-text-property (point) 'wl-folder-is-group
))
2199 (when (looking-at "^[ ]*\\(.*\\):\\([0-9\\*-]*\\)/\\([0-9\\*-]*\\)/\\([0-9\\*]*\\)")
2200 ;;(looking-at "^[ ]*\\([^\\[].+\\):\\([0-9\\*-]*/[0-9\\*-]*/[0-9\\*]*\\)")
2201 (setq cur-new
(string-to-number
2202 (wl-match-buffer 2)))
2203 (setq cur-unread
(string-to-number
2204 (wl-match-buffer 3)))
2205 (setq cur-all
(string-to-number
2206 (wl-match-buffer 4)))
2207 (delete-region (match-beginning 2)
2209 (goto-char (match-beginning 2))
2210 (insert (format "%s/%s/%s"
2211 (setq new-new
(+ cur-new
(nth 0 diffs
)))
2212 (setq new-unread
(+ cur-unread
(nth 1 diffs
)))
2213 (setq new-all
(+ cur-all
(nth 2 diffs
)))))
2214 (wl-folder-put-folder-property (match-beginning 2) (point) id is-group
)
2215 (if wl-use-highlight-mouse-line
2216 (put-text-property (match-beginning 2) (point)
2217 'mouse-face
'highlight
))
2218 (wl-highlight-folder-group-line (list new-new new-unread new-all
))
2219 (setq buffer-read-only t
)
2220 (set-buffer-modified-p nil
)))))
2222 (defun wl-folder-update-line (nums &optional is-group
)
2223 (let ((inhibit-read-only t
)
2224 (buffer-read-only nil
)
2228 (setq id
(get-text-property (point) 'wl-folder-entity-id
))
2229 (setq is-group
(get-text-property (point) 'wl-folder-is-group
))
2230 (if (looking-at "^[ ]*\\(.*\\):\\([0-9\\*-]*/[0-9\\*-]*/[0-9\\*]*\\)")
2231 ;;; (looking-at "^[ ]*\\([^\\[].+\\):\\([0-9\\*-]*/[0-9\\*-]*/[0-9\\*]*\\)")
2233 (delete-region (match-beginning 2)
2235 (goto-char (match-beginning 2))
2236 (insert (format "%s/%s/%s"
2237 (or (nth 0 nums
) "*")
2238 (or (and (nth 0 nums
)(nth 1 nums
)
2239 (+ (nth 0 nums
)(nth 1 nums
)))
2241 (or (nth 2 nums
) "*")))
2242 (wl-folder-put-folder-property (match-beginning 2) (point) id is-group
)
2244 ;; update only colors
2245 (wl-highlight-folder-group-line nums
)
2246 (wl-highlight-folder-current-line nums
))
2248 (set-buffer-modified-p nil
))))))
2250 (defun wl-folder-goto-folder (&optional arg
)
2251 "Visit some folder."
2253 (wl-folder-goto-folder-subr nil arg
))
2255 (defun wl-folder-goto-folder-sticky ()
2256 "Visit some folder and make it sticky."
2258 (wl-folder-goto-folder-subr nil t
))
2260 (defun wl-folder-goto-draft-folder (&optional arg
)
2261 "Visit draft folder."
2263 (wl-folder-goto-folder-subr wl-draft-folder arg
))
2265 (defun wl-folder-revisit-last-visited-folder (&optional arg
)
2266 "Revisit last visited folder."
2269 (wl-folder-get-folder-name-by-id wl-folder-buffer-last-visited-entity-id
)))
2271 (y-or-n-p (format "Revisit %s? " folder
)))
2272 (wl-folder-goto-folder-subr folder arg
))))
2274 (defun wl-folder-goto-folder-subr (&optional folder sticky
)
2276 (let (summary-buf fld-name entity id error-selecting
)
2277 ;;; (setq fld-name (wl-folder-get-entity-from-buffer))
2278 ;;; (if (or (null fld-name)
2279 ;;; (assoc fld-name wl-folder-group-alist))
2280 (setq fld-name wl-default-folder
)
2281 (setq fld-name
(or folder
2283 (wl-summary-read-folder fld-name
))))
2284 (if (and (setq entity
2285 (wl-folder-search-entity-by-name fld-name
2288 (setq id
(wl-folder-get-entity-id entity
)))
2289 (wl-folder-set-current-entity-id id
))
2290 (setq summary-buf
(wl-summary-get-buffer-create fld-name sticky
))
2291 (if (or wl-stay-folder-window wl-summary-use-frame
)
2292 (wl-folder-select-buffer summary-buf
)
2293 (if (and summary-buf
2294 (get-buffer-window summary-buf
))
2296 (wl-summary-goto-folder-subr fld-name
2297 (wl-summary-get-sync-range
2298 (wl-folder-get-elmo-folder fld-name
))
2301 (defun wl-folder-suspend ()
2303 (run-hooks 'wl-folder-suspend-hook
)
2304 (wl-folder-info-save)
2305 (elmo-crosspost-message-alist-save)
2307 ;(if (fboundp 'mmelmo-cleanup-entity-buffers)
2308 ;(mmelmo-cleanup-entity-buffers))
2309 (bury-buffer wl-folder-buffer-name
)
2310 (dolist (summary-buf (wl-collect-summary))
2311 (bury-buffer summary-buf
))
2312 (dolist (draft-buf (wl-collect-draft))
2313 (bury-buffer draft-buf
))
2314 (delete-windows-on wl-folder-buffer-name t
))
2316 (defun wl-folder-info-save ()
2317 (when (and wl-folder-info-save
2318 wl-folder-info-alist-modified
)
2319 (let ((entities (list wl-folder-entity
))
2320 entity entity-stack info-alist info
)
2322 (setq entity
(wl-pop entities
))
2326 (wl-push entities entity-stack
))
2327 (setq entities
(nth 2 entity
)))
2329 (when (and (setq info
(elmo-folder-get-info
2330 (wl-folder-get-elmo-folder entity
)))
2331 (not (equal info
'(nil))))
2333 (wl-append info-alist
(list (list (elmo-string entity
)
2334 (list (nth 3 info
) ;; max
2335 (nth 2 info
) ;; length
2337 (nth 1 info
)) ;; unread
2340 (setq entities
(wl-pop entity-stack
))))
2341 (elmo-msgdb-finfo-save info-alist
)
2342 (setq wl-folder-info-alist-modified nil
))))
2344 (defun wl-folder-goto-first-unread-folder (&optional arg
)
2346 (let ((entities (list wl-folder-entity
))
2347 entity entity-stack ret-val
2352 (setq entity
(wl-pop entities
))
2356 (wl-push entities entity-stack
))
2357 (setq entities
(nth 2 entity
)))
2359 (if (and (setq finfo
(wl-folder-get-entity-info entity
))
2360 (and (nth 0 finfo
)(nth 1 finfo
))
2361 (> (+ (nth 0 finfo
)(nth 1 finfo
)) 0))
2362 (throw 'done entity
))
2363 (wl-append ret-val
(list entity
))))
2365 (setq entities
(wl-pop entity-stack
))))))
2369 (wl-folder-jump-folder first-entity
)
2371 (wl-folder-goto-folder-subr first-entity
))
2372 (message "No unread folder"))))
2374 (defun wl-folder-jump-folder (&optional fld-name noopen
)
2377 (setq fld-name
(wl-summary-read-folder wl-default-folder
)))
2378 (goto-char (point-min))
2380 (wl-folder-open-folder fld-name
))
2381 (and (wl-folder-buffer-search-entity fld-name
)
2382 (beginning-of-line)))
2384 (defun wl-folder-get-entity-list (entity)
2385 (let ((entities (list entity
))
2386 entity-stack ret-val
)
2388 (setq entity
(wl-pop entities
))
2392 (wl-push entities entity-stack
))
2393 (setq entities
(nth 2 entity
)))
2395 (wl-append ret-val
(list entity
))))
2397 (setq entities
(wl-pop entity-stack
))))
2400 (defun wl-folder-open-unread-folder (entity)
2402 (let ((alist (wl-folder-get-entity-list entity
))
2404 finfo path-list path id
)
2406 (when (and (setq finfo
(wl-folder-get-entity-info (car alist
)))
2407 (nth 0 finfo
) (nth 1 finfo
)
2408 (> (+ (nth 0 finfo
)(nth 1 finfo
)) 0))
2409 (setq unread
(+ unread
(+ (nth 0 finfo
)(nth 1 finfo
))))
2410 (setq id
(wl-folder-get-entity-id (car alist
)))
2411 (setq path
(delete id
(wl-folder-get-path
2415 (if (not (member path path-list
))
2416 (wl-append path-list
(list path
))))
2417 (setq alist
(cdr alist
)))
2419 (wl-folder-open-folder-sub (car path-list
))
2420 (setq path-list
(cdr path-list
)))
2421 (message "%s unread folder"
2422 (if (> unread
0) unread
"No")))))
2424 (defun wl-folder-open-unread-current-entity ()
2426 (let ((entity-name (wl-folder-get-entity-from-buffer))
2427 (group (wl-folder-buffer-group-p)))
2429 (wl-folder-open-unread-folder
2431 (wl-folder-search-group-entity-by-name entity-name
2435 (defun wl-folder-open-only-unread-folder ()
2438 (wl-folder-prev-entity-skip-invalid t
)
2439 (wl-folder-get-entity-from-buffer t
))))
2440 (wl-folder-open-all-unread-folder)
2442 (goto-char (point-max))
2443 (while (and (re-search-backward
2444 "^[ ]*\\[[-]\\].+:0/0/[0-9-]+" nil t
)
2446 (wl-folder-jump-to-current-entity) ;; close it
2448 (wl-folder-move-path id
)
2451 (defun wl-folder-open-all-unread-folder (&optional arg
)
2454 (wl-folder-prev-entity-skip-invalid t
)
2455 (wl-folder-get-entity-from-buffer t
))))
2456 (wl-folder-open-unread-folder wl-folder-entity
)
2458 (wl-folder-move-path id
)
2459 (goto-char (point-min))
2460 (wl-folder-next-unread t
))))
2462 (defun wl-folder-open-folder (&optional fld-name
)
2465 (setq fld-name
(wl-summary-read-folder wl-default-folder
)))
2466 (let ((entity (wl-folder-search-entity-by-name
2467 fld-name wl-folder-entity
'folder
)))
2469 (let* ((id (wl-folder-get-entity-id entity
))
2470 (path (and id
(wl-folder-get-path wl-folder-entity id
))))
2471 (if path
(wl-folder-open-folder-sub path
)))
2472 (message "%s: not found" fld-name
))))
2474 (defun wl-folder-open-folder-sub (path)
2475 (let ((inhibit-read-only t
)
2476 (buffer-read-only nil
)
2480 (goto-char (point-min))
2482 (wl-folder-buffer-search-group
2483 (wl-folder-get-petname
2484 (if (stringp (car path
))
2486 (wl-folder-get-folder-name-by-id
2489 (setq path
(cdr path
))
2490 (if (and (wl-folder-buffer-group-p)
2491 (looking-at wl-folder-group-regexp
)
2492 (string= "+" (wl-match-buffer 2)));; closed group
2494 (setq indent
(wl-match-buffer 1))
2495 (setq name
(wl-folder-get-entity-from-buffer))
2496 (setq entity
(wl-folder-search-group-entity-by-name
2500 (setcdr (assoc (car entity
) wl-folder-group-alist
) t
)
2501 (if (eq 'access
(cadr entity
))
2502 (wl-folder-maybe-load-folder-list entity
))
2503 (wl-folder-insert-entity indent entity
)
2504 (delete-region (save-excursion (beginning-of-line)
2506 (save-excursion (end-of-line)
2508 (set-buffer-modified-p nil
))))
2510 (defun wl-folder-open-all-pre ()
2511 (let ((entities (list wl-folder-entity
))
2512 entity entity-stack group-entry
)
2514 (setq entity
(wl-pop entities
))
2517 (unless (or (not (setq group-entry
2518 (assoc (car entity
) wl-folder-group-alist
)))
2520 (setcdr group-entry t
)
2521 (when (eq 'access
(cadr entity
))
2522 (wl-folder-maybe-load-folder-list entity
)))
2524 (wl-push entities entity-stack
))
2525 (setq entities
(nth 2 entity
))))
2527 (setq entities
(wl-pop entity-stack
))))))
2529 (defun wl-folder-open-all (&optional refresh
)
2531 (let* ((inhibit-read-only t
)
2532 (buffer-read-only nil
)
2533 (len (length wl-folder-group-alist
))
2538 (wl-folder-prev-entity-skip-invalid t
)
2539 (wl-folder-get-entity-from-buffer t
)))
2540 (alist wl-folder-group-alist
))
2542 (setcdr (pop alist
) t
))
2544 (wl-folder-insert-entity " " wl-folder-entity
)
2545 (wl-folder-move-path id
))
2546 (elmo-with-progress-display
2547 (wl-folder-open-all (length wl-folder-group-alist
))
2548 "Opening all folders"
2549 (wl-folder-open-all-pre)
2551 (goto-char (point-min))
2552 (while (re-search-forward
2553 "^\\([ ]*\\)\\[\\([+]\\)\\]\\(.+\\):[-0-9-]+/[0-9-]+/[0-9-]+$"
2555 (setq indent
(wl-match-buffer 1))
2556 (setq name
(wl-folder-get-entity-from-buffer))
2557 (setq entity
(wl-folder-search-group-entity-by-name
2561 (setcdr (assoc (car entity
) wl-folder-group-alist
) t
)
2563 (wl-folder-insert-entity indent entity
)
2564 (delete-region (save-excursion (beginning-of-line)
2566 (save-excursion (end-of-line)
2568 (elmo-progress-notify 'wl-folder-open-all
)))))
2569 (wl-highlight-folder-path wl-folder-buffer-cur-path
)
2570 (set-buffer-modified-p nil
)))
2572 (defun wl-folder-close-all ()
2574 (let ((inhibit-read-only t
)
2575 (buffer-read-only nil
)
2576 (alist wl-folder-group-alist
)
2578 (wl-folder-prev-entity-skip-invalid t
)
2579 (wl-folder-get-entity-from-buffer t
))))
2581 (setcdr (car alist
) nil
)
2582 (setq alist
(cdr alist
)))
2583 (setcdr (assoc (car wl-folder-entity
) wl-folder-group-alist
) t
)
2585 (wl-folder-insert-entity " " wl-folder-entity
)
2586 (wl-folder-move-path id
)
2587 (wl-highlight-folder-path wl-folder-buffer-cur-path
)
2589 (set-buffer-modified-p nil
)))
2591 (defun wl-folder-open-close ()
2592 "Open or close parent entity."
2594 (unless (wl-folder-get-entity-from-buffer)
2595 (error "No folder"))
2597 (if (wl-folder-buffer-group-p)
2598 ;; if group (whether opend or closed.)
2599 (wl-folder-jump-to-current-entity)
2602 (setq indent
(save-excursion
2603 (re-search-forward "\\([ ]*\\)." nil t
)
2604 (wl-match-buffer 1)))
2605 (while (looking-at indent
)
2607 (wl-folder-jump-to-current-entity)))
2609 (defsubst wl-folder-access-subscribe-p
(group folder
)
2610 (let (subscr regexp match
)
2611 (if (setq subscr
(wl-get-assoc-list-value
2612 wl-folder-access-subscribe-alist
2615 (setq regexp
(mapconcat 'identity
(cdr subscr
) "\\|"))
2616 (setq match
(string-match regexp folder
))
2622 (defun wl-folder-update-access-group (entity new-flist
)
2623 (let ((flist (nth 2 entity
))
2624 (unsubscribes (nth 3 entity
))
2625 diff new-unsubscribes removes
2626 subscribed-list folder group entry
)
2627 (elmo-with-progress-display
2628 (wl-folder-update-access-group (+ (length flist
) (length unsubscribes
)))
2629 "Updating access group"
2630 ;; check subscribed groups
2633 ((listp (car flist
)) ;; group
2634 (setq group
(elmo-string (caar flist
)))
2636 ((assoc group new-flist
) ;; found in new-flist
2637 (setq new-flist
(delete (assoc group new-flist
)
2639 (if (wl-folder-access-subscribe-p (car entity
) group
)
2640 (wl-append subscribed-list
(list (car flist
)))
2641 (wl-append new-unsubscribes
(list (car flist
)))
2644 (setq wl-folder-group-alist
2645 (delete (wl-string-assoc group wl-folder-group-alist
)
2646 wl-folder-group-alist
))
2647 (wl-append removes
(list (list group
))))))
2649 (setq folder
(elmo-string (car flist
)))
2651 ((member folder new-flist
) ;; found in new-flist
2652 (setq new-flist
(delete folder new-flist
))
2653 (if (wl-folder-access-subscribe-p (car entity
) folder
)
2654 (wl-append subscribed-list
(list (car flist
)))
2655 (wl-append new-unsubscribes
(list folder
))
2658 (wl-append removes
(list folder
))))))
2659 (elmo-progress-notify 'wl-folder-update-access-group
)
2660 (setq flist
(cdr flist
)))
2661 ;; check unsubscribed groups
2664 ((listp (car unsubscribes
))
2665 (when (setq entry
(assoc (caar unsubscribes
) new-flist
))
2666 (setq new-flist
(delete entry new-flist
))
2667 (wl-append new-unsubscribes
(list (car unsubscribes
)))))
2669 (when (member (car unsubscribes
) new-flist
)
2670 (setq new-flist
(delete (car unsubscribes
) new-flist
))
2671 (wl-append new-unsubscribes
(list (car unsubscribes
))))))
2672 (elmo-progress-notify 'wl-folder-update-access-group
)
2673 (setq unsubscribes
(cdr unsubscribes
)))
2675 (if (or new-flist removes
)
2678 (mapcar '(lambda (x)
2679 (cond ((consp x
) (list (car x
) 'access
))
2683 (let ((new-list new-flist
))
2685 (if (not (wl-folder-access-subscribe-p
2687 (if (listp (car new-list
))
2692 (wl-append new-unsubscribes
(list (car new-list
)))
2693 (setq new-flist
(delete (car new-list
) new-flist
)))
2695 ((listp (car new-list
))
2696 ;; check group exists
2697 (if (wl-string-assoc (caar new-list
) wl-folder-group-alist
)
2699 (message "%s: group already exists." (caar new-list
))
2701 (wl-append new-unsubscribes
(list (car new-list
)))
2702 (setq new-flist
(delete (car new-list
) new-flist
)))
2703 (wl-append wl-folder-group-alist
2704 (list (cons (caar new-list
) nil
)))))))
2705 (setq new-list
(cdr new-list
)))))
2707 (message "%d new folder(s)." (length new-flist
)))
2708 (wl-append new-flist subscribed-list
) ;; new is first
2709 (run-hooks 'wl-folder-update-access-group-hook
)
2710 (setcdr (cdr entity
) (list new-flist new-unsubscribes
))
2711 (list diff new-flist new-unsubscribes removes
)))
2713 (defun wl-folder-prefetch-entity (entity)
2714 "Prefetch all new messages in the ENTITY."
2717 (let ((flist (nth 2 entity
))
2722 (setq result
(wl-folder-prefetch-entity (car flist
)))
2723 (setq sum-done
(+ sum-done
(car result
)))
2724 (setq sum-all
(+ sum-all
(cdr result
)))
2725 (setq flist
(cdr flist
)))
2726 (message "Prefetched %d/%d message(s) in \"%s\"."
2728 (wl-folder-get-petname (car entity
)))
2729 (cons sum-done sum-all
)))
2731 (let* ((folder (wl-folder-get-elmo-folder entity
))
2732 (nums (wl-folder-get-entity-info entity
))
2733 (wl-summary-highlight (if (or (wl-summary-sticky-p folder
)
2734 (wl-summary-always-sticky-folder-p
2736 wl-summary-highlight
))
2737 wl-summary-exit-next-move
2738 wl-auto-select-first ret-val
2740 (setq count
(or (car nums
) 0))
2741 (setq count
(+ count
(wl-folder-count-incorporates folder
)))
2742 (if (or (null (car nums
)) ; unknown
2744 (save-window-excursion
2746 (let ((wl-summary-buffer-name
2747 (if (setq sticky
(get-buffer
2748 (wl-summary-sticky-buffer-name
2749 (elmo-folder-name-internal
2751 ;; Sticky folder exists.
2752 (wl-summary-sticky-buffer-name
2753 (elmo-folder-name-internal folder
))
2755 wl-summary-buffer-name
2756 (symbol-name this-command
))))
2757 (wl-summary-use-frame nil
)
2758 (wl-summary-always-sticky-folder-list nil
))
2759 (wl-summary-goto-folder-subr entity
2760 (wl-summary-get-sync-range
2763 (setq ret-val
(wl-summary-incorporate))
2765 (wl-summary-save-status)
2770 (defun wl-folder-count-incorporates (folder)
2772 (dolist (number (elmo-folder-list-flagged folder
'any
))
2773 (when (member (wl-summary-message-mark folder number
)
2774 wl-summary-incorporate-marks
)
2778 (defun wl-folder-prefetch-current-entity (&optional no-check
)
2779 "Prefetch all uncached messages in the folder at position.
2780 If current line is group folder, all subfolders are prefetched."
2783 (let ((entity-name (wl-folder-get-entity-from-buffer))
2784 (group (wl-folder-buffer-group-p))
2785 wl-folder-check-entity-hook
2790 (wl-folder-search-group-entity-by-name entity-name
2794 (wl-folder-check-entity entity
))
2795 (wl-folder-prefetch-entity entity
)))))
2797 ;(defun wl-folder-drop-unsync-entity (entity)
2798 ; "Drop all unsync messages in the ENTITY."
2801 ; (let ((flist (nth 2 entity)))
2803 ; (wl-folder-drop-unsync-entity (car flist))
2804 ; (setq flist (cdr flist)))))
2806 ; (let ((nums (wl-folder-get-entity-info entity))
2807 ; wl-summary-highlight wl-auto-select-first new)
2808 ; (setq new (or (car nums) 0))
2810 ; (save-window-excursion
2812 ; (let ((wl-summary-buffer-name (concat
2813 ; wl-summary-buffer-name
2814 ; (symbol-name this-command))))
2815 ; (wl-summary-goto-folder-subr entity 'no-sync nil)
2816 ; (wl-summary-drop-unsync)
2817 ; (wl-summary-exit)))))))))
2819 ;(defun wl-folder-drop-unsync-current-entity (&optional force-check)
2820 ; "Drop all unsync messages in the folder at position.
2821 ;If current line is group folder, all subfolders are dropped.
2822 ;If optional arg exists, don't check any folders."
2825 ; (let ((entity-name (wl-folder-get-entity-from-buffer))
2826 ; (group (wl-folder-buffer-group-p))
2827 ; wl-folder-check-entity-hook
2828 ; summary-buf entity)
2829 ; (when (and entity-name
2831 ; "Drop all unsync messages in %s? " entity-name)))
2834 ; (wl-folder-search-group-entity-by-name entity-name
2837 ; (if (null force-check)
2838 ; (wl-folder-check-entity entity))
2839 ; (wl-folder-drop-unsync-entity entity)
2840 ; (message "All unsync messages in %s are dropped!" entity-name)))))
2842 (defun wl-folder-write-current-folder ()
2843 "Write message to current folder's newsgroup or mailing-list.
2844 Call `wl-summary-write-current-folder' with current folder name."
2846 (unless (wl-folder-buffer-group-p)
2847 (wl-summary-write-current-folder
2848 (wl-folder-get-entity-from-buffer))))
2850 (defun wl-folder-mimic-kill-buffer ()
2851 "Kill the current (Folder) buffer with query."
2853 (let ((bufname (read-buffer (format "Kill buffer: (default %s) "
2855 wl-interactive-exit
)
2856 (if (or (not bufname
)
2857 (string-equal bufname
"")
2858 (string-equal bufname
(buffer-name)))
2860 (kill-buffer bufname
))))
2862 (defun wl-folder-create-subr (folder)
2863 (let ((name (elmo-folder-name-internal folder
)))
2864 (unless (elmo-folder-creatable-p folder
)
2865 (error "Folder %s does not exist" name
))
2866 (unless (y-or-n-p (format "Folder %s does not exist, create it? " name
))
2867 (error "Folder %s is not created" name
))
2869 (setq wl-folder-entity-hashtb
2870 (wl-folder-create-entity-hashtb name wl-folder-entity-hashtb
))
2871 (unless (elmo-folder-create folder
)
2872 (error "Create folder failed"))))
2874 (defun wl-folder-confirm-existence (folder &optional force
)
2876 (unless (elmo-folder-exists-p folder
)
2877 (wl-folder-create-subr folder
))
2878 (unless (or (wl-folder-entity-exists-p (elmo-folder-name-internal folder
))
2879 (and (elmo-folder-msgdb-path folder
)
2880 (file-exists-p (elmo-folder-msgdb-path folder
)))
2881 (elmo-folder-exists-p folder
))
2882 (wl-folder-create-subr folder
))))
2884 (defun wl-folder-virtual ()
2885 "Goto virtual folder."
2887 (let ((entity (wl-folder-get-entity-from-buffer)))
2888 (if (wl-folder-buffer-group-p)
2892 (mapconcat 'identity
2893 (wl-folder-get-entity-list
2894 (wl-folder-search-group-entity-by-name
2896 wl-folder-entity
)) ","))))
2897 (unless entity
(error "No folder"))
2898 (wl-folder-goto-folder-subr
2900 (wl-read-search-condition
2901 wl-fldmgr-make-filter-default
)
2904 (defun wl-folder-pick ()
2907 (let* ((condition (car (elmo-parse-search-condition
2908 (wl-read-search-condition
2909 wl-summary-pick-field-default
))))
2910 (entity (wl-folder-get-entity-from-buffer))
2912 (if (wl-folder-buffer-group-p)
2913 (wl-folder-get-entity-list
2914 (wl-folder-search-group-entity-by-name
2919 (while (car folder-list
)
2920 (setq ret
(elmo-folder-search
2921 (wl-folder-get-elmo-folder (car folder-list
))
2926 (list (cons (car folder-list
) ret
)))))
2927 (setq folder-list
(cdr folder-list
)))
2929 (message "%s are picked."
2930 (mapconcat '(lambda (res)
2933 (length (cdr res
))))
2936 (message "No message was picked.")))))
2938 (defun wl-folder-jump-to-next-summary ()
2940 (when (wl-collect-summary)
2941 (if (get-buffer-window (car (wl-collect-summary)))
2942 (switch-to-buffer-other-window (car (wl-collect-summary))))
2943 (wl-summary-next-buffer)))
2945 (defun wl-folder-jump-to-previous-summary ()
2947 (when (wl-collect-summary)
2948 (if (get-buffer-window (car (wl-collect-summary)))
2949 (switch-to-buffer-other-window (car (wl-collect-summary))))
2950 (wl-summary-previous-buffer)))
2954 (defvar wl-folder-complete-folder-candidate nil
)
2956 (defun wl-folder-complete-folder (string predicate flag
)
2957 (cond ((or (string-match "^\\(/[^/]*/\\)\\(.*\\)$" string
) ; filter
2958 (string-match "^\\(\*\\|\*.*,\\)\\([^,]*\\)$" string
) ; multi
2959 (string-match "^\\(|[^|]*|:?\\)\\(.*\\)$" string
) ;pipe-src
2960 (string-match "^\\(|\\)\\([^|]*\\)$" string
)) ;pipe-dst
2961 (let* ((str1 (match-string 1 string
))
2962 (str2 (match-string 2 string
))
2963 (str2-comp (wl-folder-complete-folder str2 predicate flag
)))
2965 ((listp str2-comp
) ; flag=t
2966 (mapcar (lambda (x) (concat str1 x
)) str2-comp
))
2967 ((stringp str2-comp
)
2968 (concat str1 str2-comp
))
2971 ((string-match "^\\(/\\)\\([^/]*\\)$" string
) ; filter-condition
2972 (let* ((str1 (match-string 1 string
))
2973 (str2 (match-string 2 string
))
2975 (wl-folder-complete-filter-condition str2 predicate flag
)))
2977 ((listp str2-comp
) ; flag=t
2978 (mapcar (lambda (x) (concat str1 x
)) str2-comp
))
2979 ((stringp str2-comp
)
2980 (concat str1 str2-comp
))
2985 (or wl-folder-complete-folder-candidate
2986 (if (memq 'read-folder wl-use-folder-petname
)
2987 (wl-folder-get-entity-with-petname)
2988 wl-folder-entity-hashtb
))))
2990 (try-completion string candidate
)
2991 (all-completions string candidate
))))))
2993 (defun wl-folder-complete-filter-condition (string predicate flag
)
2995 ((string-match "^\\(.*|\\|.*&\\|.*(\\)\\([^:]*\\)$" string
)
2996 (let* ((str1 (match-string 1 string
))
2997 (str2 (match-string 2 string
))
2999 (wl-folder-complete-filter-condition str2 predicate flag
)))
3001 ((listp str2-comp
) ; flag=t
3002 (mapcar (lambda (x) (concat str1 x
)) str2-comp
))
3003 ((stringp str2-comp
)
3004 (concat str1 str2-comp
))
3009 (mapcar (lambda (x) (list (concat (downcase x
) ":")))
3010 (wl-search-condition-fields))))
3012 (try-completion string candidate
)
3013 (all-completions string candidate
))))))
3016 (product-provide (provide 'wl-folder
) (require 'wl-version
))
3018 ;;; wl-folder.el ends here