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