Re: [PATCH] Map missing content-type to "" instead of nil

Subject: Re: [PATCH] Map missing content-type to "" instead of nil

Date: Fri, 25 Oct 2019 09:28:27 +0100

To: keithp@keithp.com, notmuch@notmuchmail.org

Cc:

From: David Edmondson


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.
_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: