Skip to content

Commit e74737b

Browse files
committed
Merge branch 'cl/send-email-reply-to'
"git send-email" learned "--reply-to=<address>" option. * cl/send-email-reply-to: send-email: support separate Reply-To address send-email: rename variable for clarity
2 parents fbc615b + d11c943 commit e74737b

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

Documentation/git-send-email.txt

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ See the CONFIGURATION section for `sendemail.multiEdit`.
8484
the value of GIT_AUTHOR_IDENT, or GIT_COMMITTER_IDENT if that is not
8585
set, as returned by "git var -l".
8686

87+
--reply-to=<address>::
88+
Specify the address where replies from recipients should go to.
89+
Use this if replies to messages should go to another address than what
90+
is specified with the --from parameter.
91+
8792
--in-reply-to=<identifier>::
8893
Make the first mail (or all the mails with `--no-thread`) appear as a
8994
reply to the given Message-Id, which avoids breaking threads to

contrib/completion/git-completion.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ _git_send_email ()
20192019
--compose --confirm= --dry-run --envelope-sender
20202020
--from --identity
20212021
--in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2022-
--no-suppress-from --no-thread --quiet
2022+
--no-suppress-from --no-thread --quiet --reply-to
20232023
--signed-off-by-cc --smtp-pass --smtp-server
20242024
--smtp-server-port --smtp-encryption= --smtp-user
20252025
--subject --suppress-cc= --suppress-from --thread --to

git-send-email.perl

+35-19
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ sub usage {
5757
--[no-]cc <str> * Email Cc:
5858
--[no-]bcc <str> * Email Bcc:
5959
--subject <str> * Email "Subject:"
60+
--reply-to <str> * Email "Reply-To:"
6061
--in-reply-to <str> * Email "In-Reply-To:"
6162
--[no-]xmailer * Add "X-Mailer:" header (default).
6263
--[no-]annotate * Review each patch that will be sent in an editor.
@@ -167,13 +168,13 @@ sub format_2822_time {
167168

168169
# Variables we fill in automatically, or via prompting:
169170
my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
170-
$initial_reply_to,$initial_subject,@files,
171+
$initial_in_reply_to,$reply_to,$initial_subject,@files,
171172
$author,$sender,$smtp_authpass,$annotate,$use_xmailer,$compose,$time);
172173

173174
my $envelope_sender;
174175

175176
# Example reply to:
176-
#$initial_reply_to = ''; #<[email protected]>';
177+
#$initial_in_reply_to = ''; #<[email protected]>';
177178

178179
my $repo = eval { Git->repository() };
179180
my @repo = $repo ? ($repo) : ();
@@ -315,7 +316,8 @@ sub signal_handler {
315316
if !$help and $dump_aliases and @ARGV;
316317
$rc = GetOptions(
317318
"sender|from=s" => \$sender,
318-
"in-reply-to=s" => \$initial_reply_to,
319+
"in-reply-to=s" => \$initial_in_reply_to,
320+
"reply-to=s" => \$reply_to,
319321
"subject=s" => \$initial_subject,
320322
"to=s" => \@initial_to,
321323
"to-cmd=s" => \$to_cmd,
@@ -681,7 +683,8 @@ sub get_patch_subject {
681683

682684
my $tpl_sender = $sender || $repoauthor || $repocommitter || '';
683685
my $tpl_subject = $initial_subject || '';
684-
my $tpl_reply_to = $initial_reply_to || '';
686+
my $tpl_in_reply_to = $initial_in_reply_to || '';
687+
my $tpl_reply_to = $reply_to || '';
685688

686689
print $c <<EOT1, Git::prefix_lines("GIT: ", __ <<EOT2), <<EOT3;
687690
From $tpl_sender # This line is ignored.
@@ -693,8 +696,9 @@ sub get_patch_subject {
693696
Clear the body content if you don't wish to send a summary.
694697
EOT2
695698
From: $tpl_sender
699+
Reply-To: $tpl_reply_to
696700
Subject: $tpl_subject
697-
In-Reply-To: $tpl_reply_to
701+
In-Reply-To: $tpl_in_reply_to
698702
699703
EOT3
700704
for my $f (@files) {
@@ -733,7 +737,10 @@ sub get_patch_subject {
733737
$sender = delete($parsed_email{'From'});
734738
}
735739
if ($parsed_email{'In-Reply-To'}) {
736-
$initial_reply_to = delete($parsed_email{'In-Reply-To'});
740+
$initial_in_reply_to = delete($parsed_email{'In-Reply-To'});
741+
}
742+
if ($parsed_email{'Reply-To'}) {
743+
$reply_to = delete($parsed_email{'Reply-To'});
737744
}
738745
if ($parsed_email{'Subject'}) {
739746
$initial_subject = delete($parsed_email{'Subject'});
@@ -916,16 +923,22 @@ sub expand_one_alias {
916923
@initial_cc = process_address_list(@initial_cc);
917924
@bcclist = process_address_list(@bcclist);
918925

919-
if ($thread && !defined $initial_reply_to && $prompting) {
920-
$initial_reply_to = ask(
926+
if ($thread && !defined $initial_in_reply_to && $prompting) {
927+
$initial_in_reply_to = ask(
921928
__("Message-ID to be used as In-Reply-To for the first email (if any)? "),
922929
default => "",
923930
valid_re => qr/\@.*\./, confirm_only => 1);
924931
}
925-
if (defined $initial_reply_to) {
926-
$initial_reply_to =~ s/^\s*<?//;
927-
$initial_reply_to =~ s/>?\s*$//;
928-
$initial_reply_to = "<$initial_reply_to>" if $initial_reply_to ne '';
932+
if (defined $initial_in_reply_to) {
933+
$initial_in_reply_to =~ s/^\s*<?//;
934+
$initial_in_reply_to =~ s/>?\s*$//;
935+
$initial_in_reply_to = "<$initial_in_reply_to>" if $initial_in_reply_to ne '';
936+
}
937+
938+
if (defined $reply_to) {
939+
$reply_to =~ s/^\s+|\s+$//g;
940+
($reply_to) = expand_aliases($reply_to);
941+
$reply_to = sanitize_address($reply_to);
929942
}
930943

931944
if (!defined $smtp_server) {
@@ -945,7 +958,7 @@ sub expand_one_alias {
945958
}
946959

947960
# Variables we set as part of the loop over files
948-
our ($message_id, %mail, $subject, $reply_to, $references, $message,
961+
our ($message_id, %mail, $subject, $in_reply_to, $references, $message,
949962
$needs_confirm, $message_num, $ask_default);
950963

951964
sub extract_valid_address {
@@ -1354,11 +1367,14 @@ sub send_message {
13541367
if ($use_xmailer) {
13551368
$header .= "X-Mailer: git-send-email $gitversion\n";
13561369
}
1357-
if ($reply_to) {
1370+
if ($in_reply_to) {
13581371

1359-
$header .= "In-Reply-To: $reply_to\n";
1372+
$header .= "In-Reply-To: $in_reply_to\n";
13601373
$header .= "References: $references\n";
13611374
}
1375+
if ($reply_to) {
1376+
$header .= "Reply-To: $reply_to\n";
1377+
}
13621378
if (@xh) {
13631379
$header .= join("\n", @xh) . "\n";
13641380
}
@@ -1533,8 +1549,8 @@ sub send_message {
15331549
return 1;
15341550
}
15351551

1536-
$reply_to = $initial_reply_to;
1537-
$references = $initial_reply_to || '';
1552+
$in_reply_to = $initial_in_reply_to;
1553+
$references = $initial_in_reply_to || '';
15381554
$subject = $initial_subject;
15391555
$message_num = 0;
15401556

@@ -1744,9 +1760,9 @@ sub send_message {
17441760

17451761
# set up for the next message
17461762
if ($thread && $message_was_sent &&
1747-
($chain_reply_to || !defined $reply_to || length($reply_to) == 0 ||
1763+
($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
17481764
$message_num == 1)) {
1749-
$reply_to = $message_id;
1765+
$in_reply_to = $message_id;
17501766
if (length $references > 0) {
17511767
$references .= "\n $message_id";
17521768
} else {

t/t9001-send-email.sh

+2
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ Message-Id: MESSAGE-ID-STRING
224224
X-Mailer: X-MAILER-STRING
225225
In-Reply-To: <[email protected]>
226226
References: <[email protected]>
227+
Reply-To: Reply <[email protected]>
227228
228229
Result: OK
229230
EOF
@@ -316,6 +317,7 @@ test_expect_success $PREREQ 'Show all headers' '
316317
--dry-run \
317318
--suppress-cc=sob \
318319
--from="Example <[email protected]>" \
320+
--reply-to="Reply <[email protected]>" \
319321
320322
321323

0 commit comments

Comments
 (0)