summaryrefslogtreecommitdiff
path: root/mailscripts.el
diff options
context:
space:
mode:
Diffstat (limited to 'mailscripts.el')
-rw-r--r--mailscripts.el49
1 files changed, 32 insertions, 17 deletions
diff --git a/mailscripts.el b/mailscripts.el
index ad5a04e..c6bb5e5 100644
--- a/mailscripts.el
+++ b/mailscripts.el
@@ -181,9 +181,15 @@ threads to the notmuch-extract-patch(1) command."
(declare-function notmuch-foreach-mime-part "notmuch")
(declare-function notmuch--call-process "notmuch-lib")
(declare-function notmuch-show-get-message-id "notmuch-show")
+(defvar gnus-article-buffer)
+(declare-function gnus-article-mime-handles "gnus-art")
;;;###autoload
-(defun notmuch-extract-message-patches (repo branch)
+(defalias 'notmuch-extract-message-patches
+ #'mailscripts-extract-message-patches)
+
+;;;###autoload
+(defun mailscripts-extract-message-patches (repo branch)
"Extract patches attached to current message to branch BRANCH in repo REPO.
The target branch may or may not already exist.
@@ -193,20 +199,25 @@ attachments with filenames which look like they were generated by
git-format-patch(1)."
(interactive
"Dgit repo: \nsnew branch name (or leave blank to apply to current HEAD): ")
- (require 'notmuch)
- (with-current-notmuch-show-message
- (let ((default-directory (expand-file-name repo))
- (mm-handle (mm-dissect-buffer t)))
- (mailscripts--check-out-branch branch)
- (notmuch-foreach-mime-part
- (lambda (p)
- (let* ((disposition (mm-handle-disposition p))
- (filename (cdr (assq 'filename disposition))))
- (and filename
- (string-match "^\\(v?[0-9]+\\)-.+\\.\\(patch\\|diff\\|txt\\)$"
- filename)
- (mm-pipe-part p "git am"))))
- mm-handle))))
+ (let ((default-directory (expand-file-name repo))
+ handles)
+ (cond ((derived-mode-p 'gnus-summary-mode 'gnus-article-mode)
+ (with-current-buffer gnus-article-buffer
+ (setq handles (mapcar #'cdr (gnus-article-mime-handles)))))
+ ((derived-mode-p 'notmuch-show-mode)
+ (with-current-notmuch-show-message
+ (notmuch-foreach-mime-part (lambda (handle) (push handle handles))
+ (mm-dissect-buffer t))))
+ (t (user-error "Unsupported major mode")))
+ (cl-callf2 cl-remove-if-not
+ (lambda (h)
+ (and-let*
+ ((filename (cdr (assq 'filename (mm-handle-disposition h)))))
+ (string-match "^\\(v?[0-9]+\\)-.+\\.\\(patch\\|diff\\|txt\\)$"
+ filename)))
+ handles)
+ (mailscripts--check-out-branch branch)
+ (dolist (handle handles) (mm-pipe-part handle "git am"))))
;;;###autoload
(define-obsolete-function-alias
@@ -215,8 +226,12 @@ git-format-patch(1)."
"mailscripts 0.22")
;;;###autoload
-(defun notmuch-extract-message-patches-to-project ()
- "Like `notmuch-extract-message-patches', but choose repo from known projects."
+(defalias 'notmuch-extract-message-patches-to-project
+ #'mailscripts-extract-message-patches-to-project)
+
+;;;###autoload
+(defun mailscripts-extract-message-patches-to-project ()
+ "Like `mailscripts-extract-message-patches', but choose repo from known projects."
(interactive)
(mailscripts--project-repo-and-branch 'notmuch-extract-message-patches))