[PATCH 1/2] emacs: Avoid `mail-header-parse-address' in `notmuch-show-clean-address'.
authorDavid Edmondson <dme@dme.org>
Wed, 25 Jan 2012 11:45:03 +0000 (11:45 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:14 +0000 (09:43 -0800)
a9/d8e4d6ed9068fa8e8591b84dac73769cbf2945 [new file with mode: 0644]

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