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
maint
Junio C Hamano 2018-03-15 15:00:45 -07:00
commit e74737b6a1
4 changed files with 43 additions and 20 deletions

View File

@ -84,6 +84,11 @@ See the CONFIGURATION section for `sendemail.multiEdit`.
the value of GIT_AUTHOR_IDENT, or GIT_COMMITTER_IDENT if that is not the value of GIT_AUTHOR_IDENT, or GIT_COMMITTER_IDENT if that is not
set, as returned by "git var -l". set, as returned by "git var -l".


--reply-to=<address>::
Specify the address where replies from recipients should go to.
Use this if replies to messages should go to another address than what
is specified with the --from parameter.

--in-reply-to=<identifier>:: --in-reply-to=<identifier>::
Make the first mail (or all the mails with `--no-thread`) appear as a Make the first mail (or all the mails with `--no-thread`) appear as a
reply to the given Message-Id, which avoids breaking threads to reply to the given Message-Id, which avoids breaking threads to

View File

@ -2019,7 +2019,7 @@ _git_send_email ()
--compose --confirm= --dry-run --envelope-sender --compose --confirm= --dry-run --envelope-sender
--from --identity --from --identity
--in-reply-to --no-chain-reply-to --no-signed-off-by-cc --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
--no-suppress-from --no-thread --quiet --no-suppress-from --no-thread --quiet --reply-to
--signed-off-by-cc --smtp-pass --smtp-server --signed-off-by-cc --smtp-pass --smtp-server
--smtp-server-port --smtp-encryption= --smtp-user --smtp-server-port --smtp-encryption= --smtp-user
--subject --suppress-cc= --suppress-from --thread --to --subject --suppress-cc= --suppress-from --thread --to

View File

@ -57,6 +57,7 @@ git send-email --dump-aliases
--[no-]cc <str> * Email Cc: --[no-]cc <str> * Email Cc:
--[no-]bcc <str> * Email Bcc: --[no-]bcc <str> * Email Bcc:
--subject <str> * Email "Subject:" --subject <str> * Email "Subject:"
--reply-to <str> * Email "Reply-To:"
--in-reply-to <str> * Email "In-Reply-To:" --in-reply-to <str> * Email "In-Reply-To:"
--[no-]xmailer * Add "X-Mailer:" header (default). --[no-]xmailer * Add "X-Mailer:" header (default).
--[no-]annotate * Review each patch that will be sent in an editor. --[no-]annotate * Review each patch that will be sent in an editor.
@ -167,13 +168,13 @@ my $re_encoded_word = qr/=\?($re_token)\?($re_token)\?($re_encoded_text)\?=/;


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


my $envelope_sender; my $envelope_sender;


# Example reply to: # Example reply to:
#$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>'; #$initial_in_reply_to = ''; #<20050203173208.GA23964@foobar.com>';


my $repo = eval { Git->repository() }; my $repo = eval { Git->repository() };
my @repo = $repo ? ($repo) : (); my @repo = $repo ? ($repo) : ();
@ -315,7 +316,8 @@ die __("--dump-aliases incompatible with other options\n")
if !$help and $dump_aliases and @ARGV; if !$help and $dump_aliases and @ARGV;
$rc = GetOptions( $rc = GetOptions(
"sender|from=s" => \$sender, "sender|from=s" => \$sender,
"in-reply-to=s" => \$initial_reply_to, "in-reply-to=s" => \$initial_in_reply_to,
"reply-to=s" => \$reply_to,
"subject=s" => \$initial_subject, "subject=s" => \$initial_subject,
"to=s" => \@initial_to, "to=s" => \@initial_to,
"to-cmd=s" => \$to_cmd, "to-cmd=s" => \$to_cmd,
@ -681,7 +683,8 @@ if ($compose) {


my $tpl_sender = $sender || $repoauthor || $repocommitter || ''; my $tpl_sender = $sender || $repoauthor || $repocommitter || '';
my $tpl_subject = $initial_subject || ''; my $tpl_subject = $initial_subject || '';
my $tpl_reply_to = $initial_reply_to || ''; my $tpl_in_reply_to = $initial_in_reply_to || '';
my $tpl_reply_to = $reply_to || '';


print $c <<EOT1, Git::prefix_lines("GIT: ", __ <<EOT2), <<EOT3; print $c <<EOT1, Git::prefix_lines("GIT: ", __ <<EOT2), <<EOT3;
From $tpl_sender # This line is ignored. From $tpl_sender # This line is ignored.
@ -693,8 +696,9 @@ for the patch you are writing.
Clear the body content if you don't wish to send a summary. Clear the body content if you don't wish to send a summary.
EOT2 EOT2
From: $tpl_sender From: $tpl_sender
Reply-To: $tpl_reply_to
Subject: $tpl_subject Subject: $tpl_subject
In-Reply-To: $tpl_reply_to In-Reply-To: $tpl_in_reply_to


EOT3 EOT3
for my $f (@files) { for my $f (@files) {
@ -733,7 +737,10 @@ EOT3
$sender = delete($parsed_email{'From'}); $sender = delete($parsed_email{'From'});
} }
if ($parsed_email{'In-Reply-To'}) { if ($parsed_email{'In-Reply-To'}) {
$initial_reply_to = delete($parsed_email{'In-Reply-To'}); $initial_in_reply_to = delete($parsed_email{'In-Reply-To'});
}
if ($parsed_email{'Reply-To'}) {
$reply_to = delete($parsed_email{'Reply-To'});
} }
if ($parsed_email{'Subject'}) { if ($parsed_email{'Subject'}) {
$initial_subject = delete($parsed_email{'Subject'}); $initial_subject = delete($parsed_email{'Subject'});
@ -916,16 +923,22 @@ sub expand_one_alias {
@initial_cc = process_address_list(@initial_cc); @initial_cc = process_address_list(@initial_cc);
@bcclist = process_address_list(@bcclist); @bcclist = process_address_list(@bcclist);


if ($thread && !defined $initial_reply_to && $prompting) { if ($thread && !defined $initial_in_reply_to && $prompting) {
$initial_reply_to = ask( $initial_in_reply_to = ask(
__("Message-ID to be used as In-Reply-To for the first email (if any)? "), __("Message-ID to be used as In-Reply-To for the first email (if any)? "),
default => "", default => "",
valid_re => qr/\@.*\./, confirm_only => 1); valid_re => qr/\@.*\./, confirm_only => 1);
} }
if (defined $initial_reply_to) { if (defined $initial_in_reply_to) {
$initial_reply_to =~ s/^\s*<?//; $initial_in_reply_to =~ s/^\s*<?//;
$initial_reply_to =~ s/>?\s*$//; $initial_in_reply_to =~ s/>?\s*$//;
$initial_reply_to = "<$initial_reply_to>" if $initial_reply_to ne ''; $initial_in_reply_to = "<$initial_in_reply_to>" if $initial_in_reply_to ne '';
}

if (defined $reply_to) {
$reply_to =~ s/^\s+|\s+$//g;
($reply_to) = expand_aliases($reply_to);
$reply_to = sanitize_address($reply_to);
} }


if (!defined $smtp_server) { if (!defined $smtp_server) {
@ -945,7 +958,7 @@ if ($compose && $compose > 0) {
} }


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


sub extract_valid_address { sub extract_valid_address {
@ -1354,11 +1367,14 @@ Message-Id: $message_id
if ($use_xmailer) { if ($use_xmailer) {
$header .= "X-Mailer: git-send-email $gitversion\n"; $header .= "X-Mailer: git-send-email $gitversion\n";
} }
if ($reply_to) { if ($in_reply_to) {


$header .= "In-Reply-To: $reply_to\n"; $header .= "In-Reply-To: $in_reply_to\n";
$header .= "References: $references\n"; $header .= "References: $references\n";
} }
if ($reply_to) {
$header .= "Reply-To: $reply_to\n";
}
if (@xh) { if (@xh) {
$header .= join("\n", @xh) . "\n"; $header .= join("\n", @xh) . "\n";
} }
@ -1533,8 +1549,8 @@ EOF
return 1; return 1;
} }


$reply_to = $initial_reply_to; $in_reply_to = $initial_in_reply_to;
$references = $initial_reply_to || ''; $references = $initial_in_reply_to || '';
$subject = $initial_subject; $subject = $initial_subject;
$message_num = 0; $message_num = 0;


@ -1744,9 +1760,9 @@ foreach my $t (@files) {


# set up for the next message # set up for the next message
if ($thread && $message_was_sent && if ($thread && $message_was_sent &&
($chain_reply_to || !defined $reply_to || length($reply_to) == 0 || ($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
$message_num == 1)) { $message_num == 1)) {
$reply_to = $message_id; $in_reply_to = $message_id;
if (length $references > 0) { if (length $references > 0) {
$references .= "\n $message_id"; $references .= "\n $message_id";
} else { } else {

View File

@ -224,6 +224,7 @@ Message-Id: MESSAGE-ID-STRING
X-Mailer: X-MAILER-STRING X-Mailer: X-MAILER-STRING
In-Reply-To: <unique-message-id@example.com> In-Reply-To: <unique-message-id@example.com>
References: <unique-message-id@example.com> References: <unique-message-id@example.com>
Reply-To: Reply <reply@example.com>


Result: OK Result: OK
EOF EOF
@ -316,6 +317,7 @@ test_expect_success $PREREQ 'Show all headers' '
--dry-run \ --dry-run \
--suppress-cc=sob \ --suppress-cc=sob \
--from="Example <from@example.com>" \ --from="Example <from@example.com>" \
--reply-to="Reply <reply@example.com>" \
--to=to@example.com \ --to=to@example.com \
--cc=cc@example.com \ --cc=cc@example.com \
--bcc=bcc@example.com \ --bcc=bcc@example.com \