unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: More address cleaning.
@ 2012-01-30 14:59 David Edmondson
  2012-01-30 15:04 ` Austin Clements
  2012-02-04 12:39 ` David Bremner
  0 siblings, 2 replies; 3+ messages in thread
From: David Edmondson @ 2012-01-30 14:59 UTC (permalink / raw)
  To: notmuch

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 <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@bar.com>"
 		  "foo [at home] <foo@bar.com>"
 		  "Foo Bar"
+		  "'Foo Bar' <foo@bar.com>"
+		  "\"'Foo Bar'\" <foo@bar.com>"
+		  "'\"Foo Bar\"' <foo@bar.com>"
+		  "'\"'Foo Bar'\"' <foo@bar.com>"
 		  "Fred Dibna \\[extraordinaire\\] <fred@dibna.com>"))
 	 (expected '("ДБ <db-uknot@stop.me.uk>"
 		     "foo (at home) <foo@bar.com>"
 		     "foo [at home] <foo@bar.com>"
 		     "Foo Bar"
+		     "Foo Bar <foo@bar.com>"
+		     "Foo Bar <foo@bar.com>"
+		     "Foo Bar <foo@bar.com>"
+		     "Foo Bar <foo@bar.com>"
 		     "Fred Dibna [extraordinaire] <fred@dibna.com>"))
 	 (output (mapcar #'notmuch-show-clean-address input)))
     (notmuch-test-expect-equal output expected)))
-- 
1.7.8.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] emacs: More address cleaning.
  2012-01-30 14:59 [PATCH] emacs: More address cleaning David Edmondson
@ 2012-01-30 15:04 ` Austin Clements
  2012-02-04 12:39 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: Austin Clements @ 2012-01-30 15:04 UTC (permalink / raw)
  To: David Edmondson; +Cc: notmuch

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 <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@bar.com>"
>  		  "foo [at home] <foo@bar.com>"
>  		  "Foo Bar"
> +		  "'Foo Bar' <foo@bar.com>"
> +		  "\"'Foo Bar'\" <foo@bar.com>"
> +		  "'\"Foo Bar\"' <foo@bar.com>"
> +		  "'\"'Foo Bar'\"' <foo@bar.com>"
>  		  "Fred Dibna \\[extraordinaire\\] <fred@dibna.com>"))
>  	 (expected '("ДБ <db-uknot@stop.me.uk>"
>  		     "foo (at home) <foo@bar.com>"
>  		     "foo [at home] <foo@bar.com>"
>  		     "Foo Bar"
> +		     "Foo Bar <foo@bar.com>"
> +		     "Foo Bar <foo@bar.com>"
> +		     "Foo Bar <foo@bar.com>"
> +		     "Foo Bar <foo@bar.com>"
>  		     "Fred Dibna [extraordinaire] <fred@dibna.com>"))
>  	 (output (mapcar #'notmuch-show-clean-address input)))
>      (notmuch-test-expect-equal output expected)))

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] emacs: More address cleaning.
  2012-01-30 14:59 [PATCH] emacs: More address cleaning David Edmondson
  2012-01-30 15:04 ` Austin Clements
@ 2012-02-04 12:39 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2012-02-04 12:39 UTC (permalink / raw)
  To: David Edmondson, notmuch

On Mon, 30 Jan 2012 14:59:54 +0000, David Edmondson <dme@dme.org> wrote:
> Remove outer single-quotes from the mailbox part. Allow for multiple
> sets of nested single and double quotes.

pushed, 

d

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-04 12:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-30 14:59 [PATCH] emacs: More address cleaning David Edmondson
2012-01-30 15:04 ` Austin Clements
2012-02-04 12:39 ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).