unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] Make `notmuch-show-clean-address' parsing-error-proof.
@ 2011-05-12 13:56 Dmitry Kurochkin
  2011-05-12 13:56 ` [PATCH 2/2] test: add "notmuch-show for message with invalid From" test Dmitry Kurochkin
  2011-06-03 21:10 ` [PATCH 1/2] Make `notmuch-show-clean-address' parsing-error-proof Carl Worth
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Kurochkin @ 2011-05-12 13:56 UTC (permalink / raw)
  To: Notmuch Mail

Mail-header-parse-address may fail for an invalid address.
Before the change, this would result in empty notmuch-show buffer
with an error message like: Scan error: "Unbalanced parentheses".
The patch wraps the function in condition-case and returns
unchanged address in case of error.
---
 emacs/notmuch-show.el |   35 +++++++++++++++++++----------------
 1 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 23291ce..bd348e1 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -224,22 +224,25 @@ same as that of the previous message."
 				 ")"))))))
 
 (defun notmuch-show-clean-address (address)
-  "Clean a single email address for display."
-  (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)))
-    ;; If the address is 'foo@bar.com <foo@bar.com>' then show just
-    ;; 'foo@bar.com'.
-    (when (string= name address)
-      (setq name nil))
-
-    (if (not name)
-	address
-      (concat name " <" address ">"))))
+  "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)))
+      ;; If the address is 'foo@bar.com <foo@bar.com>' then show just
+      ;; 'foo@bar.com'.
+      (when (string= name address)
+        (setq name nil))
+
+      (if (not name)
+        address
+        (concat name " <" address ">")))
+    (error address)))
 
 (defun notmuch-show-insert-headerline (headers date tags depth)
   "Insert a notmuch style headerline based on HEADERS for a
-- 
1.7.5.1

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

* [PATCH 2/2] test: add "notmuch-show for message with invalid From" test
  2011-05-12 13:56 [PATCH 1/2] Make `notmuch-show-clean-address' parsing-error-proof Dmitry Kurochkin
@ 2011-05-12 13:56 ` Dmitry Kurochkin
  2011-06-03 21:10 ` [PATCH 1/2] Make `notmuch-show-clean-address' parsing-error-proof Carl Worth
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Kurochkin @ 2011-05-12 13:56 UTC (permalink / raw)
  To: Notmuch Mail

---
 test/emacs |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/test/emacs b/test/emacs
index 2e85b0c..f2983a7 100755
--- a/test/emacs
+++ b/test/emacs
@@ -37,8 +37,21 @@ output=$(test_emacs "(notmuch-show \"$maildir_storage_thread\") (princ (buffer-s
 expected=$(cat $EXPECTED/notmuch-show-thread-maildir-storage)
 test_expect_equal "$output" "$expected"
 
+test_begin_subtest "notmuch-show for message with invalid From"
+add_message "[subject]=\"message-with-invalid-from\"" "[from]=\"\\\"Invalid \\\" From\\\" <test_suite@notmuchmail.org>\""
+thread=$(notmuch search --output=threads subject:message-with-invalid-from)
+output=$(test_emacs "(notmuch-show \"$thread\") (princ (buffer-string))")
+test_expect_equal "$output" \
+'"Invalid " From" <test_suite@notmuchmail.org> (2001-01-05) (inbox)
+Subject: message-with-invalid-from
+To: Notmuch Test Suite <test_suite@notmuchmail.org>
+Date: Tue, 05 Jan 2001 15:43:57 -0000
+
+This is just a test message (#1)'
+
 test_begin_subtest "Navigation of notmuch-search to thread view"
 output=$(test_emacs '(notmuch-search "tag:inbox") (notmuch-test-wait) (goto-char (point-min)) (re-search-forward "Working with Maildir") (notmuch-search-show-thread) (notmuch-test-wait) (princ (buffer-string))')
+expected=$(cat $EXPECTED/notmuch-show-thread-maildir-storage)
 test_expect_equal "$output" "$expected"
 
 test_begin_subtest "Add tag from search view"
-- 
1.7.5.1

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

* Re: [PATCH 1/2] Make `notmuch-show-clean-address' parsing-error-proof.
  2011-05-12 13:56 [PATCH 1/2] Make `notmuch-show-clean-address' parsing-error-proof Dmitry Kurochkin
  2011-05-12 13:56 ` [PATCH 2/2] test: add "notmuch-show for message with invalid From" test Dmitry Kurochkin
@ 2011-06-03 21:10 ` Carl Worth
  1 sibling, 0 replies; 3+ messages in thread
From: Carl Worth @ 2011-06-03 21:10 UTC (permalink / raw)
  To: Dmitry Kurochkin, Notmuch Mail

[-- Attachment #1: Type: text/plain, Size: 829 bytes --]

On Thu, 12 May 2011 17:56:25 +0400, Dmitry Kurochkin <dmitry.kurochkin@gmail.com> wrote:
> Mail-header-parse-address may fail for an invalid address.
> Before the change, this would result in empty notmuch-show buffer
> with an error message like: Scan error: "Unbalanced parentheses".
> The patch wraps the function in condition-case and returns
> unchanged address in case of error.

Thanks for the patch, Dmitry. I've just pushed this.

And thanks as well for the test case. I actually pushed the test-case
commit before the bug-fix commit. I like to do things in that order so
that I can:

	1. Apply the new test case
	2. Run "make test" and see the failure
	3. Apply the bug fix
	4. Run "make test" and see the test pass

With a sequence like that, it's very easy for me to feel very
comfortable committing the code.

-Carl

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

end of thread, other threads:[~2011-06-03 21:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-12 13:56 [PATCH 1/2] Make `notmuch-show-clean-address' parsing-error-proof Dmitry Kurochkin
2011-05-12 13:56 ` [PATCH 2/2] test: add "notmuch-show for message with invalid From" test Dmitry Kurochkin
2011-06-03 21:10 ` [PATCH 1/2] Make `notmuch-show-clean-address' parsing-error-proof Carl Worth

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).