summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinglu Chen <public@yoctocell.xyz>2021-01-20 09:56:23 +0100
committerKyle Meyer <kyle@kyleam.com>2021-01-20 21:33:10 -0500
commitc9228b90ceed55502cfcbf70d5c9332028860100 (patch)
tree2cfd7a9360ac1d07f578c3151a813d1e9c8debb9
parenta8d858b6658fc4f0b9fe71073c958b342425f7a0 (diff)
downloadpiem-c9228b90ceed55502cfcbf70d5c9332028860100.tar.gz
gnus: Add piem-gnus-mid-to-thread
Inserts a string of the whole thread in mbox format. Message-Id: <796fb84d852f2a5adea1502db144dae1bdc4fe0c.1611132172.git.public@yoctocell.xyz>
-rw-r--r--piem-gnus.el41
1 files changed, 37 insertions, 4 deletions
diff --git a/piem-gnus.el b/piem-gnus.el
index 5f10be8..867b45f 100644
--- a/piem-gnus.el
+++ b/piem-gnus.el
@@ -28,6 +28,7 @@
;;; Code:
(require 'gnus)
+(require 'gnus-art)
(require 'gnus-sum)
(require 'message)
(require 'piem)
@@ -55,8 +56,38 @@
(match-string 1 mid)
mid)))))
-;; 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-mid-to-thread (mid)
+ (when (and (derived-mode-p 'gnus-summary-mode)
+ (string-equal (substring
+ (mail-header-id (gnus-summary-article-header))
+ 1 -1) ; Remove "<" and ">"
+ mid))
+ (save-excursion
+ ;; Cursor has to be at the root of the thread
+ (gnus-summary-refer-parent-article most-positive-fixnum)
+ (let ((articles (gnus-summary-articles-in-thread))
+ messages
+ ;; Just show raw message
+ (gnus-have-all-headers t)
+ gnus-article-prepare-hook
+ gnus-article-decode-hook
+ gnus-display-mime-function
+ gnus-break-pages)
+ (mapc (lambda (article)
+ (gnus-summary-display-article article)
+ (push (format
+ "From mboxrd@z Thu Jan 1 00:00:00 1970\n%s\n"
+ (replace-regexp-in-string ; From-munge
+ "^>*From "
+ ">\\&"
+ (with-current-buffer gnus-article-buffer
+ (buffer-substring-no-properties
+ (point-min)
+ (point-max)))))
+ messages))
+ articles)
+ (lambda ()
+ (insert (apply #'concat (nreverse messages))))))))
(defun piem-gnus-am-ready-mbox ()
"Return a function that inserts an am-ready mbox.
@@ -97,10 +128,12 @@ the mode if ARG is omitted or nil."
(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))
+ (add-hook 'piem-get-mid-functions #'piem-gnus-get-mid)
+ (add-hook 'piem-mid-to-thread-functions #'piem-gnus-mid-to-thread))
(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)))
+ (remove-hook 'piem-get-mid-functions #'piem-gnus-get-mid)
+ (remove-hook 'piem-mid-to-thread-functions #'piem-gnus-mid-to-thread)))
;;; piem-gnus.el ends here
(provide 'piem-gnus)