1 ;;; wl-action.el --- Mark and actions in the Summary mode for Wanderlust.
3 ;; Copyright (C) 2003 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
35 (defalias-maybe 'wl-summary-target-mark 'ignore)
36 (defalias-maybe 'wl-summary-target-mark-region 'ignore))
38 (defsubst wl-summary-action-mark (action)
40 (defsubst wl-summary-action-symbol (action)
42 (defsubst wl-summary-action-argument-function (action)
44 (defsubst wl-summary-action-set-function (action)
46 (defsubst wl-summary-action-exec-function (action)
48 (defsubst wl-summary-action-face (action)
50 (defsubst wl-summary-action-docstring (action)
51 (concat (nth 6 action)
52 "\nThis function is defined by `wl-summary-define-mark-action'."))
55 (defun wl-summary-set-mark (&optional set-mark number interactive data)
57 "Set temporary mark SET-MARK on the message with NUMBER.
58 NUMBER is the message number to set the mark on.
59 INTERACTIVE is set as t if it have to run interactively.
60 DATA is passed to the set-action function of the action as an argument.
61 Return number if put mark succeed"
62 (let* ((set-mark (or set-mark
63 (completing-read "Mark: " wl-summary-mark-action-list)))
64 (current (wl-summary-message-number))
65 (action (assoc set-mark wl-summary-mark-action-list))
66 visible mark cur-mark)
67 (when (zerop (elmo-folder-length wl-summary-buffer-elmo-folder))
68 (error "Set mark failed"))
73 ;; Jump to message if cursor is not on the message.
74 (when (and (setq visible (wl-summary-message-visible-p number))
75 (not (eq number current)))
76 (wl-summary-jump-to-msg number))
79 (setq cur-mark (nth 1 (wl-summary-registered-temp-mark number)))
82 (if (wl-summary-reserve-temp-mark-p cur-mark)
84 (error "Already marked as `%s'" cur-mark))
85 (when (and interactive
87 (wl-summary-action-argument-function action))
88 (setq data (funcall (wl-summary-action-argument-function action)
89 (wl-summary-action-symbol action)
91 ;; Unset the current mark.
92 (wl-summary-unset-mark number)
94 (funcall (wl-summary-action-set-function action)
96 (wl-summary-action-mark action)
99 (wl-summary-put-temp-mark set-mark)
100 (when wl-summary-highlight
101 (wl-highlight-summary-current-line))
103 (wl-summary-print-argument number data)))
104 (set-buffer-modified-p nil)
108 (if (or interactive (interactive-p))
109 (if (eq wl-summary-move-direction-downward nil)
111 (wl-summary-next))))))
113 (defun wl-summary-register-target-mark (number mark data)
114 (or (memq number wl-summary-buffer-target-mark-list)
115 (setq wl-summary-buffer-target-mark-list
116 (cons number wl-summary-buffer-target-mark-list))))
118 (defun wl-summary-unregister-target-mark (number)
119 (setq wl-summary-buffer-target-mark-list
120 (delq number wl-summary-buffer-target-mark-list)))
122 (defun wl-summary-have-target-mark-p (number)
123 (memq number wl-summary-buffer-target-mark-list))
125 (defun wl-summary-target-mark-set-action (action)
126 (unless (eq (wl-summary-action-symbol action) 'target-mark)
128 (goto-char (point-min))
129 (let ((numlist wl-summary-buffer-number-list)
131 ;; use firstly marked message.
132 (when (wl-summary-action-argument-function action)
134 (if (memq (car numlist) wl-summary-buffer-target-mark-list)
135 (setq number (car numlist)
137 (setq numlist (cdr numlist)))
138 (wl-summary-jump-to-msg number)
139 (setq data (funcall (wl-summary-action-argument-function action)
140 (wl-summary-action-symbol action) number)))
142 (when (string= (wl-summary-temp-mark) "*")
143 (let (wl-summary-buffer-disp-msg)
144 (when (setq number (wl-summary-message-number))
145 (wl-summary-set-mark (wl-summary-action-mark action)
147 (setq wl-summary-buffer-target-mark-list
148 (delq number wl-summary-buffer-target-mark-list)))))
150 (setq mlist wl-summary-buffer-target-mark-list)
152 (wl-summary-register-temp-mark (car mlist)
153 (wl-summary-action-mark action) data)
154 (setq wl-summary-buffer-target-mark-list
155 (delq (car mlist) wl-summary-buffer-target-mark-list))
156 (setq mlist (cdr mlist)))))))
158 ;; wl-summary-buffer-temp-mark-list specification
159 ;; ((1 "D" nil)(2 "o" "+fuga")(3 "O" "+hoge"))
160 (defun wl-summary-register-temp-mark (number mark mark-info)
161 (let ((elem (assq number wl-summary-buffer-temp-mark-list)))
162 (setq wl-summary-buffer-temp-mark-list
163 (delq elem wl-summary-buffer-temp-mark-list)))
164 (setq wl-summary-buffer-temp-mark-list
165 (cons (list number mark mark-info) wl-summary-buffer-temp-mark-list)))
167 (defun wl-summary-unregister-temp-mark (number)
168 (let ((elem (assq number wl-summary-buffer-temp-mark-list)))
169 (setq wl-summary-buffer-temp-mark-list
170 (delq elem wl-summary-buffer-temp-mark-list))))
172 (defun wl-summary-registered-temp-mark (number)
173 (assq number wl-summary-buffer-temp-mark-list))
175 (defun wl-summary-collect-temp-mark (mark &optional begin end)
180 (narrow-to-region (or begin (point-min))(or end (point-max)))
181 (goto-char (point-min))
183 (if (eq wl-summary-buffer-view 'thread)
184 (let (number entity mark-info)
186 (setq number (wl-summary-message-number)
187 entity (wl-thread-get-entity number)
188 mark-info (wl-summary-registered-temp-mark number))
189 ;; toplevel message mark.
190 (when (string= (nth 1 mark-info) mark)
191 (setq mark-list (cons mark-info mark-list)))
192 ;; When thread is closed...children should also be checked.
193 (unless (wl-thread-entity-get-opened entity)
194 (dolist (msg (wl-thread-get-children-msgs number))
195 (setq mark-info (wl-summary-registered-temp-mark
197 (when (string= (nth 1 mark-info) mark)
198 (setq mark-list (cons mark-info mark-list)))))
200 (let (number mark-info)
202 (setq number (wl-summary-message-number)
203 mark-info (wl-summary-registered-temp-mark number))
204 (when (string= (nth 1 mark-info) mark)
205 (setq mark-list (cons mark-info mark-list)))
209 (dolist (mark-info wl-summary-buffer-temp-mark-list)
210 (when (string= (nth 1 mark-info) mark)
211 (setq mark-list (cons mark-info mark-list))))
215 (defun wl-summary-unset-mark (&optional number interactive)
216 "Unset temporary mark of the message with NUMBER.
217 NUMBER is the message number to unset the mark.
218 If not specified, the message on the cursor position is treated.
219 Optional INTERACTIVE is non-nil when it should be called interactively.
220 Return number if put mark succeed"
224 (let ((buffer-read-only nil)
228 (when (and (setq visible (wl-summary-message-visible-p number))
229 (not (eq number (wl-summary-message-number))))
230 (wl-summary-jump-to-msg number))
232 number (wl-summary-message-number)))
233 (setq mark (wl-summary-temp-mark))
234 ;; Remove from temporal mark structure.
235 (wl-summary-unregister-target-mark number)
236 (wl-summary-unregister-temp-mark number)
237 ;; Delete mark on buffer.
239 (unless (string= mark " ")
240 (wl-summary-put-temp-mark
241 (or (wl-summary-get-score-mark number)
243 (setq action (assoc mark wl-summary-mark-action-list))
244 (when wl-summary-highlight
245 (wl-highlight-summary-current-line))
246 (when (wl-summary-action-argument-function action)
247 (wl-summary-remove-argument)))
248 (set-buffer-modified-p nil))))
250 ;; (if (or interactive (interactive-p))
251 ;; (if (eq wl-summary-move-direction-downward nil)
253 ;; (wl-summary-next))))
256 (defun wl-summary-make-destination-numbers-list (mark-list)
257 (let (dest-numbers dest-number)
258 (dolist (elem mark-list)
259 (setq dest-number (assoc (nth 2 elem) dest-numbers))
261 (unless (memq (car elem) (cdr dest-number))
262 (nconc dest-number (list (car elem))))
263 (setq dest-numbers (nconc dest-numbers
269 (defun wl-summary-move-mark-list-messages (mark-list folder-name message)
273 (let ((start (point))
274 (refiles (mapcar 'car mark-list))
277 dst-msgs ; loop counter
280 (setq refile-len (length refiles))
281 (goto-char start) ; avoid moving cursor to
284 (when (> refile-len elmo-display-progress-threshold)
285 (elmo-progress-set 'elmo-folder-move-messages
289 (setq result (elmo-folder-move-messages
290 wl-summary-buffer-elmo-folder
292 (if (eq folder-name 'null)
294 (wl-folder-get-elmo-folder folder-name))
295 (wl-summary-buffer-msgdb)
296 (not (null (cdr dst-msgs)))
301 (when result ; succeeded.
303 (wl-summary-delete-messages-on-buffer refiles)
304 ;; update wl-summary-buffer-temp-mark-list.
305 (dolist (mark-info mark-list)
306 (setq wl-summary-buffer-temp-mark-list
307 (delq mark-info wl-summary-buffer-temp-mark-list))))
308 (elmo-progress-clear 'elmo-folder-move-messages)
309 (message (concat message "done"))
310 (wl-summary-set-message-modified)
311 ;; Return the operation failed message numbers.
314 (length refiles))))))
316 (defun wl-summary-get-refile-destination-subr (action number learn)
317 (let* ((number (or number (wl-summary-message-number)))
319 (elmo-message-field wl-summary-buffer-elmo-folder
320 number 'message-id)))
322 (elmo-message-entity wl-summary-buffer-elmo-folder
324 folder cur-mark tmp-folder)
327 (message "Cannot decide destination.")
330 (message "No message.")
332 (setq folder (wl-summary-read-folder
333 (or (wl-refile-guess entity) wl-trash-folder)
334 (format "for %s " action)))
335 ;; Cache folder hack by okada@opaopa.org
336 (when (and (eq (elmo-folder-type-internal
337 (wl-folder-get-elmo-folder
338 (wl-folder-get-realname folder))) 'cache)
342 (elmo-cache-get-path-subr
343 (elmo-msgid-to-cache msgid)))))))
344 (setq folder tmp-folder)
345 (message "Force refile to %s." folder))
346 (if (string= folder (wl-summary-buffer-folder-name))
347 (error "Same folder"))
348 (if (or (not (elmo-folder-writable-p (wl-folder-get-elmo-folder folder)))
349 (string= folder wl-queue-folder)
350 (string= folder wl-draft-folder))
351 (error "Don't set as target: %s" folder))
354 (wl-refile-learn entity folder))
358 (defun wl-summary-define-mark-action ()
360 (dolist (action wl-summary-mark-action-list)
361 (fset (intern (format "wl-summary-%s" (wl-summary-action-symbol action)))
362 `(lambda (&optional number data)
363 ,(wl-summary-action-docstring action)
365 (wl-summary-set-mark ,(wl-summary-action-mark action)
366 number (interactive-p) data)))
367 (fset (intern (format "wl-summary-%s-region"
368 (wl-summary-action-symbol action)))
370 ,(wl-summary-action-docstring action)
374 (wl-summary-mark-region-subr
375 (quote ,(intern (format "wl-summary-%s"
376 (wl-summary-action-symbol action))))
378 (if (quote ,(wl-summary-action-argument-function action))
380 ,(wl-summary-action-argument-function action))
381 (quote ,(wl-summary-action-symbol action))
382 (wl-summary-message-number)))))))
383 (fset (intern (format "wl-summary-target-mark-%s"
384 (wl-summary-action-symbol action)))
386 ,(wl-summary-action-docstring action)
388 (wl-summary-target-mark-set-action (quote ,action))))
389 (fset (intern (format "wl-thread-%s"
390 (wl-summary-action-symbol action)))
392 ,(wl-summary-action-docstring action)
394 (wl-thread-call-region-func
395 (quote ,(intern (format "wl-summary-%s-region"
396 (wl-summary-action-symbol action))))
399 (wl-summary-goto-top-of-current-thread))
400 (if (not wl-summary-move-direction-downward)
402 (wl-thread-goto-bottom-of-sub-thread)
403 (if wl-summary-buffer-disp-msg
404 (wl-summary-redisplay)))))))
406 (defun wl-summary-get-dispose-folder (folder)
407 (if (string= folder wl-trash-folder)
409 (let* ((type (or (wl-get-assoc-list-value wl-dispose-folder-alist folder)
411 (cond ((stringp type)
413 ((or (equal type 'remove) (equal type 'null))
415 (t;; (equal type 'trash)
416 (let ((trash-folder (wl-folder-get-elmo-folder wl-trash-folder)))
417 (unless (elmo-folder-exists-p trash-folder)
419 (format "Trash Folder %s does not exist, create it? "
421 (elmo-folder-create trash-folder)
422 (error "Trash Folder is not created"))))
426 (defun wl-summary-exec-action-dispose (mark-list)
427 (wl-summary-move-mark-list-messages mark-list
428 (wl-summary-get-dispose-folder
429 (wl-summary-buffer-folder-name))
430 "Disposing messages..."))
433 (defun wl-summary-exec-action-delete (mark-list)
434 (wl-summary-move-mark-list-messages mark-list
436 "Deleting messages..."))
439 (defun wl-summary-set-action-refile (number mark data)
440 (let ((policy (wl-get-assoc-list-value wl-refile-policy-alist
441 (wl-summary-buffer-folder-name)))
442 (elem wl-summary-mark-action-list))
443 (if (eq policy 'copy)
445 (when (eq (wl-summary-action-symbol (car elem)) 'copy)
446 (wl-summary-register-temp-mark number
447 (wl-summary-action-mark (car elem))
450 (setq elem (cdr elem)))
451 (wl-summary-register-temp-mark number mark data)
452 (setq wl-summary-buffer-prev-refile-destination data))))
454 (defun wl-summary-get-refile-destination (action number)
455 "Decide refile destination."
456 (wl-summary-get-refile-destination-subr action number t))
458 (defun wl-summary-exec-action-refile (mark-list)
460 (let ((start (point))
462 (refile-len (length mark-list))
463 dst-msgs ; loop counter
467 (wl-summary-make-destination-numbers-list mark-list))
468 (goto-char start) ; avoid moving cursor to the bottom line.
469 (when (> refile-len elmo-display-progress-threshold)
470 (elmo-progress-set 'elmo-folder-move-messages
471 refile-len "Refiling messages..."))
475 (setq result (elmo-folder-move-messages
476 wl-summary-buffer-elmo-folder
478 (wl-folder-get-elmo-folder
479 (car (car dst-msgs)))
480 (wl-summary-buffer-msgdb)
481 (not (null (cdr dst-msgs)))
486 (if result ; succeeded.
489 (wl-summary-delete-messages-on-buffer (cdr (car dst-msgs)))
490 (setq wl-summary-buffer-temp-mark-list
491 (wl-delete-associations
493 wl-summary-buffer-temp-mark-list)))
495 (+ failures (length (cdr (car dst-msgs))))))
496 (setq dst-msgs (cdr dst-msgs)))
497 (elmo-progress-clear 'elmo-folder-move-messages)
501 (defun wl-summary-get-copy-destination (action number)
502 (wl-summary-get-refile-destination-subr action number nil))
504 (defun wl-summary-exec-action-copy (mark-list)
506 (let ((start (point))
508 (refile-len (length mark-list))
509 dst-msgs ; loop counter
513 (wl-summary-make-destination-numbers-list mark-list))
514 (goto-char start) ; avoid moving cursor to the bottom line.
515 (when (> refile-len elmo-display-progress-threshold)
516 (elmo-progress-set 'elmo-folder-move-messages
517 refile-len "Copying messages..."))
521 (setq result (elmo-folder-move-messages
522 wl-summary-buffer-elmo-folder
524 (wl-folder-get-elmo-folder
525 (car (car dst-msgs)))
526 (wl-summary-buffer-msgdb)
527 (not (null (cdr dst-msgs)))
528 t ; t is no-delete (copy)
532 (if result ; succeeded.
535 (wl-summary-delete-copy-marks-on-buffer (cdr (car dst-msgs)))
536 (setq wl-summary-buffer-temp-mark-list
537 (wl-delete-associations
539 wl-summary-buffer-temp-mark-list)))
541 (+ failures (length (cdr (car dst-msgs))))))
542 (setq dst-msgs (cdr dst-msgs)))
543 (elmo-progress-clear 'elmo-folder-move-messages)
547 (defun wl-summary-exec-action-prefetch (mark-list)
550 (length (length mark-list))
551 (mark-list-copy (copy-sequence mark-list))
554 (dolist (mark-info mark-list-copy)
555 (message "Prefetching...(%d/%d)"
556 (setq count (+ 1 count)) length)
557 (if (wl-summary-prefetch-msg (car mark-info))
559 (wl-summary-unset-mark (car mark-info))
562 (message "Prefetching...done")
566 (defun wl-summary-get-resend-address (action number)
567 "Decide resend address."
568 (completing-read "Resend message to: " 'wl-complete-address))
570 (defun wl-summary-exec-action-resend (mark-list)
572 (dolist (mark-info mark-list)
573 (if (condition-case nil
575 (wl-summary-exec-action-resend-subr (car mark-info)
579 (wl-summary-unmark (car mark-info))
583 (defun wl-summary-exec-action-resend-subr (number address)
584 "Resend the message with NUMBER to ADDRESS."
585 (message "Resending message to %s..." address)
586 (let ((folder wl-summary-buffer-elmo-folder))
588 ;; We first set up a normal mail buffer.
589 (set-buffer (get-buffer-create " *wl-draft-resend*"))
590 (buffer-disable-undo (current-buffer))
592 (setq wl-sent-message-via nil)
593 ;; Insert our usual headers.
594 (wl-draft-insert-from-field)
595 (wl-draft-insert-date-field)
596 (insert "To: " address "\n")
597 (goto-char (point-min))
598 ;; Rename them all to "Resent-*".
599 (while (re-search-forward "^[A-Za-z]" nil t)
604 (delete-region (point) (point-max))
606 ;; Insert the message to be resent.
609 (elmo-message-fetch folder number
610 (elmo-make-fetch-strategy 'entire)
611 nil (current-buffer) 'unread)
613 (goto-char (point-min))
614 (search-forward "\n\n")
617 (narrow-to-region beg (point))
618 (wl-draft-delete-fields wl-ignored-resent-headers)
619 (goto-char (point-max)))
620 (insert mail-header-separator)
621 ;; Rename all old ("Previous-")Resent headers.
622 (while (re-search-backward "^\\(Previous-\\)*Resent-" beg t)
624 (insert "Previous-"))
625 ;; Quote any "From " lines at the beginning.
627 (when (looking-at "From ")
628 (replace-match "X-From-Line: ")))
630 (wl-draft-dispatch-message)
631 (kill-buffer (current-buffer)))
632 (message "Resending message to %s...done" address)))
635 (defun wl-summary-remove-argument ()
637 (let ((inhibit-read-only t)
638 (buffer-read-only nil)
639 (buf (current-buffer))
643 (search-forward "\r")
646 (setq rs (next-single-property-change sol 'wl-summary-action-argument
648 (setq re (next-single-property-change rs 'wl-summary-action-argument
650 (put-text-property rs re 'wl-summary-action-argument nil)
651 (put-text-property rs re 'invisible nil)
653 (delete-char (- eol re)))))
655 (defun wl-summary-collect-numbers-region (begin end)
656 "Return a list of message number in the region specified by BEGIN and END."
660 (narrow-to-region (or begin (point-min))(or end (point-max)))
661 (goto-char (point-min))
663 (if (eq wl-summary-buffer-view 'thread)
664 (let (number entity mark-info)
666 (setq numbers (cons (wl-summary-message-number) numbers)
667 entity (wl-thread-get-entity number))
668 ;; When thread is closed...children should also be checked.
669 (unless (wl-thread-entity-get-opened entity)
670 (dolist (msg (wl-thread-get-children-msgs number))
671 (setq numbers (cons msg numbers))))
673 (let (number mark-info)
675 (setq numbers (cons (wl-summary-message-number) numbers))
679 (defun wl-summary-exec (&optional numbers)
682 collected pair action modified)
683 (dolist (action wl-summary-mark-action-list)
684 (setq collected (cons (cons
685 (wl-summary-action-mark action)
687 (dolist (mark-info wl-summary-buffer-temp-mark-list)
689 (when (memq (nth 0 mark-info) numbers)
690 (setq pair (assoc (nth 1 mark-info) collected)))
691 (setq pair (assoc (nth 1 mark-info) collected)))
692 (setq pair (assoc (nth 1 mark-info) collected))
693 (setcdr pair (cons mark-info (cdr pair))))
694 ;; collected is a pair of
695 ;; mark-string and a list of mark-info
696 (dolist (pair collected)
697 (setq action (assoc (car pair) wl-summary-mark-action-list))
698 (when (and (cdr pair) (wl-summary-action-exec-function action))
700 (setq failures (+ failures (funcall
701 (wl-summary-action-exec-function action)
704 (wl-summary-set-message-modified))
705 (run-hooks 'wl-summary-exec-hook)
706 ;; message buffer is not up-to-date
707 (unless (and wl-message-buffer
708 (eq (wl-summary-message-number)
709 (with-current-buffer wl-message-buffer
710 wl-message-buffer-cur-number)))
711 (wl-summary-toggle-disp-msg 'off)
712 (setq wl-message-buffer nil))
713 (set-buffer-modified-p nil)
715 (format "%d execution(s) were failed" failures))))
717 (defun wl-summary-exec-region (beg end)
720 (wl-summary-collect-numbers-region beg end)))
722 (defun wl-summary-read-folder (default &optional purpose ignore-error
724 (let ((fld (completing-read
725 (format "Folder name %s(%s): " (or purpose "")
727 'wl-folder-complete-folder
728 nil nil (or init wl-default-spec)
729 'wl-read-folder-hist)))
730 (if (or (string= fld wl-default-spec)
733 (setq fld (elmo-string (wl-folder-get-realname fld)))
734 (if (string-match "\n" fld)
735 (error "Not supported folder name: %s" fld))
739 (wl-folder-confirm-existence
740 (wl-folder-get-elmo-folder
743 (wl-folder-confirm-existence (wl-folder-get-elmo-folder
747 (defun wl-summary-print-argument (msg-num folder)
748 "Print action argument on line."
750 (wl-summary-remove-argument)
752 (let ((inhibit-read-only t)
753 (folder (copy-sequence folder))
754 (buffer-read-only nil)
756 (setq len (string-width folder))
760 (search-forward "\r")
763 (let ((width (cond (wl-summary-width
764 (1- wl-summary-width))
765 (wl-summary-print-argument-within-window
766 (1- (window-width)))))
769 (if (and width (> (+ c len) width))
771 (move-to-column width)
772 (setq c (current-column))
773 (while (> (+ c len) width)
775 (setq c (current-column)))
776 (when (< (+ c len) width)
777 (setq folder (concat " " folder)))
779 (put-text-property rs re 'invisible t))
781 (> (setq padding (- width len c)) 0))
782 (setq folder (concat (make-string padding ?\ )
785 (put-text-property rs re 'wl-summary-action-argument t)
787 (wl-highlight-action-argument-string folder)
789 (set-buffer-modified-p nil))))))
791 (defsubst wl-summary-reserve-temp-mark-p (mark)
792 "Return t if temporal MARK should be reserved."
793 (member mark wl-summary-reserve-mark-list))
795 (defun wl-summary-refile-prev-destination ()
796 "Refile message to previously refiled destination."
798 (funcall (symbol-function 'wl-summary-refile)
799 wl-summary-buffer-prev-refile-destination)
800 (if (eq wl-summary-move-direction-downward nil)
804 (defsubst wl-summary-no-auto-refile-message-p (msg)
805 (member (elmo-msgdb-get-mark (wl-summary-buffer-msgdb) msg)
806 wl-summary-auto-refile-skip-marks))
808 (defun wl-summary-auto-refile (&optional open-all)
809 "Set refile mark automatically according to 'wl-refile-guess-by-rule'."
811 (message "Marking...")
813 (if (and (eq wl-summary-buffer-view 'thread)
815 (wl-thread-open-all))
816 (let* ((spec (wl-summary-buffer-folder-name))
819 number dst thr-entity)
822 (setq number (wl-summary-message-number))
823 (dolist (number (cons number
824 (and (eq wl-summary-buffer-view 'thread)
825 ;; process invisible children.
826 (not (wl-thread-entity-get-opened
828 (wl-thread-get-entity number))))
829 (wl-thread-entity-get-descendant
831 (when (and (not (wl-summary-no-auto-refile-message-p
834 (wl-folder-get-realname
835 (wl-refile-guess-by-rule
836 (elmo-msgdb-overview-get-entity
837 number (wl-summary-buffer-msgdb)))))
838 (not (equal dst spec))
839 (let ((pair (assoc dst checked-dsts))
846 (wl-folder-confirm-existence
847 (wl-folder-get-elmo-folder dst))
850 (setq checked-dsts (cons (cons dst ret) checked-dsts))
852 (if (funcall (symbol-function 'wl-summary-refile) number dst)
854 (message "Marking...%d message(s)." count)))
857 (message "No message was marked.")
858 (message "Marked %d message(s)." count)))))
860 (defun wl-summary-unmark (&optional number)
861 "Unmark marks (temporary, refile, copy, delete)of current line.
862 If optional argument NUMBER is specified, unmark message specified by NUMBER."
864 (wl-summary-unset-mark number (interactive-p)))
866 (defun wl-summary-unmark-region (beg end)
870 (narrow-to-region beg end)
871 (goto-char (point-min))
872 (if (eq wl-summary-buffer-view 'thread)
875 (let* ((number (wl-summary-message-number))
876 (entity (wl-thread-get-entity number)))
877 (if (wl-thread-entity-get-opened entity)
878 ;; opened...unmark line.
881 (wl-summary-delete-marks-on-buffer
882 (wl-thread-get-children-msgs number))))
886 (forward-line 1))))))
888 (defun wl-summary-mark-region-subr (function beg end data)
891 (narrow-to-region beg end)
892 (goto-char (point-min))
893 (if (eq wl-summary-buffer-view 'thread)
896 (let* ((number (wl-summary-message-number))
897 (entity (wl-thread-get-entity number))
898 (wl-summary-move-direction-downward t)
900 (if (wl-thread-entity-get-opened entity)
901 ;; opened...delete line.
902 (funcall function nil data)
904 (setq children (wl-thread-get-children-msgs number))
906 (funcall function (pop children) data)))
909 (funcall function nil data)
910 (forward-line 1))))))
912 (defun wl-summary-target-mark-all ()
914 (wl-summary-target-mark-region (point-min) (point-max))
915 (setq wl-summary-buffer-target-mark-list
916 (elmo-folder-list-messages wl-summary-buffer-elmo-folder
919 (defun wl-summary-delete-all-mark (mark)
920 (goto-char (point-min))
922 (when (string= (wl-summary-temp-mark) mark)
926 (dolist (mark-info wl-summary-buffer-temp-mark-list)
927 (when (string= (nth 1 mark-info) mark)
928 (setq deleted (cons mark-info deleted))))
929 (dolist (delete deleted)
930 (setq wl-summary-buffer-temp-mark-list
931 (delq delete wl-summary-buffer-temp-mark-list)))))
933 (defun wl-summary-unmark-all ()
934 "Unmark all according to what you input."
936 (let ((unmarks (string-to-char-list (read-from-minibuffer "Unmark: ")))
940 (setq cur-mark (char-to-string (car unmarks)))
941 (wl-summary-delete-all-mark cur-mark)
942 (setq unmarks (cdr unmarks))))))
944 (defun wl-summary-target-mark-thread ()
946 (wl-thread-call-region-func 'wl-summary-target-mark-region t))
949 (product-provide (provide 'wl-action) (require 'wl-version))
951 ;;; wl-action.el ends here