From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
To: Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH 1/2] Make `notmuch-show-clean-address' parsing-error-proof.
Date: Thu, 12 May 2011 17:56:25 +0400 [thread overview]
Message-ID: <1305208586-24689-1-git-send-email-dmitry.kurochkin@gmail.com> (raw)
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
next reply other threads:[~2011-05-12 13:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-12 13:56 Dmitry Kurochkin [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1305208586-24689-1-git-send-email-dmitry.kurochkin@gmail.com \
--to=dmitry.kurochkin@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).