diff options
-rw-r--r-- | piem-gnus.el | 13 | ||||
-rw-r--r-- | piem-notmuch.el | 15 | ||||
-rw-r--r-- | piem.el | 26 |
3 files changed, 36 insertions, 18 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 diff --git a/piem-notmuch.el b/piem-notmuch.el index 41f2793..493b724 100644 --- a/piem-notmuch.el +++ b/piem-notmuch.el @@ -85,9 +85,15 @@ have surrounding brackets." (defun piem-notmuch-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 'notmuch-show-mode) (let* ((handle (piem-notmuch--with-current-message (mm-dissect-buffer))) @@ -106,10 +112,11 @@ message itself if it looks like a patch." (push patch patches))) handle) (when patches - (setq patches (nreverse patches)) + (setq patches (sort (nreverse patches) + (lambda (x y) (< (car x) (car y))))) (cons (lambda () (dolist (patch patches) - (insert patch))) + (insert (cdr patch)))) "mbox")))))) (defun piem-notmuch-extract-patch-am-ready-mbox () @@ -817,17 +817,21 @@ message for MID, not the entire thread." ;;;; Patch handling (defun piem-am-extract-attached-patch (handle) - "Return content for HANDLE if it looks like a patch." - (and (listp handle) - (let ((type (mm-handle-media-type handle)) - (filename (mm-handle-filename handle))) - (or (member type '("text/x-diff" "text/x-patch")) - (and filename - (equal type "text/plain") - (string-suffix-p ".patch" filename t)))) - (with-temp-buffer - (mm-display-inline handle) - (buffer-substring-no-properties (point-min) (point-max))))) + "Get the content for HANDLE if it looks like a patch. +The return value is of the form (N . CONTENT), where N is the +number at the start of the file name." + (when (listp handle) + (let ((type (mm-handle-media-type handle)) + (filename (mm-handle-filename handle))) + (and (or (member type '("text/x-diff" "text/x-patch")) + (and filename + (equal type "text/plain") + (string-suffix-p ".patch" filename t))) + (with-temp-buffer + (mm-display-inline handle) + (cons + (string-to-number filename) + (buffer-substring-no-properties (point-min) (point-max)))))))) (defun piem-extract-mbox-info (&optional buffer) "Collect information from message in BUFFER. |