From: Kyle Meyer <email@example.com> To: firstname.lastname@example.org Subject: [PATCH 2/3] piem-notmuch-am-ready-mbox: Improve handling of attachments Date: Sun, 03 Jan 2021 18:09:38 GMT [thread overview] Message-ID: <email@example.com> (raw) In-Reply-To: <firstname.lastname@example.org> piem-notmuch-am-ready-mbox tries to get attached patches from the plist returned by notmuch-show-get-message-properties. This works okay for simple cases, but it doesn't find a patch if the content is encoded or if the MIME tree isn't structured as expected. Instead use mm-decode functions to get a list of handles and display their content. This new approach, as well as the previous one, probably isn't compatible with `format-patch --attach' patches, but I'm not going to worry about that until I actually see such a patch in the wild. --- piem-notmuch.el | 55 ++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/piem-notmuch.el b/piem-notmuch.el index ff8654c..94b1fa0 100644 --- a/piem-notmuch.el +++ b/piem-notmuch.el @@ -28,6 +28,7 @@ ;;; Code: +(require 'mm-decode) (require 'notmuch) (require 'piem) (require 'subr-x) @@ -78,29 +79,37 @@ (defun piem-notmuch-am-ready-mbox () those parts' contents (in order) as the mbox. Otherwise, use the message itself if it looks like a patch." (when (derived-mode-p 'notmuch-show-mode) - (let ((body (car (plist-get (notmuch-show-get-message-properties) - :body)))) - (pcase (plist-get body :content-type) - ((and "text/plain" - (guard (string-match-p piem-patch-subject-re - (notmuch-show-get-subject)))) - (let ((id (notmuch-show-get-message-id))) - (lambda () - (call-process notmuch-command nil t nil - "show" "--format=mbox" id)))) - ("multipart/mixed" - (when-let ((patches - (delq nil - (mapcar (lambda (part) - (and (piem-am-patch-attachment-p - (plist-get part :content-type) - (plist-get part :filename)) - (plist-get part :content))) - (plist-get body :content))))) - (cons (lambda () - (dolist (patch patches) - (insert patch))) - "mbox"))))))) + (if (string-prefix-p + "multipart/" + (plist-get + (car (plist-get (notmuch-show-get-message-properties) + :body)) + :content-type)) + (let (patches) + (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)))) + (mm-dissect-buffer))) + (when patches + (setq patches (nreverse patches)) + (cons (lambda () + (dolist (patch patches) + (insert patch))) + "mbox"))) + (when (string-match-p piem-patch-subject-re + (notmuch-show-get-subject)) + (let ((id (notmuch-show-get-message-id))) + (lambda () + (call-process notmuch-command nil t nil + "show" "--format=mbox" id))))))) ;;;###autoload (define-minor-mode piem-notmuch-mode -- 2.29.2
next prev parent reply other threads:[~2021-01-03 18:09 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-03 18:09 [PATCH 0/3] notmuch: Improve handling of attached patches Kyle Meyer 2021-01-03 18:09 ` [PATCH 1/3] piem-notmuch--with-current-message: Declare debug and indent specs Kyle Meyer 2021-01-03 18:09 ` Kyle Meyer [this message] 2021-01-04 1:53 ` [PATCH 2/3] piem-notmuch-am-ready-mbox: Improve handling of attachments Kyle Meyer 2021-01-04 1:54 ` [PATCH v2 0/3] notmuch: Improve handling of attached patches Kyle Meyer 2021-01-04 1:54 ` [PATCH v2 1/3] piem-notmuch--with-current-message: Declare debug and indent specs Kyle Meyer 2021-01-04 1:54 ` [PATCH v2 2/3] piem-notmuch-am-ready-mbox: Improve handling of attachments Kyle Meyer 2021-01-04 1:54 ` [PATCH v2 3/3] gnus, notmuch: Absorb now-shared bits into patch attachment helper Kyle Meyer 2021-01-03 18:09 ` [PATCH " 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: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://git.kyleam.com/ * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --subject='Re: [PATCH 2/3] piem-notmuch-am-ready-mbox: Improve handling of attachments' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://git.kyleam.com/piem/ 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).