aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2021-01-04 01:54:48 +0000
committerKyle Meyer <kyle@kyleam.com>2021-01-03 22:44:19 -0500
commit57f802b2a43ac64c28a5a9ddb9da0afaf910975e (patch)
treee9b2d38b28c3846fa405c95619ebfca9bf19757f
parentf5d67001ed706407b8fcda5447da64a4c215f0c2 (diff)
downloadpiem-57f802b2a43ac64c28a5a9ddb9da0afaf910975e.tar.gz
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>
-rw-r--r--piem-gnus.el14
-rw-r--r--piem-notmuch.el10
-rw-r--r--piem.el21
3 files changed, 17 insertions, 28 deletions
diff --git a/piem-gnus.el b/piem-gnus.el
index c6b9d0c..5f10be8 100644
--- a/piem-gnus.el
+++ b/piem-gnus.el
@@ -66,18 +66,8 @@ message itself if it looks like a patch."
(when (derived-mode-p 'gnus-article-mode 'gnus-summary-mode)
(cond
(gnus-article-mime-handles
- (when-let ((patches
- (delq nil
- (mapcar (lambda (handle)
- (and (listp handle)
- (piem-am-patch-attachment-p
- (mm-handle-media-type handle)
- (mm-handle-filename handle))
- (with-temp-buffer
- (mm-display-inline handle)
- (buffer-substring-no-properties
- (point-min) (point-max)))))
- gnus-article-mime-handles))))
+ (when-let ((patches (delq nil (mapcar #'piem-am-extract-attached-patch
+ gnus-article-mime-handles))))
(cons (lambda ()
(dolist (patch patches)
(insert patch)))
diff --git a/piem-notmuch.el b/piem-notmuch.el
index 915675e..37e695b 100644
--- a/piem-notmuch.el
+++ b/piem-notmuch.el
@@ -92,14 +92,8 @@ message itself if it looks like a patch."
"show" "--format=mbox" id))))
(notmuch-foreach-mime-part
(lambda (p)
- (and (piem-am-patch-attachment-p
- (mm-handle-media-type p)
- (mm-handle-filename p))
- (with-temp-buffer
- (mm-display-inline p)
- (push (buffer-substring-no-properties
- (point-min) (point-max))
- patches))))
+ (when-let ((patch (piem-am-extract-attached-patch p)))
+ (push patch patches)))
handle)
(when patches
(setq patches (nreverse patches))
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.