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)
105 (when (and (eq wl-summary-buffer-view 'thread)
107 (wl-thread-open-close 'force-open))
111 (if (or interactive (interactive-p))
112 (if (eq wl-summary-move-direction-downward nil)
114 (wl-summary-next))))))
116 (defun wl-summary-register-target-mark (number mark data)
117 (or (memq number wl-summary-buffer-target-mark-list)
118 (setq wl-summary-buffer-target-mark-list
119 (cons number wl-summary-buffer-target-mark-list))))
121 (defun wl-summary-unregister-target-mark (number)
122 (setq wl-summary-buffer-target-mark-list
123 (delq number wl-summary-buffer-target-mark-list)))
125 (defun wl-summary-have-target-mark-p (number)
126 (memq number wl-summary-buffer-target-mark-list))
128 (defun wl-summary-target-mark-set-action (action)
129 (unless (eq (wl-summary-action-symbol action) 'target-mark)
130 (unless wl-summary-buffer-target-mark-list (error "no target"))
132 (goto-char (point-min))
133 (let ((numlist wl-summary-buffer-number-list)
135 ;; use firstly marked message.
136 (when (wl-summary-action-argument-function action)
138 (if (memq (car numlist) wl-summary-buffer-target-mark-list)
139 (setq number (car numlist)
141 (setq numlist (cdr numlist)))
142 (wl-summary-jump-to-msg number)
143 (setq data (funcall (wl-summary-action-argument-function action)
144 (wl-summary-action-symbol action) number)))
146 (when (string= (wl-summary-temp-mark) "*")
147 (let (wl-summary-buffer-disp-msg)
148 (when (setq number (wl-summary-message-number))
149 (wl-summary-set-mark (wl-summary-action-mark action)
151 (setq wl-summary-buffer-target-mark-list
152 (delq number wl-summary-buffer-target-mark-list)))))
154 (setq mlist wl-summary-buffer-target-mark-list)
156 (wl-summary-register-temp-mark (car mlist)
157 (wl-summary-action-mark action) data)
158 (setq wl-summary-buffer-target-mark-list
159 (delq (car mlist) wl-summary-buffer-target-mark-list))
160 (setq mlist (cdr mlist)))))))
162 ;; wl-summary-buffer-temp-mark-list specification
163 ;; ((1 "D" nil)(2 "o" "+fuga")(3 "O" "+hoge"))
164 (defun wl-summary-register-temp-mark (number mark mark-info)
165 (let ((elem (assq number wl-summary-buffer-temp-mark-list)))
166 (setq wl-summary-buffer-temp-mark-list
167 (delq elem wl-summary-buffer-temp-mark-list)))
168 (setq wl-summary-buffer-temp-mark-list
169 (cons (list number mark mark-info) wl-summary-buffer-temp-mark-list)))
171 (defun wl-summary-unregister-temp-mark (number)
172 (let ((elem (assq number wl-summary-buffer-temp-mark-list)))
173 (setq wl-summary-buffer-temp-mark-list
174 (delq elem wl-summary-buffer-temp-mark-list))))
176 (defun wl-summary-registered-temp-mark (number)
177 (and wl-summary-buffer-temp-mark-list
178 (assq number wl-summary-buffer-temp-mark-list)))
180 (defun wl-summary-collect-temp-mark (mark &optional begin end)
185 (narrow-to-region (or begin (point-min))(or end (point-max)))
186 (goto-char (point-min))
188 (if (eq wl-summary-buffer-view 'thread)
189 (let (number entity mark-info)
191 (setq number (wl-summary-message-number)
192 entity (wl-thread-get-entity number)
193 mark-info (wl-summary-registered-temp-mark number))
194 ;; toplevel message mark.
195 (when (string= (nth 1 mark-info) mark)
196 (setq mark-list (cons mark-info mark-list)))
197 ;; When thread is closed...children should also be checked.
198 (unless (wl-thread-entity-get-opened entity)
199 (dolist (msg (wl-thread-get-children-msgs number))
200 (setq mark-info (wl-summary-registered-temp-mark
202 (when (string= (nth 1 mark-info) mark)
203 (setq mark-list (cons mark-info mark-list)))))
205 (let (number mark-info)
207 (setq number (wl-summary-message-number)
208 mark-info (wl-summary-registered-temp-mark number))
209 (when (string= (nth 1 mark-info) mark)
210 (setq mark-list (cons mark-info mark-list)))
214 (dolist (mark-info wl-summary-buffer-temp-mark-list)
215 (when (string= (nth 1 mark-info) mark)
216 (setq mark-list (cons mark-info mark-list))))
220 (defun wl-summary-unset-mark (&optional number interactive force)
221 "Unset temporary mark of the message with NUMBER.
222 NUMBER is the message number to unset the mark.
223 If not specified, the message on the cursor position is treated.
224 Optional INTERACTIVE is non-nil when it should be called interactively.
225 If optional FORCE is non-nil, remove scored mark too.
226 Return number if put mark succeed"
230 (let ((buffer-read-only nil)
234 (when (and (setq visible (wl-summary-message-visible-p number))
235 (not (eq number (wl-summary-message-number))))
236 (wl-summary-jump-to-msg number))
238 number (wl-summary-message-number)))
239 (setq mark (wl-summary-temp-mark))
240 ;; Remove from temporal mark structure.
241 (wl-summary-unregister-target-mark number)
242 (wl-summary-unregister-temp-mark number)
243 ;; Delete mark on buffer.
245 (unless (string= mark " ")
246 (wl-summary-put-temp-mark
247 (or (unless force (wl-summary-get-score-mark number))
249 (setq action (assoc mark wl-summary-mark-action-list))
250 (when wl-summary-highlight
251 (wl-highlight-summary-current-line))
252 (when (wl-summary-action-argument-function action)
253 (wl-summary-remove-argument)))
254 (set-buffer-modified-p nil))))
256 ;; (if (or interactive (interactive-p))
257 ;; (if (eq wl-summary-move-direction-downward nil)
259 ;; (wl-summary-next))))
262 (defun wl-summary-make-destination-numbers-list (mark-list)
263 (let (dest-numbers dest-number)
264 (dolist (elem mark-list)
265 (setq dest-number (assoc (nth 2 elem) dest-numbers))
267 (unless (memq (car elem) (cdr dest-number))
268 (nconc dest-number (list (car elem))))
269 (setq dest-numbers (nconc dest-numbers
275 (defun wl-summary-move-mark-list-messages (mark-list folder-name message)
279 (let ((start (point))
280 (refiles (mapcar 'car mark-list))
283 dst-msgs ; loop counter
286 (setq refile-len (length refiles))
287 (goto-char start) ; avoid moving cursor to
290 (when (> refile-len elmo-display-progress-threshold)
291 (elmo-progress-set 'elmo-folder-move-messages
295 (setq result (elmo-folder-move-messages
296 wl-summary-buffer-elmo-folder
298 (if (eq folder-name 'null)
300 (wl-folder-get-elmo-folder folder-name))))
302 (when result ; succeeded.
304 (wl-summary-delete-messages-on-buffer refiles)
305 ;; update wl-summary-buffer-temp-mark-list.
306 (dolist (mark-info mark-list)
307 (setq wl-summary-buffer-temp-mark-list
308 (delq mark-info wl-summary-buffer-temp-mark-list))))
309 (elmo-progress-clear 'elmo-folder-move-messages)
310 (message (concat message "done"))
311 (wl-summary-set-message-modified)
312 ;; Return the operation failed message numbers.
315 (length refiles))))))
317 (defun wl-summary-get-refile-destination-subr (action number learn)
318 (let* ((number (or number (wl-summary-message-number)))
320 (elmo-message-field wl-summary-buffer-elmo-folder
321 number 'message-id)))
323 (elmo-message-entity wl-summary-buffer-elmo-folder
325 folder cur-mark tmp-folder)
328 (message "Cannot decide destination.")
331 (message "No message.")
333 (setq folder (wl-summary-read-folder
334 (or (wl-refile-guess entity) wl-trash-folder)
335 (format "for %s " action)))
336 ;; Cache folder hack by okada@opaopa.org
337 (when (and (eq (elmo-folder-type-internal
338 (wl-folder-get-elmo-folder
339 (wl-folder-get-realname folder))) 'cache)
343 (elmo-cache-get-path-subr
344 (elmo-msgid-to-cache msgid)))))))
345 (setq folder tmp-folder)
346 (message "Force refile to %s." folder))
347 (if (string= folder (wl-summary-buffer-folder-name))
348 (error "Same folder"))
349 (if (or (not (elmo-folder-writable-p (wl-folder-get-elmo-folder folder)))
350 (string= folder wl-queue-folder)
351 (string= folder wl-draft-folder))
352 (error "Don't set as target: %s" folder))
355 (wl-refile-learn entity folder))
359 (defun wl-summary-define-mark-action ()
361 (dolist (action wl-summary-mark-action-list)
362 (fset (intern (format "wl-summary-%s" (wl-summary-action-symbol action)))
363 `(lambda (&optional number data)
364 ,(wl-summary-action-docstring action)
366 (wl-summary-set-mark ,(wl-summary-action-mark action)
367 number (interactive-p) data)))
368 (fset (intern (format "wl-summary-%s-region"
369 (wl-summary-action-symbol action)))
371 ,(wl-summary-action-docstring action)
375 (wl-summary-mark-region-subr
376 (quote ,(intern (format "wl-summary-%s"
377 (wl-summary-action-symbol action))))
379 (if (quote ,(wl-summary-action-argument-function action))
381 ,(wl-summary-action-argument-function action))
382 (quote ,(wl-summary-action-symbol action))
383 (wl-summary-message-number)))))))
384 (fset (intern (format "wl-summary-target-mark-%s"
385 (wl-summary-action-symbol action)))
387 ,(wl-summary-action-docstring action)
389 (wl-summary-target-mark-set-action (quote ,action))))
390 (fset (intern (format "wl-thread-%s"
391 (wl-summary-action-symbol action)))
393 ,(wl-summary-action-docstring action)
395 (wl-thread-call-region-func
396 (quote ,(intern (format "wl-summary-%s-region"
397 (wl-summary-action-symbol action))))
400 (wl-summary-goto-top-of-current-thread))
401 (if (not wl-summary-move-direction-downward)
403 (wl-thread-goto-bottom-of-sub-thread)
404 (if wl-summary-buffer-disp-msg
405 (wl-summary-redisplay)))))))
407 (defun wl-summary-get-dispose-folder (folder)
408 (if (string= folder wl-trash-folder)
410 (let* ((type (or (wl-get-assoc-list-value wl-dispose-folder-alist folder)
412 (cond ((stringp type)
414 ((or (equal type 'remove) (equal type 'null))
416 (t;; (equal type 'trash)
417 (let ((trash-folder (wl-folder-get-elmo-folder wl-trash-folder)))
418 (unless (elmo-folder-exists-p trash-folder)
420 (format "Trash Folder %s does not exist, create it? "
422 (elmo-folder-create trash-folder)
423 (error "Trash Folder is not created"))))
427 (defun wl-summary-exec-action-dispose (mark-list)
428 (wl-summary-move-mark-list-messages mark-list
429 (wl-summary-get-dispose-folder
430 (wl-summary-buffer-folder-name))
431 "Disposing messages..."))
434 (defun wl-summary-exec-action-delete (mark-list)
435 (wl-summary-move-mark-list-messages mark-list
437 "Deleting messages..."))
440 (defun wl-summary-set-action-refile (number mark data)
442 (error "Destination folder is empty"))
443 (wl-summary-register-temp-mark number mark data)
444 (setq wl-summary-buffer-prev-refile-destination data))
446 (defun wl-summary-get-refile-destination (action number)
447 "Decide refile destination."
448 (wl-summary-get-refile-destination-subr action number t))
450 (defun wl-summary-exec-action-refile (mark-list)
452 (let ((start (point))
454 (refile-len (length mark-list))
457 (setq dst-msgs (wl-summary-make-destination-numbers-list mark-list))
458 (goto-char start) ; avoid moving cursor to the bottom line.
459 (when (> refile-len elmo-display-progress-threshold)
460 (elmo-progress-set 'elmo-folder-move-messages
461 refile-len "Refiling messages..."))
462 (dolist (pair dst-msgs)
463 (if (condition-case nil
464 (elmo-folder-move-messages
465 wl-summary-buffer-elmo-folder
467 (wl-folder-get-elmo-folder (car pair)))
471 (wl-summary-delete-messages-on-buffer (cdr pair))
472 (setq wl-summary-buffer-temp-mark-list
473 (wl-delete-associations
475 wl-summary-buffer-temp-mark-list)))
476 (setq failures (+ failures (length (cdr pair))))))
477 (elmo-progress-clear 'elmo-folder-move-messages)
479 (message "Refiling messages...done"))
483 (defun wl-summary-get-copy-destination (action number)
484 (wl-summary-get-refile-destination-subr action number nil))
486 (defun wl-summary-exec-action-copy (mark-list)
488 (let ((start (point))
490 (refile-len (length mark-list))
494 (wl-summary-make-destination-numbers-list mark-list))
495 (goto-char start) ; avoid moving cursor to the bottom line.
496 (when (> refile-len elmo-display-progress-threshold)
497 (elmo-progress-set 'elmo-folder-move-messages
498 refile-len "Copying messages..."))
499 (dolist (pair dst-msgs)
500 (if (condition-case nil
501 (elmo-folder-move-messages
502 wl-summary-buffer-elmo-folder
504 (wl-folder-get-elmo-folder (car pair))
509 (wl-summary-delete-copy-marks-on-buffer (cdr pair))
510 (setq wl-summary-buffer-temp-mark-list
511 (wl-delete-associations
513 wl-summary-buffer-temp-mark-list)))
514 (setq failures (+ failures (length (cdr pair))))))
515 (elmo-progress-clear 'elmo-folder-move-messages)
517 (message "Copying messages...done"))
521 (defun wl-summary-exec-action-prefetch (mark-list)
524 (length (length mark-list))
525 (mark-list-copy (copy-sequence mark-list))
528 (dolist (mark-info mark-list-copy)
529 (message "Prefetching...(%d/%d)"
530 (setq count (+ 1 count)) length)
531 (if (wl-summary-prefetch-msg (car mark-info))
533 (wl-summary-unset-mark (car mark-info))
536 (message "Prefetching...done")
540 (defun wl-summary-get-resend-address (action number)
541 "Decide resend address."
542 (wl-address-read-from-minibuffer "Resend message to: "))
544 (defun wl-summary-exec-action-resend (mark-list)
546 (dolist (mark-info mark-list)
547 (if (condition-case nil
549 (wl-summary-exec-action-resend-subr (car mark-info)
553 (wl-summary-unmark (car mark-info))
557 (defun wl-summary-exec-action-resend-subr (number address)
558 "Resend the message with NUMBER to ADDRESS."
559 (message "Resending message to %s..." address)
560 (let ((folder wl-summary-buffer-elmo-folder))
562 ;; We first set up a normal mail buffer.
563 (set-buffer (get-buffer-create " *wl-draft-resend*"))
564 (set-buffer-multibyte nil)
566 (setq wl-sent-message-via nil)
567 ;; Insert our usual headers.
568 (wl-draft-insert-from-field)
569 (wl-draft-insert-date-field)
570 (insert "To: " address "\n")
571 (goto-char (point-min))
572 ;; Rename them all to "Resent-*".
573 (while (re-search-forward "^[A-Za-z]" nil t)
578 (delete-region (point) (point-max))
580 ;; Insert the message to be resent.
582 ;; elmo-message-fetch is erase current buffer before fetch message
583 (elmo-message-fetch-string folder number
584 (if wl-summary-resend-use-cache
585 (elmo-make-fetch-strategy
587 (elmo-file-cache-get-path
589 folder number 'message-id)))
590 (elmo-make-fetch-strategy 'entire))
592 (goto-char (point-min))
593 (search-forward "\n\n")
596 (narrow-to-region beg (point))
597 (wl-draft-delete-fields wl-ignored-resent-headers)
598 (goto-char (point-max)))
599 (insert mail-header-separator)
600 ;; Rename all old ("Previous-")Resent headers.
601 (while (re-search-backward "^\\(Previous-\\)*Resent-" beg t)
603 (insert "Previous-"))
604 ;; Quote any "From " lines at the beginning.
606 (when (looking-at "From ")
607 (replace-match "X-From-Line: ")))
608 (run-hooks 'wl-summary-resend-hook)
610 (wl-draft-dispatch-message)
611 (kill-buffer (current-buffer)))
612 (message "Resending message to %s...done" address)))
615 (defun wl-summary-remove-argument ()
617 (let ((inhibit-read-only t)
618 (buffer-read-only nil)
619 (buf (current-buffer))
623 (search-forward "\r")
626 (setq rs (next-single-property-change sol 'wl-summary-action-argument
628 (setq re (next-single-property-change rs 'wl-summary-action-argument
630 (put-text-property rs re 'wl-summary-action-argument nil)
631 (put-text-property rs re 'invisible nil)
633 (delete-char (- eol re)))))
635 (defun wl-summary-collect-numbers-region (begin end)
636 "Return a list of message number in the region specified by BEGIN and END."
640 (wl-summary-narrow-to-region (or begin (point-min))(or end (point-max)))
641 (goto-char (point-min))
643 (if (eq wl-summary-buffer-view 'thread)
646 (setq numbers (cons (wl-summary-message-number) numbers)
647 entity (wl-thread-get-entity number))
648 ;; When thread is closed...children should also be checked.
649 (unless (wl-thread-entity-get-opened entity)
650 (dolist (msg (wl-thread-get-children-msgs number))
651 (setq numbers (cons msg numbers))))
655 (setq numbers (cons (wl-summary-message-number) numbers))
657 (nreverse (delq nil numbers))))))
659 (defun wl-summary-exec (&optional numbers)
662 collected pair action modified)
663 (dolist (action wl-summary-mark-action-list)
664 (setq collected (cons (cons
665 (wl-summary-action-mark action)
667 (dolist (mark-info wl-summary-buffer-temp-mark-list)
669 (when (or (null numbers)
670 (memq (nth 0 mark-info) numbers))
671 (assoc (nth 1 mark-info) collected)))
673 (setcdr pair (cons mark-info (cdr pair)))))
674 ;; collected is a pair of
675 ;; mark-string and a list of mark-info
676 (dolist (pair collected)
678 (setq action (assoc (car pair) wl-summary-mark-action-list))
679 (when (wl-summary-action-exec-function action)
681 (setq failures (+ failures (funcall
682 (wl-summary-action-exec-function action)
685 (wl-summary-set-message-modified))
686 (run-hooks 'wl-summary-exec-hook)
687 ;; message buffer is not up-to-date
688 (unless (and wl-message-buffer
689 (eq (wl-summary-message-number)
690 (with-current-buffer wl-message-buffer
691 wl-message-buffer-cur-number)))
692 (wl-summary-toggle-disp-msg 'off)
693 (setq wl-message-buffer nil))
694 (set-buffer-modified-p nil)
696 (message "%d execution(s) were failed" failures))))
698 (defun wl-summary-exec-region (beg end)
701 (wl-summary-collect-numbers-region beg end)))
703 (defun wl-summary-read-folder (default &optional purpose ignore-error
705 (let ((fld (completing-read
706 (format "Folder name %s(%s): " (or purpose "")
708 'wl-folder-complete-folder
709 nil nil (or init wl-default-spec)
710 'wl-read-folder-history)))
711 (if (or (string= fld wl-default-spec)
714 (setq fld (elmo-string (wl-folder-get-realname fld)))
715 (if (string-match "\n" fld)
716 (error "Not supported folder name: %s" fld))
720 (wl-folder-confirm-existence
721 (wl-folder-get-elmo-folder
724 (wl-folder-confirm-existence (wl-folder-get-elmo-folder
728 (defun wl-summary-print-argument (msg-num data)
729 "Print action argument on line."
731 (wl-summary-remove-argument)
733 (let ((inhibit-read-only t)
734 (data (copy-sequence data))
735 (buffer-read-only nil)
737 (setq len (string-width data))
741 (search-forward "\r")
744 (let ((width (cond (wl-summary-width
745 (1- wl-summary-width))
746 (wl-summary-print-argument-within-window
747 (1- (window-width)))))
753 (move-to-column width)
754 (setq c (current-column))
755 (while (> (+ c len) width)
757 (setq c (current-column)))
758 (when (< (+ c len) width)
759 (setq data (concat " " data)))
761 (put-text-property rs re 'invisible t))
763 (> (setq padding (- width len c)) 0))
764 (setq data (concat (make-string padding ?\ ) data)))
766 (put-text-property rs re 'wl-summary-action-argument t)
768 (wl-highlight-action-argument-string data)
770 (set-buffer-modified-p nil))))))
772 (defsubst wl-summary-reserve-temp-mark-p (mark)
773 "Return t if temporal MARK should be reserved."
774 (member mark wl-summary-reserve-mark-list))
776 ;; Refile prev destination
777 (defun wl-summary-refile-prev-destination ()
778 "Refile message to previously refiled destination."
780 (funcall (symbol-function 'wl-summary-refile)
781 (wl-summary-message-number)
782 wl-summary-buffer-prev-refile-destination)
783 (if (and (interactive-p)
784 (eq wl-summary-move-direction-downward nil))
788 (defun wl-summary-refile-prev-destination-region (beg end)
789 "Refile messages in the region to previously refiled destination."
791 (wl-summary-mark-region-subr 'wl-summary-refile
793 wl-summary-buffer-prev-refile-destination))
795 (defun wl-thread-refile-prev-destination (arg)
796 "Refile messages in the thread to previously refiled destination."
798 (wl-thread-call-region-func
799 'wl-summary-refile-prev-destination-region
802 (defun wl-summary-target-mark-refile-prev-destination ()
803 "Refile messages with target mark to previously refiled destination."
805 (let ((elem wl-summary-mark-action-list)
808 (when (eq (wl-summary-action-symbol (car elem)) 'refile)
809 (setq action (car elem))
811 (setq elem (cdr elem)))
812 (wl-summary-target-mark-set-action
815 'refile-prev-destination
816 (lambda (&rest args) wl-summary-buffer-prev-refile-destination)
822 (defsubst wl-summary-no-auto-refile-message-p (number)
823 (member (wl-summary-message-mark wl-summary-buffer-elmo-folder number)
824 wl-summary-auto-refile-skip-marks))
826 (defvar wl-auto-refile-guess-functions
827 '(wl-refile-guess-by-rule)
828 "*List of functions which is used for guessing refile destination folder.")
830 (defun wl-summary-auto-refile (&optional open-all)
831 "Set refile mark automatically according to 'wl-refile-guess-by-rule'."
833 (message "Marking...")
835 (if (and (eq wl-summary-buffer-view 'thread)
837 (wl-thread-open-all))
838 (let* ((spec (wl-summary-buffer-folder-name))
841 number dst thr-entity)
844 (setq number (wl-summary-message-number))
845 (dolist (number (cons number
846 (and (eq wl-summary-buffer-view 'thread)
847 ;; process invisible children.
848 (not (wl-thread-entity-get-opened
850 (wl-thread-get-entity number))))
851 (wl-thread-entity-get-descendant
853 (when (and (not (wl-summary-no-auto-refile-message-p number))
854 (not (wl-summary-reserve-temp-mark-p
855 (nth 1 (wl-summary-registered-temp-mark number))))
857 (wl-folder-get-realname
859 (elmo-message-entity wl-summary-buffer-elmo-folder
861 wl-auto-refile-guess-functions)))
862 (not (equal dst spec))
863 (let ((pair (assoc dst checked-dsts))
870 (wl-folder-confirm-existence
871 (wl-folder-get-elmo-folder dst))
874 (setq checked-dsts (cons (cons dst ret) checked-dsts))
876 (if (funcall (symbol-function 'wl-summary-refile) number dst)
878 (message "Marking...%d message(s)." count)))
881 (message "No message was marked.")
882 (message "Marked %d message(s)." count)))))
884 (defun wl-summary-unmark (&optional number)
885 "Unmark marks (temporary, refile, copy, delete)of current line.
886 If optional argument NUMBER is specified, unmark message specified by NUMBER."
888 (wl-summary-unset-mark number (interactive-p)))
890 (defun wl-summary-unmark-region (beg end)
894 (wl-summary-narrow-to-region beg end)
895 (goto-char (point-min))
896 (if (eq wl-summary-buffer-view 'thread)
899 (let* ((number (wl-summary-message-number))
900 (entity (wl-thread-get-entity number)))
901 (if (wl-thread-entity-get-opened entity)
902 ;; opened...unmark line.
905 (wl-summary-delete-marks-on-buffer
906 (wl-thread-get-children-msgs number))))
910 (forward-line 1))))))
912 (defun wl-summary-mark-region-subr (function beg end data)
915 (wl-summary-narrow-to-region beg end)
916 (goto-char (point-min))
917 (if (eq wl-summary-buffer-view 'thread)
920 (let* ((number (wl-summary-message-number))
921 (entity (wl-thread-get-entity number))
922 (wl-summary-move-direction-downward t)
924 (if (wl-thread-entity-get-opened entity)
925 ;; opened...delete line.
926 (funcall function nil data)
928 (setq children (wl-thread-get-children-msgs number))
930 (funcall function (pop children) data)))
933 (funcall function nil data)
934 (forward-line 1))))))
936 (defun wl-summary-target-mark-all ()
938 (wl-summary-target-mark-region (point-min) (point-max)))
940 (defun wl-summary-delete-all-mark (mark)
941 (goto-char (point-min))
943 (when (string= (wl-summary-temp-mark) mark)
946 (if (string= mark "*")
947 (setq wl-summary-buffer-target-mark-list nil)
949 (dolist (mark-info wl-summary-buffer-temp-mark-list)
950 (when (string= (nth 1 mark-info) mark)
951 (setq deleted (cons mark-info deleted))))
952 (dolist (delete deleted)
953 (setq wl-summary-buffer-temp-mark-list
954 (delq delete wl-summary-buffer-temp-mark-list))))))
956 (defun wl-summary-unmark-all ()
957 "Unmark all according to what you input."
959 (let ((unmarks (string-to-char-list (read-from-minibuffer "Unmark: ")))
963 (setq cur-mark (char-to-string (car unmarks)))
964 (wl-summary-delete-all-mark cur-mark)
965 (setq unmarks (cdr unmarks))))))
967 (defun wl-summary-target-mark-thread ()
969 (wl-thread-call-region-func 'wl-summary-target-mark-region t))
972 (product-provide (provide 'wl-action) (require 'wl-version))
974 ;;; wl-action.el ends here