[PATCH 3/4] emacs: Avoid `mail-header-parse-address' in `notmuch-show-clean-address'.
authorDavid Edmondson <dme@dme.org>
Tue, 17 Jan 2012 12:52:27 +0000 (12:52 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:42:25 +0000 (09:42 -0800)
63/4783670fd89f3837f539b06b34145433f56146 [new file with mode: 0644]

diff --git a/63/4783670fd89f3837f539b06b34145433f56146 b/63/4783670fd89f3837f539b06b34145433f56146
new file mode 100644 (file)
index 0000000..1c88bcc
--- /dev/null
@@ -0,0 +1,126 @@
+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 2E9A8429E5A\r
+       for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 04:52:48 -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 5M6FxTgZsDDO for <notmuch@notmuchmail.org>;\r
+       Tue, 17 Jan 2012 04:52:47 -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 6BF00429E3B\r
+       for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 04:52:47 -0800 (PST)\r
+Received: by wibhr12 with SMTP id hr12so3405338wib.26\r
+       for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 04:52:46 -0800 (PST)\r
+Received: by 10.180.84.133 with SMTP id z5mr22717168wiy.10.1326804766277;\r
+       Tue, 17 Jan 2012 04:52:46 -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 g12sm43726534wiw.10.2012.01.17.04.52.43\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Tue, 17 Jan 2012 04:52:44 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id 06C7FA051F; Tue, 17 Jan 2012 12:52:42 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/4] emacs: Avoid `mail-header-parse-address' in\r
+       `notmuch-show-clean-address'.\r
+Date: Tue, 17 Jan 2012 12:52:27 +0000\r
+Message-Id: <1326804748-8989-4-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <1326804748-8989-1-git-send-email-dme@dme.org>\r
+References: <1326804748-8989-1-git-send-email-dme@dme.org>\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: Tue, 17 Jan 2012 12:52:48 -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
+ emacs/notmuch-show.el |   48 +++++++++++++++++++++++++++++++++++-------------\r
+ 1 files changed, 35 insertions(+), 13 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 797f94b..8b2fbb3 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -227,21 +227,43 @@ indentation."\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
+-- \r
+1.7.7.3\r
+\r