mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
emacs: avoid type errors due to nil as content-type
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.
This commit is contained in:
parent
f1ae9addc6
commit
1f14dbfbd7
2 changed files with 29 additions and 23 deletions
|
@ -552,16 +552,19 @@ This replaces spaces, percents, and double quotes in STR with
|
||||||
;;; MML Utilities
|
;;; MML Utilities
|
||||||
|
|
||||||
(defun notmuch-match-content-type (t1 t2)
|
(defun notmuch-match-content-type (t1 t2)
|
||||||
"Return t if t1 and t2 are matching content types, taking wildcards into account."
|
"Return t if t1 and t2 are matching content types.
|
||||||
(let ((st1 (split-string t1 "/"))
|
Take wildcards into account."
|
||||||
(st2 (split-string t2 "/")))
|
(and (stringp t1)
|
||||||
(if (or (string= (cadr st1) "*")
|
(stringp t2)
|
||||||
(string= (cadr st2) "*"))
|
(let ((st1 (split-string t1 "/"))
|
||||||
;; Comparison of content types should be case insensitive.
|
(st2 (split-string t2 "/")))
|
||||||
(string= (downcase (car st1))
|
(if (or (string= (cadr st1) "*")
|
||||||
(downcase (car st2)))
|
(string= (cadr st2) "*"))
|
||||||
(string= (downcase t1)
|
;; Comparison of content types should be case insensitive.
|
||||||
(downcase t2)))))
|
(string= (downcase (car st1))
|
||||||
|
(downcase (car st2)))
|
||||||
|
(string= (downcase t1)
|
||||||
|
(downcase t2))))))
|
||||||
|
|
||||||
(defvar notmuch-multipart/alternative-discouraged
|
(defvar notmuch-multipart/alternative-discouraged
|
||||||
'(;; Avoid HTML parts.
|
'(;; Avoid HTML parts.
|
||||||
|
|
|
@ -581,16 +581,17 @@ message at DEPTH in the current thread."
|
||||||
;; alternative (even if we can't render it).
|
;; alternative (even if we can't render it).
|
||||||
(push (list content-id msg part) notmuch-show--cids)))
|
(push (list content-id msg part) notmuch-show--cids)))
|
||||||
;; Recurse on sub-parts
|
;; Recurse on sub-parts
|
||||||
(pcase-let ((`(,type ,subtype)
|
(when-let ((type (plist-get part :content-type)))
|
||||||
(split-string (downcase (plist-get part :content-type)) "/")))
|
(pcase-let ((`(,type ,subtype)
|
||||||
(cond ((equal type "multipart")
|
(split-string (downcase type) "/")))
|
||||||
(mapc (apply-partially #'notmuch-show--register-cids msg)
|
(cond ((equal type "multipart")
|
||||||
(plist-get part :content)))
|
(mapc (apply-partially #'notmuch-show--register-cids msg)
|
||||||
((and (equal type "message")
|
(plist-get part :content)))
|
||||||
(equal subtype "rfc822"))
|
((and (equal type "message")
|
||||||
(notmuch-show--register-cids
|
(equal subtype "rfc822"))
|
||||||
msg
|
(notmuch-show--register-cids
|
||||||
(car (plist-get (car (plist-get part :content)) :body)))))))
|
msg
|
||||||
|
(car (plist-get (car (plist-get part :content)) :body))))))))
|
||||||
|
|
||||||
(defun notmuch-show--get-cid-content (cid)
|
(defun notmuch-show--get-cid-content (cid)
|
||||||
"Return a list (CID-content content-type) or nil.
|
"Return a list (CID-content content-type) or nil.
|
||||||
|
@ -948,7 +949,8 @@ will return nil if the CID is unknown or cannot be retrieved."
|
||||||
|
|
||||||
(defun notmuch-show-mime-type (part)
|
(defun notmuch-show-mime-type (part)
|
||||||
"Return the correct mime-type to use for 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")
|
(or (and (string= content-type "application/octet-stream")
|
||||||
(notmuch-show-get-mime-type-of-application/octet-stream part))
|
(notmuch-show-get-mime-type-of-application/octet-stream part))
|
||||||
(and (string= content-type "inline patch")
|
(and (string= content-type "inline patch")
|
||||||
|
@ -988,7 +990,7 @@ this part.")
|
||||||
HIDE determines whether to show or hide the part and the button
|
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
|
as follows: If HIDE is nil, show the part and the button. If HIDE
|
||||||
is t, hide the part initially and show the button."
|
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))
|
(mime-type (notmuch-show-mime-type part))
|
||||||
(nth (plist-get part :id))
|
(nth (plist-get part :id))
|
||||||
(long (and (notmuch-match-content-type mime-type "text/*")
|
(long (and (notmuch-match-content-type mime-type "text/*")
|
||||||
|
@ -1000,7 +1002,8 @@ is t, hide the part initially and show the button."
|
||||||
;; the first (or only) part if this is text/plain.
|
;; the first (or only) part if this is text/plain.
|
||||||
(button (and (funcall notmuch-show-insert-header-p-function part hide)
|
(button (and (funcall notmuch-show-insert-header-p-function part hide)
|
||||||
(notmuch-show-insert-part-header
|
(notmuch-show-insert-part-header
|
||||||
nth mime-type content-type
|
nth mime-type
|
||||||
|
(and content-type (downcase content-type))
|
||||||
(plist-get part :filename))))
|
(plist-get part :filename))))
|
||||||
;; Hide the part initially if HIDE is t, or if it is too long
|
;; Hide the part initially if HIDE is t, or if it is too long
|
||||||
;; and we have a button to allow toggling.
|
;; and we have a button to allow toggling.
|
||||||
|
|
Loading…
Reference in a new issue