[PATCH 1/2] emacs: Avoid `mail-header-parse-address' in `notmuch-show-clean-address'.

Thomas Jost schnouki at schnouki.net
Wed Jan 25 04:51:46 PST 2012


On Wed, 25 Jan 2012 11:45:03 +0000, David Edmondson <dme at dme.org> wrote:
> `mail-header-parse-address' expects un-decoded mailbox parts, which is
> not what we have at this point. Replace it with simple string
> deconstruction.
> 
> Mark the corresponding test as no longer broken.
> 
> Minor whitespace cleanup.
> ---
>  emacs/notmuch-show.el          |   50 ++++++++++++++++++++++++++++-----------
>  test/emacs-address-cleaning.sh |    1 -
>  2 files changed, 36 insertions(+), 15 deletions(-)
> 
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index e6a5b31..1fd2524 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -289,21 +289,43 @@ operation on the contents of the current buffer."
>    "Try to clean a single email ADDRESS for display.  Return
>  unchanged ADDRESS if parsing fails."
>    (condition-case nil
> -    (let* ((parsed (mail-header-parse-address address))
> -	   (address (car parsed))
> -	   (name (cdr parsed)))
> -      ;; Remove double quotes. They might be required during transport,
> -      ;; but we don't need to see them.
> -      (when name
> -        (setq name (replace-regexp-in-string "\"" "" name)))
> +    (let (p-name p-address)
> +      ;; It would be convenient to use `mail-header-parse-address',
> +      ;; but that expects un-decoded mailbox parts, whereas our
> +      ;; mailbox parts are already decoded (and hence may contain
> +      ;; UTF-8). Given that notmuch should handle most of the awkward
> +      ;; cases, some simple string deconstruction should be sufficient
> +      ;; here.
> +      (cond
> +       ;; "User <user at dom.ain>" style.
> +       ((string-match "\\(.*\\) <\\(.*\\)>" address)
> +	(setq p-name (match-string 1 address)
> +	      p-address (match-string 2 address)))
> +
> +       ;; "<user at dom.ain>" style.
> +       ((string-match "<\\(.*\\)>" address)
> +	(setq p-address (match-string 1 address)))
> +
> +       ;; Everything else.
> +       (t
> +	(setq p-address address)))
> +
> +      ;; Remove outer double quotes. They might be required during
> +      ;; transport, but we don't need to see them.
> +      (when (and p-name
> +		 (string-match "^\"\\(.*\\)\"$" p-name))
> +	(setq p-name (match-string 1 p-name)))
> +
>        ;; If the address is 'foo at bar.com <foo at bar.com>' then show just
>        ;; 'foo at bar.com'.
> -      (when (string= name address)
> -        (setq name nil))
> -
> -      (if (not name)
> -        address
> -        (concat name " <" address ">")))
> +      (when (string= p-name p-address)
> +	(setq p-name nil))
> +
> +      ;; If no name results, return just the address.
> +      (if (not p-name)
> +	  p-address
> +	;; Otherwise format the name and address together.
> +	(concat p-name " <" p-address ">")))
>      (error address)))
>  
>  (defun notmuch-show-insert-headerline (headers date tags depth)
> @@ -1417,7 +1439,7 @@ than only the current message."
>    (interactive "P\nsPipe message to command: ")
>    (let (shell-command)
>      (if entire-thread
> -	(setq shell-command 
> +	(setq shell-command
>  	      (concat notmuch-command " show --format=mbox "
>  		      (shell-quote-argument
>  		       (mapconcat 'identity (notmuch-show-get-message-ids-for-open-messages) " OR "))
> diff --git a/test/emacs-address-cleaning.sh b/test/emacs-address-cleaning.sh
> index 0d85bdc..51018fe 100755
> --- a/test/emacs-address-cleaning.sh
> +++ b/test/emacs-address-cleaning.sh
> @@ -12,7 +12,6 @@ test_emacs_expect_t \
>      '(load "emacs-address-cleaning.el") (notmuch-test-address-cleaning-2)'
>  
>  test_begin_subtest "notmuch-test-address-clean part 3"
> -test_subtest_known_broken
>  test_emacs_expect_t \
>      '(load "emacs-address-cleaning.el") (notmuch-test-address-cleaning-3)'
>  
> -- 
> 1.7.8.3

Hello David,

Works fine for me, but this also breaks en Emacs test:

 FAIL   notmuch-show for message with invalid From
	--- emacs.10.expected	2012-01-25 12:50:00.310786410 +0000
	+++ emacs.10.output	2012-01-25 12:50:00.310786410 +0000
	@@ -1,4 +1,4 @@
	-"Invalid " From" <test_suite at notmuchmail.org> (2001-01-05) (inbox)
	+Invalid " From <test_suite at notmuchmail.org> (2001-01-05) (inbox)
	 Subject: message-with-invalid-from
	 To: Notmuch Test Suite <test_suite at notmuchmail.org>
	 Date: Fri, 05 Jan 2001 15:43:57 +0000
nil

Thanks for this patch anyway :)

Regards,

-- 
Thomas/Schnouki
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20120125/91a0f5a3/attachment.pgp>


More information about the notmuch mailing list