[PATCH] emacs: More address cleaning.
On Mon, 30 Jan 2012 14:59:54 +, David Edmondson wrote: > Remove outer single-quotes from the mailbox part. Allow for multiple > sets of nested single and double quotes. pushed, d
Re: [PATCH] emacs: More address cleaning.
On Mon, 30 Jan 2012 14:59:54 +, David Edmondson d...@dme.org wrote: Remove outer single-quotes from the mailbox part. Allow for multiple sets of nested single and double quotes. pushed, d ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch
[PATCH] emacs: More address cleaning.
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 at bar.com ' then show just ;; 'foo at 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
[PATCH] emacs: More address cleaning.
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 at bar.com ' then show just >;; 'foo at 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)))
Re: [PATCH] emacs: More address cleaning.
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 'f...@bar.com f...@bar.com' then show just ;; 'f...@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) f...@bar.com foo [at home] f...@bar.com Foo Bar + 'Foo Bar' f...@bar.com + \'Foo Bar'\ f...@bar.com + '\Foo Bar\' f...@bar.com + '\'Foo Bar'\' f...@bar.com Fred Dibna \\[extraordinaire\\] f...@dibna.com)) (expected '(ДБ db-uk...@stop.me.uk foo (at home) f...@bar.com foo [at home] f...@bar.com Foo Bar + Foo Bar f...@bar.com + Foo Bar f...@bar.com + Foo Bar f...@bar.com + Foo Bar f...@bar.com Fred Dibna [extraordinaire] f...@dibna.com)) (output (mapcar #'notmuch-show-clean-address input))) (notmuch-test-expect-equal output expected))) ___ notmuch mailing list notmuch@notmuchmail.org http://notmuchmail.org/mailman/listinfo/notmuch