From d47b5152aa614a917b2537a9ddd5122e18aa88e1 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sat, 6 Jun 2020 13:53:06 -0400 Subject: gnus: Add support for piem-am-ready-mbox As with the notmuch- counterpart added in the previous commit, I only put this through very light testing, but it at least works in some cases. --- piem-gnus.el | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'piem-gnus.el') diff --git a/piem-gnus.el b/piem-gnus.el index 037b0f3..ad74452 100644 --- a/piem-gnus.el +++ b/piem-gnus.el @@ -27,6 +27,7 @@ ;;; Code: (require 'gnus) +(require 'gnus-sum) (require 'message) (require 'piem) @@ -56,6 +57,40 @@ ;; If there is an easy way to generate an mbox for a thread in Gnus, a ;; function for `piem-mid-to-thread-functions' should be defined. +(defun piem-gnus-am-ready-mbox () + "Return a function that inserts an am-ready mbox. +If the buffer has any MIME parts that look a patch, use those +part's content (in order) as the mbox. Otherwise, use the +message itself if it looks like a patch." + (when (derived-mode-p 'gnus-article-mode) + (cond + (gnus-article-mime-handles + (let ((patches + (delq nil + (mapcar (lambda (handle) + (and (listp handle) + (member (caar (cdr handle)) + '("text/x-diff" "text/x-patch")) + (with-temp-buffer + (mm-display-inline handle) + (buffer-substring-no-properties + (point-min) (point-max))))) + gnus-article-mime-handles)))) + (when patches + (lambda () + (dolist (patch patches) + (insert patch)))))) + (gnus-article-buffer + (let ((patch (with-current-buffer gnus-article-buffer + (save-restriction + (widen) + (and (string-match-p piem-patch-subject-re + (message-field-value "subject")) + (buffer-substring-no-properties + (point-min) (point-max))))))) + (when patch + (lambda () (insert patch)))))))) + ;;;###autoload (define-minor-mode piem-gnus-mode "Toggle Gnus support for piem. @@ -66,8 +101,10 @@ the mode if ARG is omitted or nil." :init-value nil (if piem-gnus-mode (progn + (add-hook 'piem-am-ready-mbox-functions #'piem-gnus-am-ready-mbox) (add-hook 'piem-get-inbox-functions #'piem-gnus-get-inbox) (add-hook 'piem-get-mid-functions #'piem-gnus-get-mid)) + (remove-hook 'piem-am-ready-mbox-functions #'piem-gnus-am-ready-mbox) (remove-hook 'piem-get-inbox-functions #'piem-gnus-get-inbox) (remove-hook 'piem-get-mid-functions #'piem-gnus-get-mid))) -- cgit v1.2.3