[PATCH 4/4] emacs: Simplify and fix `notmuch-mua-prompt-for-sender'
authorAustin Clements <amdragon@MIT.EDU>
Thu, 20 Feb 2014 19:16:37 +0000 (14:16 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:00:06 +0000 (10:00 -0800)
c4/d0c85ad913f4d8cbfb08c2b59c2a74b63999f4 [new file with mode: 0644]

diff --git a/c4/d0c85ad913f4d8cbfb08c2b59c2a74b63999f4 b/c4/d0c85ad913f4d8cbfb08c2b59c2a74b63999f4
new file mode 100644 (file)
index 0000000..3306489
--- /dev/null
@@ -0,0 +1,148 @@
+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 2A46E431FD5\r
+       for <notmuch@notmuchmail.org>; Thu, 20 Feb 2014 11:16:54 -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 0F53ZaSnHOuK for <notmuch@notmuchmail.org>;\r
+       Thu, 20 Feb 2014 11:16:50 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (dmz-mailsec-scanner-2.mit.edu\r
+       [18.9.25.13])\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 99143431FC0\r
+       for <notmuch@notmuchmail.org>; Thu, 20 Feb 2014 11:16:47 -0800 (PST)\r
+X-AuditID: 1209190d-f79776d000000ce9-ed-5306549e7d8d\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-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id A0.04.03305.E9456035; Thu, 20 Feb 2014 14:16:46 -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 s1KJGht8026147; \r
+       Thu, 20 Feb 2014 14:16:44 -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 s1KJGfZl012830\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-0004ZC-2b; Thu, 20 Feb 2014 14:16:41 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/4] emacs: Simplify and fix `notmuch-mua-prompt-for-sender'\r
+Date: Thu, 20 Feb 2014 14:16:37 -0500\r
+Message-Id: <1392923797-17045-5-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+NgFjrBIsWRmVeSWpSXmKPExsUixG6nojsvhC3Y4MJRJYvXCyaxWVy/OZPZ\r
+       gclj9dpOFo9nq24xBzBFcdmkpOZklqUW6dslcGX8+/SOueCUVEVT02OmBsY9ol2MnBwSAiYS\r
+       28+uZoawxSQu3FvPBmILCcxmkuhc4N3FyAVkb2SU+Nj/lR3COcIkcezpT1YIZy6jxMUT38Ha\r
+       2QQ0JLbtX84IYosISEvsvDubFcRmFrCR2PzxMVhcWMBHYs62pUwgNouAqkTXt0fsIDavgIPE\r
+       iZ9fGSHOUJJYeGobWC+ngKPE0v4PQDYH0DIHic6tOhMY+RcwMqxilE3JrdLNTczMKU5N1i1O\r
+       TszLSy3SNdLLzSzRS00p3cQICiROSd4djO8OKh1iFOBgVOLhPSHFFizEmlhWXJl7iFGSg0lJ\r
+       lHdFAFCILyk/pTIjsTgjvqg0J7X4EKMEB7OSCG+TDVCONyWxsiq1KB8mJc3BoiTOW2vxK0hI\r
+       ID2xJDU7NbUgtQgmK8PBoSTBGxoM1ChYlJqeWpGWmVOCkGbi4AQZzgM0PDIIZHhxQWJucWY6\r
+       RP4Uoy7H+wV/PzEKseTl56VKifM+BSkSACnKKM2DmwNLAK8YxYHeEuadD7KOB5g84Ca9AlrC\r
+       BLSkZCMryJKSRISUVANjTs27c7NnrHO+EPPwocG2U0Gnux8/FP70qNf1VJDt1l4PM8ZO8dKQ\r
+       75y2cRoiMgbG8l4CBrUdSgsW71zoOnsLw1pZ7aAV72aeVVvHzRL17fi9y8cWiky71e8pV/sy\r
+       jKUsRNSlPnCh/TPpHJuT5scLptw/lWQfZr1vTnO9x3HXPy/bNFpPr2dWYinOSDTUYi4qTgQA\r
+       EJQD1tsCAAA=\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:16:54 -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, but this has\r
+several problems.  First, it uses `mail-extract-address-components',\r
+which is meant for displaying email addresses, not general-purpose\r
+parsing, and hence performs many canonicalizations that can interfere\r
+with this use.  For example, configuring notmuch-identities to\r
+("Austin <austin@example.com>"), will cause\r
+`notmuch-mua-prompt-for-sender' to lose the name part entirely and\r
+return " <austin@example.com>".  Second, though less serious, the\r
+prompt specialization means the user can't enter a different name like\r
+they can if their identities have different names.\r
+\r
+This patch rewrites `notmuch-mua-prompt-for-sender' to simply prompt\r
+for a full identity, where the list of identities is derived from\r
+either notmuch-identities or the user's Notmuch configuration.\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
+ emacs/notmuch-mua.el | 33 +++++++++------------------------\r
+ 1 file changed, 9 insertions(+), 24 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+index f2df770..4a485a4 100644\r
+--- a/emacs/notmuch-mua.el\r
++++ b/emacs/notmuch-mua.el\r
+@@ -286,30 +286,15 @@ 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
++  (let ((identities (or notmuch-identities\r
++                      (let ((name (notmuch-user-name)))\r
++                        (mapcar (lambda (addr) (concat name " <" addr ">"))\r
++                                (cons (notmuch-user-primary-email)\r
++                                      (notmuch-user-other-email)))))))\r
++    (ido-completing-read "Send mail from: " identities\r
++                       nil nil nil 'notmuch-mua-sender-history\r
++                       (car identities))))\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