(require 'wl-summary)
(eval-when-compile
+ (defalias-maybe 'wl-summary-target-mark 'ignore)
(defalias-maybe 'wl-summary-target-mark-region 'ignore))
(defsubst wl-summary-action-mark (action)
(current (wl-summary-message-number))
(action (assoc set-mark wl-summary-mark-action-list))
visible mark cur-mark)
+ (when (zerop (elmo-folder-length wl-summary-buffer-elmo-folder))
+ (error "Set mark failed"))
(prog1
(save-excursion
;; Put mark
- (setq visible (or
- ;; not-interactive and visible
- (and number (wl-summary-jump-to-msg number))
- ;; interactive
- (and (null number) current))
- number (or number current)
- cur-mark (nth 1 (wl-summary-registered-temp-mark number)))
+ (if number
+ ;; Jump to message if cursor is not on the message.
+ (when (and (setq visible (wl-summary-message-visible-p number))
+ (not (eq number current)))
+ (wl-summary-jump-to-msg number))
+ (setq visible t
+ number current))
+ (setq cur-mark (nth 1 (wl-summary-registered-temp-mark number)))
+ (unless number
+ (error "No message"))
(if (wl-summary-reserve-temp-mark-p cur-mark)
(when interactive
(error "Already marked as `%s'" cur-mark))
(setq data (funcall (wl-summary-action-argument-function action)
(wl-summary-action-symbol action)
number)))
+ ;; Unset the current mark.
(wl-summary-unset-mark number)
- (when visible
- (wl-summary-mark-line set-mark)
- (when wl-summary-highlight
- (wl-highlight-summary-current-line))
- (when data
- (wl-summary-print-argument number data)))
;; Set action.
(funcall (wl-summary-action-set-function action)
number
(wl-summary-action-mark action)
data)
+ (when visible
+ (wl-summary-put-temp-mark set-mark)
+ (when wl-summary-highlight
+ (wl-highlight-summary-current-line))
+ (when data
+ (wl-summary-print-argument number data)))
(set-buffer-modified-p nil)
;; Return value.
number))
(cons number wl-summary-buffer-target-mark-list))))
(defun wl-summary-unregister-target-mark (number)
- (delq number wl-summary-buffer-target-mark-list))
+ (setq wl-summary-buffer-target-mark-list
+ (delq number wl-summary-buffer-target-mark-list)))
(defun wl-summary-have-target-mark-p (number)
(memq number wl-summary-buffer-target-mark-list))
(defun wl-summary-target-mark-set-action (action)
(unless (eq (wl-summary-action-symbol action) 'target-mark)
+ (unless wl-summary-buffer-target-mark-list (error "no target"))
(save-excursion
(goto-char (point-min))
(let ((numlist wl-summary-buffer-number-list)
(let (wl-summary-buffer-disp-msg)
(when (setq number (wl-summary-message-number))
(wl-summary-set-mark (wl-summary-action-mark action)
- number nil data)
+ nil nil data)
(setq wl-summary-buffer-target-mark-list
(delq number wl-summary-buffer-target-mark-list)))))
(forward-line 1))
(delq elem wl-summary-buffer-temp-mark-list))))
(defun wl-summary-registered-temp-mark (number)
- (assq number wl-summary-buffer-temp-mark-list))
+ (and wl-summary-buffer-temp-mark-list
+ (assq number wl-summary-buffer-temp-mark-list)))
(defun wl-summary-collect-temp-mark (mark &optional begin end)
(if (or begin end)
mark-list)))
;; Unset mark
-(defun wl-summary-unset-mark (&optional number interactive)
+(defun wl-summary-unset-mark (&optional number interactive force)
"Unset temporary mark of the message with NUMBER.
NUMBER is the message number to unset the mark.
If not specified, the message on the cursor position is treated.
Optional INTERACTIVE is non-nil when it should be called interactively.
+If optional FORCE is non-nil, remove scored mark too.
Return number if put mark succeed"
(interactive)
(save-excursion
(let ((buffer-read-only nil)
visible mark action)
(if number
- (setq visible (wl-summary-jump-to-msg number))
- (setq visible t))
- (setq number (or number (wl-summary-message-number)))
+ ;; Jump to message
+ (when (and (setq visible (wl-summary-message-visible-p number))
+ (not (eq number (wl-summary-message-number))))
+ (wl-summary-jump-to-msg number))
+ (setq visible t
+ number (wl-summary-message-number)))
+ (setq mark (wl-summary-temp-mark))
+ ;; Remove from temporal mark structure.
+ (wl-summary-unregister-target-mark number)
+ (wl-summary-unregister-temp-mark number)
;; Delete mark on buffer.
(when visible
- (setq mark (wl-summary-temp-mark))
(unless (string= mark " ")
- (delete-backward-char 1)
- (insert (or (wl-summary-get-score-mark number)
- " "))
+ (wl-summary-put-temp-mark
+ (or (unless force (wl-summary-get-score-mark number))
+ " "))
(setq action (assoc mark wl-summary-mark-action-list))
(when wl-summary-highlight
(wl-highlight-summary-current-line))
(when (wl-summary-action-argument-function action)
(wl-summary-remove-argument)))
- (set-buffer-modified-p nil))
- ;; Remove from temporal mark structure.
- (wl-summary-unregister-target-mark number)
- (wl-summary-unregister-temp-mark number)))
+ (set-buffer-modified-p nil))))
;; Move the cursor.
;; (if (or interactive (interactive-p))
;; (if (eq wl-summary-move-direction-downward nil)
refiles
(if (eq folder-name 'null)
'null
- (wl-folder-get-elmo-folder folder-name))
- (wl-summary-buffer-msgdb)
- (not (null (cdr dst-msgs)))
- nil ; no-delete
- nil ; same-number
- t))
+ (wl-folder-get-elmo-folder folder-name))))
(error nil))
(when result ; succeeded.
;; update buffer.
;; Refile action
(defun wl-summary-set-action-refile (number mark data)
- (let ((policy (wl-get-assoc-list-value wl-refile-policy-alist
- (wl-summary-buffer-folder-name)))
- (elem wl-summary-mark-action-list))
- (if (eq policy 'copy)
- (while elem
- (when (eq (wl-summary-action-symbol (car elem)) 'copy)
- (wl-summary-register-temp-mark number
- (wl-summary-action-mark (car elem))
- data)
- (setq elem nil))
- (setq elem (cdr elem)))
- (wl-summary-register-temp-mark number mark data)
- (setq wl-summary-buffer-prev-refile-destination data))))
+ (when (null data)
+ (error "Destination folder is empty"))
+ (wl-summary-register-temp-mark number mark data)
+ (setq wl-summary-buffer-prev-refile-destination data))
(defun wl-summary-get-refile-destination (action number)
"Decide refile destination."
(setq result (elmo-folder-move-messages
wl-summary-buffer-elmo-folder
(cdr (car dst-msgs))
- (wl-folder-get-elmo-folder
- (car (car dst-msgs)))
- (wl-summary-buffer-msgdb)
- (not (null (cdr dst-msgs)))
- nil ; no-delete
- nil ; same-number
- t))
+ (wl-folder-get-elmo-folder (car (car dst-msgs)))))
(error nil))
(if result ; succeeded.
(progn
;; update buffer.
(wl-summary-delete-messages-on-buffer (cdr (car dst-msgs)))
(setq wl-summary-buffer-temp-mark-list
- (wl-delete-associations
+ (wl-delete-associations
(cdr (car dst-msgs))
wl-summary-buffer-temp-mark-list)))
(setq failures
(+ failures (length (cdr (car dst-msgs))))))
(setq dst-msgs (cdr dst-msgs)))
(elmo-progress-clear 'elmo-folder-move-messages)
+ (if (<= failures 0)
+ (message "Refiling messages...done"))
failures)))
;; Copy action
(setq result nil)
(condition-case nil
(setq result (elmo-folder-move-messages
- wl-summary-buffer-elmo-folder
- (cdr (car dst-msgs))
- (wl-folder-get-elmo-folder
- (car (car dst-msgs)))
- (wl-summary-buffer-msgdb)
- (not (null (cdr dst-msgs)))
- t ; t is no-delete (copy)
- nil ; same-number
- t))
+ wl-summary-buffer-elmo-folder
+ (cdr (car dst-msgs))
+ (wl-folder-get-elmo-folder (car (car dst-msgs)))
+ 'no-delete))
(error nil))
(if result ; succeeded.
(progn
;; update buffer.
(wl-summary-delete-copy-marks-on-buffer (cdr (car dst-msgs)))
(setq wl-summary-buffer-temp-mark-list
- (wl-delete-associations
+ (wl-delete-associations
(cdr (car dst-msgs))
wl-summary-buffer-temp-mark-list)))
(setq failures
(+ failures (length (cdr (car dst-msgs))))))
(setq dst-msgs (cdr dst-msgs)))
(elmo-progress-clear 'elmo-folder-move-messages)
+ (if (<= failures 0)
+ (message "Copying messages...done"))
failures)))
;; Prefetch.
(defun wl-summary-exec-action-prefetch (mark-list)
(save-excursion
- (let* ((buffer-read-only nil)
- (count 0)
+ (let* ((count 0)
(length (length mark-list))
(mark-list-copy (copy-sequence mark-list))
(pos (point))
- (failures 0)
- new-mark)
+ (failures 0))
(dolist (mark-info mark-list-copy)
(message "Prefetching...(%d/%d)"
(setq count (+ 1 count)) length)
- (setq new-mark (wl-summary-prefetch-msg (car mark-info)))
- (if new-mark
+ (if (wl-summary-prefetch-msg (car mark-info))
(progn
(wl-summary-unset-mark (car mark-info))
- (when (wl-summary-jump-to-msg (car mark-info))
- (wl-summary-persistent-mark) ; move
- (delete-backward-char 1)
- (insert new-mark)
- (when wl-summary-highlight
- (wl-highlight-summary-current-line))
- (save-excursion
- (goto-char pos)
- (sit-for 0))))
+ (sit-for 0))
(incf failures)))
(message "Prefetching...done")
0)))
;; Resend.
(defun wl-summary-get-resend-address (action number)
"Decide resend address."
- (wl-complete-field-to "Resend message to: "))
+ (wl-address-read-from-minibuffer "Resend message to: "))
(defun wl-summary-exec-action-resend (mark-list)
(let ((failure 0))
(goto-char beg)
(when (looking-at "From ")
(replace-match "X-From-Line: ")))
+ (run-hooks 'wl-summary-resend-hook)
;; Send it.
(wl-draft-dispatch-message)
(kill-buffer (current-buffer)))
(save-excursion
(save-restriction
(let (numbers)
- (narrow-to-region (or begin (point-min))(or end (point-max)))
+ (wl-summary-narrow-to-region (or begin (point-min))(or end (point-max)))
(goto-char (point-min))
;; for thread...
(if (eq wl-summary-buffer-view 'thread)
- (let (number entity mark-info)
+ (let (number entity)
(while (not (eobp))
(setq numbers (cons (wl-summary-message-number) numbers)
entity (wl-thread-get-entity number))
(dolist (msg (wl-thread-get-children-msgs number))
(setq numbers (cons msg numbers))))
(forward-line 1)))
- (let (number mark-info)
+ (let (number)
(while (not (eobp))
(setq numbers (cons (wl-summary-message-number) numbers))
(forward-line 1))))
- numbers))))
+ (nreverse (delq nil numbers))))))
(defun wl-summary-exec (&optional numbers)
(interactive)
(let ((failures 0)
collected pair action modified)
(dolist (action wl-summary-mark-action-list)
- (setq collected (cons (cons
+ (setq collected (cons (cons
(wl-summary-action-mark action)
nil) collected)))
(dolist (mark-info wl-summary-buffer-temp-mark-list)
- (if numbers
- (when (memq (nth 0 mark-info) numbers)
- (setq pair (assoc (nth 1 mark-info) collected)))
- (setq pair (assoc (nth 1 mark-info) collected)))
- (setq pair (assoc (nth 1 mark-info) collected))
- (setcdr pair (cons mark-info (cdr pair))))
+ (setq pair
+ (when (or (null numbers)
+ (memq (nth 0 mark-info) numbers))
+ (assoc (nth 1 mark-info) collected)))
+ (if pair
+ (setcdr pair (cons mark-info (cdr pair)))))
;; collected is a pair of
;; mark-string and a list of mark-info
(dolist (pair collected)
(setq wl-message-buffer nil))
(set-buffer-modified-p nil)
(when (> failures 0)
- (format "%d execution(s) were failed" failures))))
+ (message "%d execution(s) were failed" failures))))
(defun wl-summary-exec-region (beg end)
(interactive "r")
default)
'wl-folder-complete-folder
nil nil (or init wl-default-spec)
- 'wl-read-folder-hist)))
+ 'wl-read-folder-history)))
(if (or (string= fld wl-default-spec)
(string= fld ""))
(setq fld default))
(search-forward "\r")
(forward-char -1)
(setq re (point))
- (setq c 0)
- (while (< c len)
- (forward-char -1)
- (setq c (+ c (char-width (following-char)))))
- (and (> c len) (setq folder (concat " " folder)))
- (setq rs (point))
- (when wl-summary-width
- (put-text-property rs re 'invisible t))
+ (let ((width (cond (wl-summary-width
+ (1- wl-summary-width))
+ (wl-summary-print-argument-within-window
+ (1- (window-width)))))
+ (c (current-column))
+ (padding 0))
+ (if (and width (> (+ c len) width))
+ (progn
+ (move-to-column width)
+ (setq c (current-column))
+ (while (> (+ c len) width)
+ (forward-char -1)
+ (setq c (current-column)))
+ (when (< (+ c len) width)
+ (setq folder (concat " " folder)))
+ (setq rs (point))
+ (put-text-property rs re 'invisible t))
+ (when (and width
+ (> (setq padding (- width len c)) 0))
+ (setq folder (concat (make-string padding ?\ )
+ folder)))
+ (setq rs (1- re))))
(put-text-property rs re 'wl-summary-action-argument t)
(goto-char re)
(wl-highlight-action-argument-string folder)
"Return t if temporal MARK should be reserved."
(member mark wl-summary-reserve-mark-list))
+;; Refile prev destination
(defun wl-summary-refile-prev-destination ()
"Refile message to previously refiled destination."
(interactive)
(funcall (symbol-function 'wl-summary-refile)
- wl-summary-buffer-prev-refile-destination
- (wl-summary-message-number))
- (if (eq wl-summary-move-direction-downward nil)
+ (wl-summary-message-number)
+ wl-summary-buffer-prev-refile-destination)
+ (if (and (interactive-p)
+ (eq wl-summary-move-direction-downward nil))
(wl-summary-prev)
(wl-summary-next)))
-(defsubst wl-summary-no-auto-refile-message-p (msg)
- (member (elmo-msgdb-get-mark (wl-summary-buffer-msgdb) msg)
+(defun wl-summary-refile-prev-destination-region (beg end)
+ "Refile messages in the region to previously refiled destination."
+ (interactive "r")
+ (wl-summary-mark-region-subr 'wl-summary-refile
+ beg end
+ wl-summary-buffer-prev-refile-destination))
+
+(defun wl-thread-refile-prev-destination (arg)
+ "Refile messages in the thread to previously refiled destination."
+ (interactive "P")
+ (wl-thread-call-region-func
+ 'wl-summary-refile-prev-destination-region
+ arg))
+
+(defun wl-summary-target-mark-refile-prev-destination ()
+ "Refile messages with target mark to previously refiled destination."
+ (interactive)
+ (let ((elem wl-summary-mark-action-list)
+ action)
+ (while elem
+ (when (eq (wl-summary-action-symbol (car elem)) 'refile)
+ (setq action (car elem))
+ (setq elem nil))
+ (setq elem (cdr elem)))
+ (wl-summary-target-mark-set-action
+ (list
+ (car action)
+ 'refile-prev-destination
+ (lambda (&rest args) wl-summary-buffer-prev-refile-destination)
+ (nth 2 action)
+ (nth 3 action)
+ (nth 4 action)
+ (nth 6 action)))))
+
+(defsubst wl-summary-no-auto-refile-message-p (number)
+ (member (wl-summary-message-mark wl-summary-buffer-elmo-folder number)
wl-summary-auto-refile-skip-marks))
+(defvar wl-auto-refile-guess-functions
+ '(wl-refile-guess-by-rule)
+ "*List of functions which is used for guessing refile destination folder.")
+
(defun wl-summary-auto-refile (&optional open-all)
"Set refile mark automatically according to 'wl-refile-guess-by-rule'."
(interactive "P")
number))
(setq dst
(wl-folder-get-realname
- (wl-refile-guess-by-rule
- (elmo-msgdb-overview-get-entity
- number (wl-summary-buffer-msgdb)))))
+ (wl-refile-guess
+ (elmo-message-entity wl-summary-buffer-elmo-folder
+ number)
+ wl-auto-refile-guess-functions)))
(not (equal dst spec))
(let ((pair (assoc dst checked-dsts))
ret)
(interactive)
(wl-summary-unset-mark number (interactive-p)))
-(defun wl-summary-target-mark (&optional number)
- "Put target mark '*' on current message.
-If optional argument NUMBER is specified, mark message specified by NUMBER."
- (interactive)
- (wl-summary-set-mark "*" number (interactive-p)))
-
(defun wl-summary-unmark-region (beg end)
(interactive "r")
(save-excursion
(save-restriction
- (narrow-to-region beg end)
+ (wl-summary-narrow-to-region beg end)
(goto-char (point-min))
(if (eq wl-summary-buffer-view 'thread)
(progn
(defun wl-summary-mark-region-subr (function beg end data)
(save-excursion
(save-restriction
- (narrow-to-region beg end)
+ (wl-summary-narrow-to-region beg end)
(goto-char (point-min))
(if (eq wl-summary-buffer-view 'thread)
(progn
children)
(if (wl-thread-entity-get-opened entity)
;; opened...delete line.
- (funcall function number data)
+ (funcall function nil data)
;; closed
(setq children (wl-thread-get-children-msgs number))
(while children
(funcall function (pop children) data)))
(forward-line 1))))
(while (not (eobp))
- (funcall function (wl-summary-message-number) data)
+ (funcall function nil data)
(forward-line 1))))))
(defun wl-summary-target-mark-all ()
(interactive)
- (wl-summary-target-mark-region (point-min) (point-max))
- (setq wl-summary-buffer-target-mark-list
- (mapcar 'car
- (elmo-msgdb-get-number-alist (wl-summary-buffer-msgdb)))))
+ (wl-summary-target-mark-region (point-min) (point-max)))
(defun wl-summary-delete-all-mark (mark)
(goto-char (point-min))
(when (string= (wl-summary-temp-mark) mark)
(wl-summary-unmark))
(forward-line 1))
- (let (deleted)
- (dolist (mark-info wl-summary-buffer-temp-mark-list)
- (when (string= (nth 1 mark-info) mark)
- (setq deleted (cons mark-info deleted))))
- (dolist (delete deleted)
- (setq wl-summary-buffer-temp-mark-list
- (delq delete wl-summary-buffer-temp-mark-list)))))
+ (if (string= mark "*")
+ (setq wl-summary-buffer-target-mark-list nil)
+ (let (deleted)
+ (dolist (mark-info wl-summary-buffer-temp-mark-list)
+ (when (string= (nth 1 mark-info) mark)
+ (setq deleted (cons mark-info deleted))))
+ (dolist (delete deleted)
+ (setq wl-summary-buffer-temp-mark-list
+ (delq delete wl-summary-buffer-temp-mark-list))))))
(defun wl-summary-unmark-all ()
"Unmark all according to what you input."