summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2020-06-06 13:53:06 -0400
committerKyle Meyer <kyle@kyleam.com>2020-06-06 15:34:35 -0400
commitd47b5152aa614a917b2537a9ddd5122e18aa88e1 (patch)
tree9263c63d640dde2751cda78c9f47b95c70ab5ff5
parent223aa17c1b917f59494634a33a30bb33ea7a4364 (diff)
downloadpiem-d47b5152aa614a917b2537a9ddd5122e18aa88e1.tar.gz
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.
-rw-r--r--piem-gnus.el37
1 files changed, 37 insertions, 0 deletions
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)))