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.
This commit is contained in:
Dmitry Kurochkin 2011-05-12 17:56:25 +04:00 committed by Carl Worth
parent 79a587d963
commit d1cbd833a7

View file

@ -224,22 +224,25 @@ same as that of the previous message."
")")))))) ")"))))))
(defun notmuch-show-clean-address (address) (defun notmuch-show-clean-address (address)
"Clean a single email address for display." "Try to clean a single email ADDRESS for display. Return
(let* ((parsed (mail-header-parse-address address)) unchanged ADDRESS if parsing fails."
(address (car parsed)) (condition-case nil
(name (cdr parsed))) (let* ((parsed (mail-header-parse-address address))
;; Remove double quotes. They might be required during transport, (address (car parsed))
;; but we don't need to see them. (name (cdr parsed)))
(when name ;; Remove double quotes. They might be required during transport,
(setq name (replace-regexp-in-string "\"" "" name))) ;; but we don't need to see them.
;; If the address is 'foo@bar.com <foo@bar.com>' then show just (when name
;; 'foo@bar.com'. (setq name (replace-regexp-in-string "\"" "" name)))
(when (string= name address) ;; If the address is 'foo@bar.com <foo@bar.com>' then show just
(setq name nil)) ;; 'foo@bar.com'.
(when (string= name address)
(setq name nil))
(if (not name) (if (not name)
address address
(concat name " <" address ">")))) (concat name " <" address ">")))
(error address)))
(defun notmuch-show-insert-headerline (headers date tags depth) (defun notmuch-show-insert-headerline (headers date tags depth)
"Insert a notmuch style headerline based on HEADERS for a "Insert a notmuch style headerline based on HEADERS for a