summaryrefslogtreecommitdiff
path: root/mailscripts.el
diff options
context:
space:
mode:
Diffstat (limited to 'mailscripts.el')
-rw-r--r--mailscripts.el29
1 files changed, 29 insertions, 0 deletions
diff --git a/mailscripts.el b/mailscripts.el
index bcdc0ad..09d213d 100644
--- a/mailscripts.el
+++ b/mailscripts.el
@@ -77,6 +77,35 @@ threads to the notmuch-extract-patch(1) command."
(interactive)
(mailscripts--projectile-repo-and-branch 'notmuch-extract-thread-patches))
+;;;###autoload
+(defun notmuch-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.
+
+Patches are applied using git-am(1), so we only consider
+attachments with filenames which look like they were generated by
+git-format-patch(1)."
+ (interactive "Dgit repo: \nsnew branch name: ")
+ (with-current-notmuch-show-message
+ (let ((default-directory (expand-file-name repo))
+ (mm-handle (mm-dissect-buffer)))
+ (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 "^[0-9]+-.+\.\\(patch\\|diff\\|txt\\)$" filename)
+ (mm-pipe-part p "git am"))))
+ mm-handle))))
+
+;;;###autoload
+(defun notmuch-extract-message-patches-projectile ()
+ "Like `notmuch-extract-message-patches', but use projectile to choose the repo."
+ (interactive)
+ (mailscripts--projectile-repo-and-branch 'notmuch-extract-message-patches))
+
(defun mailscripts--check-out-branch (branch)
(call-process-shell-command
(format "git checkout -b %s"