From: Tom Russello <tom.russello@grenoble-inp.org>
To: git@vger.kernel.org
Cc: erwan.mathoniere@grenoble-inp.org, samuel.groot@grenoble-inp.org,
jordan.de-gea@grenoble-inp.org, matthieu.moy@grenoble-inp.fr,
e@80x24.org, aaron@schrab.com, gitster@pobox.com,
Tom Russello <tom.russello@grenoble-inp.org>
Subject: [PATCH v3 5/6] send-email: --in-reply-to=<file> populates the fields
Date: Tue, 7 Jun 2016 16:05:18 +0200 [thread overview]
Message-ID: <20160607140519.23418-1-tom.russello@grenoble-inp.org> (raw)
In-Reply-To: <20160607140148.23242-5-tom.russello@grenoble-inp.org>
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@grenoble-inp.org>
Signed-off-by: Samuel GROOT <samuel.groot@grenoble-inp.org>
Signed-off-by: Matthieu MOY <matthieu.moy@grenoble-inp.fr>
---
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@example.com
+ To: to1@example.com
+ Cc: cc1@example.com, cc2@example.com,
+ cc3@example.com
+ Date: Sat, 12 Jun 2010 15:53:58 +0200
+ Message-Id: <author_123456@example.com>
+ References: <firstauthor_654321@example.com>
+ <secondauthor_01546567@example.com>
+ <thirdauthor_1395838@example.com>
+
+ 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@example.com>" \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ -2 \
+ 2>errors &&
+ grep "From: Example <nobody@example.com>" msgtxt1 &&
+ grep "In-Reply-To: <author_123456@example.com>" 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@example.com &&
+ echo "$cc_adr" | grep to1@example.com &&
+ echo "$cc_adr" | grep cc1@example.com &&
+ echo "$cc_adr" | grep cc2@example.com &&
+ echo "$cc_adr" | grep cc3@example.com &&
+ echo "$ref_adr" | grep "<firstauthor_654321@example.com>" &&
+ echo "$ref_adr" | grep "<secondauthor_01546567@example.com>" &&
+ echo "$ref_adr" | grep "<thirdauthor_1395838@example.com>" &&
+ echo "$ref_adr" | grep "<author_123456@example.com>" &&
+ echo "$ref_adr" | grep -v "References: <author_123456@example.com>"
+'
+
+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@example.com>" \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ -1 \
+ 2>errors &&
+ grep "From: Example <nobody@example.com>" msgtxt1 &&
+ grep "In-Reply-To: <author_123456@example.com>" 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@example.com &&
+ echo "$cc_adr" | grep to1@example.com &&
+ echo "$cc_adr" | grep cc1@example.com &&
+ echo "$cc_adr" | grep cc2@example.com &&
+ echo "$cc_adr" | grep cc3@example.com &&
+ echo "$ref_adr" | grep "<firstauthor_654321@example.com>" &&
+ echo "$ref_adr" | grep "<secondauthor_01546567@example.com>" &&
+ echo "$ref_adr" | grep "<thirdauthor_1395838@example.com>" &&
+ echo "$ref_adr" | grep "<author_123456@example.com>" &&
+ echo "$ref_adr" | grep -v "References: <author_123456@example.com>"
+'
+
+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@example.com>" \
+ --smtp-server="$(pwd)/fake.sendmail" \
+ -1 \
+ 2>errors &&
+ grep "Subject: Re: subject goes here" msgtxt3
+'
+
test_done
--
2.8.3
next prev parent reply other threads:[~2016-06-07 14:05 UTC|newest]
Thread overview: 96+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-23 19:30 [RFC-PATCH 0/2] send-email: new --quote-mail option Tom Russello
2016-05-23 19:30 ` [RFC-PATCH 1/2] send-email: new option to quote an email and reply to Tom Russello
2016-05-23 19:55 ` Eric Wong
2016-05-23 20:07 ` Matthieu Moy
2016-05-23 22:10 ` Samuel GROOT
2016-05-24 12:43 ` Samuel GROOT
2016-05-24 12:49 ` Matthieu Moy
2016-05-24 22:30 ` Aaron Schrab
2016-05-25 0:04 ` Tom Russello
2016-05-24 21:23 ` Eric Wong
2016-05-23 20:00 ` Matthieu Moy
2016-05-24 23:31 ` Samuel GROOT
2016-05-25 6:29 ` Matthieu Moy
2016-05-25 15:40 ` Junio C Hamano
2016-05-25 16:56 ` Matthieu Moy
2016-05-25 18:15 ` Junio C Hamano
2016-05-25 18:31 ` Matthieu Moy
2016-05-26 0:08 ` Samuel GROOT
2016-05-27 9:06 ` Matthieu Moy
2016-05-23 19:30 ` [RFC-PATCH 2/2] t9001: adding --quote-mail option test Tom Russello
2016-05-23 20:05 ` Matthieu Moy
2016-05-23 19:38 ` [RFC-PATCH 0/2] send-email: new --quote-mail option Matthieu Moy
2016-05-23 19:56 ` Samuel GROOT
2016-05-27 17:11 ` [RFC-PATCH v2 0/2] send-email: new --quote-email option Tom Russello
2016-05-27 17:11 ` [RFC-PATCH v2 1/2] send-email: quote-email populates the fields Tom Russello
2016-05-28 14:35 ` Matthieu Moy
2016-05-29 23:38 ` Tom Russello
2016-05-27 17:11 ` [RFC-PATCH v2 2/2] send-email: quote-email quotes the message body Tom Russello
2016-05-28 15:01 ` Matthieu Moy
2016-05-29 11:41 ` Tom Russello
2016-06-07 14:01 ` [PATCH v3 0/6] send-email: cleaner tests and quote email Tom Russello
2016-06-07 14:01 ` [PATCH v3 1/6] t9001: non order-sensitive file comparison Tom Russello
2016-06-08 1:07 ` Junio C Hamano
2016-06-08 8:23 ` Samuel GROOT
2016-06-08 16:09 ` Junio C Hamano
2016-06-08 16:46 ` Samuel GROOT
2016-06-09 6:01 ` Matthieu Moy
2016-06-13 22:21 ` Samuel GROOT
2016-06-09 5:51 ` Matthieu Moy
2016-06-09 8:15 ` Tom Russello
2016-06-07 14:01 ` [PATCH v3 2/6] t9001: check email address is in Cc: field Tom Russello
2016-06-09 5:55 ` Matthieu Moy
2016-06-13 22:23 ` Samuel GROOT
2016-06-07 14:01 ` [PATCH v3 3/6] t9001: shorten send-email's output Tom Russello
2016-06-08 8:36 ` Eric Wong
2016-06-08 9:30 ` Samuel GROOT
2016-06-09 6:03 ` Matthieu Moy
2016-06-07 14:01 ` [PATCH v3 4/6] send-email: create email parser subroutine Tom Russello
2016-06-07 14:05 ` Tom Russello [this message]
2016-06-07 14:05 ` [PATCH v3 6/6] send-email: add option --cite to quote the message body Tom Russello
2016-06-08 13:01 ` (unknown), Samuel GROOT
2016-06-08 13:01 ` [PATCH v4 1/6] t9001: non order-sensitive file comparison Samuel GROOT
2016-06-08 14:22 ` Remi Galan Alfonso
2016-06-08 14:29 ` Samuel GROOT
2016-06-08 16:56 ` Junio C Hamano
2016-06-08 19:21 ` Samuel GROOT
2016-06-08 17:17 ` Junio C Hamano
2016-06-08 19:19 ` Samuel GROOT
2016-06-08 13:01 ` [PATCH v4 2/6] t9001: check email address is in Cc: field Samuel GROOT
2016-06-08 17:34 ` Junio C Hamano
2016-06-08 19:23 ` Samuel GROOT
2016-06-08 13:01 ` [PATCH v4 3/6] send-email: shorten send-email's output Samuel GROOT
2016-06-08 17:37 ` Junio C Hamano
2016-06-08 19:18 ` Samuel GROOT
2016-06-08 19:33 ` Junio C Hamano
2016-06-08 19:40 ` Samuel GROOT
2016-06-09 6:17 ` Matthieu Moy
2016-06-13 22:19 ` Samuel GROOT
2016-06-08 13:01 ` [PATCH v4 4/6] send-email: create email parser subroutine Samuel GROOT
2016-06-08 17:58 ` Junio C Hamano
2016-06-08 18:12 ` Eric Sunshine
2016-06-08 18:32 ` Junio C Hamano
2016-06-08 19:26 ` Samuel GROOT
2016-06-08 19:31 ` Junio C Hamano
2016-06-08 19:42 ` Samuel GROOT
2016-06-08 19:30 ` Samuel GROOT
2016-06-08 20:13 ` Eric Sunshine
2016-06-08 20:17 ` Junio C Hamano
2016-06-08 23:54 ` Samuel GROOT
2016-06-09 0:21 ` Eric Wong
2016-06-13 22:18 ` Samuel GROOT
2016-06-13 22:47 ` Eric Wong
2016-06-14 22:18 ` Samuel GROOT
2016-06-09 6:51 ` Eric Sunshine
2016-06-13 22:15 ` Samuel GROOT
2016-06-08 19:36 ` Samuel GROOT
2016-06-08 20:38 ` Eric Wong
2016-06-08 13:07 ` [PATCH v4 5/6] send-email: --in-reply-to=<file> populate header fields Samuel GROOT
2016-06-08 18:23 ` Junio C Hamano
2016-06-14 22:26 ` Samuel GROOT
2016-06-09 9:45 ` Matthieu Moy
2016-06-14 22:35 ` Samuel GROOT
2016-06-08 13:08 ` [PATCH v4 6/6] send-email: add option --cite to quote the message body Samuel GROOT
2016-06-09 11:49 ` Matthieu Moy
2016-06-14 22:53 ` Samuel GROOT
2016-06-15 22:21 ` Tom Russello
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160607140519.23418-1-tom.russello@grenoble-inp.org \
--to=tom.russello@grenoble-inp.org \
--cc=aaron@schrab.com \
--cc=e@80x24.org \
--cc=erwan.mathoniere@grenoble-inp.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jordan.de-gea@grenoble-inp.org \
--cc=matthieu.moy@grenoble-inp.fr \
--cc=samuel.groot@grenoble-inp.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).