--- /dev/null
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 20FBA431FD8\r
+ for <notmuch@notmuchmail.org>; Thu, 20 Feb 2014 11:17:25 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 4ZzhO0ASWFuq for <notmuch@notmuchmail.org>;\r
+ Thu, 20 Feb 2014 11:17:21 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (dmz-mailsec-scanner-4.mit.edu\r
+ [18.9.25.15])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 45A6D431FD9\r
+ for <notmuch@notmuchmail.org>; Thu, 20 Feb 2014 11:16:56 -0800 (PST)\r
+X-AuditID: 1209190f-f790b6d000000c3a-e0-530654a7ec8d\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id B4.71.03130.7A456035; Thu, 20 Feb 2014 14:16:55 -0500 (EST)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id s1KJGhuo014147; \r
+ Thu, 20 Feb 2014 14:16:43 -0500\r
+Received: from drake.dyndns.org (26-4-182.dynamic.csail.mit.edu [18.26.4.182])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s1KJGfVH012828\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Thu, 20 Feb 2014 14:16:42 -0500\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1WGZ6v-0004Z6-1T; Thu, 20 Feb 2014 14:16:41 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/4] emacs: Build forwarded message buffer more directly\r
+Date: Thu, 20 Feb 2014 14:16:34 -0500\r
+Message-Id: <1392923797-17045-2-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.8.4.rc3\r
+In-Reply-To: <1392923797-17045-1-git-send-email-amdragon@mit.edu>\r
+References: <1392923797-17045-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixCmqrLs8hC3Y4ORCMYvXCyaxWVy/OZPZ\r
+ gclj9dpOFo9nq24xBzBFcdmkpOZklqUW6dslcGW8fj+TvWCebMXF509YGhg3S3QxcnJICJhI\r
+ vF3UzgJhi0lcuLeerYuRi0NIYDaTRM/TuUwQzkZGifvzTkE5R5gk5m1dDlU2l1HiwYw5YP1s\r
+ AhoS2/YvZwSxRQSkJXbenc0KYjML2Ehs/vgYLC4s4CHxs+8QmM0ioCpxY/NpMJtXwEHi2II3\r
+ jBB3KEksPLUNrJdTwFFiaf8HIJsDaJmDROdWnQmM/AsYGVYxyqbkVunmJmbmFKcm6xYnJ+bl\r
+ pRbpmujlZpbopaaUbmIEh5Ik/w7GbweVDjEKcDAq8fCekGILFmJNLCuuzD3EKMnBpCTKuyIA\r
+ KMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmEt8kGKMebklhZlVqUD5OS5mBREuettfgVJCSQnliS\r
+ mp2aWpBaBJOV4eBQkuD1AMaMkGBRanpqRVpmTglCmomDE2Q4D9DwfcEgw4sLEnOLM9Mh8qcY\r
+ FaXEeV1AmgVAEhmleXC9sFh/xSgO9IowbxBIFQ8wTcB1vwIazAQ0uGQjK8jgkkSElFQDo4r9\r
+ G+GUfz4l2a7Om3MO7bf7NnMmZ+r2XYqvtl5wly2WFjvoZJI+4eaORfO7Jx/YOGPWzRTZDKm/\r
+ woeOXck7H80quqpe0Oanxtfd4lsvHlDnijTc6/rikoXFZlvVrwfiVkaq1HsFeAleal3GJSa2\r
+ YlrJj4x9joUW52Y9OzLLuevbboVDf5ZI2SuxFGckGmoxFxUnAgAdlMeP0AIAAA==\r
+Cc: bjonnh-nm@bjonnh.net\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 20 Feb 2014 19:17:25 -0000\r
+\r
+Previously, we used `message-forward' to build forwarded messages, but\r
+this function is simply too high-level to be a good fit for some of\r
+what we do.\r
+\r
+First, since `message-forward' builds a full forward message buffer\r
+given the message to forward, we have to duplicate much of the logic\r
+in `notmuch-mua-mail' to patch the notmuch-y things into the built\r
+buffer.\r
+\r
+Second, `message-forward' constructs the From header from\r
+user-full-name and user-mail-address. As a result, if we prompt the\r
+user for an identity, we have to parse it into name and address\r
+components, just to have it put back together by `message-forward'.\r
+This process is not entirely loss-less because\r
+`mail-extract-address-components' does a lot of canonicalization\r
+(since it's intended for displaying addresses, not for parsing them).\r
+\r
+To fix these problems, don't use `message-forward' at all.\r
+`message-forward' itself is basically just a call to `message-mail'\r
+and `message-forward-make-body'. Do this ourselves, but call\r
+`notmuch-mua-mail' instead of `message-mail' so we can directly build\r
+a notmuch-y message and control the From header.\r
+\r
+This also fixes a bug that was a direct consequence of our use of\r
+`mail-extract-address-components': if the user chose an identity that\r
+had no name part (or the name part matched the mailbox), we would bind\r
+user-full-name to nil, which would cause an exception in the bowels of\r
+message-mode because user-full-name is expected to always be a string\r
+(even if it's just "").\r
+---\r
+ emacs/notmuch-mua.el | 33 +++++++++++----------------------\r
+ 1 file changed, 11 insertions(+), 22 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+index 481abd7..f2df770 100644\r
+--- a/emacs/notmuch-mua.el\r
++++ b/emacs/notmuch-mua.el\r
+@@ -231,21 +231,6 @@ list."\r
+ (message-goto-body)\r
+ (set-buffer-modified-p nil))\r
+ \r
+-(defun notmuch-mua-forward-message ()\r
+- (funcall (notmuch-mua-get-switch-function) (current-buffer))\r
+- (message-forward)\r
+-\r
+- (when notmuch-mua-user-agent-function\r
+- (let ((user-agent (funcall notmuch-mua-user-agent-function)))\r
+- (when (not (string= "" user-agent))\r
+- (message-add-header (format "User-Agent: %s" user-agent)))))\r
+- (message-sort-headers)\r
+- (message-hide-headers)\r
+- (set-buffer-modified-p nil)\r
+- (notmuch-mua-maybe-set-window-dedicated)\r
+-\r
+- (message-goto-to))\r
+-\r
+ (defun notmuch-mua-mail (&optional to subject other-headers &rest other-args)\r
+ "Invoke the notmuch mail composition window.\r
+ \r
+@@ -345,13 +330,17 @@ The current buffer must contain an RFC2822 message to forward.\r
+ \r
+ If PROMPT-FOR-SENDER is non-nil, the user will be prompted for\r
+ the From: address first."\r
+- (if (or prompt-for-sender notmuch-always-prompt-for-sender)\r
+- (let* ((sender (notmuch-mua-prompt-for-sender))\r
+- (address-components (mail-extract-address-components sender))\r
+- (user-full-name (car address-components))\r
+- (user-mail-address (cadr address-components)))\r
+- (notmuch-mua-forward-message))\r
+- (notmuch-mua-forward-message)))\r
++ (let* ((cur (current-buffer))\r
++ (message-forward-decoded-p nil)\r
++ (subject (message-make-forward-subject))\r
++ (other-headers\r
++ (when (or prompt-for-sender notmuch-always-prompt-for-sender)\r
++ (list (cons 'From (notmuch-mua-prompt-for-sender))))))\r
++ (notmuch-mua-mail nil subject other-headers nil (notmuch-mua-get-switch-function))\r
++ (message-forward-make-body cur)\r
++ ;; `message-forward-make-body' shows the User-agent header. Hide\r
++ ;; it again.\r
++ (message-hide-headers)))\r
+ \r
+ (defun notmuch-mua-new-reply (query-string &optional prompt-for-sender reply-all)\r
+ "Compose a reply to the message identified by QUERY-STRING.\r
+-- \r
+1.8.4.rc3\r
+\r