aboutsummaryrefslogtreecommitdiff
path: root/piem-gnus.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2022-07-09 02:45:14 -0400
committerKyle Meyer <kyle@kyleam.com>2022-07-10 10:19:44 -0400
commit6776cacf0e524389d8177df7e295ea38e7116a73 (patch)
treefd0b92ad245c5c9defdc163741baeea67ad38e7a /piem-gnus.el
parent67411fadab680b01d9027a3f4833ef8892377874 (diff)
downloadpiem-6776cacf0e524389d8177df7e295ea38e7116a73.tar.gz
piem-am: Order attached patches by file name prefix
When extracting patches from attachments, piem-gnus-am-ready-mbox and piem-notmuch-am-ready-mbox construct the mbox messages in the same order as the attachments. This depends on the sender attaching the patches in ascending order. Be a bit more helpful in situations where the sender attaches the patches out of order by reordering patches according to the NNNN- prefix that git-format-patch adds to the start of the patch file name. This approach won't be able to reliably sort patches that aren't generated by git-format-patch, but that's outside of any use case that piem is intended to support. Suggested-by: Ihor Radchenko <yantar92@gmail.com> Link: https://inbox.kyleam.com/piem/87mtdj9dzt.fsf@localhost Message-Id: <878rp2pyx1.fsf@kyleam.com>
Diffstat (limited to 'piem-gnus.el')
-rw-r--r--piem-gnus.el13
1 files changed, 10 insertions, 3 deletions
diff --git a/piem-gnus.el b/piem-gnus.el
index c62a2e6..4011fa2 100644
--- a/piem-gnus.el
+++ b/piem-gnus.el
@@ -91,17 +91,24 @@
(defun piem-gnus-am-ready-mbox ()
"Return a function that inserts an am-ready mbox.
+
If the buffer has any MIME parts that look like a patch, use
-those parts' contents (in order) as the mbox. Otherwise, use the
-message itself if it looks like a patch."
+those parts' contents as the mbox, ordering the patches based on
+the number at the start of the file name. If none of the file
+names start with a number, retain the original order of the
+attachments.
+
+If no MIME parts look like a patch, use the message itself if it
+looks like a patch."
(when (derived-mode-p 'gnus-article-mode 'gnus-summary-mode)
(cond
(gnus-article-mime-handles
(when-let ((patches (delq nil (mapcar #'piem-am-extract-attached-patch
gnus-article-mime-handles))))
+ (setq patches (sort patches (lambda (x y) (< (car x) (car y)))))
(cons (lambda ()
(dolist (patch patches)
- (insert patch)))
+ (insert (cdr patch))))
"mbox")))
(gnus-article-buffer
(when-let ((patch (with-current-buffer gnus-article-buffer