Skip to content

Commit

Permalink
mu4e-compose: implement mu4e-compose-supersede
Browse files Browse the repository at this point in the history
Hook up `message-supersede` which you can /supersede/ your own messages;
that is, send the message as kind-of reply to the same recipients. This
only works if you were the sender.

This should help for #2584.
  • Loading branch information
djcb committed Nov 22, 2023
1 parent e0826d1 commit 087d06c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
5 changes: 5 additions & 0 deletions NEWS.org
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
~#'mu4e-personal-or-alternative-address-p~. This only works for
[[info:(message) Wide Reply][wide-replies]].

- Another new function is ~mu4e-compose-supersede~ (not bound to any key by
default), with which you can /supersede/ your own messages; that is, send
the message as a kind-of reply to the same recipients. This only works if
you were the sender.

- The special mailing list handling is gone; ~mu4e-compose-reply~ and
~mu4e-compose-wide-reply~ should take care of that. There's also
~message-reply-to-function~ for ultimate control; see [[info:(message)
Expand Down
44 changes: 37 additions & 7 deletions mu4e/mu4e-compose.el
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ PARENT is the \"parent\" message; nil
(if (eq compose-type 'forward)
(with-temp-buffer
(insert-file-contents-literally
(mu4e-message-readable-path parent) nil nil nil t)
(mu4e-message-readable-path parent)
nil nil nil t)
(buffer-string))
(mu4e--decoded-message parent)))))
;; we handle it ourselves.
Expand All @@ -708,9 +709,23 @@ PARENT is the \"parent\" message; nil
"Message headers to hide when composing.
This is mu4e's version of `message-hidden-headers'.")

(defun mu4e--message-is-yours-p (func &rest args)
"Mu4e advise for `message-is-yours'.
Is this address yours?"
(if (mu4e-running-p)
(let ((sender (message-fetch-field "from"))
(from (message-fetch-field "sender")))
(message "yours? %s %s" sender from)
(or (and sender (mu4e-personal-or-alternative-address-p
(car (mail-header-parse-address sender))))
(and from (mu4e-personal-or-alternative-address-p
(car (mail-header-parse-address from))))))
(apply func args)))

(defun mu4e--compose-setup-post (compose-type &optional parent)
"Prepare the new message buffer."
(mu4e-compose-mode)

;; remember some variables, e.g for user hooks.
(setq-local
mu4e-compose-parent-message parent
Expand Down Expand Up @@ -757,13 +772,15 @@ all others (the message replied to / forwarded / ...).
COMPOSE-FUNC is a function / lambda to create the specific type
of message."
(cl-assert (member compose-type '(reply forward edit new)))

(unless (mu4e-running-p) (mu4e 'background)) ;; start if needed
(let* ((parent
(when (member compose-type '(reply forward edit))
(mu4e-message-at-point)))
(mu4e-compose-parent-message parent)
(mu4e-compose-type compose-type))

(advice-add 'message-is-yours-p :around #'mu4e--message-is-yours-p)

(run-hooks 'mu4e-compose-pre-hook) ;; run the pre-hook. Still useful?
(mu4e--context-autoswitch parent mu4e-compose-context-policy)
(with-current-buffer
Expand All @@ -782,22 +799,33 @@ of message."
'new (lambda (_parent) (message-mail))))

;;;###autoload
(defun mu4e-compose-reply (&optional wide)
"Reply to the message at point."
(defun mu4e-compose-reply (&optional reply-type)
"Reply to the message at point with REPLY-TYPE.
REPLY-TYPE is either nil (normal reply), \='wide or \='supersede."
(interactive)
(cl-assert (when reply-type (member reply-type '(wide supersede))))
(mu4e--compose-setup
'reply
(lambda (parent)
(mu4e--decoded-message parent)
(message-reply nil wide)
(pcase reply-type
('wide (message-reply nil t))
('supersede (message-supersede))
(_ (message-reply))) ;; vanilla reply
(message-goto-body)
(insert (mu4e--compose-cite parent)))))

;;;###autoload
(defun mu4e-compose-wide-reply ()
"Reply to the message at point to all recipients."
(interactive)
(mu4e-compose-reply 'wide))
(interactive) (mu4e-compose-reply 'wide))

;;;###autoload
(defun mu4e-compose-supersede ()
"Supersede message at point.
Message must be from current user, as determined through
`mu4e-personal-or-alternative-address-p'."
(interactive) (mu4e-compose-reply 'supersede))

;;;###autoload
(defun mu4e-compose-forward ()
Expand Down Expand Up @@ -838,6 +866,8 @@ of message."
(with-temp-buffer
(insert-file-contents path)
(message-resend address))))



;;; Compose Mail

Expand Down
11 changes: 11 additions & 0 deletions mu4e/mu4e.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,16 @@ For more information, see @ref{(message) Forwarding}.
To influence the way a message is forwarded, you can use the variables
@code{message-forward-as-mime} and @code{message-forward-show-mml}.

@subsection Supersede

Occasionally, it can be useful to ``supersede'' a message you sent; this is
somewhat like a wide-reply, but with the all the same recipients as the original
message, as determined by @code{mu4e-personal-or-alternative-address-p}.

For this, there @t{mu4e-compose-supersede} (no default keybinding).

This wraps @code{message-supersede}.

@subsection Resend

You can re-send some existing message with @t{mu4e-compose-resend} from within
Expand All @@ -1689,6 +1699,7 @@ the headers view or when looking at some specific message.
This re-sends the message without letting you edit it, as per @ref{(message)
Resending}.


@node Composer Keybindings
@section Keybindings

Expand Down

0 comments on commit 087d06c

Please sign in to comment.