aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinglu Chen <public@yoctocell.xyz>2021-04-03 14:30:35 +0200
committerXinglu Chen <public@yoctocell.xyz>2021-04-03 14:30:35 +0200
commit44e07c7ff663836e9d1f66958c39dea8c9c284ee (patch)
tree55b6da6e2ed58b65f1b162fd79e4a6cd4a135493
parent19e857181bef33e000289504c09c9993731d79d9 (diff)
git-email: Don't insert 'to' address if already there.
* git-email.el (git-email--compose-email): Don't insert a 'to' address if one is already found in the patch. This makes it possible to override the result of 'git-email-get-to-address-functions'.
-rw-r--r--git-email.el31
1 files changed, 19 insertions, 12 deletions
diff --git a/git-email.el b/git-email.el
index 20b9400..3d3d71b 100644
--- a/git-email.el
+++ b/git-email.el
@@ -300,18 +300,25 @@ so might not always work."
Extracts the relevant headers and the diff from the PATCH-FILE and inserts
them into the message buffer."
(let* ((headers (git-email--extract-headers patch-file))
- ;; Remove empty headers.
- (used-headers (seq-filter
- (lambda (header)
- (not (string-equal (car (cdr header)) "")))
- headers))
- (sendemail-to (run-hook-with-args-until-success
- 'git-email-get-to-address-functions))
- ;; Get 'to' address from git.
- (to (if (string-equal sendemail-to "")
- "*** TO ADDRESS HERE ***"
- sendemail-to))
- (diff (git-email--extract-diff patch-file)))
+ ;; Remove empty headers.
+ (used-headers (seq-filter
+ (lambda (header)
+ (not (string-equal (cdr header) "")))
+ headers))
+ (to-address (seq-position used-headers
+ 'to
+ (lambda (a b)
+ (equal (car a) b))))
+ ;; Don't insert 'to' address if the patch already contains one.
+ (sendemail-to (if to-address
+ (cdr (nth to-address used-headers))
+ (run-hook-with-args-until-success
+ 'git-email-get-to-address-functions)))
+ (to (if (string-equal sendemail-to "")
+ "*** TO ADDRESS HERE ***"
+ sendemail-to))
+ (diff (git-email--extract-diff patch-file)))
+ (print to-address)
(funcall git-email-compose-email-function to
;; Remove 'subject' header, otherwise two subject headers will be
;; inserted.