[PATCH v2] emacs: Simplify and fix `notmuch-mua-prompt-for-sender'
authorAustin Clements <amdragon@MIT.EDU>
Thu, 27 Feb 2014 18:10:54 +0000 (13:10 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:00:17 +0000 (10:00 -0800)
40/35f8548b32274fb64500e607c9ae0a04398788 [new file with mode: 0644]

diff --git a/40/35f8548b32274fb64500e607c9ae0a04398788 b/40/35f8548b32274fb64500e607c9ae0a04398788
new file mode 100644 (file)
index 0000000..8aa498d
--- /dev/null
@@ -0,0 +1,152 @@
+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 DC73E431FAF\r
+       for <notmuch@notmuchmail.org>; Thu, 27 Feb 2014 10:11:10 -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 UmaNpR+p7DYu for <notmuch@notmuchmail.org>;\r
+       Thu, 27 Feb 2014 10:11:04 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
+       [18.7.68.35])\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 7B53D431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 27 Feb 2014 10:11:04 -0800 (PST)\r
+X-AuditID: 12074423-f79726d000000cc9-64-530f7fb5580e\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       (using TLS with cipher AES256-SHA (256/256 bits))\r
+       (Client did not present a certificate)\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 8D.8D.03273.5BF7F035; Thu, 27 Feb 2014 13:11:01 -0500 (EST)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s1RIAx57006187; \r
+       Thu, 27 Feb 2014 13:10:59 -0500\r
+Received: from drake.dyndns.org\r
+       (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (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 s1RIAvat014764\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Thu, 27 Feb 2014 13:10:58 -0500\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1WJ5Q8-0005Ms-NE; Thu, 27 Feb 2014 13:10:56 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2] emacs: Simplify and fix `notmuch-mua-prompt-for-sender'\r
+Date: Thu, 27 Feb 2014 13:10:54 -0500\r
+Message-Id: <1393524654-20502-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.8.4.rc3\r
+In-Reply-To: <87fvndfm3k.fsf@qmul.ac.uk>\r
+References: <87fvndfm3k.fsf@qmul.ac.uk>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrJIsWRmVeSWpSXmKPExsUixG6noru1nj/Y4NBbS4vVc3ksrt+cyezA\r
+       5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZfx88YS5YLNUxbcps5kbGKeIdjFyckgImEhs\r
+       e3+ZBcIWk7hwbz1bFyMXh5DAbCaJFxfvsUA4Gxkljl59xQ7h3GGSuPVnIiOEM5dRYuOx72D9\r
+       bAIaEtv2L2cEsUUEpCV23p3NCmIzCzhKfN6/iA3EFhbwljjV9xWsnkVAVeJR13xmEJtXwEHi\r
+       +76VbBB3KEksPLUNrJcTaOaNJdPBaoQE1CUav3ezT2DkX8DIsIpRNiW3Sjc3MTOnODVZtzg5\r
+       MS8vtUjXTC83s0QvNaV0EyM4lFyUdzD+Oah0iFGAg1GJh3eiJ3+wEGtiWXFl7iFGSQ4mJVHe\r
+       YzVAIb6k/JTKjMTijPii0pzU4kOMEhzMSiK8J6qBcrwpiZVVqUX5MClpDhYlcd5ai19BQgLp\r
+       iSWp2ampBalFMFkZDg4lCV6ROqBGwaLU9NSKtMycEoQ0EwcnyHAeoOFKIDW8xQWJucWZ6RD5\r
+       U4y6HO8X/P3EKMSSl5+XKiXO+60WqEgApCijNA9uDiwFvGIUB3pLmJcLZBQPMH3ATXoFtIQJ\r
+       aMlRaR6QJSWJCCmpBsbdm9+9u98Z/+Z76rY1ym//MbS4Tt2/zHauz/t3mtqMvAItL1fy6ESm\r
+       2P3XEX0fbvCsudN8cXr/wulHuHpZ9hqH//t5Uuzj1ncHHR++3f5PebGjqG2i8L09hxRrp2+T\r
+       mFUT28S3WF/r0UI3DzNrY9WNvMeZWPkXqxhtjT8s+UJlxZyAh266B34rsRRnJBpqMRcVJwIA\r
+       mFoin9wCAAA=\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, 27 Feb 2014 18:11:11 -0000\r
+\r
+`notmuch-mua-prompt-for-sender' is over-engineered and often wrong.\r
+It attempts to detect when all identities have the same name and\r
+specialize the prompt to just the email address part.  However, to do\r
+this it uses `mail-extract-address-components', which is meant for\r
+displaying email addresses, not general-purpose parsing, and hence\r
+performs many canonicalizations that can interfere with this use.  For\r
+example, configuring notmuch-identities to ("Austin\r
+<austin@example.com>"), will cause `notmuch-mua-prompt-for-sender' to\r
+lose the name part entirely and return " <austin@example.com>".\r
+\r
+This patch rewrites `notmuch-mua-prompt-for-sender' to simply prompt\r
+for a full identity when notmuch-identities is configured, or to\r
+prompt for a sender address when it isn't.\r
+\r
+The original code also did several strange things, like using `eval'\r
+and specifying that this function was interactive.  As a side-effect,\r
+this patch fixes these problems.  And it adds a docstring.\r
+---\r
+\r
+Mark, is this better?\r
+\r
+emacs/notmuch-mua.el | 37 +++++++++++++------------------------\r
+ 1 file changed, 13 insertions(+), 24 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+index f2df770..b16a10e 100644\r
+--- a/emacs/notmuch-mua.el\r
++++ b/emacs/notmuch-mua.el\r
+@@ -286,30 +286,19 @@ the From: header is already filled in by notmuch."\r
+       (ad-activate 'ido-completing-read)))\r
\r
+ (defun notmuch-mua-prompt-for-sender ()\r
+-  (interactive)\r
+-  (let (name addresses one-name-only)\r
+-    ;; If notmuch-identities is non-nil, check if there is a fixed user name.\r
+-    (if notmuch-identities\r
+-      (let ((components (mapcar 'mail-extract-address-components notmuch-identities)))\r
+-        (setq name          (caar components)\r
+-              addresses     (mapcar 'cadr components)\r
+-              one-name-only (eval\r
+-                             (cons 'and\r
+-                                   (mapcar (lambda (identity)\r
+-                                             (string-equal name (car identity)))\r
+-                                           components)))))\r
+-      ;; If notmuch-identities is nil, use values from the notmuch configuration file.\r
+-      (setq name          (notmuch-user-name)\r
+-          addresses     (cons (notmuch-user-primary-email) (notmuch-user-other-email))\r
+-          one-name-only t))\r
+-    ;; Now prompt the user, either for an email address only or for a full identity.\r
+-    (if one-name-only\r
+-      (let ((address\r
+-             (ido-completing-read (concat "Sender address for " name ": ") addresses\r
+-                                  nil nil nil 'notmuch-mua-sender-history (car addresses))))\r
+-        (concat name " <" address ">"))\r
+-      (ido-completing-read "Send mail From: " notmuch-identities\r
+-                         nil nil nil 'notmuch-mua-sender-history (car notmuch-identities)))))\r
++  "Prompt for a sender from the user's configured identities."\r
++  (if notmuch-identities\r
++      (ido-completing-read "Send mail from: " notmuch-identities\r
++                         nil nil nil 'notmuch-mua-sender-history\r
++                         (car notmuch-identities))\r
++    (let* ((name (notmuch-user-name))\r
++         (addrs (cons (notmuch-user-primary-email)\r
++                      (notmuch-user-other-email)))\r
++         (address\r
++          (ido-completing-read (concat "Sender address for " name ": ") addrs\r
++                               nil nil nil 'notmuch-mua-sender-history\r
++                               (car addrs))))\r
++      (concat name " <" address ">"))))\r
\r
+ (put 'notmuch-mua-new-mail 'notmuch-prefix-doc "... and prompt for sender")\r
+ (defun notmuch-mua-new-mail (&optional prompt-for-sender)\r
+-- \r
+1.8.4.rc3\r
+\r