From 1838fcff2583e5344880c6e3f62943824fb3ec2e Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 30 Mar 2012 01:32:21 +2000 Subject: [PATCH] Re: [BUG/PATCH v2] emacs: Fix the References header in reply --- c9/5680633fb8ff721b13f2799334f31f5bebbed2 | 189 ++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 c9/5680633fb8ff721b13f2799334f31f5bebbed2 diff --git a/c9/5680633fb8ff721b13f2799334f31f5bebbed2 b/c9/5680633fb8ff721b13f2799334f31f5bebbed2 new file mode 100644 index 000000000..2be8401a4 --- /dev/null +++ b/c9/5680633fb8ff721b13f2799334f31f5bebbed2 @@ -0,0 +1,189 @@ +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 89521431FAF + for ; Wed, 28 Mar 2012 22:32:26 -0700 (PDT) +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 iVi3+ZVkW7Bg for ; + Wed, 28 Mar 2012 22:32:25 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU + [18.9.25.14]) + by olra.theworths.org (Postfix) with ESMTP id 12FF9431FAE + for ; Wed, 28 Mar 2012 22:32:24 -0700 (PDT) +X-AuditID: 1209190e-b7f7c6d0000008c3-3e-4f73f3e81975 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id E1.70.02243.8E3F37F4; Thu, 29 Mar 2012 01:32:24 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q2T5WNp2008977; + Thu, 29 Mar 2012 01:32:23 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q2T5WMqH009428 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 29 Mar 2012 01:32:23 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SD7y9-0006pc-OY; Thu, 29 Mar 2012 01:32:21 -0400 +Date: Thu, 29 Mar 2012 01:32:21 -0400 +From: Austin Clements +To: Adam Wolfe Gordon +Subject: Re: [BUG/PATCH v2] emacs: Fix the References header in reply +Message-ID: <20120329053221.GA2670@mit.edu> +References: <1332991226-510-1-git-send-email-awg+notmuch@xvx.ca> + <1332996818-15700-1-git-send-email-awg+notmuch@xvx.ca> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <1332996818-15700-1-git-send-email-awg+notmuch@xvx.ca> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFupjleLIzCtJLcpLzFFi42IRYrdT133xudjf4MZ1Dosje2axW1y/OZPZ + gcnj2apbzB5NPxazBjBFcdmkpOZklqUW6dslcGWcuNbNWLBNteLNr0+sDYxdcl2MnBwSAiYS + N2/0sUDYYhIX7q1n62Lk4hAS2Mco8bRpApSzgVHixc2Z7CBVQgInmSRmdUZBJJYwSnz4+ZwV + JMEioCpx88sfZhCbTUBDYtv+5YwgtoiAlsSP9V/BapgFpCW+/W5mArGFBVwlut6+BovzCmhL + PH6+jBViQaXEs6OL2SDighInZz5hgejVkrjx7yVQLwfYnOX/OEBMTgFniaYpKiAVogIqElNO + bmObwCg0C0nzLCTNsxCaFzAyr2KUTcmt0s1NzMwpTk3WLU5OzMtLLdI11svNLNFLTSndxAgK + ak5Jvh2MXw8qHWIU4GBU4uFV0in2F2JNLCuuzD3EKMnBpCTKm/IJKMSXlJ9SmZFYnBFfVJqT + WnyIUYKDWUmE1/0cUI43JbGyKrUoHyYlzcGiJM6rpvXOT0ggPbEkNTs1tSC1CCYrw8GhJMEb + DoxeIcGi1PTUirTMnBKENBMHJ8hwHqDhKSA1vMUFibnFmekQ+VOMuhzr3l25zCjEkpeflyol + zmsOUiQAUpRRmgc3B5aMXjGKA70lzOsIUsUDTGRwk14BLWECWrLkSD7IkpJEhJRUA+NKu8eH + Fje7sMb8L9iU/PR2d9OZ9mvvBCd/Wipvxrft3bOG5OefK5QkS8IsOC6yibX8197VpNe6Klb/ + dP3CntXbulQ8HqsdP9VxtWjmJ3WX+V8FbnqsfnLojpLKFsPaNvfmFV97JgjwbAtYqr436ipv + /cogy6/lEptYT/5YomnmyfR99v43UxqUWIozEg21mIuKEwGPw+coIQMAAA== +Cc: notmuch@notmuchmail.org +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, 29 Mar 2012 05:32:26 -0000 + +Quoth Adam Wolfe Gordon on Mar 28 at 10:53 pm: +> In the new reply code, the References header gets inserted by +> message.el using a function called message-shorten-references. Unlike +> all the other header-inserting functions, it doesn't put a newline +> after the header, causing the next header to end up on the same +> line. In our case, this header happened to be User-Agent, so it's hard +> to notice. This is probably a bug in message.el, but we need to work +> around it. +> +> This fixes the problem by wrapping message-shorten-references in a +> function that inserts a newline after if necessary. This should +> protect against the message.el bug being fixed in the future. +> --- + +Ugh. message-mode is such a rat's nest. I dug through this and it +looks like message-shorten-references really is at fault here. + +I'm sure you already tracked this down, but for others who may be +interested, ultimately, the headers are inserted by +mail-header-format, which calls formatter functions or, if there is no +formatter, mail-header-format-function. mail-header-format-function +inserts a newline after the header and, indeed, mail-header-format +does not insert anything between headers, so this is clearly up to the +formatter. message-shorten-references, however, inserts its header by +calling message-insert-header, which looks remarkably like +mail-header-format-function, minus the newline. Ironically, +message-shorten-references appears to be the only formatter configured +by default. + +> This version adds the local variables to suppress 'cl warings, per +> id:"1332995623-9055-1-git-send-email-amdragon@mit.edu". +> +> emacs/notmuch-mua.el | 26 +++++++++++++++++++++++--- +> 1 files changed, 23 insertions(+), 3 deletions(-) +> +> diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el +> index 24918d3..0d3fcd3 100644 +> --- a/emacs/notmuch-mua.el +> +++ b/emacs/notmuch-mua.el +> @@ -90,6 +90,15 @@ list." +> else if (notmuch-match-content-type (plist-get part :content-type) "text/*") +> collect part)) +> +> +;; There is a bug in emacs 23's message.el that results in a newline +> +;; not being inserted after the References header, so the next header +> +;; is concatenated to the end of it. This function fixes the problem, +> +;; while guarding against the possibility that some current or future +> +;; version of emacs has the bug fixed. +> +(defun notmuch-mua-insert-references (header references) +> + (message-shorten-references header references) +> + (unless (bolp) (insert "\n"))) +> + + +Would it be safer to call whatever was associated with References in +message-header-format-alist, rather than hard-coding +message-shorten-references? + +> (defun notmuch-mua-reply (query-string &optional sender reply-all) +> (let ((args '("reply" "--format=json")) +> reply +> @@ -125,9 +134,16 @@ list." +> ;; Overlay the composition window on that being used to read +> ;; the original message. +> ((same-window-regexps '("\\*mail .*"))) +> - (notmuch-mua-mail (plist-get reply-headers :To) +> - (plist-get reply-headers :Subject) +> - (notmuch-plist-to-alist reply-headers))) +> + +> + ;; We modify message-header-format-alist to get around a bug in message.el. +> + ;; See the comment above on notmuch-mua-insert-references. +> + (let ((message-header-format-alist +> + (append '((References . notmuch-mua-insert-references)) + +(cons '(References . notmuch-mua-insert-references) ...) + +> + (remove-if (lambda (x) (eq (car x) 'References)) +> + message-header-format-alist)))) + +(assq-delete-all 'References (copy-alist message-header-format-alist))? + +Hmm. That's less shorter than I would have expected, but I think it's +less opaque. + +Actually, if I'm reading mail-header-format correctly, the order of +this alist controls the order of the headers, so maybe what you +actually want is + +(mapcar (lambda (x) (if (eq (car x) 'References) + '(References . notmuch-mua-insert-references) + x)) + message-header-format-alist) + +> + (notmuch-mua-mail (plist-get reply-headers :To) +> + (plist-get reply-headers :Subject) +> + (notmuch-plist-to-alist reply-headers)))) +> ;; Insert the message body - but put it in front of the signature +> ;; if one is present +> (goto-char (point-max)) +> @@ -301,3 +317,7 @@ simply runs the corresponding `message-mode' hook functions." +> ;; +> +> (provide 'notmuch-mua) +> + +> +;; Local Variables: +> +;; byte-compile-warnings: (not cl-functions) +> +;; End: + +This won't be necessary if you use assq-delete-all or mapcar, but if +you stick with the remove-if, you should also change the + (eval-when-compile (require 'cl)) +to + (require 'cl) -- 2.26.2