send-email: support separate Reply-To address
authorChristian Ludwig <chrissicool@gmail.com>
Sat, 3 Mar 2018 23:58:14 +0000 (00:58 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Mar 2018 08:18:00 +0000 (00:18 -0800)
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>
Documentation/git-send-email.txt
contrib/completion/git-completion.bash
git-send-email.perl
t/t9001-send-email.sh
index 8060ea35c5f932c1e4328f000a501ff399418f27..71ef97ba9b22aad996049bd0c1500a835a433350 100644 (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
        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>::
        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
index 3683c772c5586ccc1f6dfc8c047919d8d96aa891..2a0dc4eef94cc1d8e3366f33856c4318425ebdfa 100644 (file)
@@ -2081,7 +2081,7 @@ _git_send_email ()
                        --compose --confirm= --dry-run --envelope-sender
                        --from --identity
                        --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
                        --smtp-server-port --smtp-encryption= --smtp-user
                        --subject --suppress-cc= --suppress-from --thread --to
index 36a0774c2d96d61c572cb15349e3633ec6b4a610..0aaf1dcbc6e96c2f370d7ec4a68b26a50957f9c1 100755 (executable)
@@ -56,6 +56,7 @@ sub usage {
     --[no-]cc               <str>  * Email Cc:
     --[no-]bcc              <str>  * Email Bcc:
     --subject               <str>  * Email "Subject:"
+    --reply-to              <str>  * Email "Reply-To:"
     --in-reply-to           <str>  * Email "In-Reply-To:"
     --[no-]xmailer                 * Add "X-Mailer:" header (default).
     --[no-]annotate                * Review each patch that will be sent in an editor.
@@ -166,7 +167,7 @@ sub format_2822_time {
 
 # Variables we fill in automatically, or via prompting:
 my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
-       $initial_in_reply_to,$initial_subject,@files,
+       $initial_in_reply_to,$reply_to,$initial_subject,@files,
        $author,$sender,$smtp_authpass,$annotate,$use_xmailer,$compose,$time);
 
 my $envelope_sender;
@@ -315,6 +316,7 @@ sub signal_handler {
 $rc = GetOptions(
                    "sender|from=s" => \$sender,
                     "in-reply-to=s" => \$initial_in_reply_to,
+                   "reply-to=s" => \$reply_to,
                    "subject=s" => \$initial_subject,
                    "to=s" => \@initial_to,
                    "to-cmd=s" => \$to_cmd,
@@ -677,6 +679,7 @@ sub get_patch_subject {
        my $tpl_sender = $sender || $repoauthor || $repocommitter || '';
        my $tpl_subject = $initial_subject || '';
        my $tpl_in_reply_to = $initial_in_reply_to || '';
+       my $tpl_reply_to = $reply_to || '';
 
        print $c <<EOT1, Git::prefix_lines("GIT: ", __ <<EOT2), <<EOT3;
 From $tpl_sender # This line is ignored.
@@ -688,6 +691,7 @@ sub get_patch_subject {
 Clear the body content if you don't wish to send a summary.
 EOT2
 From: $tpl_sender
+Reply-To: $tpl_reply_to
 Subject: $tpl_subject
 In-Reply-To: $tpl_in_reply_to
 
@@ -730,6 +734,9 @@ sub get_patch_subject {
        if ($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'}) {
                $initial_subject = delete($parsed_email{'Subject'});
                print $c2 "Subject: " .
@@ -923,6 +930,12 @@ sub expand_one_alias {
        $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) {
        my @sendmail_paths = qw( /usr/sbin/sendmail /usr/lib/sendmail );
        push @sendmail_paths, map {"$_/sendmail"} split /:/, $ENV{PATH};
@@ -1354,6 +1367,9 @@ sub send_message {
                $header .= "In-Reply-To: $in_reply_to\n";
                $header .= "References: $references\n";
        }
+       if ($reply_to) {
+               $header .= "Reply-To: $reply_to\n";
+       }
        if (@xh) {
                $header .= join("\n", @xh) . "\n";
        }
index 4d261c2a9c2a8081b07ee8db39d0983f0a470341..c97356a1ba082b26931f0e0d7cb00519483f9db3 100755 (executable)
@@ -199,6 +199,7 @@ Message-Id: MESSAGE-ID-STRING
 X-Mailer: X-MAILER-STRING
 In-Reply-To: <unique-message-id@example.com>
 References: <unique-message-id@example.com>
+Reply-To: Reply <reply@example.com>
 
 Result: OK
 EOF
@@ -291,6 +292,7 @@ test_expect_success $PREREQ 'Show all headers' '
                --dry-run \
                --suppress-cc=sob \
                --from="Example <from@example.com>" \
+               --reply-to="Reply <reply@example.com>" \
                --to=to@example.com \
                --cc=cc@example.com \
                --bcc=bcc@example.com \