discussion and development of piem
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: piem@inbox.kyleam.com
Subject: [PATCH 4/4] gnus, notmuch: Consider text/plain patch attachments
Date: Sun, 22 Nov 2020 15:46:09 -0500	[thread overview]
Message-ID: <20201122204609.12604-5-kyle@kyleam.com> (raw)
In-Reply-To: <20201122204609.12604-1-kyle@kyleam.com>

When inspecting attachments for generating an am-ready mbox, both
-notmuch and -gnus limit the operation to attachments with text/x-diff
or text/x-patch content types.  That has worked okay for me, though
I've run into a few cases where I couldn't apply a patch attachment
because it had a text/plain content type.

To do something useful in this case, check the file name to see
whether it looks like a patch.
 piem-gnus.el    |  3 ++-
 piem-notmuch.el |  3 ++-
 piem.el         | 10 +++++++---
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/piem-gnus.el b/piem-gnus.el
index ca128fb..9dc4ae8 100644
--- a/piem-gnus.el
+++ b/piem-gnus.el
@@ -70,7 +70,8 @@ (defun piem-gnus-am-ready-mbox ()
                         (mapcar (lambda (handle)
                                   (and (listp handle)
-                                        (mm-handle-media-type handle))
+                                        (mm-handle-media-type handle)
+                                        (mm-handle-filename handle))
                                          (mm-display-inline handle)
diff --git a/piem-notmuch.el b/piem-notmuch.el
index 8f5ef77..58e4d88 100644
--- a/piem-notmuch.el
+++ b/piem-notmuch.el
@@ -92,7 +92,8 @@ (defun piem-notmuch-am-ready-mbox ()
                      (delq nil
                            (mapcar (lambda (part)
                                      (and (piem-am-patch-attachment-p
-                                           (plist-get part :content-type))
+                                           (plist-get part :content-type)
+                                           (plist-get part :filename))
                                           (plist-get part :content)))
                                    (plist-get body :content)))))
            (cons (lambda ()
diff --git a/piem.el b/piem.el
index 9cc6a88..bee17c0 100644
--- a/piem.el
+++ b/piem.el
@@ -561,10 +561,14 @@ (defun piem-inject-thread-into-maildir (mid &optional message-only)
 ;;;; Patch handling
-(defun piem-am-patch-attachment-p (type)
+(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\"."
-  (member type '("text/x-diff" "text/x-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-extract-mbox-info (&optional buffer)
   "Collect information from message in BUFFER.

  parent reply	other threads:[~2020-11-22 20:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-22 20:46 [PATCH 0/4] Support text/plain patch attachments Kyle Meyer
2020-11-22 20:46 ` [PATCH 1/4] gnus: Prefer mm-handle-media-type over direct access Kyle Meyer
2020-11-22 20:46 ` [PATCH 2/4] gnus, notmuch: Share "attachment is patch?" logic Kyle Meyer
2020-11-22 20:46 ` [PATCH 3/4] Use when-let in a few more spots Kyle Meyer
2020-11-22 20:46 ` Kyle Meyer [this message]
2020-11-22 21:10   ` [PATCH 4/4] gnus, notmuch: Consider text/plain patch attachments Kyle Meyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://git.kyleam.com/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201122204609.12604-5-kyle@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=piem@inbox.kyleam.com \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).