Skip to contentSkip to conversation

send-email: Use To: headers in patch files

PATCH Superseded Stephen Boyd 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 send-email: Use To: headers in patch files

It's a minor annoyance when you take the painstaking time to setup To:
headers for each patch in a large series, and then go out to send the series with git-send-email and watch git ignore the To: headers in the patch files.

Therefore, always add To: headers from a patch file to the To: headers for that message. Keep the prompt for the blanket To: header so as to not break scripts (and user expectations). This means even if a patch has a To: header, git will prompt for the To: address. Otherwise, we'll need to introduce interface breakage to either request the header for each patch missing a To: header or default the header to whatever To:
address is found first (be it in a patch or from user input). Both of these options don't seem very obvious/useful.

---

This is a resend of a patch a few weeks ago with some added tests.

 git-send-email.perl   |    7 +++++++
 t/t9001-send-email.sh |   22 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 0 deletions(-)
git-send-email.perl +7 -0
index e1f29a7..d6028ec 100755
@@ -1176,6 +1176,13 @@ foreach my $t (@files) {
 					$1, $_) unless $quiet;
 				push @cc, $1;
 			}
+			elsif (/^To:\s+(.*)$/) {
+				foreach my $addr (parse_address_line($1)) {
+					printf("(mbox) Adding to: %s from line '%s'\n",
+						$addr, $_) unless $quiet;
+					push @to, sanitize_address($addr);
+				}
+			}
 			elsif (/^Cc:\s+(.*)$/) {
 				foreach my $addr (parse_address_line($1)) {
 					if (unquote_rfc2047($addr) eq $sender) {
t/t9001-send-email.sh +22 -0
index 71b3df9..6bd9ea7 100755
@@ -947,6 +947,28 @@ test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
 	! grep "RCPT TO:<[email protected]>" stdout
 '
 
+test_expect_success $PREREQ 'patches To headers are used by default' '
+	patch=`git format-patch -1 --to="[email protected]"` &&
+	git send-email \
+		--dry-run \
+		--from="Example <[email protected]>" \
+		--smtp-server relay.example.com \
+		$patch >stdout &&
+	grep "RCPT TO:<[email protected]>" stdout
+'
+
+test_expect_success $PREREQ 'patches To headers are appended to' '
+	patch=`git format-patch -1 --to="[email protected]"` &&
+	git send-email \
+		--dry-run \
+		--from="Example <[email protected]>" \
+		[email protected] \
+		--smtp-server relay.example.com \
+		$patch >stdout &&
+	grep "RCPT TO:<[email protected]>" stdout &&
+	grep "RCPT TO:<[email protected]>" stdout
+'
+
 test_expect_success $PREREQ 'setup expect' '
 cat >email-using-8bit <<EOF
 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
Signature · 1 line
1.7.3.16.g5d4d9
#1 lore raw
Quoted 9 lines · Stephen Boyd

+test_expect_success $PREREQ 'patches To headers are used by default' '
+       patch=git format-patch -1 --to="[email protected]" &&
+       git send-email \
+               --dry-run \
+               --from="Example <[email protected]>" \
+               --smtp-server relay.example.com \
+               $patch >stdout &&
+       grep "RCPT TO:<[email protected]>" stdout
+'

Why not:

    git format-patch -1 --to="[email protected]" &&
    test_when_finished "rm *.patch" &&
    git send-email [...] *.patch >out &&
    [...]
#2 lore raw

PATCH v2 1/1 send-email: Use To: headers in patch files

It's a minor annoyance when you take the painstaking time to setup To:
headers for each patch in a large series, and then go out to send the series with git-send-email and watch git ignore the To: headers in the patch files.

Therefore, always add To: headers from a patch file to the To: headers for that message. Keep the prompt for the blanket To: header so as to not break scripts (and user expectations). This means even if a patch has a To: header, git will prompt for the To: address. Otherwise, we'll need to introduce interface breakage to either request the header for each patch missing a To: header or default the header to whatever To:
address is found first (be it in a patch or from user input). Both of these options don't seem very obvious/useful.

---

Changes since v1:
- Added test_when_finished calls.

 git-send-email.perl   |    7 +++++++
 t/t9001-send-email.sh |   24 ++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
git-send-email.perl +7 -0
index e1f29a7..d6028ec 100755
@@ -1176,6 +1176,13 @@ foreach my $t (@files) {
 					$1, $_) unless $quiet;
 				push @cc, $1;
 			}
+			elsif (/^To:\s+(.*)$/) {
+				foreach my $addr (parse_address_line($1)) {
+					printf("(mbox) Adding to: %s from line '%s'\n",
+						$addr, $_) unless $quiet;
+					push @to, sanitize_address($addr);
+				}
+			}
 			elsif (/^Cc:\s+(.*)$/) {
 				foreach my $addr (parse_address_line($1)) {
 					if (unquote_rfc2047($addr) eq $sender) {
t/t9001-send-email.sh +24 -0
index 71b3df9..294e31f 100755
@@ -947,6 +947,30 @@ test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
 	! grep "RCPT TO:<[email protected]>" stdout
 '
 
+test_expect_success $PREREQ 'patches To headers are used by default' '
+	patch=`git format-patch -1 --to="[email protected]"` &&
+	test_when_finished "rm $patch" &&
+	git send-email \
+		--dry-run \
+		--from="Example <[email protected]>" \
+		--smtp-server relay.example.com \
+		$patch >stdout &&
+	grep "RCPT TO:<[email protected]>" stdout
+'
+
+test_expect_success $PREREQ 'patches To headers are appended to' '
+	patch=`git format-patch -1 --to="[email protected]"` &&
+	test_when_finished "rm $patch" &&
+	git send-email \
+		--dry-run \
+		--from="Example <[email protected]>" \
+		[email protected] \
+		--smtp-server relay.example.com \
+		$patch >stdout &&
+	grep "RCPT TO:<[email protected]>" stdout &&
+	grep "RCPT TO:<[email protected]>" stdout
+'
+
 test_expect_success $PREREQ 'setup expect' '
 cat >email-using-8bit <<EOF
 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
Signature · 1 line
1.7.3.16.g5d4d9