Take an email message file, parse it and fill the "From", "To", "Cc", "In-reply-to", "References" fields appropriately. If `--compose` option is set, it will also fill the subject field with `Re: [<email_file>'s subject]` in the introductory message. Signed-off-by: Tom RUSSELLO <tom.russello@xxxxxxxxxxxxxxxx> Signed-off-by: Samuel GROOT <samuel.groot@xxxxxxxxxxxxxxxx> Signed-off-by: Matthieu MOY <matthieu.moy@xxxxxxxxxxxxxxx> --- Check if the string given by argument with `--in-reply-to` leads to an existing plain text file. If not, consider it as a message-id. Changes sinces v2: - Fill the References: field to keep the thread even if some emails have been removed - Explicit error with a proper "if" when an error occured during email file opening - More precise comments - More tests Documentation/git-send-email.txt | 9 +++-- git-send-email.perl | 49 +++++++++++++++++++++++- t/t9001-send-email.sh | 83 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+), 5 deletions(-) diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index edbba3a..21776f0 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -84,13 +84,16 @@ 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". ---in-reply-to=<identifier>:: +--in-reply-to=<Message-Id|email_file>:: 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 - provide a new patch series. + reply to the given Message-Id (given directly by argument or via the email + file), which avoids breaking threads to provide a new patch series. The second and subsequent emails will be sent as replies according to the `--[no]-chain-reply-to` setting. + +Furthermore, if the argument is an email file, parse it and populate header +fields appropriately for the reply. ++ So for example when `--thread` and `--no-chain-reply-to` are specified, the second and subsequent patches will be replies to the first one like in the illustration below where `[PATCH v2 0/3]` is in reply to `[PATCH 0/2]`: diff --git a/git-send-email.perl b/git-send-email.perl index db114ae..66aa2cd 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -55,6 +55,7 @@ git send-email --dump-aliases --[no-]bcc <str> * Email Bcc: --subject <str> * Email "Subject:" --in-reply-to <str> * Email "In-Reply-To:" + --in-reply-to <file> * Populate header fields appropriately. --[no-]xmailer * Add "X-Mailer:" header (default). --[no-]annotate * Review each patch that will be sent in an editor. --compose * Open an editor for introduction. @@ -160,7 +161,7 @@ my $re_encoded_word = qr/=\?($re_token)\?($re_token)\?($re_encoded_text)\?=/; # Variables we fill in automatically, or via prompting: my (@to,$no_to,@initial_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh, - $initial_reply_to,$initial_subject,@files, + $initial_reply_to,$initial_references,$initial_subject,@files, $author,$sender,$smtp_authpass,$annotate,$use_xmailer,$compose,$time); my $envelope_sender; @@ -639,6 +640,50 @@ if (@files) { usage(); } +if ($initial_reply_to && -f $initial_reply_to) { + my $error = validate_patch($initial_reply_to); + die "fatal: $initial_reply_to: $error\nwarning: no patches were sent\n" + if $error; + + open my $fh, "<", $initial_reply_to or die "can't open file $initial_reply_to"; + my $mail = parse_email($fh); + close $fh; + + my $initial_sender = $sender || $repoauthor || $repocommitter || ''; + + my $prefix_re = ""; + my $subject_re = $mail->{"subject"}[0]; + if ($subject_re =~ /^[^Re:]/) { + $prefix_re = "Re: "; + } + $initial_subject = $prefix_re . $subject_re; + + push @initial_to, $mail->{"from"}[0]; + + foreach my $to_addr (parse_address_line(join ",", @{$mail->{"to"}})) { + if (!($to_addr eq $initial_sender)) { + push @initial_cc, $to_addr; + } + } + + foreach my $cc_addr (parse_address_line(join ",", @{$mail->{"cc"}})) { + my $qaddr = unquote_rfc2047($cc_addr); + my $saddr = sanitize_address($qaddr); + if ($saddr eq $initial_sender) { + next if ($suppress_cc{'self'}); + } else { + next if ($suppress_cc{'cc'}); + } + push @initial_cc, $cc_addr; + } + + $initial_reply_to = $mail->{"message-id"}[0]; + if ($mail->{"references"}) { + $initial_references = join("", @{$mail->{"references"}}) . + " " . $initial_reply_to; + } +} + sub get_patch_subject { my $fn = shift; open (my $fh, '<', $fn); @@ -1426,7 +1471,7 @@ Message-Id: $message_id } $reply_to = $initial_reply_to; -$references = $initial_reply_to || ''; +$references = $initial_references || $initial_reply_to || ''; $subject = $initial_subject; $message_num = 0; diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 9b1e56f..2d67f6d 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1892,4 +1892,87 @@ test_expect_success $PREREQ 'leading and trailing whitespaces are removed' ' test_cmp_noorder expected-list actual-list ' +test_expect_success $PREREQ 'setup expect' ' + cat >email <<-\EOF + Subject: subject goes here + From: author@xxxxxxxxxxx + To: to1@xxxxxxxxxxx + Cc: cc1@xxxxxxxxxxx, cc2@xxxxxxxxxxx, + cc3@xxxxxxxxxxx + Date: Sat, 12 Jun 2010 15:53:58 +0200 + Message-Id: <author_123456@xxxxxxxxxxx> + References: <firstauthor_654321@xxxxxxxxxxx> + <secondauthor_01546567@xxxxxxxxxxx> + <thirdauthor_1395838@xxxxxxxxxxx> + + Have you seen my previous email? + > Previous content + EOF +' + +test_expect_success $PREREQ 'Fields with --in-reply-to are correct' ' + clean_fake_sendmail && + git send-email \ + --in-reply-to=email \ + --from="Example <nobody@xxxxxxxxxxx>" \ + --smtp-server="$(pwd)/fake.sendmail" \ + -2 \ + 2>errors && + grep "From: Example <nobody@xxxxxxxxxxx>" msgtxt1 && + grep "In-Reply-To: <author_123456@xxxxxxxxxxx>" msgtxt1 && + to_adr=$(awk "/^To: /{flag=1}/^Cc: /{flag=0} flag {print}" msgtxt1) && + cc_adr=$(awk "/^Cc: /{flag=1}/^Subject: /{flag=0} flag {print}" msgtxt1) && + ref_adr=$(awk "/^References: /{flag=1}/^MIME-Version: /{flag=0} flag {print}" \ + msgtxt1) && + echo "$to_adr" | grep author@xxxxxxxxxxx && + echo "$cc_adr" | grep to1@xxxxxxxxxxx && + echo "$cc_adr" | grep cc1@xxxxxxxxxxx && + echo "$cc_adr" | grep cc2@xxxxxxxxxxx && + echo "$cc_adr" | grep cc3@xxxxxxxxxxx && + echo "$ref_adr" | grep "<firstauthor_654321@xxxxxxxxxxx>" && + echo "$ref_adr" | grep "<secondauthor_01546567@xxxxxxxxxxx>" && + echo "$ref_adr" | grep "<thirdauthor_1395838@xxxxxxxxxxx>" && + echo "$ref_adr" | grep "<author_123456@xxxxxxxxxxx>" && + echo "$ref_adr" | grep -v "References: <author_123456@xxxxxxxxxxx>" +' + +test_expect_success $PREREQ 'Fields with --in-reply-to and --compose are correct' ' + clean_fake_sendmail && + git send-email \ + --in-reply-to=email \ + --compose \ + --from="Example <nobody@xxxxxxxxxxx>" \ + --smtp-server="$(pwd)/fake.sendmail" \ + -1 \ + 2>errors && + grep "From: Example <nobody@xxxxxxxxxxx>" msgtxt1 && + grep "In-Reply-To: <author_123456@xxxxxxxxxxx>" msgtxt1 && + grep "Subject: Re: subject goes here" msgtxt1 && + to_adr=$(awk "/^To: /{flag=1}/^Cc: /{flag=0} flag {print}" msgtxt1) && + cc_adr=$(awk "/^Cc: /{flag=1}/^Subject: /{flag=0} flag {print}" msgtxt1) && + ref_adr=$(awk "/^References: /{flag=1}/^MIME-Version: /{flag=0} flag {print}" \ + msgtxt1) && + echo "$to_adr" | grep author@xxxxxxxxxxx && + echo "$cc_adr" | grep to1@xxxxxxxxxxx && + echo "$cc_adr" | grep cc1@xxxxxxxxxxx && + echo "$cc_adr" | grep cc2@xxxxxxxxxxx && + echo "$cc_adr" | grep cc3@xxxxxxxxxxx && + echo "$ref_adr" | grep "<firstauthor_654321@xxxxxxxxxxx>" && + echo "$ref_adr" | grep "<secondauthor_01546567@xxxxxxxxxxx>" && + echo "$ref_adr" | grep "<thirdauthor_1395838@xxxxxxxxxxx>" && + echo "$ref_adr" | grep "<author_123456@xxxxxxxxxxx>" && + echo "$ref_adr" | grep -v "References: <author_123456@xxxxxxxxxxx>" +' + +test_expect_success $PREREQ 'Re: written only once with --in-reply-to and --compose ' ' + git send-email \ + --in-reply-to=msgtxt1 \ + --compose \ + --from="Example <nobody@xxxxxxxxxxx>" \ + --smtp-server="$(pwd)/fake.sendmail" \ + -1 \ + 2>errors && + grep "Subject: Re: subject goes here" msgtxt3 +' + test_done -- 2.8.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html