From: Austin Clements Date: Thu, 20 Feb 2014 19:16:34 +0000 (+1900) Subject: [PATCH 1/4] emacs: Build forwarded message buffer more directly X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d4db379c93be85baf4c05f613b55b35743765a9d;p=notmuch-archives.git [PATCH 1/4] emacs: Build forwarded message buffer more directly --- diff --git a/53/c97eedc1cbe525abddf653cb97920be90b3963 b/53/c97eedc1cbe525abddf653cb97920be90b3963 new file mode 100644 index 000000000..11bf058b6 --- /dev/null +++ b/53/c97eedc1cbe525abddf653cb97920be90b3963 @@ -0,0 +1,163 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 20FBA431FD8 + for ; Thu, 20 Feb 2014 11:17:25 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 4ZzhO0ASWFuq for ; + Thu, 20 Feb 2014 11:17:21 -0800 (PST) +Received: from dmz-mailsec-scanner-4.mit.edu (dmz-mailsec-scanner-4.mit.edu + [18.9.25.15]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 45A6D431FD9 + for ; Thu, 20 Feb 2014 11:16:56 -0800 (PST) +X-AuditID: 1209190f-f790b6d000000c3a-e0-530654a7ec8d +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP + id B4.71.03130.7A456035; Thu, 20 Feb 2014 14:16:55 -0500 (EST) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id s1KJGhuo014147; + Thu, 20 Feb 2014 14:16:43 -0500 +Received: from drake.dyndns.org (26-4-182.dynamic.csail.mit.edu [18.26.4.182]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s1KJGfVH012828 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 20 Feb 2014 14:16:42 -0500 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1WGZ6v-0004Z6-1T; Thu, 20 Feb 2014 14:16:41 -0500 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 1/4] emacs: Build forwarded message buffer more directly +Date: Thu, 20 Feb 2014 14:16:34 -0500 +Message-Id: <1392923797-17045-2-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 1.8.4.rc3 +In-Reply-To: <1392923797-17045-1-git-send-email-amdragon@mit.edu> +References: <1392923797-17045-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixCmqrLs8hC3Y4ORCMYvXCyaxWVy/OZPZ + gclj9dpOFo9nq24xBzBFcdmkpOZklqUW6dslcGW8fj+TvWCebMXF509YGhg3S3QxcnJICJhI + vF3UzgJhi0lcuLeerYuRi0NIYDaTRM/TuUwQzkZGifvzTkE5R5gk5m1dDlU2l1HiwYw5YP1s + AhoS2/YvZwSxRQSkJXbenc0KYjML2Ehs/vgYLC4s4CHxs+8QmM0ioCpxY/NpMJtXwEHi2II3 + jBB3KEksPLUNrJdTwFFiaf8HIJsDaJmDROdWnQmM/AsYGVYxyqbkVunmJmbmFKcm6xYnJ+bl + pRbpmujlZpbopaaUbmIEh5Ik/w7GbweVDjEKcDAq8fCekGILFmJNLCuuzD3EKMnBpCTKuyIA + KMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmEt8kGKMebklhZlVqUD5OS5mBREuettfgVJCSQnliS + mp2aWpBaBJOV4eBQkuD1AMaMkGBRanpqRVpmTglCmomDE2Q4D9DwfcEgw4sLEnOLM9Mh8qcY + FaXEeV1AmgVAEhmleXC9sFh/xSgO9IowbxBIFQ8wTcB1vwIazAQ0uGQjK8jgkkSElFQDo4r9 + G+GUfz4l2a7Om3MO7bf7NnMmZ+r2XYqvtl5wly2WFjvoZJI+4eaORfO7Jx/YOGPWzRTZDKm/ + woeOXck7H80quqpe0Oanxtfd4lsvHlDnijTc6/rikoXFZlvVrwfiVkaq1HsFeAleal3GJSa2 + YlrJj4x9joUW52Y9OzLLuevbboVDf5ZI2SuxFGckGmoxFxUnAgAdlMeP0AIAAA== +Cc: bjonnh-nm@bjonnh.net +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Thu, 20 Feb 2014 19:17:25 -0000 + +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 +