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)
56 "Set temporary mark SET-MARK on the message with NUMBER.
57 NUMBER is the message number to set the mark on.
58 INTERACTIVE is set as t if it have to run interactively.
59 DATA is passed to the set-action function of the action as an argument.
60 Return number if put mark succeed"
61 (let* ((set-mark (or set-mark
62 (completing-read "Mark: " wl-summary-mark-action-list)))
63 (current (wl-summary-message-number))
64 (action (assoc set-mark wl-summary-mark-action-list))
65 visible mark cur-mark)
66 (when (zerop (elmo-folder-length wl-summary-buffer-elmo-folder))
67 (error "Set mark failed"))
72 ;; Jump to message if cursor is not on the message.
73 (when (and (setq visible (wl-summary-message-visible-p number))
74 (not (eq number current)))
75 (wl-summary-jump-to-msg number))
78 (setq cur-mark (nth 1 (wl-summary-registered-temp-mark number)))
81 (if (wl-summary-reserve-temp-mark-p cur-mark)
83 (error "Already marked as `%s'" cur-mark))
84 (when (and interactive
86 (wl-summary-action-argument-function action))
87 (setq data (funcall (wl-summary-action-argument-function action)
88 (wl-summary-action-symbol action)
90 ;; Unset the current mark.
91 (wl-summary-unset-mark number)
93 (funcall (wl-summary-action-set-function action)
95 (wl-summary-action-mark action)
98 (wl-summary-put-temp-mark set-mark)
99 (when wl-summary-highlight
100 (wl-highlight-summary-current-line))
102 (wl-summary-print-argument number data)))
103 (when (and (eq wl-summary-buffer-view 'thread)
105 (wl-thread-open-children number))
106 (set-buffer-modified-p nil)
111 (if (eq wl-summary-move-direction-downward nil)
113 (wl-summary-next))))))
115 (defun wl-summary-register-target-mark (number mark data)
116 (or (memq number wl-summary-buffer-target-mark-list)
117 (setq wl-summary-buffer-target-mark-list
118 (cons number wl-summary-buffer-target-mark-list))))
120 (defun wl-summary-unregister-target-mark (number)
121 (setq wl-summary-buffer-target-mark-list
122 (delq number wl-summary-buffer-target-mark-list)))
124 (defun wl-summary-have-target-mark-p (number)
125 (memq number wl-summary-buffer-target-mark-list))
127 (defun wl-summary-target-mark-set-action (action)
128 (unless (eq (wl-summary-action-symbol action) 'target-mark)
129 (unless wl-summary-buffer-target-mark-list (error "no target"))
131 (goto-char (point-min))
132 (let ((numlist wl-summary-buffer-number-list)
134 ;; use firstly marked message.
135 (when (wl-summary-action-argument-function action)
137 (if (memq (car numlist) wl-summary-buffer-target-mark-list)
138 (setq number (car numlist)
140 (setq numlist (cdr numlist)))
141 (wl-summary-jump-to-msg number)
142 (setq data (funcall (wl-summary-action-argument-function action)
143 (wl-summary-action-symbol action) number)))
145 (when (string= (wl-summary-temp-mark) "*")
146 (let (wl-summary-buffer-disp-msg)
147 (when (setq number (wl-summary-message-number))
148 (wl-summary-set-mark (wl-summary-action-mark action)
150 (setq wl-summary-buffer-target-mark-list
151 (delq number wl-summary-buffer-target-mark-list)))))
153 (setq mlist wl-summary-buffer-target-mark-list)
155 (wl-summary-register-temp-mark (car mlist)
156 (wl-summary-action-mark action) data)
157 (setq wl-summary-buffer-target-mark-list
158 (delq (car mlist) wl-summary-buffer-target-mark-list))
159 (setq mlist (cdr mlist)))))))
161 ;; wl-summary-buffer-temp-mark-list specification
162 ;; ((1 "D" nil)(2 "o" "+fuga")(3 "O" "+hoge"))
163 (defun wl-summary-register-temp-mark (number mark mark-info)
164 (let ((elem (assq number wl-summary-buffer-temp-mark-list)))
165 (setq wl-summary-buffer-temp-mark-list
166 (delq elem wl-summary-buffer-temp-mark-list)))
167 (setq wl-summary-buffer-temp-mark-list
168 (cons (list number mark mark-info) wl-summary-buffer-temp-mark-list)))
170 (defun wl-summary-unregister-temp-mark (number)
171 (let ((elem (assq number wl-summary-buffer-temp-mark-list)))
172 (setq wl-summary-buffer-temp-mark-list
173 (delq elem wl-summary-buffer-temp-mark-list))))
175 (defun wl-summary-registered-temp-mark (number)
176 (and wl-summary-buffer-temp-mark-list
177 (assq number wl-summary-buffer-temp-mark-list)))
179 (defun wl-summary-collect-temp-mark (mark &optional begin end)
184 (narrow-to-region (or begin (point-min))(or end (point-max)))
185 (goto-char (point-min))
187 (if (eq wl-summary-buffer-view 'thread)
188 (let (number entity mark-info)
190 (setq number (wl-summary-message-number)
191 entity (wl-thread-get-entity number)
192 mark-info (wl-summary-registered-temp-mark number))
193 ;; toplevel message mark.
194 (when (string= (nth 1 mark-info) mark)
195 (setq mark-list (cons mark-info mark-list)))
196 ;; When thread is closed...children should also be checked.
197 (unless (wl-thread-entity-get-opened entity)
198 (dolist (msg (wl-thread-get-children-msgs number))
199 (setq mark-info (wl-summary-registered-temp-mark
201 (when (string= (nth 1 mark-info) mark)
202 (setq mark-list (cons mark-info mark-list)))))
204 (let (number mark-info)
206 (setq number (wl-summary-message-number)
207 mark-info (wl-summary-registered-temp-mark number))
208 (when (string= (nth 1 mark-info) mark)
209 (setq mark-list (cons mark-info mark-list)))
213 (dolist (mark-info wl-summary-buffer-temp-mark-list)
214 (when (string= (nth 1 mark-info) mark)
215 (setq mark-list (cons mark-info mark-list))))
219 (defun wl-summary-unset-mark (&optional number interactive force)
220 "Unset temporary mark of the message with NUMBER.
221 NUMBER is the message number to unset the mark.
222 If not specified, the message on the cursor position is treated.
223 Optional INTERACTIVE is non-nil when it should be called interactively.
224 If optional FORCE is non-nil, remove scored mark too.
225 Return number if put mark succeed"
229 (let ((buffer-read-only nil)
233 (when (and (setq visible (wl-summary-message-visible-p number))
234 (not (eq number (wl-summary-message-number))))
235 (wl-summary-jump-to-msg number))
237 number (wl-summary-message-number)))
238 (setq mark (wl-summary-temp-mark))
239 ;; Remove from temporal mark structure.
240 (wl-summary-unregister-target-mark number)
241 (wl-summary-unregister-temp-mark number)
242 ;; Delete mark on buffer.
244 (unless (string= mark " ")
245 (wl-summary-put-temp-mark
246 (or (unless force (wl-summary-get-score-mark number))
248 (setq action (assoc mark wl-summary-mark-action-list))
249 (when wl-summary-highlight
250 (wl-highlight-summary-current-line))
251 (when (wl-summary-action-argument-function action)
252 (wl-summary-remove-argument)))
253 (set-buffer-modified-p nil))))
255 ;; (if (or interactive (interactive-p))
256 ;; (if (eq wl-summary-move-direction-downward nil)
258 ;; (wl-summary-next))))
261 (defun wl-summary-make-destination-numbers-list (mark-list)
262 (let (dest-numbers dest-number)
263 (dolist (elem mark-list)
264 (setq dest-number (assoc (nth 2 elem) dest-numbers))
266 (unless (memq (car elem) (cdr dest-number))
267 (nconc dest-number (list (car elem))))
268 (setq dest-numbers (nconc dest-numbers
274 (defun wl-summary-move-mark-list-messages (mark-list folder-name message)
278 (let ((start (point))
279 (refiles (mapcar 'car mark-list))
282 dst-msgs ; loop counter
285 (setq refile-len (length refiles))
286 (goto-char start) ; avoid moving cursor to
289 (when (> refile-len elmo-display-progress-threshold)
290 (elmo-progress-set 'elmo-folder-move-messages
294 (setq result (elmo-folder-move-messages
295 wl-summary-buffer-elmo-folder
297 (if (eq folder-name 'null)
299 (wl-folder-get-elmo-folder folder-name))))
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)
441 (error "Destination folder is empty"))
442 (wl-summary-register-temp-mark number mark data)
443 (setq wl-summary-buffer-prev-refile-destination data))
445 (defun wl-summary-get-refile-destination (action number)
446 "Decide refile destination."
447 (wl-summary-get-refile-destination-subr action number t))
449 (defun wl-summary-exec-action-refile (mark-list)
451 (let ((start (point))
453 (refile-len (length mark-list))
456 (setq dst-msgs (wl-summary-make-destination-numbers-list mark-list))
457 (goto-char start) ; avoid moving cursor to the bottom line.
458 (when (> refile-len elmo-display-progress-threshold)
459 (elmo-progress-set 'elmo-folder-move-messages
460 refile-len "Refiling messages..."))
461 (dolist (pair dst-msgs)
462 (if (condition-case nil
463 (elmo-folder-move-messages
464 wl-summary-buffer-elmo-folder
466 (wl-folder-get-elmo-folder (car pair)))
470 (wl-summary-delete-messages-on-buffer (cdr pair))
471 (setq wl-summary-buffer-temp-mark-list
472 (wl-delete-associations
474 wl-summary-buffer-temp-mark-list)))
475 (setq failures (+ failures (length (cdr pair))))))
476 (elmo-progress-clear 'elmo-folder-move-messages)
478 (message "Refiling messages...done"))
482 (defun wl-summary-get-copy-destination (action number)
483 (wl-summary-get-refile-destination-subr action number nil))
485 (defun wl-summary-exec-action-copy (mark-list)
487 (let ((start (point))
489 (refile-len (length mark-list))
493 (wl-summary-make-destination-numbers-list mark-list))
494 (goto-char start) ; avoid moving cursor to the bottom line.
495 (when (> refile-len elmo-display-progress-threshold)
496 (elmo-progress-set 'elmo-folder-move-messages
497 refile-len "Copying messages..."))
498 (dolist (pair dst-msgs)
499 (if (condition-case nil
500 (elmo-folder-move-messages
501 wl-summary-buffer-elmo-folder
503 (wl-folder-get-elmo-folder (car pair))
508 (wl-summary-delete-copy-marks-on-buffer (cdr pair))
509 (setq wl-summary-buffer-temp-mark-list
510 (wl-delete-associations
512 wl-summary-buffer-temp-mark-list)))
513 (setq failures (+ failures (length (cdr pair))))))
514 (elmo-progress-clear 'elmo-folder-move-messages)
516 (message "Copying messages...done"))
520 (defun wl-summary-exec-action-prefetch (mark-list)
523 (length (length mark-list))
524 (mark-list-copy (copy-sequence mark-list))
527 (dolist (mark-info mark-list-copy)
528 (message "Prefetching...(%d/%d)"
529 (setq count (+ 1 count)) length)
530 (if (wl-summary-prefetch-msg (car mark-info))
532 (wl-summary-unset-mark (car mark-info))
535 (message "Prefetching...done")
539 (defun wl-summary-get-resend-address (action number)
540 "Decide resend address."
541 (wl-address-read-from-minibuffer "Resend message to: "))
543 (defun wl-summary-exec-action-resend (mark-list)
545 (dolist (mark-info mark-list)
546 (if (condition-case nil
548 (wl-summary-exec-action-resend-subr (car mark-info)
552 (wl-summary-unmark (car mark-info))
556 (defun wl-summary-exec-action-resend-subr (number address)
557 "Resend the message with NUMBER to ADDRESS."
558 (message "Resending message to %s..." address)
559 (let ((folder wl-summary-buffer-elmo-folder))
561 ;; We first set up a normal mail buffer.
562 (set-buffer (get-buffer-create " *wl-draft-resend*"))
563 (set-buffer-multibyte nil)
565 (setq wl-sent-message-via nil)
566 ;; Insert our usual headers.
567 (wl-draft-insert-from-field)
568 (wl-draft-insert-date-field)
569 (insert "To: " address "\n")
570 (goto-char (point-min))
571 ;; Rename them all to "Resent-*".
572 (while (re-search-forward "^[A-Za-z]" nil t)
577 (delete-region (point) (point-max))
579 ;; Insert the message to be resent.
581 ;; elmo-message-fetch is erase current buffer before fetch message
582 (elmo-message-fetch-string folder number
583 (if wl-summary-resend-use-cache
584 (elmo-make-fetch-strategy
586 (elmo-file-cache-get-path
588 folder number 'message-id)))
589 (elmo-make-fetch-strategy 'entire))
591 (goto-char (point-min))
592 (search-forward "\n\n")
595 (narrow-to-region beg (point))
596 (wl-draft-delete-fields wl-ignored-resent-headers)
597 (goto-char (point-max)))
598 (insert mail-header-separator)
599 ;; Rename all old ("Previous-")Resent headers.
600 (while (re-search-backward "^\\(Previous-\\)*Resent-" beg t)
602 (insert "Previous-"))
603 ;; Quote any "From " lines at the beginning.
605 (when (looking-at "From ")
606 (replace-match "X-From-Line: ")))
607 (run-hooks 'wl-summary-resend-hook)
609 (wl-draft-dispatch-message)
610 (kill-buffer (current-buffer)))
611 (message "Resending message to %s...done" address)))
614 (defun wl-summary-remove-argument ()
616 (let ((inhibit-read-only t)
617 (buffer-read-only nil)
618 (buf (current-buffer))
622 (search-forward "\r")
625 (setq rs (next-single-property-change sol 'wl-summary-action-argument
627 (setq re (next-single-property-change rs 'wl-summary-action-argument
629 (put-text-property rs re 'wl-summary-action-argument nil)
630 (put-text-property rs re 'invisible nil)
632 (delete-char (- eol re)))))
634 (defun wl-summary-collect-numbers-region (begin end)
635 "Return a list of message number in the region specified by BEGIN and END."
639 (wl-summary-narrow-to-region (or begin (point-min))(or end (point-max)))
640 (goto-char (point-min))
642 (if (eq wl-summary-buffer-view 'thread)
645 (setq numbers (cons (wl-summary-message-number) numbers)
646 entity (wl-thread-get-entity number))
647 ;; When thread is closed...children should also be checked.
648 (unless (wl-thread-entity-get-opened entity)
649 (dolist (msg (wl-thread-get-children-msgs number))
650 (setq numbers (cons msg numbers))))
654 (setq numbers (cons (wl-summary-message-number) numbers))
656 (nreverse (delq nil numbers))))))
658 (defun wl-summary-exec (&optional numbers)
661 collected pair action modified)
662 (dolist (action wl-summary-mark-action-list)
663 (setq collected (cons (cons
664 (wl-summary-action-mark action)
666 (dolist (mark-info wl-summary-buffer-temp-mark-list)
668 (when (or (null numbers)
669 (memq (nth 0 mark-info) numbers))
670 (assoc (nth 1 mark-info) collected)))
672 (setcdr pair (cons mark-info (cdr pair)))))
673 ;; collected is a pair of
674 ;; mark-string and a list of mark-info
675 (dolist (pair collected)
677 (setq action (assoc (car pair) wl-summary-mark-action-list))
678 (when (wl-summary-action-exec-function action)
680 (setq failures (+ failures (funcall
681 (wl-summary-action-exec-function action)
684 (wl-summary-set-message-modified))
685 (run-hooks 'wl-summary-exec-hook)
686 ;; message buffer is not up-to-date
687 (unless (and wl-message-buffer
688 (eq (wl-summary-message-number)
689 (with-current-buffer wl-message-buffer
690 wl-message-buffer-cur-number)))
691 (wl-summary-toggle-disp-msg 'off)
692 (setq wl-message-buffer nil))
693 (set-buffer-modified-p nil)
695 (message "%d execution(s) were failed" failures))))
697 (defun wl-summary-exec-region (beg end)
700 (wl-summary-collect-numbers-region beg end)))
702 (defun wl-summary-read-folder (default &optional purpose ignore-error
704 (let ((fld (completing-read
705 (format "Folder name %s(%s): " (or purpose "")
707 'wl-folder-complete-folder
708 nil nil (or init wl-default-spec)
709 'wl-read-folder-history)))
710 (if (or (string= fld wl-default-spec)
713 (setq fld (elmo-string (wl-folder-get-realname fld)))
714 (if (string-match "\n" fld)
715 (error "Not supported folder name: %s" fld))
719 (wl-folder-confirm-existence
720 (wl-folder-get-elmo-folder
723 (wl-folder-confirm-existence (wl-folder-get-elmo-folder
727 (defun wl-summary-print-argument (msg-num data)
728 "Print action argument on line."
730 (wl-summary-remove-argument)
732 (let ((inhibit-read-only t)
733 (data (copy-sequence data))
734 (buffer-read-only nil)
736 (setq len (string-width data))
740 (search-forward "\r")
743 (let ((width (cond (wl-summary-width
744 (1- wl-summary-width))
745 (wl-summary-print-argument-within-window
746 (1- (window-width)))))
752 (move-to-column width)
753 (setq c (current-column))
754 (while (> (+ c len) width)
756 (setq c (current-column)))
757 (when (< (+ c len) width)
758 (setq data (concat " " data)))
760 (put-text-property rs re 'invisible t))
762 (> (setq padding (- width len c)) 0))
763 (setq data (concat (make-string padding ?\ ) data)))
765 (put-text-property rs re 'wl-summary-action-argument t)
767 (wl-highlight-action-argument-string data)
769 (set-buffer-modified-p nil))))))
771 (defsubst wl-summary-reserve-temp-mark-p (mark)
772 "Return t if temporal MARK should be reserved."
773 (member mark wl-summary-reserve-mark-list))
775 ;; Refile prev destination
776 (defun wl-summary-refile-prev-destination ()
777 "Refile message to previously refiled destination."
779 (funcall (symbol-function 'wl-summary-refile)
780 (wl-summary-message-number)
781 wl-summary-buffer-prev-refile-destination)
782 (if (and (interactive-p)
783 (eq wl-summary-move-direction-downward nil))
787 (defun wl-summary-refile-prev-destination-region (beg end)
788 "Refile messages in the region to previously refiled destination."
790 (wl-summary-mark-region-subr 'wl-summary-refile
792 wl-summary-buffer-prev-refile-destination))
794 (defun wl-thread-refile-prev-destination (arg)
795 "Refile messages in the thread to previously refiled destination."
797 (wl-thread-call-region-func
798 'wl-summary-refile-prev-destination-region
801 (defun wl-summary-target-mark-refile-prev-destination ()
802 "Refile messages with target mark to previously refiled destination."
804 (let ((elem wl-summary-mark-action-list)
807 (when (eq (wl-summary-action-symbol (car elem)) 'refile)
808 (setq action (car elem))
810 (setq elem (cdr elem)))
811 (wl-summary-target-mark-set-action
814 'refile-prev-destination
815 (lambda (&rest args) wl-summary-buffer-prev-refile-destination)
821 (defsubst wl-summary-no-auto-refile-message-p (number)
822 (member (wl-summary-message-mark wl-summary-buffer-elmo-folder number)
823 wl-summary-auto-refile-skip-marks))
825 (defvar wl-auto-refile-guess-functions
826 '(wl-refile-guess-by-rule)
827 "*List of functions which is used for guessing refile destination folder.")
829 (defun wl-summary-auto-refile (&optional open-all)
830 "Set refile mark automatically according to 'wl-refile-guess-by-rule'."
832 (message "Marking...")
834 (if (and (eq wl-summary-buffer-view 'thread)
836 (wl-thread-open-all))
837 (let* ((spec (wl-summary-buffer-folder-name))
840 number dst thr-entity)
843 (setq number (wl-summary-message-number))
844 (dolist (number (cons number
845 (and (eq wl-summary-buffer-view 'thread)
846 ;; process invisible children.
847 (not (wl-thread-entity-get-opened
849 (wl-thread-get-entity number))))
850 (wl-thread-entity-get-descendant
852 (when (and (not (wl-summary-no-auto-refile-message-p number))
853 (not (wl-summary-reserve-temp-mark-p
854 (nth 1 (wl-summary-registered-temp-mark number))))
856 (wl-folder-get-realname
858 (elmo-message-entity wl-summary-buffer-elmo-folder
860 wl-auto-refile-guess-functions)))
861 (not (equal dst spec))
862 (let ((pair (assoc dst checked-dsts))
869 (wl-folder-confirm-existence
870 (wl-folder-get-elmo-folder dst))
873 (setq checked-dsts (cons (cons dst ret) checked-dsts))
875 (if (funcall (symbol-function 'wl-summary-refile) number dst)
877 (message "Marking...%d message(s)." count)))
880 (message "No message was marked.")
881 (message "Marked %d message(s)." count)))))
883 (defun wl-summary-unmark (&optional number)
884 "Unmark marks (temporary, refile, copy, delete)of current line.
885 If optional argument NUMBER is specified, unmark message specified by NUMBER."
887 (wl-summary-unset-mark number (interactive-p)))
889 (defun wl-summary-unmark-region (beg end)
893 (wl-summary-narrow-to-region beg end)
894 (goto-char (point-min))
895 (if (eq wl-summary-buffer-view 'thread)
898 (let* ((number (wl-summary-message-number))
899 (entity (wl-thread-get-entity number)))
900 (if (wl-thread-entity-get-opened entity)
901 ;; opened...unmark line.
904 (wl-summary-delete-marks-on-buffer
905 (wl-thread-get-children-msgs number))))
909 (forward-line 1))))))
911 (defun wl-summary-mark-region-subr (function beg end data)
914 (wl-summary-narrow-to-region beg end)
915 (goto-char (point-min))
916 (if (eq wl-summary-buffer-view 'thread)
919 (let* ((number (wl-summary-message-number))
920 (entity (wl-thread-get-entity number))
921 (wl-summary-move-direction-downward t)
923 (if (wl-thread-entity-get-opened entity)
924 ;; opened...delete line.
925 (funcall function nil data)
927 (setq children (wl-thread-get-children-msgs number))
929 (funcall function (pop children) data)))
932 (funcall function nil data)
933 (forward-line 1))))))
935 (defun wl-summary-target-mark-all ()
937 (wl-summary-target-mark-region (point-min) (point-max)))
939 (defun wl-summary-delete-all-mark (mark)
940 (goto-char (point-min))
942 (when (string= (wl-summary-temp-mark) mark)
945 (if (string= mark "*")
946 (setq wl-summary-buffer-target-mark-list nil)
948 (dolist (mark-info wl-summary-buffer-temp-mark-list)
949 (when (string= (nth 1 mark-info) mark)
950 (setq deleted (cons mark-info deleted))))
951 (dolist (delete deleted)
952 (setq wl-summary-buffer-temp-mark-list
953 (delq delete wl-summary-buffer-temp-mark-list))))))
955 (defun wl-summary-unmark-all ()
956 "Unmark all according to what you input."
958 (let ((unmarks (string-to-char-list (read-from-minibuffer "Unmark: ")))
962 (setq cur-mark (char-to-string (car unmarks)))
963 (wl-summary-delete-all-mark cur-mark)
964 (setq unmarks (cdr unmarks))))))
966 (defun wl-summary-target-mark-thread ()
968 (wl-thread-call-region-func 'wl-summary-target-mark-region t))
971 (product-provide (provide 'wl-action) (require 'wl-version))
973 ;;; wl-action.el ends here