-(defun notmuch-get-bodypart-content (msg part process-crypto)
- (or (plist-get part :content)
- (notmuch-get-bodypart-binary msg part process-crypto)))
+(defun notmuch-get-bodypart-text (msg part process-crypto)
+ "Return the text content of PART in MSG.
+
+This returns the content of the given part as a multibyte Lisp
+string after performing content transfer decoding and any
+necessary charset decoding. It is an error to use this for
+non-text/* parts."
+ (let ((content (plist-get part :content)))
+ (when (not content)
+ ;; Use show --format=sexp to fetch decoded content
+ (let* ((args `("show" "--format=sexp" "--include-html"
+ ,(format "--part=%s" (plist-get part :id))
+ ,@(when process-crypto '("--decrypt"))
+ ,(notmuch-id-to-query (plist-get msg :id))))
+ (npart (apply #'notmuch-call-notmuch-sexp args)))
+ (setq content (plist-get npart :content))
+ (when (not content)
+ (error "Internal error: No :content from %S" args))))
+ content))