[PATCH] emacs: More address cleaning.
authorDavid Edmondson <dme@dme.org>
Mon, 30 Jan 2012 14:59:54 +0000 (14:59 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:40 +0000 (09:43 -0800)
bd/3c13adc90c618187c8d5a1faecc223d3050874 [new file with mode: 0644]

diff --git a/bd/3c13adc90c618187c8d5a1faecc223d3050874 b/bd/3c13adc90c618187c8d5a1faecc223d3050874
new file mode 100644 (file)
index 0000000..92ee689
--- /dev/null
@@ -0,0 +1,128 @@
+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 EDC1B429E34\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 07:00:04 -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 C8L2jqD6TRXW for <notmuch@notmuchmail.org>;\r
+       Mon, 30 Jan 2012 07:00:04 -0800 (PST)\r
+Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
+ [74.125.82.45])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ DB4CA431FBC   for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 07:00:03 -0800\r
+ (PST)\r
+Received: by wgbdt12 with SMTP id dt12so4091508wgb.2\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 07:00:01 -0800 (PST)\r
+Received: by 10.180.99.199 with SMTP id es7mr27969100wib.10.1327935601284;\r
+       Mon, 30 Jan 2012 07:00:01 -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 fr8sm53142847wib.10.2012.01.30.06.59.59\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Mon, 30 Jan 2012 07:00:00 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id 714ED9FDD7; Mon, 30 Jan 2012 14:59:58 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: =?UTF-8?q?=5BPATCH=5D=20emacs=3A=20More=20address=20cleaning=2E?=\r
+Date: Mon, 30 Jan 2012 14:59:54 +0000\r
+Message-Id: <1327935594-14180-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.8.3\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\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: Mon, 30 Jan 2012 15:00:05 -0000\r
+\r
+Remove outer single-quotes from the mailbox part. Allow for multiple\r
+sets of nested single and double quotes.\r
+\r
+Add more tests.\r
+---\r
+ emacs/notmuch-show.el          |   24 +++++++++++++++++-------\r
+ test/emacs-address-cleaning.el |    8 ++++++++\r
+ 2 files changed, 25 insertions(+), 7 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 84ac624..7bfbda9 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -315,15 +315,25 @@ unchanged ADDRESS if parsing fails."\r
+        (t\r
+       (setq p-address address)))\r
\r
+-      ;; Remove elements of the mailbox part that are not relevant for\r
+-      ;; display, even if they are required during transport.\r
+       (when p-name\r
+-      ;; Outer double quotes.\r
+-      (when (string-match "^\"\\(.*\\)\"$" p-name)\r
+-        (setq p-name (match-string 1 p-name)))\r
+-\r
++      ;; Remove elements of the mailbox part that are not relevant for\r
++      ;; display, even if they are required during transport:\r
++      ;;\r
+       ;; Backslashes.\r
+-      (setq p-name (replace-regexp-in-string "\\\\" "" p-name)))\r
++      (setq p-name (replace-regexp-in-string "\\\\" "" p-name))\r
++\r
++      ;; Outer single and double quotes, which might be nested.\r
++      (loop\r
++       with start-of-loop\r
++       do (setq start-of-loop p-name)\r
++\r
++       when (string-match "^\"\\(.*\\)\"$" p-name)\r
++       do (setq p-name (match-string 1 p-name))\r
++\r
++       when (string-match "^'\\(.*\\)'$" p-name)\r
++       do (setq p-name (match-string 1 p-name))\r
++\r
++       until (string= start-of-loop p-name)))\r
\r
+       ;; If the address is 'foo@bar.com <foo@bar.com>' then show just\r
+       ;; 'foo@bar.com'.\r
+diff --git a/test/emacs-address-cleaning.el b/test/emacs-address-cleaning.el\r
+index 3b0b109..8423245 100644\r
+--- a/test/emacs-address-cleaning.el\r
++++ b/test/emacs-address-cleaning.el\r
+@@ -21,11 +21,19 @@\r
+                 "foo (at home) <foo@bar.com>"\r
+                 "foo [at home] <foo@bar.com>"\r
+                 "Foo Bar"\r
++                "'Foo Bar' <foo@bar.com>"\r
++                "\"'Foo Bar'\" <foo@bar.com>"\r
++                "'\"Foo Bar\"' <foo@bar.com>"\r
++                "'\"'Foo Bar'\"' <foo@bar.com>"\r
+                 "Fred Dibna \\[extraordinaire\\] <fred@dibna.com>"))\r
+        (expected '("ДБ <db-uknot@stop.me.uk>"\r
+                    "foo (at home) <foo@bar.com>"\r
+                    "foo [at home] <foo@bar.com>"\r
+                    "Foo Bar"\r
++                   "Foo Bar <foo@bar.com>"\r
++                   "Foo Bar <foo@bar.com>"\r
++                   "Foo Bar <foo@bar.com>"\r
++                   "Foo Bar <foo@bar.com>"\r
+                    "Fred Dibna [extraordinaire] <fred@dibna.com>"))\r
+        (output (mapcar #'notmuch-show-clean-address input)))\r
+     (notmuch-test-expect-equal output expected)))\r
+-- \r
+1.7.8.3\r
+\r