unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Cc: bjonnh-nm@bjonnh.net
Subject: [PATCH 1/4] emacs: Build forwarded message buffer more directly
Date: Thu, 20 Feb 2014 14:16:34 -0500	[thread overview]
Message-ID: <1392923797-17045-2-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1392923797-17045-1-git-send-email-amdragon@mit.edu>

Previously, we used `message-forward' to build forwarded messages, but
this function is simply too high-level to be a good fit for some of
what we do.

First, since `message-forward' builds a full forward message buffer
given the message to forward, we have to duplicate much of the logic
in `notmuch-mua-mail' to patch the notmuch-y things into the built
buffer.

Second, `message-forward' constructs the From header from
user-full-name and user-mail-address.  As a result, if we prompt the
user for an identity, we have to parse it into name and address
components, just to have it put back together by `message-forward'.
This process is not entirely loss-less because
`mail-extract-address-components' does a lot of canonicalization
(since it's intended for displaying addresses, not for parsing them).

To fix these problems, don't use `message-forward' at all.
`message-forward' itself is basically just a call to `message-mail'
and `message-forward-make-body'.  Do this ourselves, but call
`notmuch-mua-mail' instead of `message-mail' so we can directly build
a notmuch-y message and control the From header.

This also fixes a bug that was a direct consequence of our use of
`mail-extract-address-components': if the user chose an identity that
had no name part (or the name part matched the mailbox), we would bind
user-full-name to nil, which would cause an exception in the bowels of
message-mode because user-full-name is expected to always be a string
(even if it's just "").
---
 emacs/notmuch-mua.el | 33 +++++++++++----------------------
 1 file changed, 11 insertions(+), 22 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 481abd7..f2df770 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -231,21 +231,6 @@ list."
   (message-goto-body)
   (set-buffer-modified-p nil))
 
-(defun notmuch-mua-forward-message ()
-  (funcall (notmuch-mua-get-switch-function) (current-buffer))
-  (message-forward)
-
-  (when notmuch-mua-user-agent-function
-    (let ((user-agent (funcall notmuch-mua-user-agent-function)))
-      (when (not (string= "" user-agent))
-	(message-add-header (format "User-Agent: %s" user-agent)))))
-  (message-sort-headers)
-  (message-hide-headers)
-  (set-buffer-modified-p nil)
-  (notmuch-mua-maybe-set-window-dedicated)
-
-  (message-goto-to))
-
 (defun notmuch-mua-mail (&optional to subject other-headers &rest other-args)
   "Invoke the notmuch mail composition window.
 
@@ -345,13 +330,17 @@ The current buffer must contain an RFC2822 message to forward.
 
 If PROMPT-FOR-SENDER is non-nil, the user will be prompted for
 the From: address first."
-  (if (or prompt-for-sender notmuch-always-prompt-for-sender)
-      (let* ((sender (notmuch-mua-prompt-for-sender))
-	     (address-components (mail-extract-address-components sender))
-	     (user-full-name (car address-components))
-	     (user-mail-address (cadr address-components)))
-	(notmuch-mua-forward-message))
-    (notmuch-mua-forward-message)))
+  (let* ((cur (current-buffer))
+	 (message-forward-decoded-p nil)
+	 (subject (message-make-forward-subject))
+	 (other-headers
+	  (when (or prompt-for-sender notmuch-always-prompt-for-sender)
+	    (list (cons 'From (notmuch-mua-prompt-for-sender))))))
+    (notmuch-mua-mail nil subject other-headers nil (notmuch-mua-get-switch-function))
+    (message-forward-make-body cur)
+    ;; `message-forward-make-body' shows the User-agent header.  Hide
+    ;; it again.
+    (message-hide-headers)))
 
 (defun notmuch-mua-new-reply (query-string &optional prompt-for-sender reply-all)
   "Compose a reply to the message identified by QUERY-STRING.
-- 
1.8.4.rc3

  reply	other threads:[~2014-02-20 19:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-20 19:16 [PATCH 0/4] Bug fixes for identity handling in Emacs Austin Clements
2014-02-20 19:16 ` Austin Clements [this message]
2014-02-20 19:16 ` [PATCH 2/4] emacs: Fix exception when fetching empty or unconfigured settings Austin Clements
2014-02-20 19:16 ` [PATCH 3/4] emacs: Fix `notmuch-user-other-email' when no other emails are configured Austin Clements
2014-02-20 19:16 ` [PATCH 4/4] emacs: Simplify and fix `notmuch-mua-prompt-for-sender' Austin Clements
2014-02-20 22:36   ` Mark Walters
2014-02-21  2:17     ` Austin Clements
2014-02-27 18:10     ` [PATCH v2] " Austin Clements
2014-03-01  9:37       ` Mark Walters
2014-03-05  0:07       ` David Bremner
2014-02-22 10:17   ` [PATCH 4/4] " Tomi Ollila
2014-02-22 23:56 ` [PATCH 0/4] Bug fixes for identity handling in Emacs David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392923797-17045-2-git-send-email-amdragon@mit.edu \
    --to=amdragon@mit.edu \
    --cc=bjonnh-nm@bjonnh.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).