diff options
Diffstat (limited to 'piem-gnus.el')
-rw-r--r-- | piem-gnus.el | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/piem-gnus.el b/piem-gnus.el index c62a2e6..b6dc672 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,44 +90,48 @@ 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)))))))) (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 (save-restriction (widen) - (and (string-match-p - piem-patch-subject-re - (mail-decode-encoded-word-string - (message-field-value "subject"))) - (buffer-substring-no-properties - (point-min) (point-max))))))) + (buffer-substring-no-properties + (point-min) (point-max)))))) (cons (lambda () (insert patch)) "mbox")))))) |