mu4e: update mu4e-compose-context-switch
Update mu4e-compose-context-switch: 1) attempt to update the message signature as well 2) remove the (no longer working) code to try to move the underlying file (which was a bit too fragile) (see issue: #2140)
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
;;; mu4e-compose.el -- part of mu4e -*- lexical-binding: t -*-
|
;;; mu4e-compose.el -- part of mu4e -*- lexical-binding: t -*-
|
||||||
|
|
||||||
;; Copyright (C) 2011-2020 Dirk-Jan C. Binnema
|
;; Copyright (C) 2011-2021 Dirk-Jan C. Binnema
|
||||||
|
|
||||||
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
@ -629,49 +629,40 @@ are optional."
|
|||||||
(defun mu4e-compose-context-switch (&optional force name)
|
(defun mu4e-compose-context-switch (&optional force name)
|
||||||
"Change the context for the current draft message.
|
"Change the context for the current draft message.
|
||||||
|
|
||||||
Same as `mu4e-context-switch' but does two things after switching
|
With NAME, switch to the context with NAME, and with FORCE non-nil,
|
||||||
when the buffer is in `mu4e-compose-mode':
|
switch even if the switch is to the same context.
|
||||||
- Changes the \"From\" field to the email address of the new context
|
|
||||||
- Moves the current message to the draft folder of the new context"
|
Like `mu4e-context-switch' but with some changes after switching:
|
||||||
|
1. Update the From and Organization headers as per the new context
|
||||||
|
2. Update the message-signature as per the new context.
|
||||||
|
|
||||||
|
Unlike some earlier version of this function, does _not_ update
|
||||||
|
the draft folder for the messages, as that would require changing
|
||||||
|
the file under our feet, which is a bit fragile."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(if (derived-mode-p 'mu4e-compose-mode)
|
|
||||||
(let ((old-context (mu4e-context-current))
|
(unless (derived-mode-p 'mu4e-compose-mode)
|
||||||
(has-file (file-exists-p (buffer-file-name))))
|
(mu4e-error "Only available in mu4e compose buffers"))
|
||||||
|
|
||||||
|
(let ((old-context (mu4e-context-current)))
|
||||||
(unless (and name (not force) (eq old-context name))
|
(unless (and name (not force) (eq old-context name))
|
||||||
(when (or (not has-file)
|
|
||||||
(not (buffer-modified-p))
|
|
||||||
(y-or-n-p
|
|
||||||
"Draft must be saved before switching context. Save?"))
|
|
||||||
(unless (and (not force)
|
(unless (and (not force)
|
||||||
(eq old-context (mu4e-context-switch nil name)))
|
(eq old-context (mu4e-context-switch nil name)))
|
||||||
|
(save-excursion
|
||||||
;; Change From / Organization if needed.
|
;; Change From / Organization if needed.
|
||||||
(message-replace-header "Organization"
|
(message-replace-header "Organization"
|
||||||
(or (message-make-organization) "")
|
(or (message-make-organization) "")
|
||||||
'("Subject")) ;; keep in same place
|
'("Subject")) ;; keep in same place
|
||||||
(message-replace-header "From"
|
(message-replace-header "From"
|
||||||
(or (mu4e~draft-from-construct) ""))
|
(or (mu4e~draft-from-construct) ""))
|
||||||
|
;; Update signature.
|
||||||
;; Move message to mu4e-draft-folder
|
(when (message-goto-signature) ;; delete old signature.
|
||||||
(if has-file
|
(if message-signature-insert-empty-line
|
||||||
(progn (save-buffer)
|
(forward-line -2) (forward-line -1))
|
||||||
(let ((msg-id (message-fetch-field "Message-ID"))
|
(delete-region (point) (point-max)))
|
||||||
(buf (current-buffer)))
|
(if (and mu4e-compose-signature-auto-include mu4e-compose-signature)
|
||||||
;; Remove the <>
|
(let ((message-signature mu4e-compose-signature))
|
||||||
(when (and msg-id (string-match "<\\(.*\\)>" msg-id))
|
(save-excursion (message-insert-signature)))))))))
|
||||||
(save-window-excursion
|
|
||||||
(mu4e--server-move (match-string 1 msg-id)
|
|
||||||
mu4e-drafts-folder nil t)
|
|
||||||
(kill-buffer buf))))) ;; Kill previous buffer
|
|
||||||
;; which points to wrong
|
|
||||||
;; file No file, just
|
|
||||||
;; change the buffer file
|
|
||||||
;; name
|
|
||||||
(setq buffer-file-name
|
|
||||||
(format "%s/%s/cur/%s"
|
|
||||||
(mu4e-root-maildir) (mu4e-get-drafts-folder)
|
|
||||||
(file-name-nondirectory (buffer-file-name)))))))))
|
|
||||||
;; Just do the standad switch
|
|
||||||
(mu4e-context-switch force name)))
|
|
||||||
|
|
||||||
(defun mu4e-sent-handler (docid path)
|
(defun mu4e-sent-handler (docid path)
|
||||||
"Handler called with DOCID and PATH for the just-sent message.
|
"Handler called with DOCID and PATH for the just-sent message.
|
||||||
|
|||||||
Reference in New Issue
Block a user