From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 2Bc+NthL+1/FXgAA0tVLHw (envelope-from ) for ; Sun, 10 Jan 2021 18:47:52 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 2BbuMdhL+1/gDQAAbx9fmQ (envelope-from ) for ; Sun, 10 Jan 2021 18:47:52 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 557869402D4 for ; Sun, 10 Jan 2021 18:47:52 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 7AE1029E80; Sun, 10 Jan 2021 13:47:32 -0500 (EST) Received: from mail.hostpark.net (mail.hostpark.net [212.243.197.30]) by mail.notmuchmail.org (Postfix) with ESMTPS id 2779329D25 for ; Sun, 10 Jan 2021 13:47:24 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id 360A116400 for ; Sun, 10 Jan 2021 19:47:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bernoul.li; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=sel2011a; t=1610304443; bh=zezYWHfZzRYLDiW 3Fz0HiOY6DFWImnD2OSRvEc5EEqU=; b=FHoC+I5lWSdsAmZsJdLPfn1dmJy2TVf D/24+8zmj9hibbfXCSiu/2cHgWtQhv7Z0Tt60VHV19I2HF6zoCNDJpGGyFeMhff3 4moii1SpJPvWjgg/GTtkZaj/hUVplU/G6DjFp2l/T0XDpaoLGuhlRiZwF02JUSEW wgXG9lJOP0XU= X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail1.hostpark.net [127.0.0.1]) (amavisd-new, port 10224) with ESMTP id iZoZUZQDflYM for ; Sun, 10 Jan 2021 19:47:23 +0100 (CET) Received: from customer (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id F1DE416505 for ; Sun, 10 Jan 2021 19:47:22 +0100 (CET) From: Jonas Bernoulli 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 Message-Id: <20210110184722.29294-5-jonas@bernoul.li> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210110184722.29294-1-jonas@bernoul.li> References: <20210110184722.29294-1-jonas@bernoul.li> MIME-Version: 1.0 Message-ID-Hash: MAQUB6TNAFHAKSJRC26GT6G6DGL5YP3K X-Message-ID-Hash: MAQUB6TNAFHAKSJRC26GT6G6DGL5YP3K X-MailFrom: jonas@bernoul.li X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 0.06 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=bernoul.li header.s=sel2011a header.b=FHoC+I5l; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 557869402D4 X-Spam-Score: 0.06 X-Migadu-Scanner: scn0.migadu.com X-TUID: uXq8xY5tC42W 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