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 (and wl-summary-buffer-temp-mark-list
174 (assq number wl-summary-buffer-temp-mark-list)))
176 (defun wl-summary-collect-temp-mark (mark &optional begin end)
181 (narrow-to-region (or begin (point-min))(or end (point-max)))
182 (goto-char (point-min))
184 (if (eq wl-summary-buffer-view 'thread)
185 (let (number entity mark-info)
187 (setq number (wl-summary-message-number)
188 entity (wl-thread-get-entity number)
189 mark-info (wl-summary-registered-temp-mark number))
190 ;; toplevel message mark.
191 (when (string= (nth 1 mark-info) mark)
192 (setq mark-list (cons mark-info mark-list)))
193 ;; When thread is closed...children should also be checked.
194 (unless (wl-thread-entity-get-opened entity)
195 (dolist (msg (wl-thread-get-children-msgs number))
196 (setq mark-info (wl-summary-registered-temp-mark
198 (when (string= (nth 1 mark-info) mark)
199 (setq mark-list (cons mark-info mark-list)))))
201 (let (number mark-info)
203 (setq number (wl-summary-message-number)
204 mark-info (wl-summary-registered-temp-mark number))
205 (when (string= (nth 1 mark-info) mark)
206 (setq mark-list (cons mark-info mark-list)))
210 (dolist (mark-info wl-summary-buffer-temp-mark-list)
211 (when (string= (nth 1 mark-info) mark)
212 (setq mark-list (cons mark-info mark-list))))
216 (defun wl-summary-unset-mark (&optional number interactive force)
217 "Unset temporary mark of the message with NUMBER.
218 NUMBER is the message number to unset the mark.
219 If not specified, the message on the cursor position is treated.
220 Optional INTERACTIVE is non-nil when it should be called interactively.
221 If optional FORCE is non-nil, remove scored mark too.
222 Return number if put mark succeed"
226 (let ((buffer-read-only nil)
230 (when (and (setq visible (wl-summary-message-visible-p number))
231 (not (eq number (wl-summary-message-number))))
232 (wl-summary-jump-to-msg number))
234 number (wl-summary-message-number)))
235 (setq mark (wl-summary-temp-mark))
236 ;; Remove from temporal mark structure.
237 (wl-summary-unregister-target-mark number)
238 (wl-summary-unregister-temp-mark number)
239 ;; Delete mark on buffer.
241 (unless (string= mark " ")
242 (wl-summary-put-temp-mark
243 (or (unless force (wl-summary-get-score-mark number))
245 (setq action (assoc mark wl-summary-mark-action-list))
246 (when wl-summary-highlight
247 (wl-highlight-summary-current-line))
248 (when (wl-summary-action-argument-function action)
249 (wl-summary-remove-argument)))
250 (set-buffer-modified-p nil))))
252 ;; (if (or interactive (interactive-p))
253 ;; (if (eq wl-summary-move-direction-downward nil)
255 ;; (wl-summary-next))))
258 (defun wl-summary-make-destination-numbers-list (mark-list)
259 (let (dest-numbers dest-number)
260 (dolist (elem mark-list)
261 (setq dest-number (assoc (nth 2 elem) dest-numbers))
263 (unless (memq (car elem) (cdr dest-number))
264 (nconc dest-number (list (car elem))))
265 (setq dest-numbers (nconc dest-numbers
271 (defun wl-summary-move-mark-list-messages (mark-list folder-name message)
275 (let ((start (point))
276 (refiles (mapcar 'car mark-list))
279 dst-msgs ; loop counter
282 (setq refile-len (length refiles))
283 (goto-char start) ; avoid moving cursor to
286 (when (> refile-len elmo-display-progress-threshold)
287 (elmo-progress-set 'elmo-folder-move-messages
291 (setq result (elmo-folder-move-messages
292 wl-summary-buffer-elmo-folder
294 (if (eq folder-name 'null)
296 (wl-folder-get-elmo-folder folder-name))))
298 (when result ; succeeded.
300 (wl-summary-delete-messages-on-buffer refiles)
301 ;; update wl-summary-buffer-temp-mark-list.
302 (dolist (mark-info mark-list)
303 (setq wl-summary-buffer-temp-mark-list
304 (delq mark-info wl-summary-buffer-temp-mark-list))))
305 (elmo-progress-clear 'elmo-folder-move-messages)
306 (message (concat message "done"))
307 (wl-summary-set-message-modified)
308 ;; Return the operation failed message numbers.
311 (length refiles))))))
313 (defun wl-summary-get-refile-destination-subr (action number learn)
314 (let* ((number (or number (wl-summary-message-number)))
316 (elmo-message-field wl-summary-buffer-elmo-folder
317 number 'message-id)))
319 (elmo-message-entity wl-summary-buffer-elmo-folder
321 folder cur-mark tmp-folder)
324 (message "Cannot decide destination.")
327 (message "No message.")
329 (setq folder (wl-summary-read-folder
330 (or (wl-refile-guess entity) wl-trash-folder)
331 (format "for %s " action)))
332 ;; Cache folder hack by okada@opaopa.org
333 (when (and (eq (elmo-folder-type-internal
334 (wl-folder-get-elmo-folder
335 (wl-folder-get-realname folder))) 'cache)
339 (elmo-cache-get-path-subr
340 (elmo-msgid-to-cache msgid)))))))
341 (setq folder tmp-folder)
342 (message "Force refile to %s." folder))
343 (if (string= folder (wl-summary-buffer-folder-name))
344 (error "Same folder"))
345 (if (or (not (elmo-folder-writable-p (wl-folder-get-elmo-folder folder)))
346 (string= folder wl-queue-folder)
347 (string= folder wl-draft-folder))
348 (error "Don't set as target: %s" folder))
351 (wl-refile-learn entity folder))
355 (defun wl-summary-define-mark-action ()
357 (dolist (action wl-summary-mark-action-list)
358 (fset (intern (format "wl-summary-%s" (wl-summary-action-symbol action)))
359 `(lambda (&optional number data)
360 ,(wl-summary-action-docstring action)
362 (wl-summary-set-mark ,(wl-summary-action-mark action)
363 number (interactive-p) data)))
364 (fset (intern (format "wl-summary-%s-region"
365 (wl-summary-action-symbol action)))
367 ,(wl-summary-action-docstring action)
371 (wl-summary-mark-region-subr
372 (quote ,(intern (format "wl-summary-%s"
373 (wl-summary-action-symbol action))))
375 (if (quote ,(wl-summary-action-argument-function action))
377 ,(wl-summary-action-argument-function action))
378 (quote ,(wl-summary-action-symbol action))
379 (wl-summary-message-number)))))))
380 (fset (intern (format "wl-summary-target-mark-%s"
381 (wl-summary-action-symbol action)))
383 ,(wl-summary-action-docstring action)
385 (wl-summary-target-mark-set-action (quote ,action))))
386 (fset (intern (format "wl-thread-%s"
387 (wl-summary-action-symbol action)))
389 ,(wl-summary-action-docstring action)
391 (wl-thread-call-region-func
392 (quote ,(intern (format "wl-summary-%s-region"
393 (wl-summary-action-symbol action))))
396 (wl-summary-goto-top-of-current-thread))
397 (if (not wl-summary-move-direction-downward)
399 (wl-thread-goto-bottom-of-sub-thread)
400 (if wl-summary-buffer-disp-msg
401 (wl-summary-redisplay)))))))
403 (defun wl-summary-get-dispose-folder (folder)
404 (if (string= folder wl-trash-folder)
406 (let* ((type (or (wl-get-assoc-list-value wl-dispose-folder-alist folder)
408 (cond ((stringp type)
410 ((or (equal type 'remove) (equal type 'null))
412 (t;; (equal type 'trash)
413 (let ((trash-folder (wl-folder-get-elmo-folder wl-trash-folder)))
414 (unless (elmo-folder-exists-p trash-folder)
416 (format "Trash Folder %s does not exist, create it? "
418 (elmo-folder-create trash-folder)
419 (error "Trash Folder is not created"))))
423 (defun wl-summary-exec-action-dispose (mark-list)
424 (wl-summary-move-mark-list-messages mark-list
425 (wl-summary-get-dispose-folder
426 (wl-summary-buffer-folder-name))
427 "Disposing messages..."))
430 (defun wl-summary-exec-action-delete (mark-list)
431 (wl-summary-move-mark-list-messages mark-list
433 "Deleting messages..."))
436 (defun wl-summary-set-action-refile (number mark data)
438 (error "Destination folder is empty"))
439 (let ((policy (wl-get-assoc-list-value wl-refile-policy-alist
440 (wl-summary-buffer-folder-name)))
441 (elem wl-summary-mark-action-list))
442 (if (eq policy 'copy)
444 (when (eq (wl-summary-action-symbol (car elem)) 'copy)
445 (wl-summary-register-temp-mark number
446 (wl-summary-action-mark (car elem))
449 (setq elem (cdr elem)))
450 (wl-summary-register-temp-mark number mark data)
451 (setq wl-summary-buffer-prev-refile-destination data))))
453 (defun wl-summary-get-refile-destination (action number)
454 "Decide refile destination."
455 (wl-summary-get-refile-destination-subr action number t))
457 (defun wl-summary-exec-action-refile (mark-list)
459 (let ((start (point))
461 (refile-len (length mark-list))
462 dst-msgs ; loop counter
466 (wl-summary-make-destination-numbers-list mark-list))
467 (goto-char start) ; avoid moving cursor to the bottom line.
468 (when (> refile-len elmo-display-progress-threshold)
469 (elmo-progress-set 'elmo-folder-move-messages
470 refile-len "Refiling messages..."))
474 (setq result (elmo-folder-move-messages
475 wl-summary-buffer-elmo-folder
477 (wl-folder-get-elmo-folder (car (car dst-msgs)))))
479 (if result ; succeeded.
482 (wl-summary-delete-messages-on-buffer (cdr (car dst-msgs)))
483 (setq wl-summary-buffer-temp-mark-list
484 (wl-delete-associations
486 wl-summary-buffer-temp-mark-list)))
488 (+ failures (length (cdr (car dst-msgs))))))
489 (setq dst-msgs (cdr dst-msgs)))
490 (elmo-progress-clear 'elmo-folder-move-messages)
494 (defun wl-summary-get-copy-destination (action number)
495 (wl-summary-get-refile-destination-subr action number nil))
497 (defun wl-summary-exec-action-copy (mark-list)
499 (let ((start (point))
501 (refile-len (length mark-list))
502 dst-msgs ; loop counter
506 (wl-summary-make-destination-numbers-list mark-list))
507 (goto-char start) ; avoid moving cursor to the bottom line.
508 (when (> refile-len elmo-display-progress-threshold)
509 (elmo-progress-set 'elmo-folder-move-messages
510 refile-len "Copying messages..."))
514 (setq result (elmo-folder-move-messages
515 wl-summary-buffer-elmo-folder
517 (wl-folder-get-elmo-folder (car (car dst-msgs)))
520 (if result ; succeeded.
523 (wl-summary-delete-copy-marks-on-buffer (cdr (car dst-msgs)))
524 (setq wl-summary-buffer-temp-mark-list
525 (wl-delete-associations
527 wl-summary-buffer-temp-mark-list)))
529 (+ failures (length (cdr (car dst-msgs))))))
530 (setq dst-msgs (cdr dst-msgs)))
531 (elmo-progress-clear 'elmo-folder-move-messages)
535 (defun wl-summary-exec-action-prefetch (mark-list)
538 (length (length mark-list))
539 (mark-list-copy (copy-sequence mark-list))
542 (dolist (mark-info mark-list-copy)
543 (message "Prefetching...(%d/%d)"
544 (setq count (+ 1 count)) length)
545 (if (wl-summary-prefetch-msg (car mark-info))
547 (wl-summary-unset-mark (car mark-info))
550 (message "Prefetching...done")
554 (defun wl-summary-get-resend-address (action number)
555 "Decide resend address."
556 (completing-read "Resend message to: " 'wl-complete-address))
558 (defun wl-summary-exec-action-resend (mark-list)
560 (dolist (mark-info mark-list)
561 (if (condition-case nil
563 (wl-summary-exec-action-resend-subr (car mark-info)
567 (wl-summary-unmark (car mark-info))
571 (defun wl-summary-exec-action-resend-subr (number address)
572 "Resend the message with NUMBER to ADDRESS."
573 (message "Resending message to %s..." address)
574 (let ((folder wl-summary-buffer-elmo-folder))
576 ;; We first set up a normal mail buffer.
577 (set-buffer (get-buffer-create " *wl-draft-resend*"))
578 (buffer-disable-undo (current-buffer))
580 (setq wl-sent-message-via nil)
581 ;; Insert our usual headers.
582 (wl-draft-insert-from-field)
583 (wl-draft-insert-date-field)
584 (insert "To: " address "\n")
585 (goto-char (point-min))
586 ;; Rename them all to "Resent-*".
587 (while (re-search-forward "^[A-Za-z]" nil t)
592 (delete-region (point) (point-max))
594 ;; Insert the message to be resent.
597 (elmo-message-fetch folder number
598 (elmo-make-fetch-strategy 'entire)
599 nil (current-buffer) 'unread)
601 (goto-char (point-min))
602 (search-forward "\n\n")
605 (narrow-to-region beg (point))
606 (wl-draft-delete-fields wl-ignored-resent-headers)
607 (goto-char (point-max)))
608 (insert mail-header-separator)
609 ;; Rename all old ("Previous-")Resent headers.
610 (while (re-search-backward "^\\(Previous-\\)*Resent-" beg t)
612 (insert "Previous-"))
613 ;; Quote any "From " lines at the beginning.
615 (when (looking-at "From ")
616 (replace-match "X-From-Line: ")))
618 (wl-draft-dispatch-message)
619 (kill-buffer (current-buffer)))
620 (message "Resending message to %s...done" address)))
623 (defun wl-summary-remove-argument ()
625 (let ((inhibit-read-only t)
626 (buffer-read-only nil)
627 (buf (current-buffer))
631 (search-forward "\r")
634 (setq rs (next-single-property-change sol 'wl-summary-action-argument
636 (setq re (next-single-property-change rs 'wl-summary-action-argument
638 (put-text-property rs re 'wl-summary-action-argument nil)
639 (put-text-property rs re 'invisible nil)
641 (delete-char (- eol re)))))
643 (defun wl-summary-collect-numbers-region (begin end)
644 "Return a list of message number in the region specified by BEGIN and END."
648 (wl-summary-narrow-to-region (or begin (point-min))(or end (point-max)))
649 (goto-char (point-min))
651 (if (eq wl-summary-buffer-view 'thread)
654 (setq numbers (cons (wl-summary-message-number) numbers)
655 entity (wl-thread-get-entity number))
656 ;; When thread is closed...children should also be checked.
657 (unless (wl-thread-entity-get-opened entity)
658 (dolist (msg (wl-thread-get-children-msgs number))
659 (setq numbers (cons msg numbers))))
663 (setq numbers (cons (wl-summary-message-number) numbers))
665 (nreverse (delq nil numbers))))))
667 (defun wl-summary-exec (&optional numbers)
670 collected pair action modified)
671 (dolist (action wl-summary-mark-action-list)
672 (setq collected (cons (cons
673 (wl-summary-action-mark action)
675 (dolist (mark-info wl-summary-buffer-temp-mark-list)
677 (when (memq (nth 0 mark-info) numbers)
678 (setq pair (assoc (nth 1 mark-info) collected)))
679 (setq pair (assoc (nth 1 mark-info) collected)))
680 (setq pair (assoc (nth 1 mark-info) collected))
681 (setcdr pair (cons mark-info (cdr pair))))
682 ;; collected is a pair of
683 ;; mark-string and a list of mark-info
684 (dolist (pair collected)
685 (setq action (assoc (car pair) wl-summary-mark-action-list))
686 (when (and (cdr pair) (wl-summary-action-exec-function action))
688 (setq failures (+ failures (funcall
689 (wl-summary-action-exec-function action)
692 (wl-summary-set-message-modified))
693 (run-hooks 'wl-summary-exec-hook)
694 ;; message buffer is not up-to-date
695 (unless (and wl-message-buffer
696 (eq (wl-summary-message-number)
697 (with-current-buffer wl-message-buffer
698 wl-message-buffer-cur-number)))
699 (wl-summary-toggle-disp-msg 'off)
700 (setq wl-message-buffer nil))
701 (set-buffer-modified-p nil)
703 (format "%d execution(s) were failed" failures))))
705 (defun wl-summary-exec-region (beg end)
708 (wl-summary-collect-numbers-region beg end)))
710 (defun wl-summary-read-folder (default &optional purpose ignore-error
712 (let ((fld (completing-read
713 (format "Folder name %s(%s): " (or purpose "")
715 'wl-folder-complete-folder
716 nil nil (or init wl-default-spec)
717 'wl-read-folder-history)))
718 (if (or (string= fld wl-default-spec)
721 (setq fld (elmo-string (wl-folder-get-realname fld)))
722 (if (string-match "\n" fld)
723 (error "Not supported folder name: %s" fld))
727 (wl-folder-confirm-existence
728 (wl-folder-get-elmo-folder
731 (wl-folder-confirm-existence (wl-folder-get-elmo-folder
735 (defun wl-summary-print-argument (msg-num folder)
736 "Print action argument on line."
738 (wl-summary-remove-argument)
740 (let ((inhibit-read-only t)
741 (folder (copy-sequence folder))
742 (buffer-read-only nil)
744 (setq len (string-width folder))
748 (search-forward "\r")
751 (let ((width (cond (wl-summary-width
752 (1- wl-summary-width))
753 (wl-summary-print-argument-within-window
754 (1- (window-width)))))
757 (if (and width (> (+ c len) width))
759 (move-to-column width)
760 (setq c (current-column))
761 (while (> (+ c len) width)
763 (setq c (current-column)))
764 (when (< (+ c len) width)
765 (setq folder (concat " " folder)))
767 (put-text-property rs re 'invisible t))
769 (> (setq padding (- width len c)) 0))
770 (setq folder (concat (make-string padding ?\ )
773 (put-text-property rs re 'wl-summary-action-argument t)
775 (wl-highlight-action-argument-string folder)
777 (set-buffer-modified-p nil))))))
779 (defsubst wl-summary-reserve-temp-mark-p (mark)
780 "Return t if temporal MARK should be reserved."
781 (member mark wl-summary-reserve-mark-list))
783 ;; Refile prev destination
784 (defun wl-summary-refile-prev-destination ()
785 "Refile message to previously refiled destination."
787 (funcall (symbol-function 'wl-summary-refile)
788 (wl-summary-message-number)
789 wl-summary-buffer-prev-refile-destination)
790 (if (and (interactive-p)
791 (eq wl-summary-move-direction-downward nil))
795 (defun wl-summary-refile-prev-destination-region (beg end)
796 "Refile messages in the region to previously refiled destination."
798 (wl-summary-mark-region-subr 'wl-summary-refile
800 wl-summary-buffer-prev-refile-destination))
802 (defun wl-thread-refile-prev-destination (arg)
803 "Refile messages in the thread to previously refiled destination."
805 (wl-thread-call-region-func
806 'wl-summary-refile-prev-destination-region
809 (defun wl-summary-target-mark-refile-prev-destination ()
810 "Refile messages with target mark to previously refiled destination."
812 (let ((elem wl-summary-mark-action-list)
815 (when (eq (wl-summary-action-symbol (car elem)) 'refile)
816 (setq action (car elem))
818 (setq elem (cdr elem)))
819 (wl-summary-target-mark-set-action
822 'refile-prev-destination
823 (lambda (&rest args) wl-summary-buffer-prev-refile-destination)
829 (defsubst wl-summary-no-auto-refile-message-p (number)
830 (member (wl-summary-message-mark wl-summary-buffer-elmo-folder number)
831 wl-summary-auto-refile-skip-marks))
833 (defvar wl-auto-refile-guess-functions
834 '(wl-refile-guess-by-rule)
835 "*List of functions which is used for guessing refile destination folder.")
837 (defun wl-summary-auto-refile (&optional open-all)
838 "Set refile mark automatically according to 'wl-refile-guess-by-rule'."
840 (message "Marking...")
842 (if (and (eq wl-summary-buffer-view 'thread)
844 (wl-thread-open-all))
845 (let* ((spec (wl-summary-buffer-folder-name))
848 number dst thr-entity)
851 (setq number (wl-summary-message-number))
852 (dolist (number (cons number
853 (and (eq wl-summary-buffer-view 'thread)
854 ;; process invisible children.
855 (not (wl-thread-entity-get-opened
857 (wl-thread-get-entity number))))
858 (wl-thread-entity-get-descendant
860 (when (and (not (wl-summary-no-auto-refile-message-p
863 (wl-folder-get-realname
865 (elmo-message-entity wl-summary-buffer-elmo-folder
867 wl-auto-refile-guess-functions)))
868 (not (equal dst spec))
869 (let ((pair (assoc dst checked-dsts))
876 (wl-folder-confirm-existence
877 (wl-folder-get-elmo-folder dst))
880 (setq checked-dsts (cons (cons dst ret) checked-dsts))
882 (if (funcall (symbol-function 'wl-summary-refile) number dst)
884 (message "Marking...%d message(s)." count)))
887 (message "No message was marked.")
888 (message "Marked %d message(s)." count)))))
890 (defun wl-summary-unmark (&optional number)
891 "Unmark marks (temporary, refile, copy, delete)of current line.
892 If optional argument NUMBER is specified, unmark message specified by NUMBER."
894 (wl-summary-unset-mark number (interactive-p)))
896 (defun wl-summary-unmark-region (beg end)
900 (wl-summary-narrow-to-region beg end)
901 (goto-char (point-min))
902 (if (eq wl-summary-buffer-view 'thread)
905 (let* ((number (wl-summary-message-number))
906 (entity (wl-thread-get-entity number)))
907 (if (wl-thread-entity-get-opened entity)
908 ;; opened...unmark line.
911 (wl-summary-delete-marks-on-buffer
912 (wl-thread-get-children-msgs number))))
916 (forward-line 1))))))
918 (defun wl-summary-mark-region-subr (function beg end data)
921 (wl-summary-narrow-to-region beg end)
922 (goto-char (point-min))
923 (if (eq wl-summary-buffer-view 'thread)
926 (let* ((number (wl-summary-message-number))
927 (entity (wl-thread-get-entity number))
928 (wl-summary-move-direction-downward t)
930 (if (wl-thread-entity-get-opened entity)
931 ;; opened...delete line.
932 (funcall function nil data)
934 (setq children (wl-thread-get-children-msgs number))
936 (funcall function (pop children) data)))
939 (funcall function nil data)
940 (forward-line 1))))))
942 (defun wl-summary-target-mark-all ()
944 (wl-summary-target-mark-region (point-min) (point-max))
945 (setq wl-summary-buffer-target-mark-list
946 (elmo-folder-list-messages wl-summary-buffer-elmo-folder
949 (defun wl-summary-delete-all-mark (mark)
950 (goto-char (point-min))
952 (when (string= (wl-summary-temp-mark) mark)
955 (if (string= mark "*")
956 (setq wl-summary-buffer-target-mark-list nil)
958 (dolist (mark-info wl-summary-buffer-temp-mark-list)
959 (when (string= (nth 1 mark-info) mark)
960 (setq deleted (cons mark-info deleted))))
961 (dolist (delete deleted)
962 (setq wl-summary-buffer-temp-mark-list
963 (delq delete wl-summary-buffer-temp-mark-list))))))
965 (defun wl-summary-unmark-all ()
966 "Unmark all according to what you input."
968 (let ((unmarks (string-to-char-list (read-from-minibuffer "Unmark: ")))
972 (setq cur-mark (char-to-string (car unmarks)))
973 (wl-summary-delete-all-mark cur-mark)
974 (setq unmarks (cdr unmarks))))))
976 (defun wl-summary-target-mark-thread ()
978 (wl-thread-call-region-func 'wl-summary-target-mark-region t))
981 (product-provide (provide 'wl-action) (require 'wl-version))
983 ;;; wl-action.el ends here