--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 E4E26431E64\r
+ for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 07:05:46 -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 sjq9MZYKi1Zo for <notmuch@notmuchmail.org>;\r
+ Mon, 30 Jan 2012 07:05:46 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+ [18.7.68.35])\r
+ by olra.theworths.org (Postfix) with ESMTP id 47A61431FBC\r
+ for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 07:05:46 -0800 (PST)\r
+X-AuditID: 12074423-b7f9c6d0000008c3-f3-4f26b1c9327e\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 30.DC.02243.9C1B62F4; Mon, 30 Jan 2012 10:05:45 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0UF5iNv005314; \r
+ Mon, 30 Jan 2012 10:05:45 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0UF5he8021054\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Mon, 30 Jan 2012 10:05:44 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1Rrsmr-0001tJ-Je; Mon, 30 Jan 2012 10:04:53 -0500\r
+Date: Mon, 30 Jan 2012 10:04:53 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: David Edmondson <dme@dme.org>\r
+Subject: Re: [PATCH] emacs: More address cleaning.\r
+Message-ID: <20120130150453.GQ17991@mit.edu>\r
+References: <1327935594-14180-1-git-send-email-dme@dme.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Disposition: inline\r
+Content-Transfer-Encoding: 8bit\r
+In-Reply-To: <1327935594-14180-1-git-send-email-dme@dme.org>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFprBKsWRmVeSWpSXmKPExsUixCmqrXtyo5q/wdTFJhb77mxhsrh+cyaz\r
+ A5PHrud/mTyerbrFHMAUxWWTkpqTWZZapG+XwJVx4s9C5oJdohUPlwc0MB4R6GLk5JAQMJF4\r
+ Mek/O4QtJnHh3no2EFtIYB+jxMuLXBD2BkaJvssuXYxcQPZJJokXfzeyQThLGCVuTb7KDFLF\r
+ IqAq8fP0RBYQm01AQ2Lb/uWMILaIgKLE/28rwDYwC0hLfPvdzARiCwsYSfy9dx+ohoODV0BH\r
+ 4v9xCYhl1hKn13SClfMKCEqcnPmEBaJVXeLPvEvMIOUgY5b/44AIy0s0b50NdgGngI3Evt9v\r
+ wbaKCqhITDm5jW0Co/AsJJNmIZk0C2HSLCSTFjCyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdI1\r
+ 08vNLNFLTSndxAiKAHYX5R2Mfw4qHWIU4GBU4uEN+qfqL8SaWFZcmXuIUZKDSUmUNxoYP0J8\r
+ SfkplRmJxRnxRaU5qcWHGCU4mJVEeN+sBsrxpiRWVqUW5cOkpDlYlMR5NbTe+QkJpCeWpGan\r
+ phakFsFkZTg4lCR4dUGGChalpqdWpGXmlCCkmTg4QYbzAA1XA6nhLS5IzC3OTIfIn2JUlBLn\r
+ 5QJJCIAkMkrz4HphCeoVozjQK8K8qiBVPMDkBtf9CmgwE9Dg5wyqIINLEhFSUg2MHXKPb03K\r
+ m6n4w7Mr2Kpafl07/x87jrn36yRv/FW7Or9mvqJ2rHrSw7D0rtdVCu6tT84+f886wXa9lck+\r
+ vhfCPSY7p87+2tIX8IbNeNf5j8Hp747wMhfah8uuE5f1Kj7a4fek/nn26bKNZVdYL0xzvBq7\r
+ 7+KrBSeE9Vw3p1/U1O7Xf6sjsu6VEktxRqKhFnNRcSIAI4R0tisDAAA=\r
+Cc: notmuch@notmuchmail.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: Mon, 30 Jan 2012 15:05:47 -0000\r
+\r
+loop freaks me out a little, but LGTM.\r
+\r
+Quoth David Edmondson on Jan 30 at 2:59 pm:\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