From e25e76951c7f7b540bf403deb819714a49631c16 Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Mon, 30 Jan 2012 14:59:54 +0000 Subject: [PATCH] [PATCH] emacs: More address cleaning. --- bd/3c13adc90c618187c8d5a1faecc223d3050874 | 128 ++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 bd/3c13adc90c618187c8d5a1faecc223d3050874 diff --git a/bd/3c13adc90c618187c8d5a1faecc223d3050874 b/bd/3c13adc90c618187c8d5a1faecc223d3050874 new file mode 100644 index 000000000..92ee68973 --- /dev/null +++ b/bd/3c13adc90c618187c8d5a1faecc223d3050874 @@ -0,0 +1,128 @@ +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 EDC1B429E34 + for ; Mon, 30 Jan 2012 07:00:04 -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 C8L2jqD6TRXW for ; + Mon, 30 Jan 2012 07:00:04 -0800 (PST) +Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com + [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + DB4CA431FBC for ; Mon, 30 Jan 2012 07:00:03 -0800 + (PST) +Received: by wgbdt12 with SMTP id dt12so4091508wgb.2 + for ; Mon, 30 Jan 2012 07:00:01 -0800 (PST) +Received: by 10.180.99.199 with SMTP id es7mr27969100wib.10.1327935601284; + Mon, 30 Jan 2012 07:00:01 -0800 (PST) +Received: from hotblack-desiato.hh.sledj.net + (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25]) + by mx.google.com with ESMTPS id fr8sm53142847wib.10.2012.01.30.06.59.59 + (version=TLSv1/SSLv3 cipher=OTHER); + Mon, 30 Jan 2012 07:00:00 -0800 (PST) +Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) + id 714ED9FDD7; Mon, 30 Jan 2012 14:59:58 +0000 (GMT) +From: David Edmondson +To: notmuch@notmuchmail.org +Subject: =?UTF-8?q?=5BPATCH=5D=20emacs=3A=20More=20address=20cleaning=2E?= +Date: Mon, 30 Jan 2012 14:59:54 +0000 +Message-Id: <1327935594-14180-1-git-send-email-dme@dme.org> +X-Mailer: git-send-email 1.7.8.3 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +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:00:05 -0000 + +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))) +-- +1.7.8.3 + -- 2.26.2