From: Jonas Bernoulli <jonas@bernoul.li>
To: notmuch@notmuchmail.org
Subject: [PATCH 4/4] emacs: avoid type errors due to nil as content-type
Date: Sun, 10 Jan 2021 19:47:22 +0100 [thread overview]
Message-ID: <20210110184722.29294-5-jonas@bernoul.li> (raw)
In-Reply-To: <20210110184722.29294-1-jonas@bernoul.li>
The output of "notmuch show --format=sexp --format-version=4"
may contain `:content-type' entries with `nil' as the value,
when it fails to detect the correct value. Account for that
in a few places where we would otherwise risk a type error.
Note that `string=' does not choke on `nil' because it uses
the `symbol-name' when encountering a symbol.
---
emacs/notmuch-lib.el | 23 +++++++++++++----------
emacs/notmuch-show.el | 29 ++++++++++++++++-------------
2 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index bc550dc2..c7bb2091 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -552,16 +552,19 @@ (defun notmuch-plist-delete (plist property)
;;; MML Utilities
(defun notmuch-match-content-type (t1 t2)
- "Return t if t1 and t2 are matching content types, taking wildcards into account."
- (let ((st1 (split-string t1 "/"))
- (st2 (split-string t2 "/")))
- (if (or (string= (cadr st1) "*")
- (string= (cadr st2) "*"))
- ;; Comparison of content types should be case insensitive.
- (string= (downcase (car st1))
- (downcase (car st2)))
- (string= (downcase t1)
- (downcase t2)))))
+ "Return t if t1 and t2 are matching content types.
+Take wildcards into account."
+ (and (stringp t1)
+ (stringp t2)
+ (let ((st1 (split-string t1 "/"))
+ (st2 (split-string t2 "/")))
+ (if (or (string= (cadr st1) "*")
+ (string= (cadr st2) "*"))
+ ;; Comparison of content types should be case insensitive.
+ (string= (downcase (car st1))
+ (downcase (car st2)))
+ (string= (downcase t1)
+ (downcase t2))))))
(defvar notmuch-multipart/alternative-discouraged
'(;; Avoid HTML parts.
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 8c846fb2..ba93febb 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -581,16 +581,17 @@ (defun notmuch-show--register-cids (msg part)
;; alternative (even if we can't render it).
(push (list content-id msg part) notmuch-show--cids)))
;; Recurse on sub-parts
- (pcase-let ((`(,type ,subtype)
- (split-string (downcase (plist-get part :content-type)) "/")))
- (cond ((equal type "multipart")
- (mapc (apply-partially #'notmuch-show--register-cids msg)
- (plist-get part :content)))
- ((and (equal type "message")
- (equal subtype "rfc822"))
- (notmuch-show--register-cids
- msg
- (car (plist-get (car (plist-get part :content)) :body)))))))
+ (when-let ((type (plist-get part :content-type)))
+ (pcase-let ((`(,type ,subtype)
+ (split-string (downcase type) "/")))
+ (cond ((equal type "multipart")
+ (mapc (apply-partially #'notmuch-show--register-cids msg)
+ (plist-get part :content)))
+ ((and (equal type "message")
+ (equal subtype "rfc822"))
+ (notmuch-show--register-cids
+ msg
+ (car (plist-get (car (plist-get part :content)) :body))))))))
(defun notmuch-show--get-cid-content (cid)
"Return a list (CID-content content-type) or nil.
@@ -948,7 +949,8 @@ (defun notmuch-show-lazy-part (part-args button)
(defun notmuch-show-mime-type (part)
"Return the correct mime-type to use for PART."
- (let ((content-type (downcase (plist-get part :content-type))))
+ (when-let ((content-type (plist-get part :content-type)))
+ (setq content-type (downcase content-type))
(or (and (string= content-type "application/octet-stream")
(notmuch-show-get-mime-type-of-application/octet-stream part))
(and (string= content-type "inline patch")
@@ -988,7 +990,7 @@ (defun notmuch-show-insert-bodypart (msg part depth &optional hide)
HIDE determines whether to show or hide the part and the button
as follows: If HIDE is nil, show the part and the button. If HIDE
is t, hide the part initially and show the button."
- (let* ((content-type (downcase (plist-get part :content-type)))
+ (let* ((content-type (plist-get part :content-type))
(mime-type (notmuch-show-mime-type part))
(nth (plist-get part :id))
(long (and (notmuch-match-content-type mime-type "text/*")
@@ -1000,7 +1002,8 @@ (defun notmuch-show-insert-bodypart (msg part depth &optional hide)
;; the first (or only) part if this is text/plain.
(button (and (funcall notmuch-show-insert-header-p-function part hide)
(notmuch-show-insert-part-header
- nth mime-type content-type
+ nth mime-type
+ (and content-type (downcase content-type))
(plist-get part :filename))))
;; Hide the part initially if HIDE is t, or if it is too long
;; and we have a button to allow toggling.
--
2.30.0
next prev parent reply other threads:[~2021-01-10 18:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-10 18:47 [PATCH 0/4] emacs: avoid type errors due to nil as content-type Jonas Bernoulli
2021-01-10 18:47 ` [PATCH 1/4] emacs: notmuch-mua-add-more-hidden-headers: use local binding Jonas Bernoulli
2021-01-10 18:47 ` [PATCH 2/4] emacs: notmuch-show--register-cids: fix names of bindings Jonas Bernoulli
2021-01-10 18:47 ` [PATCH 3/4] emacs: notmuch-show--get-cid-content: cosmetics Jonas Bernoulli
2021-01-10 18:47 ` Jonas Bernoulli [this message]
2021-01-10 20:11 ` [PATCH 0/4] emacs: avoid type errors due to nil as content-type David Edmondson
2021-01-10 20:47 ` Jonas Bernoulli
2021-01-11 19:52 ` Tomi Ollila
2021-01-12 9:49 ` Jonas Bernoulli
2021-01-12 14:02 ` Tomi Ollila
2021-01-15 11:39 ` David Bremner
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=20210110184722.29294-5-jonas@bernoul.li \
--to=jonas@bernoul.li \
--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).