From 57f802b2a43ac64c28a5a9ddb9da0afaf910975e Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Mon, 4 Jan 2021 01:54:48 +0000 Subject: gnus, notmuch: Absorb now-shared bits into patch attachment helper With the previous commit, -notmuch more closely follows -gnus in its handling of attachments (e.g., getting the content with mm-display-inline). Replace piem-am-patch-attachment-p with a helper that has this shared logic. Message-Id: <20210104015435.18397-4-kyle@kyleam.com> --- piem.el | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'piem.el') diff --git a/piem.el b/piem.el index bf79813..8c23e7b 100644 --- a/piem.el +++ b/piem.el @@ -40,6 +40,7 @@ (require 'cl-lib) (require 'mail-extr) (require 'message) +(require 'mm-decode) (require 'piem-maildir) (require 'rfc2047) (require 'subr-x) @@ -573,14 +574,18 @@ This function depends on :url being configured for entries in ;;;; Patch handling -(defun piem-am-patch-attachment-p (type filename) - "Return non-nil if an attachment should be treated as a patch. -TYPE is a media type such as \"text/x-patch\". FILENAME is the -attachment file name, if any." - (or (member type '("text/x-diff" "text/x-patch")) - (and filename - (equal type "text/plain") - (string-match-p "\\.patch\\'" filename)))) +(defun piem-am-extract-attached-patch (handle) + "Return content for HANDLE if it looks like a patch." + (and (listp handle) + (let ((type (mm-handle-media-type handle)) + (filename (mm-handle-filename handle))) + (or (member type '("text/x-diff" "text/x-patch")) + (and filename + (equal type "text/plain") + (string-match-p "\\.patch\\'" filename)))) + (with-temp-buffer + (mm-display-inline handle) + (buffer-substring-no-properties (point-min) (point-max))))) (defun piem-extract-mbox-info (&optional buffer) "Collect information from message in BUFFER. -- cgit v1.2.3