aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelle Licht <jlicht@fsfe.org>2023-06-10 11:58:55 +0200
committerKyle Meyer <kyle@kyleam.com>2023-06-10 19:08:02 -0400
commit4b9490abb372b1bd66444f780a2fe352c5a89a2f (patch)
tree47b02afb0d1b4971722814bf654da392a05148e6
parent0eca53e702ac209efacb86f64fc86ea54286ef35 (diff)
downloadpiem-4b9490abb372b1bd66444f780a2fe352c5a89a2f.tar.gz
gnus: Skip adding mboxrd from-line when not needed
When using Gnus over NNTP, `gnus-summary-display-article' shows a plain message, but when debbugs.el visits an issue message with Gnus, it's already in mbox format. Link: https://inbox.kyleam.com/piem/87cz2dun0y.fsf@kyleam.com Message-ID: <20230610095858.26982-3-jlicht@fsfe.org>
-rw-r--r--piem-gnus.el36
1 files changed, 26 insertions, 10 deletions
diff --git a/piem-gnus.el b/piem-gnus.el
index 4011fa2..7120512 100644
--- a/piem-gnus.el
+++ b/piem-gnus.el
@@ -56,6 +56,21 @@
(match-string 1 mid)
mid)))))
+(defun piem-gnus--from-line (buffer)
+ "Split a buffer into from-line and the rest of the message.
+
+Returns a cons of the first line of BUFFER, if it is an mboxrd
+from-line (or nil if none), and the remaining lines of BUFFER."
+ (with-current-buffer buffer
+ (let ((start (point-min))
+ (end (point-max)))
+ (goto-char start)
+ (let* ((eol (line-end-position))
+ (line (buffer-substring-no-properties start eol)))
+ (if (string-match-p "^From " line)
+ (cons line (buffer-substring-no-properties (+ eol 1) end))
+ (cons nil (buffer-substring-no-properties start end)))))))
+
(defun piem-gnus-mid-to-thread (mid)
(when (and (derived-mode-p 'gnus-summary-mode)
(string-equal (substring
@@ -75,16 +90,17 @@
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))
+ (let ((from-line-cons
+ (piem-gnus--from-line gnus-article-buffer)))
+ (push (format
+ "%s\n%s\n"
+ (or (car from-line-cons)
+ "From mboxrd@z Thu Jan 1 00:00:00 1970")
+ (replace-regexp-in-string
+ "^>*From "
+ ">\\&"
+ (cdr from-line-cons)))
+ messages)))
articles)
(lambda ()
(insert (apply #'concat (nreverse messages))))))))