* [PATCH] Map missing content-type to "" instead of nil
@ 2019-10-24 23:08 keithp
2019-10-25 8:28 ` David Edmondson
0 siblings, 1 reply; 2+ messages in thread
From: keithp @ 2019-10-24 23:08 UTC (permalink / raw)
To: notmuch
From: Keith Packard <keithp@keithp.com>
When a message part has no content type, a 'nil' value results in many
failures when passed to functions like 'downcase'. Instead of
crashing, map a nil value to the empty string, "", so that the show
operation doesn't crash.
Signed-off-by: Keith Packard <keithp@keithp.com>
---
emacs/notmuch-show.el | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index e13ca3d7..7e3d0501 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -556,6 +556,10 @@ message at DEPTH in the current thread."
"Alist from raw content ID to (MSG PART).")
(make-variable-buffer-local 'notmuch-show--cids)
+(defun notmuch-show--plist-get(l m)
+ (let ((e (plist-get l m)))
+ (if e e "")))
+
(defun notmuch-show--register-cids (msg part)
"Register content-IDs in PART and all of PART's sub-parts."
(let ((content-id (plist-get part :content-id)))
@@ -570,7 +574,7 @@ message at DEPTH in the current thread."
(push (list content-id msg part) notmuch-show--cids)))
;; Recurse on sub-parts
(let ((ctype (notmuch-split-content-type
- (downcase (plist-get part :content-type)))))
+ (downcase (notmuch-show--plist-get part :content-type)))))
(cond ((equal (first ctype) "multipart")
(mapc (apply-partially #'notmuch-show--register-cids msg)
(plist-get part :content)))
@@ -594,7 +598,7 @@ will return nil if the CID is unknown or cannot be retrieved."
;; reference the same cid: part many times (hundreds!).
(content (notmuch-get-bodypart-binary
msg part notmuch-show-process-crypto 'cache))
- (content-type (plist-get part :content-type)))
+ (content-type (notmuch-show--plist-get part :content-type)))
(list content content-type)))))
(defun notmuch-show-setup-w3m ()
@@ -620,7 +624,7 @@ will return nil if the CID is unknown or cannot be retrieved."
;; MIME part renderers
(defun notmuch-show-multipart/*-to-list (part)
- (mapcar (lambda (inner-part) (plist-get inner-part :content-type))
+ (mapcar (lambda (inner-part) (notmuch-show--plist-get inner-part :content-type))
(plist-get part :content)))
(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)
@@ -631,7 +635,7 @@ will return nil if the CID is unknown or cannot be retrieved."
;; but it's not clear that this is the wrong thing to do - which
;; should be chosen if there are more than one that match?
(mapc (lambda (inner-part)
- (let* ((inner-type (plist-get inner-part :content-type))
+ (let* ((inner-type (notmuch-show--plist-get inner-part :content-type))
(hide (not (or notmuch-show-all-multipart/alternative-parts
(string= chosen-type inner-type)))))
(notmuch-show-insert-bodypart msg inner-part depth hide)))
@@ -948,7 +952,7 @@ will return nil if the CID is unknown or cannot be retrieved."
(defun notmuch-show-mime-type (part)
"Return the correct mime-type to use for PART."
- (let ((content-type (downcase (plist-get part :content-type))))
+ (let ((content-type (downcase (notmuch-show--plist-get part :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")
@@ -989,7 +993,7 @@ 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 (downcase (notmuch-show--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/*")
--
2.24.0.rc0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Map missing content-type to "" instead of nil
2019-10-24 23:08 [PATCH] Map missing content-type to "" instead of nil keithp
@ 2019-10-25 8:28 ` David Edmondson
0 siblings, 0 replies; 2+ messages in thread
From: David Edmondson @ 2019-10-25 8:28 UTC (permalink / raw)
To: keithp, notmuch
On Thursday, 2019-10-24 at 16:08:00 -07, keithp@keithp.com wrote:
> From: Keith Packard <keithp@keithp.com>
>
> When a message part has no content type, a 'nil' value results
> in many failures when passed to functions like 'downcase'.
> Instead of crashing, map a nil value to the empty string, "", so
> that the show operation doesn't crash.
>
> Signed-off-by: Keith Packard <keithp@keithp.com> ---
> emacs/notmuch-show.el | 16 ++++++++++------ 1 file changed, 10
> insertions(+), 6 deletions(-)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index
> e13ca3d7..7e3d0501 100644 --- a/emacs/notmuch-show.el +++
> b/emacs/notmuch-show.el @@ -556,6 +556,10 @@ message at DEPTH in
> the current thread."
> "Alist from raw content ID to (MSG PART).")
> (make-variable-buffer-local 'notmuch-show--cids)
> +(defun notmuch-show--plist-get(l m)
We would generally have a space after “get”.
> + (let ((e (plist-get l m))) + (if e e "")))
Isn't this:
(or (plist-get l m) "")
> (defun notmuch-show--register-cids (msg part)
> "Register content-IDs in PART and all of PART's sub-parts."
> (let ((content-id (plist-get part :content-id)))
> @@ -570,7 +574,7 @@ message at DEPTH in the current thread."
> (push (list content-id msg part) notmuch-show--cids)))
> ;; Recurse on sub-parts
> (let ((ctype (notmuch-split-content-type
> - (downcase (plist-get part :content-type)))))
> + (downcase (notmuch-show--plist-get part :content-type)))))
> (cond ((equal (first ctype) "multipart")
> (mapc (apply-partially #'notmuch-show--register-cids msg)
> (plist-get part :content)))
> @@ -594,7 +598,7 @@ will return nil if the CID is unknown or cannot be retrieved."
> ;; reference the same cid: part many times (hundreds!).
> (content (notmuch-get-bodypart-binary
> msg part notmuch-show-process-crypto 'cache))
> - (content-type (plist-get part :content-type)))
> + (content-type (notmuch-show--plist-get part :content-type)))
> (list content content-type)))))
>
> (defun notmuch-show-setup-w3m ()
> @@ -620,7 +624,7 @@ will return nil if the CID is unknown or cannot be retrieved."
> ;; MIME part renderers
>
> (defun notmuch-show-multipart/*-to-list (part)
> - (mapcar (lambda (inner-part) (plist-get inner-part :content-type))
> + (mapcar (lambda (inner-part) (notmuch-show--plist-get inner-part :content-type))
> (plist-get part :content)))
>
> (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)
> @@ -631,7 +635,7 @@ will return nil if the CID is unknown or cannot be retrieved."
> ;; but it's not clear that this is the wrong thing to do - which
> ;; should be chosen if there are more than one that match?
> (mapc (lambda (inner-part)
> - (let* ((inner-type (plist-get inner-part :content-type))
> + (let* ((inner-type (notmuch-show--plist-get inner-part :content-type))
> (hide (not (or notmuch-show-all-multipart/alternative-parts
> (string= chosen-type inner-type)))))
> (notmuch-show-insert-bodypart msg inner-part depth hide)))
> @@ -948,7 +952,7 @@ will return nil if the CID is unknown or cannot be retrieved."
>
> (defun notmuch-show-mime-type (part)
> "Return the correct mime-type to use for PART."
> - (let ((content-type (downcase (plist-get part :content-type))))
> + (let ((content-type (downcase (notmuch-show--plist-get part :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")
> @@ -989,7 +993,7 @@ 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 (downcase (notmuch-show--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/*")
> --
> 2.24.0.rc0
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
dme.
--
Music has magic, it's good clear syncopation.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-25 8:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-24 23:08 [PATCH] Map missing content-type to "" instead of nil keithp
2019-10-25 8:28 ` David Edmondson
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).