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 6F094429E39 for ; Wed, 25 Jan 2012 05:54:07 -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 AejxQu9kLC0a for ; Wed, 25 Jan 2012 05:54:06 -0800 (PST) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 7DE30431FD5 for ; Wed, 25 Jan 2012 05:54:06 -0800 (PST) Received: by wibhi8 with SMTP id hi8so2501276wib.26 for ; Wed, 25 Jan 2012 05:54:05 -0800 (PST) MIME-Version: 1.0 Received: by 10.180.101.35 with SMTP id fd3mr28169765wib.22.1327499645249; Wed, 25 Jan 2012 05:54:05 -0800 (PST) Received: from hotblack-desiato.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25]) by mx.google.com with ESMTPS id di5sm1833222wib.3.2012.01.25.05.54.03 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 25 Jan 2012 05:54:03 -0800 (PST) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id 003CD9FBD5; Wed, 25 Jan 2012 13:54:01 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 1/3] emacs: Avoid `mail-header-parse-address' in `notmuch-show-clean-address'. Date: Wed, 25 Jan 2012 13:53:58 +0000 Message-Id: <1327499640-11747-2-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.8.3 In-Reply-To: <1327499640-11747-1-git-send-email-dme@dme.org> References: <1327491904-28416-1-git-send-email-dme@dme.org> <1327499640-11747-1-git-send-email-dme@dme.org> X-Gm-Message-State: ALoCoQn26I2zbi6CwSplB3/Bcumml5lF647S/srBC8D1jjIg+MQOopvDlO60hfRuDV5iQB8FTf2p 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: Wed, 25 Jan 2012 13:54:07 -0000 `mail-header-parse-address' expects un-decoded mailbox parts, which is not what we have at this point. Replace it with simple string deconstruction. Mark the corresponding test as no longer broken. Minor whitespace cleanup. --- emacs/notmuch-show.el | 50 ++++++++++++++++++++++++++++----------- test/emacs-address-cleaning.sh | 1 - 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index e6a5b31..1fd2524 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -289,21 +289,43 @@ operation on the contents of the current buffer." "Try to clean a single email ADDRESS for display. Return unchanged ADDRESS if parsing fails." (condition-case nil - (let* ((parsed (mail-header-parse-address address)) - (address (car parsed)) - (name (cdr parsed))) - ;; Remove double quotes. They might be required during transport, - ;; but we don't need to see them. - (when name - (setq name (replace-regexp-in-string "\"" "" name))) + (let (p-name p-address) + ;; It would be convenient to use `mail-header-parse-address', + ;; but that expects un-decoded mailbox parts, whereas our + ;; mailbox parts are already decoded (and hence may contain + ;; UTF-8). Given that notmuch should handle most of the awkward + ;; cases, some simple string deconstruction should be sufficient + ;; here. + (cond + ;; "User " style. + ((string-match "\\(.*\\) <\\(.*\\)>" address) + (setq p-name (match-string 1 address) + p-address (match-string 2 address))) + + ;; "" style. + ((string-match "<\\(.*\\)>" address) + (setq p-address (match-string 1 address))) + + ;; Everything else. + (t + (setq p-address address))) + + ;; Remove outer double quotes. They might be required during + ;; transport, but we don't need to see them. + (when (and p-name + (string-match "^\"\\(.*\\)\"$" p-name)) + (setq p-name (match-string 1 p-name))) + ;; If the address is 'foo@bar.com ' then show just ;; 'foo@bar.com'. - (when (string= name address) - (setq name nil)) - - (if (not name) - address - (concat name " <" address ">"))) + (when (string= p-name p-address) + (setq p-name nil)) + + ;; If no name results, return just the address. + (if (not p-name) + p-address + ;; Otherwise format the name and address together. + (concat p-name " <" p-address ">"))) (error address))) (defun notmuch-show-insert-headerline (headers date tags depth) @@ -1417,7 +1439,7 @@ than only the current message." (interactive "P\nsPipe message to command: ") (let (shell-command) (if entire-thread - (setq shell-command + (setq shell-command (concat notmuch-command " show --format=mbox " (shell-quote-argument (mapconcat 'identity (notmuch-show-get-message-ids-for-open-messages) " OR ")) diff --git a/test/emacs-address-cleaning.sh b/test/emacs-address-cleaning.sh index 0d85bdc..51018fe 100755 --- a/test/emacs-address-cleaning.sh +++ b/test/emacs-address-cleaning.sh @@ -12,7 +12,6 @@ test_emacs_expect_t \ '(load "emacs-address-cleaning.el") (notmuch-test-address-cleaning-2)' test_begin_subtest "notmuch-test-address-clean part 3" -test_subtest_known_broken test_emacs_expect_t \ '(load "emacs-address-cleaning.el") (notmuch-test-address-cleaning-3)' -- 1.7.8.3