On Sat, Nov 07 2015, Mark Walters wrote:
> From: David Edmondson <d...@dme.org>
>
> Move the determination of whether a part header is required to a
> distinct function.
> ---
>  emacs/notmuch-show.el | 25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index 49fd198..47a02e5 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -929,6 +929,21 @@ (defun notmuch-show-lazy-part (part-args button)
>        ;; showable this returns nil.
>        (notmuch-show-create-part-overlays button part-beg part-end))))
>  
> +(defun notmuch-show-mime-type (part)
> +  "Return the correct mime-type to use for PART."
> +  (let ((content-type (downcase (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")
> +          "text/x-diff")
> +     content-type)))
> +
> +(defun notmuch-show-insert-header-p (part hide)
> +  "Return non-NIL if a header button should be inserted for this part."
> +  (let ((mime-type (notmuch-show-mime-type part)))
> +    (not (and (string= mime-type "text/plain")
> +           (<= (plist-get part :id) 1)))))

It would be nice to have a comment here that explained the logic being
applied (i.e. parts get a header unless they are text/plain and the
first part). (It actually took me a minute to figure out what the logic
was...)

> +
>  (defun notmuch-show-insert-bodypart (msg part depth &optional hide)
>    "Insert the body part PART at depth DEPTH in the current thread.
>  
> @@ -939,11 +954,7 @@ (defun notmuch-show-insert-bodypart (msg part depth 
> &optional hide)
>  useful for quoting in replies)."
>  
>    (let* ((content-type (downcase (plist-get part :content-type)))
> -      (mime-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")
> -                          "text/x-diff")
> -                     content-type))
> +      (mime-type (notmuch-show-mime-type part))
>        (nth (plist-get part :id))
>        (long (and (notmuch-match-content-type mime-type "text/*")
>                   (> notmuch-show-max-text-part-size 0)
> @@ -951,8 +962,8 @@ (defun notmuch-show-insert-bodypart (msg part depth 
> &optional hide)
>        (beg (point))
>        ;; We omit the part button for the first (or only) part if
>        ;; this is text/plain, or HIDE is 'no-buttons.

Part of this comment now belongs up above.

> -      (button (unless (or (equal hide 'no-buttons)
> -                          (and (string= mime-type "text/plain") (<= nth 1)))
> +      (button (when (and (not (equal hide 'no-buttons))
> +                         (notmuch-show-insert-header-p part hide))
>                  (notmuch-show-insert-part-header nth mime-type 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 (thus reply which
> -- 
> 2.1.4
_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to