From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:267::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id UPD5M2QI8l8zLAAAsNZ9tg (envelope-from ); Sun, 03 Jan 2021 18:09:40 +0000 Received: from out0.migadu.com ([2001:41d0:2:267::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id SLLyA2QI8l+HAgAAbx9fmQ (envelope-from ); Sun, 03 Jan 2021 18:09:40 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1609697379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cqjMGb6ZH1b+bek/8UyOHzn76bpUmne+dcTtaAAXk94=; b=hPTrtKrDsZBdcxlS10L4anskyvH53MB5sffeHGdEHOzZGjjmkqo6oBXDBZfWRKRQhCQGCS BwzFCWoqQKo6s6J19pAob3WgFl+yzn2XLG4p1gPd4Zo5sgofcFCgfQIpWQDjg6LBdCqsDP JRqifyUf9cWVyh7XjoMF4EZtIaYZ/PSnEcnpETi70oGsagQnU/68P1UBxtGqlOXUgmfgYK FAAgocZQKVsSfeG7uzWOlWeGuyJnAcTPkRepAs4rHFj4BXenVI4nBt75k/k7giQPtd7igA W7oHNLr8NdnNur52Aqf8xB1Bej7cHFcQ3TGIDQbEkjO1jEpAC8T//rB3ZP6FHw== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [PATCH 3/3] gnus, notmuch: Absorb now-shared bits into patch attachment helper Message-Id: <20210103180912.17404-4-kyle@kyleam.com> In-Reply-To: <20210103180912.17404-1-kyle@kyleam.com> References: <20210103180912.17404-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com Date: Sun, 03 Jan 2021 18:09:39 GMT X-TUID: tKYB1oPrBVtP 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. --- piem-gnus.el | 14 ++------------ piem-notmuch.el | 10 ++-------- piem.el | 21 +++++++++++++-------- 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 @@ (defun piem-gnus-am-ready-mbox () (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 94b1fa0..07f17d4 100644 --- a/piem-notmuch.el +++ b/piem-notmuch.el @@ -89,14 +89,8 @@ (defun piem-notmuch-am-ready-mbox () (piem-notmuch--with-current-message (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))) (mm-dissect-buffer))) (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 @@ (defun piem-inject-thread-into-maildir (mid &optional message-only) ;;;; 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. -- 2.29.2