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 2A46E431FD5 for ; Thu, 20 Feb 2014 11:16:54 -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 0F53ZaSnHOuK for ; Thu, 20 Feb 2014 11:16:50 -0800 (PST) Received: from dmz-mailsec-scanner-2.mit.edu (dmz-mailsec-scanner-2.mit.edu [18.9.25.13]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 99143431FC0 for ; Thu, 20 Feb 2014 11:16:47 -0800 (PST) X-AuditID: 1209190d-f79776d000000ce9-ed-5306549e7d8d 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-2.mit.edu (Symantec Messaging Gateway) with SMTP id A0.04.03305.E9456035; Thu, 20 Feb 2014 14:16:46 -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 s1KJGht8026147; Thu, 20 Feb 2014 14:16:44 -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 s1KJGfZl012830 (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-0004ZC-2b; Thu, 20 Feb 2014 14:16:41 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 4/4] emacs: Simplify and fix `notmuch-mua-prompt-for-sender' Date: Thu, 20 Feb 2014 14:16:37 -0500 Message-Id: <1392923797-17045-5-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+NgFjrBIsWRmVeSWpSXmKPExsUixG6nojsvhC3Y4MJRJYvXCyaxWVy/OZPZ gclj9dpOFo9nq24xBzBFcdmkpOZklqUW6dslcGX8+/SOueCUVEVT02OmBsY9ol2MnBwSAiYS 28+uZoawxSQu3FvPBmILCcxmkuhc4N3FyAVkb2SU+Nj/lR3COcIkcezpT1YIZy6jxMUT38Ha 2QQ0JLbtX84IYosISEvsvDubFcRmFrCR2PzxMVhcWMBHYs62pUwgNouAqkTXt0fsIDavgIPE iZ9fGSHOUJJYeGobWC+ngKPE0v4PQDYH0DIHic6tOhMY+RcwMqxilE3JrdLNTczMKU5N1i1O TszLSy3SNdLLzSzRS00p3cQICiROSd4djO8OKh1iFOBgVOLhPSHFFizEmlhWXJl7iFGSg0lJ lHdFAFCILyk/pTIjsTgjvqg0J7X4EKMEB7OSCG+TDVCONyWxsiq1KB8mJc3BoiTOW2vxK0hI ID2xJDU7NbUgtQgmK8PBoSTBGxoM1ChYlJqeWpGWmVOCkGbi4AQZzgM0PDIIZHhxQWJucWY6 RP4Uoy7H+wV/PzEKseTl56VKifM+BSkSACnKKM2DmwNLAK8YxYHeEuadD7KOB5g84Ca9AlrC BLSkZCMryJKSRISUVANjTs27c7NnrHO+EPPwocG2U0Gnux8/FP70qNf1VJDt1l4PM8ZO8dKQ 75y2cRoiMgbG8l4CBrUdSgsW71zoOnsLw1pZ7aAV72aeVVvHzRL17fi9y8cWiky71e8pV/sy jKUsRNSlPnCh/TPpHJuT5scLptw/lWQfZr1vTnO9x3HXPy/bNFpPr2dWYinOSDTUYi4qTgQA EJQD1tsCAAA= 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:16:54 -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, but this has several problems. First, 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 " ". Second, though less serious, the prompt specialization means the user can't enter a different name like they can if their identities have different names. This patch rewrites `notmuch-mua-prompt-for-sender' to simply prompt for a full identity, where the list of identities is derived from either notmuch-identities or the user's Notmuch configuration. 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. --- emacs/notmuch-mua.el | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el index f2df770..4a485a4 100644 --- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -286,30 +286,15 @@ 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." + (let ((identities (or notmuch-identities + (let ((name (notmuch-user-name))) + (mapcar (lambda (addr) (concat name " <" addr ">")) + (cons (notmuch-user-primary-email) + (notmuch-user-other-email))))))) + (ido-completing-read "Send mail from: " identities + nil nil nil 'notmuch-mua-sender-history + (car identities)))) (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