* mu4e: cleanup dynamic folder usage in mu4e-compose

This commit is contained in:
djcb
2012-10-01 21:18:06 +03:00
parent c482f744b2
commit 3e522598d2

View File

@ -56,12 +56,15 @@ the From: address.)"
(defcustom mu4e-sent-messages-behavior 'sent (defcustom mu4e-sent-messages-behavior 'sent
"Determines what mu4e does with sent messages - this is a symbol "Determines what mu4e does with sent messages - this is a symbol
which can be either: 'sent --> move the sent message to the which can be either:
Sent-folder (`mu4e-sent-folder') 'trash --> move the sent message
to the Trash-folder (`mu4e-trash-folder') 'delete --> delete the * 'sent --> move the sent message to the Sent-folder (`mu4e-sent-folder')
sent message. Note, when using GMail/IMAP, you should set this to * 'trash --> move the sent message to the Trash-folder (`mu4e-trash-folder')
either 'trash or 'delete, since GMail already takes care of keeping * 'delete --> delete the sent message.
copies in the sent folder."
Note, when using GMail/IMAP, you should set this to either 'trash
or 'delete, since GMail already takes care of keeping copies in the
sent folder."
:type 'symbol :type 'symbol
:safe 'symbolp :safe 'symbolp
:group 'mu4e-compose) :group 'mu4e-compose)
@ -79,8 +82,9 @@ compose-type is either /reply/ or /forward/, the variable
being forwarded / edited.") being forwarded / edited.")
(defvar mu4e-compose-parent-message nil (defvar mu4e-compose-parent-message nil
"The parent message plist (ie., the message being replied to, "The parent message plist -- the message being replied to,
forwarded or edited) in `mu4e-compose-pre-hook.") forwarded or edited; used in `mu4e-compose-pre-hook. For new
messages, it is nil.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -355,7 +359,6 @@ You can append flags."
"\n\n" "\n\n"
(mu4e~compose-cite-original origmsg)))) (mu4e~compose-cite-original origmsg))))
(defun mu4e~compose-newmsg-construct () (defun mu4e~compose-newmsg-construct ()
"Create a new message." "Create a new message."
(concat (concat
@ -365,22 +368,9 @@ You can append flags."
(mu4e~compose-header "Subject" "") (mu4e~compose-header "Subject" "")
(mu4e~compose-common-construct))) (mu4e~compose-common-construct)))
(defvar mu4e~compose-trash-folder nil
"The trash-folder for this compose buffer, based on
`mu4e-trash-folder', which will be evaluated once.")
(defvar mu4e~compose-sent-folder nil
"The sent-folder for this compose buffer, based on
`mu4e-sent-folder', which will be evaluated once.")
(defvar mu4e~compose-drafts-folder nil (defvar mu4e~compose-drafts-folder nil
"The drafts-folder for this compose buffer, based on "The drafts-folder for this compose buffer, based on
`mu4e-drafts-folder', which will be evaluated once.") mu4e-drafts-folder', which will be evaluated once.")
(defmacro mu4e~compose-setup-folder (var func msg)
"Create a buffer-permanent local folder variable."
`(progn
(set (make-local-variable ,var) (,func ,msg))
(put ,var 'permanent-local t)))
(defun mu4e~compose-open-draft (compose-type &optional msg) (defun mu4e~compose-open-draft (compose-type &optional msg)
"Open a draft file for a new message (when COMPOSE-TYPE is reply, forward or new), "Open a draft file for a new message (when COMPOSE-TYPE is reply, forward or new),
@ -388,38 +378,32 @@ or open an existing draft (when COMPOSE-TYPE is edit).
The name of the draft folder is constructed from the concatenation The name of the draft folder is constructed from the concatenation
of `mu4e-maildir' and `mu4e-drafts-folder' (the latter will be of `mu4e-maildir' and `mu4e-drafts-folder' (the latter will be
evaluated, and its value will be available through evaluated). The message file name is a unique name determined by
`mu4e~compose-drafts-folder'). The message file name is a unique `mu4e-send-draft-file-name'. The initial contents will be created
name determined by `mu4e-send-draft-file-name'. The initial from either `mu4e~compose-reply-construct', or
contents will be created from either `mu4e~compose-forward-construct' or
`mu4e~compose-reply-construct', or `mu4e~compose-forward-construct' `mu4e~compose-newmsg-construct'."
or `mu4e~compose-newmsg-construct'. ;; evaluate mu4e-drafts-folder once, here, and use that value throughout.
(set (make-local-variable 'mu4e~compose-drafts-folder)
Also sets `mu4e~compose-trash-folder', `mu4e~compose-drafts-folder' (mu4e-get-drafts-folder msg))
and `mu4e~compose-sent-folder' as buffer-local, permanent (put 'mu4e~compose-drafts-folder 'permanent-local t)
variables. Note that when re-editing messages, the value of
mu4e-drafts-folder is ignored."
(unless mu4e-maildir (mu4e-error "mu4e-maildir not set")) (unless mu4e-maildir (mu4e-error "mu4e-maildir not set"))
(if (eq compose-type 'edit) (if (eq compose-type 'edit)
(find-file (mu4e-message-field msg :path)) (find-file (mu4e-message-field msg :path))
(let* ((draftdir (mu4e-get-drafts-folder msg)) (let ((draftpath
(draftfile (mu4e~compose-message-filename-construct "DS")) (format "%s/%s/cur/%s"
(draftpath (concat mu4e-maildir draftdir "/cur/" draftfile))) mu4e-maildir
mu4e~compose-drafts-folder
(mu4e~compose-message-filename-construct "DS"))))
(find-file draftpath) (find-file draftpath)
(insert (insert
(case compose-type (case compose-type
(reply (mu4e~compose-reply-construct msg)) (reply (mu4e~compose-reply-construct msg))
(forward (mu4e~compose-forward-construct msg)) (forward (mu4e~compose-forward-construct msg))
(new (mu4e~compose-newmsg-construct)) (new (mu4e~compose-newmsg-construct))
(t (mu4e-error "unsupported compose-type %S" compose-type)))))) (t (mu4e-error "unsupported compose-type %S" compose-type)))))))
;; now, or draft file has been setup. setup the buffer-local special dirs.
(mu4e~compose-setup-folder 'mu4e~compose-trash-folder mu4e-get-trash-folder msg)
(mu4e~compose-setup-folder 'mu4e~compose-drafts-folder mu4e-get-drafts-folder msg)
(mu4e~compose-setup-folder 'mu4e~compose-sent-folder mu4e-get-sent-folder msg))
;; 'fcc' refers to saving a copy of a sent message to a certain folder. that's ;; 'fcc' refers to saving a copy of a sent message to a certain folder. that's
;; what these 'Sent mail' folders are for! ;; what these 'Sent mail' folders are for!
;; ;;
@ -439,8 +423,8 @@ needed, set the Fcc header, and register the handler function."
(let* ((mdir (let* ((mdir
(case mu4e-sent-messages-behavior (case mu4e-sent-messages-behavior
(delete nil) (delete nil)
(trash mu4e~compose-trash-folder) (trash (mu4e-get-trash-folder mu4e-compose-parent-message))
(sent mu4e~compose-sent-folder) (sent (mu4e-get-sent-folder mu4e-compose-parent-message))
(otherwise (otherwise
(mu4e-error "unsupported value '%S' `mu4e-sent-messages-behavior'." (mu4e-error "unsupported value '%S' `mu4e-sent-messages-behavior'."
mu4e-sent-messages-behavior)))) mu4e-sent-messages-behavior))))
@ -596,11 +580,12 @@ Optionally (when forwarding) INCLUDES contains a list of
for the attachements to include; file-name refers to for the attachements to include; file-name refers to
a file which our backend has conveniently saved for us (as a a file which our backend has conveniently saved for us (as a
tempfile)." tempfile)."
;; Run the hooks defined for `mu4e-compose-pre-hook'. If compose-type is ;; Run the hooks defined for `mu4e-compose-pre-hook'. If compose-type is
;; `reply', `forward' or `edit', `mu4e-compose-parent-message' points to the ;; `reply', `forward' or `edit', `mu4e-compose-parent-message' points to the
;; message being forwarded or replied to, otherwise it is nil. ;; message being forwarded or replied to, otherwise it is nil.
(setq mu4e-compose-parent-message original-msg) (set (make-local-variable 'mu4e-compose-parent-message) original-msg)
(put 'mu4e-compose-parent-message 'permanent-local t)
(run-hooks 'mu4e-compose-pre-hook) (run-hooks 'mu4e-compose-pre-hook)
;; this opens (or re-opens) a messages with all the basic headers set. ;; this opens (or re-opens) a messages with all the basic headers set.