Skip to content

Commit 9d13eff

Browse files
author
Lluís Vilanova
committed
Add support for "mail" command
Besides the regular arguments, it implements some additional magit^Wmagic to auto-extract email recipients from the cover letter.
1 parent 082a2e8 commit 9d13eff

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

magit-stgit.el

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ Else, asks the user for a patch name."
266266
(?\r "Show" magit-stgit-show)
267267
(?a "Goto" magit-stgit-goto-popup)
268268
;;
269+
(?m "Mail patches" magit-stgit-mail-popup)
270+
;;
269271
(?g "Refresh" magit-stgit-refresh-popup)
270272
(?r "Repair" magit-stgit-repair)
271273
(?R "Rebase" magit-stgit-rebase-popup)
@@ -539,6 +541,67 @@ Use ARGS to pass additional arguments."
539541
(interactive (magit-stgit-redo-arguments))
540542
(magit-run-stgit "redo" args))
541543

544+
;;;; magit-stgit-mail
545+
546+
(magit-define-popup magit-stgit-mail-popup
547+
"Popup console for StGit mail."
548+
'magit-stgit-commands
549+
:man-page "stg-mail"
550+
:switches '((?m "Generate an mbox file instead of sending" "--mbox")
551+
(?g "Use git send-email" "--git" t)
552+
(?A "Auto-detect To, Cc and Bcc for all patches from cover"
553+
"--auto-recipients" t))
554+
:options '((?o "Set file as cover message" "--cover="
555+
(lambda (prompt default) (read-file-name "Find file: " default)))
556+
(?v "Add version to [PATCH ...]" "--version=")
557+
(?p "Add prefix to [... PATCH ...]" "--prefix=")
558+
(?t "Mail To" "--to=")
559+
(?c "Mail Cc" "--cc=")
560+
(?b "Mail Bcc:" "--bcc="))
561+
:actions '((?m "Send" magit-stgit-mail)))
562+
563+
;;;###autoload
564+
(defun magit-stgit-mail (patches &rest args)
565+
"Send PATCHES with \"stg mail\".
566+
567+
If a cover is specified, it will be searched to automatically set
568+
the To, Cc, and Bcc fields for all patches."
569+
(interactive (list (magit-stgit-read-patches t t t t "Send patch")
570+
(magit-stgit-mail-arguments)))
571+
(setq args (-flatten args)) ; nested list when called from popup
572+
(let* ((auto "--auto-recipients")
573+
(have-auto (member auto args))
574+
(cover (car (delq nil (mapcar (lambda (arg)
575+
(if (string-prefix-p "--cover=" arg)
576+
arg nil))
577+
args))))
578+
(cover-pos -1))
579+
(when have-auto
580+
(setq args (delete auto args)))
581+
(when (and have-auto cover)
582+
(setq cover (substring cover 8))
583+
(setq cover (with-temp-buffer (insert-file-contents cover)
584+
(buffer-string)))
585+
(while (setq cover-pos
586+
(string-match
587+
"^\\(To\\|Cc\\|Bcc\\):[[:space:]]+\\(.*\\)[[:space:]]*$"
588+
cover (1+ cover-pos)))
589+
(let ((field (match-string 1 cover))
590+
(recipient (match-string 2 cover)))
591+
(setq field (match-string 1 cover))
592+
(when (string-match "<" recipient)
593+
(setq recipient (format "\"%s\"" recipient)))
594+
(cond ((equal field "To")
595+
(setq args (cons (format "--to=%s" recipient)
596+
args)))
597+
((equal field "Cc")
598+
(setq args (cons (format "--cc=%s" recipient)
599+
args)))
600+
((equal field "Bcc")
601+
(setq args (cons (format "--bcc=%s" recipient)
602+
args)))))))
603+
(magit-run-stgit-async "mail" args patches)))
604+
542605
;;; Mode
543606

544607
(defvar magit-stgit-mode-map

0 commit comments

Comments
 (0)