* mu4e-send.el: make sure messages are saved before moving them from draft -->

sent (or elsewhere)
This commit is contained in:
djcb 2012-03-28 18:58:43 +03:00
parent 25801c7c51
commit ad0c315c02
1 changed files with 78 additions and 59 deletions

View File

@ -293,7 +293,9 @@ use the new docid. Returns the full path to the new message."
(let ((message-hidden-headers
`("^References:" "^Face:" "^X-Face:" "^X-Draft-From:"
"^User-agent:")))
(message-hide-headers))
(use-local-map mu4e-edit-mode-map)
(message-hide-headers)
(make-local-variable 'after-save-hook)
@ -309,7 +311,12 @@ use the new docid. Returns the full path to the new message."
;; register the function; this function will be called when the '(:sent...)'
;; message is received (see mu4e-proc.el) with parameters docid and path
(setq mu4e-proc-sent-func 'mu4e-sent-handler))
(setq mu4e-proc-sent-func 'mu4e-sent-handler)
;; set the default directory to the user's home dir; this is probably more
;; useful e.g. when finding an attachment file the directory the current
;; mail files lives in...
(setq default-directory (expand-file-name "~/"))))
@ -371,21 +378,29 @@ using Gnus' `message-mode'."
(defun mu4e-sent-handler (docid path)
"Handler function, called with DOCID and PATH for the just-sent
message."
(with-current-buffer (find-file-noselect path)
;; make sure this buffer is saved
(save-buffer)
(message "Mail sent")
;; for Forward ('Passed') and Replied messages, try to set the appropriate
;; flag at the message forwarded or replied-to
(mu4e-send-set-parent-flag docid path)
;; handle the draft -- should it be moved to the send folder, or elsewhere?
(mu4e-send-save-copy-maybe docid path))
(mu4e-send-save-copy-maybe docid path)
;; now, get rid of the buffer
(kill-buffer)))
(defun mu4e-send-save-copy-maybe (docid path)
"Handler function, called with DOCID and PATH for the just-sent
message."
message, which will move it to the sent-folder or elsewhere,
depending on the value of `mu4e-sent-messages-behavior'.
Function assumes that it's executed in the context of the message
buffer."
;; first, what to do with the draft message in PATH?
(with-current-buffer (find-file-noselect path)
(if (eq mu4e-sent-messages-behavior 'delete)
(progn
(save-buffer)
(mu4e-proc-remove-msg docid)) ;; remove it
;; otherwise,
(progn ;; prepare the message for saving
@ -396,10 +411,11 @@ message."
(replace-match "")
(error "cannot find mail-header-separator"))
(save-buffer)
(message nil)
;; ok, all seems well, well move the message to the sent-folder
(if (eq mu4e-sent-messages-behavior 'trash)
(mu4e-proc-move-msg docid mu4e-trash-folder "+T-D+S")
(mu4e-proc-move-msg docid mu4e-sent-folder "-T-D+S")))))))
(mu4e-proc-move-msg docid mu4e-sent-folder "-T-D+S"))))))
(defun mu4e-send-set-parent-flag (docid path)
@ -415,8 +431,11 @@ corresponding with the /last/ message-id in the references header.
Now, if the message has been determined to be either a forwarded
message or a reply, we instruct the server to update that message
with resp. the 'P' (passed) flag for a forwarded message, or the
'R' flag for a replied message."
(with-current-buffer (find-file-noselect path)
'R' flag for a replied message.
Function assumes that it's executed in the context of the message
buffer.
"
(let ((in-reply-to (message-fetch-field "in-reply-to"))
(forwarded-from)
(references (message-fetch-field "references")))
@ -434,6 +453,6 @@ with resp. the 'P' (passed) flag for a forwarded message, or the
(when (and in-reply-to (string-match "<\\(.*\\)>" in-reply-to))
(mu4e-proc-flag (match-string 1 in-reply-to) "+R"))
(when (and forwarded-from (string-match "<\\(.*\\)>" forwarded-from))
(mu4e-proc-flag (match-string 1 forwarded-from) "+P")))))
(mu4e-proc-flag (match-string 1 forwarded-from) "+P"))))
(provide 'mu4e-send)