From 2f3bd58c03ac66ba9017d485715b74f19e3cae7d Mon Sep 17 00:00:00 2001 From: djcb Date: Thu, 26 Apr 2012 18:08:42 +0300 Subject: [PATCH] * mu4e-compose.el: let message-mode FCC take care of saving to sent-messages - replace the old system with a bit less rube-goldbergesque (only a bit) system. Immediate advantage is that attachments are now also present in the saved messages, i.e. the copy is now the /same/ as what is sent, rather than an approximation. 'fcc' refers to saving a copy of a sent message to a certain folder. that's what these 'Sent mail' folders are for! We let message mode take care of this by adding a field Fcc: in the "message-send-hook" (ie., just before sending). message mode will then take care of the saving when the message is actually sent. note, where and if you make this copy depends on the value of `mu4e-sent-messages-behavior'. - also quite a bit of cleanup in particular on mu4e~compose --- emacs/mu4e-compose.el | 338 +++++++++++++++++++++++------------------- 1 file changed, 184 insertions(+), 154 deletions(-) diff --git a/emacs/mu4e-compose.el b/emacs/mu4e-compose.el index bd5f758a..dcc79d6f 100644 --- a/emacs/mu4e-compose.el +++ b/emacs/mu4e-compose.el @@ -26,7 +26,7 @@ ;; gnus' message mode ;;; Code: - ;; we use some stuff from gnus.. +;; we use some stuff from gnus.. (require 'cl) (require 'message) (require 'mail-parse) @@ -69,6 +69,19 @@ sent folder." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defun mu4e-compose-attach-captured-message() + "Insert the last captured message file as an attachment." + (interactive) + (unless mu4e-captured-message + (error "No message has been captured")) + (let ((path (plist-get mu4e-captured-message :path))) + (unless (file-exists-p path) + (error "Captured message file not found")) + (mml-attach-file + path + "message/rfc822" + (or (plist-get mu4e-captured-message :subject) "No subject") + "attachment"))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -105,7 +118,6 @@ return nil." (lambda (msgid) (format "<%s>" msgid)) refs ",")))) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; determine the recipient fields for new messages @@ -151,11 +163,11 @@ field before, goes to the Cc:-list (if we're doing a reply-to-all)." the original message ORIGMSG, and whether it's a reply-all." (when reply-all (let* ((cc-lst ;; get the cc-field from the original, remove dups - (delete-duplicates - (append - (plist-get origmsg :to) - (plist-get origmsg :cc)) - :test #'mu4e~compose-address-cell-equal)) + (delete-duplicates + (append + (plist-get origmsg :to) + (plist-get origmsg :cc)) + :test #'mu4e~compose-address-cell-equal)) ;; now we have the basic list, but we must remove ;; addresses also in the to list (cc-lst @@ -177,19 +189,19 @@ the original message ORIGMSG, and whether it's a reply-all." cc-lst)))) cc-lst))) - (defun mu4e~compose-recipients-construct (field origmsg &optional reply-all) - "Create value (a string) for the recipient field FIELD (a +(defun mu4e~compose-recipients-construct (field origmsg &optional reply-all) + "Create value (a string) for the recipient field FIELD (a symbol, :to or :cc), based on the original message ORIGMSG, and (optionally) REPLY-ALL which indicates this is a reply-to-all message. Return nil if there are no recipients for the particular field." - (mu4e~compose-recipients-list-to-string - (case field - (:to - (mu4e~compose-create-to-lst origmsg)) - (:cc - (mu4e~compose-create-cc-lst origmsg reply-all)) - (otherwise - (error "Unsupported field"))))) + (mu4e~compose-recipients-list-to-string + (case field + (:to + (mu4e~compose-create-to-lst origmsg)) + (:cc + (mu4e~compose-create-cc-lst origmsg reply-all)) + (otherwise + (error "Unsupported field"))))) (defun mu4e~compose-from-construct () @@ -202,7 +214,6 @@ nil, function returns nil." (format "%s" user-mail-address)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - (defun mu4e~compose-insert-mail-header-separator () "Insert `mail-header-separator' in the first empty line of the message. message-mode needs this line to know where the headers end @@ -212,7 +223,7 @@ separator is never written to file. Also see `mu4e-remove-mail-header-separator'." (save-excursion (goto-char (point-min)) - ;; search for the first empty line + ;; search for the first empty line (if (search-forward-regexp (concat "^$")) (replace-match (propertize mail-header-separator 'read-only t 'intangible t)) @@ -236,22 +247,40 @@ never hits the disk. Also see `mu4e~compose-insert-mail-header-separator." are more than 1 (based on ORIGMSG)." (let* ((recipnum (+ (length (mu4e~compose-create-to-lst origmsg)) - (length (mu4e~compose-create-cc-lst origmsg t)))) + (length (mu4e~compose-create-cc-lst origmsg t)))) (response (if (= recipnum 1) - ?a ;; with one recipient, we can reply to 'all'.... - (mu4e-read-option - "Reply to " - `( (,(format "all %d recipients" recipnum)) - ("sender only")))))) + ?a ;; with one recipient, we can reply to 'all'.... + (mu4e-read-option + "Reply to " + `( (,(format "all %d recipients" recipnum)) + ("sender only")))))) (= response ?a))) +(defun mu4e~compose-message-filename-construct (&optional flagstr) + "Construct a randomized name for a message file with flags FLAGSTR; it looks +something like +