Skip to content

Commit 3ec6167

Browse files
peffgitster
authored andcommitted
send-email: handle to/cc/bcc from --compose message
If the user writes a message via --compose, send-email will pick up various headers like "From", "Subject", etc and use them for other patches as if they were specified on the command-line. But we don't handle "To", "Cc", or "Bcc" this way; we just tell the user "those aren't interpeted yet" and ignore them. But it seems like an obvious thing to want, especially as the same feature exists when the cover letter is generated separately by format-patch. There it is gated behind the --to-cover option, but I don't think we'd need the same control here; since we generate the --compose template ourselves based on the existing input, if the user leaves the lines unchanged then the behavior remains the same. So let's fill in the implementation; like those other headers we already handle, we just need to assign to the initial_* variables. The only difference in this case is that they are arrays, so we'll feed them through parse_address_line() to split them (just like we would when reading a single string via prompting). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 637e894 commit 3ec6167

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

Documentation/git-send-email.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ This option may be specified multiple times.
6868
Invoke a text editor (see GIT_EDITOR in linkgit:git-var[1])
6969
to edit an introductory message for the patch series.
7070
+
71-
When `--compose` is used, git send-email will use the From, Subject,
72-
Reply-To, and In-Reply-To headers specified in the message. If the body
73-
of the message (what you type after the headers and a blank line) only
74-
contains blank (or Git: prefixed) lines, the summary won't be sent, but
75-
the headers mentioned above will be used unless they are removed.
71+
When `--compose` is used, git send-email will use the From, To, Cc, Bcc,
72+
Subject, Reply-To, and In-Reply-To headers specified in the message. If
73+
the body of the message (what you type after the headers and a blank
74+
line) only contains blank (or Git: prefixed) lines, the summary won't be
75+
sent, but the headers mentioned above will be used unless they are
76+
removed.
7677
+
7778
Missing From or In-Reply-To headers will be prompted for.
7879
+

git-send-email.perl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,9 @@ sub get_patch_subject {
861861
my $tpl_subject = $initial_subject || '';
862862
my $tpl_in_reply_to = $initial_in_reply_to || '';
863863
my $tpl_reply_to = $reply_to || '';
864+
my $tpl_to = join(',', @initial_to);
865+
my $tpl_cc = join(',', @initial_cc);
866+
my $tpl_bcc = join(', ', @initial_bcc);
864867

865868
print $c <<EOT1, Git::prefix_lines("GIT: ", __(<<EOT2)), <<EOT3;
866869
From $tpl_sender # This line is ignored.
@@ -872,6 +875,9 @@ sub get_patch_subject {
872875
Clear the body content if you don't wish to send a summary.
873876
EOT2
874877
From: $tpl_sender
878+
To: $tpl_to
879+
Cc: $tpl_cc
880+
Bcc: $tpl_bcc
875881
Reply-To: $tpl_reply_to
876882
Subject: $tpl_subject
877883
In-Reply-To: $tpl_in_reply_to
@@ -928,8 +934,14 @@ sub get_patch_subject {
928934
} elsif (/^From:\s*(.+)\s*$/i) {
929935
$sender = $1;
930936
next;
931-
} elsif (/^(?:To|Cc|Bcc):/i) {
932-
print __("To/Cc/Bcc fields are not interpreted yet, they have been ignored\n");
937+
} elsif (/^To:\s*(.+)\s*$/i) {
938+
@initial_to = parse_address_line($1);
939+
next;
940+
} elsif (/^Cc:\s*(.+)\s*$/i) {
941+
@initial_cc = parse_address_line($1);
942+
next;
943+
} elsif (/^Bcc:/i) {
944+
@initial_bcc = parse_address_line($1);
933945
next;
934946
}
935947
print $c2 $_;

t/t9001-send-email.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,7 +2522,7 @@ test_expect_success $PREREQ '--compose handles lowercase headers' '
25222522

25232523
test_expect_success $PREREQ '--compose handles to headers' '
25242524
write_script fake-editor <<-\EOF &&
2525-
sed "s/^$/To: [email protected]\n/" <"$1" >"$1.tmp" &&
2525+
sed "s/^To: .*/&, [email protected]/" <"$1" >"$1.tmp" &&
25262526
echo this is the body >>"$1.tmp" &&
25272527
mv "$1.tmp" "$1"
25282528
EOF
@@ -2534,10 +2534,16 @@ test_expect_success $PREREQ '--compose handles to headers' '
25342534
25352535
--smtp-server="$(pwd)/fake.sendmail" \
25362536
HEAD^ &&
2537-
# Ideally the "to" header we specified would be used,
2538-
# but the program explicitly warns that these are
2539-
# ignored. For now, just make sure we did not abort.
2540-
grep "To:" msgtxt1
2537+
# Check both that the cover letter used our modified "to" line,
2538+
# but also that it was picked up for the patch.
2539+
q_to_tab >expect <<-\EOF &&
2540+
2541+
2542+
EOF
2543+
grep -A1 "^To:" msgtxt1 >msgtxt1.to &&
2544+
test_cmp expect msgtxt1.to &&
2545+
grep -A1 "^To:" msgtxt2 >msgtxt2.to &&
2546+
test_cmp expect msgtxt2.to
25412547
'
25422548

25432549
test_done

0 commit comments

Comments
 (0)