diff options
author | Dmitry Kurochkin <dmitry.kurochkin@gmail.com> | 2011-05-12 17:56:25 +0400 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2011-06-03 14:08:26 -0700 |
commit | d1cbd833a7b3ebfaeb0252b9c7fc98762a5f3961 (patch) | |
tree | 1320c439d04277497b5bf4ea8289e6c26c9e1074 /emacs | |
parent | 79a587d9636b8d0064f50bef8651ec6ccd1a94fb (diff) |
Make `notmuch-show-clean-address' parsing-error-proof.
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.
Diffstat (limited to 'emacs')
-rw-r--r-- | 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 47757a91..fb91c838 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 |