summaryrefslogtreecommitdiff
path: root/lisp/mail
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2018-06-09 11:03:20 +0300
committerEli Zaretskii <eliz@gnu.org>2018-06-09 11:03:20 +0300
commitca369a8ca67a4cb279a5412cca36109e719a520e (patch)
treec65e52d0a1b68e862bef06adbc53c1a0e3a34be0 /lisp/mail
parentf716ad94a8b0417d006a86baaa1977a40574407c (diff)
downloademacs-ca369a8ca67a4cb279a5412cca36109e719a520e.tar.gz
Allow to reset Deleted flag when exporting messages in Rmail
* lisp/mail/rmailout.el (rmail-output-reset-deleted-flag): New defcustom. (rmail-output): When 'rmail-output-reset-deleted-flag' is non-nil, reset the Deleted flag of the appended messages, and if COUNT is greater than 1, do not ignore deleted messages. Update the doc string accordingly. (Bug#31271) * doc/emacs/rmail.texi (Rmail Output): Document 'rmail-output-reset-deleted-flag'. * etc/NEWS: Mention the new user option.
Diffstat (limited to 'lisp/mail')
-rw-r--r--lisp/mail/rmailout.el70
1 files changed, 50 insertions, 20 deletions
diff --git a/lisp/mail/rmailout.el b/lisp/mail/rmailout.el
index eee8805ab4c..824b1a59fb9 100644
--- a/lisp/mail/rmailout.el
+++ b/lisp/mail/rmailout.el
@@ -56,6 +56,13 @@ The function `rmail-delete-unwanted-fields' uses this, ignoring case."
regexp)
:group 'rmail-output)
+(defcustom rmail-output-reset-deleted-flag nil
+ "Non-nil means reset the \"deleted\" flag when outputting a message to a file."
+ :type '(choice (const :tag "Output with the \"deleted\" flag reset" t)
+ (const :tag "Output with the \"deleted\" flag intact" nil))
+ :version "27.1"
+ :group 'rmail-output)
+
(defun rmail-output-read-file-name ()
"Read the file name to use for `rmail-output'.
Set `rmail-default-file' to this name as well as returning it.
@@ -472,9 +479,15 @@ buffer, updates it accordingly.
This command always outputs the complete message header, even if
the header display is currently pruned.
+If `rmail-output-reset-deleted-flag' is non-nil, the message's
+deleted flag is reset in the message appended to the destination
+file. Otherwise, the appended message will remain marked as
+deleted if it was deleted before invoking this command.
+
Optional prefix argument COUNT (default 1) says to output that
many consecutive messages, starting with the current one (ignoring
-deleted messages). If `rmail-delete-after-output' is non-nil, deletes
+deleted messages, unless `rmail-output-reset-deleted-flag' is
+non-nil). If `rmail-delete-after-output' is non-nil, deletes
messages after output.
The optional third argument NOATTRIBUTE, if non-nil, says not to
@@ -533,30 +546,47 @@ from a non-Rmail buffer. In this case, COUNT is ignored."
(if (zerop rmail-total-messages)
(error "No messages to output"))
(let ((orig-count count)
- beg end)
+ beg end delete-attr-reset-p)
(while (> count 0)
- (setq beg (rmail-msgbeg rmail-current-message)
- end (rmail-msgend rmail-current-message))
- ;; All access to the buffer's local variables is now finished...
- (save-excursion
- ;; ... so it is ok to go to a different buffer.
- (if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer))
- (setq cur (current-buffer))
- (save-restriction
- (widen)
- (with-temp-buffer
- (insert-buffer-substring cur beg end)
- (if babyl-format
- (rmail-output-as-babyl file-name noattribute)
- (rmail-output-as-mbox file-name noattribute)))))
+ (when (and rmail-output-reset-deleted-flag
+ (rmail-message-deleted-p rmail-current-message))
+ (rmail-set-attribute rmail-deleted-attr-index nil)
+ (setq delete-attr-reset-p t))
+ ;; Make sure we undo our messing with the DELETED attribute.
+ (unwind-protect
+ (progn
+ (setq beg (rmail-msgbeg rmail-current-message)
+ end (rmail-msgend rmail-current-message))
+ ;; All access to the buffer's local variables is now finished...
+ (save-excursion
+ ;; ... so it is ok to go to a different buffer.
+ (if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer))
+ (setq cur (current-buffer))
+ (save-restriction
+ (widen)
+ (with-temp-buffer
+ (insert-buffer-substring cur beg end)
+ (if babyl-format
+ (rmail-output-as-babyl file-name noattribute)
+ (rmail-output-as-mbox file-name noattribute))))))
+ (if delete-attr-reset-p
+ (rmail-set-attribute rmail-deleted-attr-index t)))
(or noattribute ; mark message as "filed"
(rmail-set-attribute rmail-filed-attr-index t))
(setq count (1- count))
(let ((next-message-p
- (if rmail-delete-after-output
- (rmail-delete-forward)
- (if (> count 0)
- (rmail-next-undeleted-message 1))))
+ (if rmail-output-reset-deleted-flag
+ (progn
+ (if rmail-delete-after-output
+ (rmail-delete-message))
+ (if (> count 0)
+ (let ((msgnum rmail-current-message))
+ (rmail-next-message 1)
+ (eq rmail-current-message (1+ msgnum)))))
+ (if rmail-delete-after-output
+ (rmail-delete-forward)
+ (if (> count 0)
+ (rmail-next-undeleted-message 1)))))
(num-appended (- orig-count count)))
(if (and (> count 0) (not next-message-p))
(error "Only %d message%s appended" num-appended