From: Xinglu Chen <public@yoctocell.xyz>
To: piem@inbox.kyleam.com
Subject: [RFC PATCH v2] gnus: Add piem-gnus-mid-to-thread
Date: Wed, 20 Jan 2021 09:56:23 +0100 [thread overview]
Message-ID: <796fb84d852f2a5adea1502db144dae1bdc4fe0c.1611132172.git.public@yoctocell.xyz> (raw)
In-Reply-To: <dde16a7a7a212e0947fdf3afad5678bac7ad2690.1610964014.git.public@yoctocell.xyz>
Inserts a string of the whole thread in mbox format.
---
Changes from v1
- Add safety check for major mode and message id before trying to generate
the mbox file
- Escape "^From" in the body to prevent ambiguity
piem-gnus.el | 40 ++++++++++++++++++++++++++++++++++++----
1 file changed, 36 insertions(+), 4 deletions(-)
diff --git a/piem-gnus.el b/piem-gnus.el
index 5f10be8..828ce1f 100644
--- a/piem-gnus.el
+++ b/piem-gnus.el
@@ -55,8 +55,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))
+ message
+ ;; 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 "
+ "^>From "
+ (with-current-buffer gnus-article-buffer
+ (buffer-substring-no-properties
+ (point-min)
+ (point-max)))))
+ message))
+ articles)
+ (lambda ()
+ (insert (apply #'concat (nreverse message))))))))
(defun piem-gnus-am-ready-mbox ()
"Return a function that inserts an am-ready mbox.
@@ -97,10 +127,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)
base-commit: 57f802b2a43ac64c28a5a9ddb9da0afaf910975e
--
2.29.2
next prev parent reply other threads:[~2021-01-20 8:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-18 10:34 [RFC PATCH] gnus: Add piem-gnus-mid-to-thread Xinglu Chen
2021-01-19 4:17 ` Kyle Meyer
2021-01-19 8:32 ` yoctocell
2021-01-19 23:41 ` Kyle Meyer
2021-01-20 7:27 ` Xinglu Chen
2021-01-20 8:56 ` Xinglu Chen [this message]
2021-01-21 2:45 ` [RFC PATCH v2] " Kyle Meyer
2021-01-21 8:36 ` Xinglu Chen
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 \
--in-reply-to=796fb84d852f2a5adea1502db144dae1bdc4fe0c.1611132172.git.public@yoctocell.xyz \
--to=public@yoctocell.xyz \
--cc=piem@inbox.kyleam.com \
/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
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
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).