send-email: support separate Reply-To address

In some projects contributions from groups are only accepted from a common group email address. But every individual may want to receive replies to her own personal address. That's what we have 'Reply-To' headers for in SMTP. So introduce an optional '--reply-to' command line option. This patch re-uses the $reply_to variable. This could break out-of-tree patches! Signed-off-by: Christian Ludwig <chrissicool@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Ludwig committed Mar 4, 2018 at 00:58 UTC d11c943c7824ed91ec396c8726d18ce687848d34
4 files changed +25 -2
Documentation/git-send-email.txt
+5
@@ -84,6 +84,11 @@ See the CONFIGURATION section for `sendemail.multiEdit`.
84 the value of GIT_AUTHOR_IDENT, or GIT_COMMITTER_IDENT if that is not
85 set, as returned by "git var -l".
86
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 +
92 --in-reply-to=<identifier>::
93 Make the first mail (or all the mails with `--no-thread`) appear as a
94 reply to the given Message-Id, which avoids breaking threads to
contrib/completion/git-completion.bash
+1 -1
@@ -2081,7 +2081,7 @@ _git_send_email ()
2081 --compose --confirm= --dry-run --envelope-sender
2082 --from --identity
2083 --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
2084 - --no-suppress-from --no-thread --quiet
2084 + --no-suppress-from --no-thread --quiet --reply-to
2085 --signed-off-by-cc --smtp-pass --smtp-server
2086 --smtp-server-port --smtp-encryption= --smtp-user
2087 --subject --suppress-cc= --suppress-from --thread --to
git-send-email.perl
+17 -1
@@ -56,6 +56,7 @@ git send-email --dump-aliases
56 --[no-]cc <str> * Email Cc:
57 --[no-]bcc <str> * Email Bcc:
58 --subject <str> * Email "Subject:"
59 + --reply-to <str> * Email "Reply-To:"
60 --in-reply-to <str> * Email "In-Reply-To:"
61 --[no-]xmailer * Add "X-Mailer:" header (default).
62 --[no-]annotate * Review each patch that will be sent in an editor.
@@ -166,7 +167,7 @@ my $re_encoded_word = qr/=\?($re_token)\?($re_token)\?($re_encoded_text)\?=/;
167
168 # Variables we fill in automatically, or via prompting:
169 my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
169 - $initial_in_reply_to,$initial_subject,@files,
170 + $initial_in_reply_to,$reply_to,$initial_subject,@files,
171 $author,$sender,$smtp_authpass,$annotate,$use_xmailer,$compose,$time);
172
173 my $envelope_sender;
@@ -315,6 +316,7 @@ die __("--dump-aliases incompatible with other options\n")
316 $rc = GetOptions(
317 "sender|from=s" => \$sender,
318 "in-reply-to=s" => \$initial_in_reply_to,
319 + "reply-to=s" => \$reply_to,
320 "subject=s" => \$initial_subject,
321 "to=s" => \@initial_to,
322 "to-cmd=s" => \$to_cmd,
@@ -677,6 +679,7 @@ if ($compose) {
679 my $tpl_sender = $sender || $repoauthor || $repocommitter || '';
680 my $tpl_subject = $initial_subject || '';
681 my $tpl_in_reply_to = $initial_in_reply_to || '';
682 + my $tpl_reply_to = $reply_to || '';
683
684 print $c <<EOT1, Git::prefix_lines("GIT: ", __ <<EOT2), <<EOT3;
685 From $tpl_sender # This line is ignored.
@@ -688,6 +691,7 @@ for the patch you are writing.
691 Clear the body content if you don't wish to send a summary.
692 EOT2
693 From: $tpl_sender
694 +Reply-To: $tpl_reply_to
695 Subject: $tpl_subject
696 In-Reply-To: $tpl_in_reply_to
697
@@ -730,6 +734,9 @@ EOT3
734 if ($parsed_email{'In-Reply-To'}) {
735 $initial_in_reply_to = delete($parsed_email{'In-Reply-To'});
736 }
737 + if ($parsed_email{'Reply-To'}) {
738 + $reply_to = delete($parsed_email{'Reply-To'});
739 + }
740 if ($parsed_email{'Subject'}) {
741 $initial_subject = delete($parsed_email{'Subject'});
742 print $c2 "Subject: " .
@@ -923,6 +930,12 @@ if (defined $initial_in_reply_to) {
930 $initial_in_reply_to = "<$initial_in_reply_to>" if $initial_in_reply_to ne '';
931 }
932
933 +if (defined $reply_to) {
934 + $reply_to =~ s/^\s+|\s+$//g;
935 + ($reply_to) = expand_aliases($reply_to);
936 + $reply_to = sanitize_address($reply_to);
937 +}
938 +
939 if (!defined $smtp_server) {
940 my @sendmail_paths = qw( /usr/sbin/sendmail /usr/lib/sendmail );
941 push @sendmail_paths, map {"$_/sendmail"} split /:/, $ENV{PATH};
@@ -1354,6 +1367,9 @@ Message-Id: $message_id
1367 $header .= "In-Reply-To: $in_reply_to\n";
1368 $header .= "References: $references\n";
1369 }
1370 + if ($reply_to) {
1371 + $header .= "Reply-To: $reply_to\n";
1372 + }
1373 if (@xh) {
1374 $header .= join("\n", @xh) . "\n";
1375 }
t/t9001-send-email.sh
+2
@@ -199,6 +199,7 @@ Message-Id: MESSAGE-ID-STRING
199 X-Mailer: X-MAILER-STRING
200 In-Reply-To: <unique-message-id@example.com>
201 References: <unique-message-id@example.com>
202 +Reply-To: Reply <reply@example.com>
203
204 Result: OK
205 EOF
@@ -291,6 +292,7 @@ test_expect_success $PREREQ 'Show all headers' '
292 --dry-run \
293 --suppress-cc=sob \
294 --from="Example <from@example.com>" \
295 + --reply-to="Reply <reply@example.com>" \
296 --to=to@example.com \
297 --cc=cc@example.com \
298 --bcc=bcc@example.com \