From: Austin Clements Date: Mon, 30 Jan 2012 15:04:53 +0000 (+1900) Subject: Re: [PATCH] emacs: More address cleaning. X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=9e484d784d298458bd9cd017c2cb5be813d681f4;p=notmuch-archives.git Re: [PATCH] emacs: More address cleaning. --- diff --git a/38/1d341e4673101eec96c1fa089473a6d4311409 b/38/1d341e4673101eec96c1fa089473a6d4311409 new file mode 100644 index 000000000..17e623f09 --- /dev/null +++ b/38/1d341e4673101eec96c1fa089473a6d4311409 @@ -0,0 +1,150 @@ +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 E4E26431E64 + for ; Mon, 30 Jan 2012 07:05:46 -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 sjq9MZYKi1Zo for ; + Mon, 30 Jan 2012 07:05:46 -0800 (PST) +Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU + [18.7.68.35]) + by olra.theworths.org (Postfix) with ESMTP id 47A61431FBC + for ; Mon, 30 Jan 2012 07:05:46 -0800 (PST) +X-AuditID: 12074423-b7f9c6d0000008c3-f3-4f26b1c9327e +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP + id 30.DC.02243.9C1B62F4; Mon, 30 Jan 2012 10:05:45 -0500 (EST) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0UF5iNv005314; + Mon, 30 Jan 2012 10:05:45 -0500 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0UF5he8021054 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Mon, 30 Jan 2012 10:05:44 -0500 (EST) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1Rrsmr-0001tJ-Je; Mon, 30 Jan 2012 10:04:53 -0500 +Date: Mon, 30 Jan 2012 10:04:53 -0500 +From: Austin Clements +To: David Edmondson +Subject: Re: [PATCH] emacs: More address cleaning. +Message-ID: <20120130150453.GQ17991@mit.edu> +References: <1327935594-14180-1-git-send-email-dme@dme.org> +MIME-Version: 1.0 +Content-Type: text/plain; charset=utf-8 +Content-Disposition: inline +Content-Transfer-Encoding: 8bit +In-Reply-To: <1327935594-14180-1-git-send-email-dme@dme.org> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFprBKsWRmVeSWpSXmKPExsUixCmqrXtyo5q/wdTFJhb77mxhsrh+cyaz + A5PHrud/mTyerbrFHMAUxWWTkpqTWZZapG+XwJVx4s9C5oJdohUPlwc0MB4R6GLk5JAQMJF4 + Mek/O4QtJnHh3no2EFtIYB+jxMuLXBD2BkaJvssuXYxcQPZJJokXfzeyQThLGCVuTb7KDFLF + IqAq8fP0RBYQm01AQ2Lb/uWMILaIgKLE/28rwDYwC0hLfPvdzARiCwsYSfy9dx+ohoODV0BH + 4v9xCYhl1hKn13SClfMKCEqcnPmEBaJVXeLPvEvMIOUgY5b/44AIy0s0b50NdgGngI3Evt9v + wbaKCqhITDm5jW0Co/AsJJNmIZk0C2HSLCSTFjCyrGKUTcmt0s1NzMwpTk3WLU5OzMtLLdI1 + 08vNLNFLTSndxAiKAHYX5R2Mfw4qHWIU4GBU4uEN+qfqL8SaWFZcmXuIUZKDSUmUNxoYP0J8 + SfkplRmJxRnxRaU5qcWHGCU4mJVEeN+sBsrxpiRWVqUW5cOkpDlYlMR5NbTe+QkJpCeWpGan + phakFsFkZTg4lCR4dUGGChalpqdWpGXmlCCkmTg4QYbzAA1XA6nhLS5IzC3OTIfIn2JUlBLn + 5QJJCIAkMkrz4HphCeoVozjQK8K8qiBVPMDkBtf9CmgwE9Dg5wyqIINLEhFSUg2MHXKPb03K + m6n4w7Mr2Kpafl07/x87jrn36yRv/FW7Or9mvqJ2rHrSw7D0rtdVCu6tT84+f886wXa9lck+ + vhfCPSY7p87+2tIX8IbNeNf5j8Hp747wMhfah8uuE5f1Kj7a4fek/nn26bKNZVdYL0xzvBq7 + 7+KrBSeE9Vw3p1/U1O7Xf6sjsu6VEktxRqKhFnNRcSIAI4R0tisDAAA= +Cc: notmuch@notmuchmail.org +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: Mon, 30 Jan 2012 15:05:47 -0000 + +loop freaks me out a little, but LGTM. + +Quoth David Edmondson on Jan 30 at 2:59 pm: +> Remove outer single-quotes from the mailbox part. Allow for multiple +> sets of nested single and double quotes. +> +> Add more tests. +> --- +> emacs/notmuch-show.el | 24 +++++++++++++++++------- +> test/emacs-address-cleaning.el | 8 ++++++++ +> 2 files changed, 25 insertions(+), 7 deletions(-) +> +> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +> index 84ac624..7bfbda9 100644 +> --- a/emacs/notmuch-show.el +> +++ b/emacs/notmuch-show.el +> @@ -315,15 +315,25 @@ unchanged ADDRESS if parsing fails." +> (t +> (setq p-address address))) +> +> - ;; Remove elements of the mailbox part that are not relevant for +> - ;; display, even if they are required during transport. +> (when p-name +> - ;; Outer double quotes. +> - (when (string-match "^\"\\(.*\\)\"$" p-name) +> - (setq p-name (match-string 1 p-name))) +> - +> + ;; Remove elements of the mailbox part that are not relevant for +> + ;; display, even if they are required during transport: +> + ;; +> ;; Backslashes. +> - (setq p-name (replace-regexp-in-string "\\\\" "" p-name))) +> + (setq p-name (replace-regexp-in-string "\\\\" "" p-name)) +> + +> + ;; Outer single and double quotes, which might be nested. +> + (loop +> + with start-of-loop +> + do (setq start-of-loop p-name) +> + +> + when (string-match "^\"\\(.*\\)\"$" p-name) +> + do (setq p-name (match-string 1 p-name)) +> + +> + when (string-match "^'\\(.*\\)'$" p-name) +> + do (setq p-name (match-string 1 p-name)) +> + +> + until (string= start-of-loop p-name))) +> +> ;; If the address is 'foo@bar.com ' then show just +> ;; 'foo@bar.com'. +> diff --git a/test/emacs-address-cleaning.el b/test/emacs-address-cleaning.el +> index 3b0b109..8423245 100644 +> --- a/test/emacs-address-cleaning.el +> +++ b/test/emacs-address-cleaning.el +> @@ -21,11 +21,19 @@ +> "foo (at home) " +> "foo [at home] " +> "Foo Bar" +> + "'Foo Bar' " +> + "\"'Foo Bar'\" " +> + "'\"Foo Bar\"' " +> + "'\"'Foo Bar'\"' " +> "Fred Dibna \\[extraordinaire\\] ")) +> (expected '("ДБ " +> "foo (at home) " +> "foo [at home] " +> "Foo Bar" +> + "Foo Bar " +> + "Foo Bar " +> + "Foo Bar " +> + "Foo Bar " +> "Fred Dibna [extraordinaire] ")) +> (output (mapcar #'notmuch-show-clean-address input))) +> (notmuch-test-expect-equal output expected)))