From: Payre Nathan <second.payre@gmail.com>
To: git@vger.kernel.org
Cc: matthieu.moy@univ-lyon1.fr, timothee.albertin@etu.univ-lyon1.fr,
daniel.bensoussan--bohm@etu.univ-lyon1.fr,
Tom Russello <tom.russello@grenoble-inp.org>
Subject: [PATCH 2/2] send-email: quote-email quotes the message body
Date: Mon, 30 Oct 2017 23:34:44 +0100 [thread overview]
Message-ID: <20171030223444.5052-3-nathan.payre@etu.univ-lyon1.fr> (raw)
In-Reply-To: <20171030223444.5052-1-nathan.payre@etu.univ-lyon1.fr>
From: Tom Russello <tom.russello@grenoble-inp.org>
---
Documentation/git-send-email.txt | 4 +-
git-send-email.perl | 80 ++++++++++++++++++++++++++++++++++++++--
t/t9001-send-email.sh | 19 +++++++++-
3 files changed, 97 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 710b5ff32..329af66af 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -107,7 +107,9 @@ Only necessary if --compose is also set. If --compose
is not set, this will be prompted for.
--quote-email=<email_file>::
- Fill appropriately header fields for the reply to the given email.
+ Fill appropriately header fields for the reply to the given email and quote
+ the message body in the cover letter if `--compose` is set or otherwise
+ after the triple-dash in the first patch given.
--subject=<string>::
Specify the initial subject of the email thread.
diff --git a/git-send-email.perl b/git-send-email.perl
index 665c47d15..6f6995c9d 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -26,6 +26,7 @@ use Text::ParseWords;
use Term::ANSIColor;
use File::Temp qw/ tempdir tempfile /;
use File::Spec::Functions qw(catdir catfile);
+use File::Copy;
use Error qw(:try);
use Cwd qw(abs_path cwd);
use Git;
@@ -57,7 +58,8 @@ git send-email --dump-aliases
--[no-]bcc <str> * Email Bcc:
--subject <str> * Email "Subject:"
--in-reply-to <str> * Email "In-Reply-To:"
- --quote-email <file> * Populate header fields appropriately.
+ --quote-email <file> * Populate header fields appropriately and
+ quote the message body.
--[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.
@@ -654,12 +656,15 @@ if (@files) {
usage();
}
+my $message_quoted;
if ($quote_email) {
my $error = validate_patch($quote_email);
die "fatal: $quote_email: $error\nwarning: no patches were sent\n"
if $error;
my @header = ();
+ my $date;
+ my $recipient;
open my $fh, "<", $quote_email or die "can't open file $quote_email";
@@ -691,7 +696,8 @@ if ($quote_email) {
}
$initial_subject = $prefix_re . $subject_re;
} elsif (/^From:\s+(.*)$/i) {
- push @initial_to, $1;
+ $recipient = $1;
+ push @initial_to, $recipient;
} elsif (/^To:\s+(.*)$/i) {
foreach my $addr (parse_address_line($1)) {
if (!($addr eq $initial_sender)) {
@@ -713,9 +719,28 @@ if ($quote_email) {
$initial_reply_to = $1;
} elsif (/^References:\s+(.*)/i) {
$initial_references = $1;
+ } elsif (/^Date: (.*)/i) {
+ $date = $1;
}
}
$initial_references = $initial_references . $initial_reply_to;
+
+ my $tpl_date = $date && "On $date, " || '';
+ $message_quoted = $tpl_date . $recipient . " wrote:\n";
+
+ # Quote the message body
+ while (<$fh>) {
+ # Turn crlf line endings into lf-only
+ s/\r//g;
+ my $space = "";
+ if (/^[^>]/) {
+ $space = " ";
+ }
+ $message_quoted .= ">" . $space . $_;
+ }
+ if (!$compose) {
+ $annotate = 1;
+ }
}
sub get_patch_subject {
@@ -743,6 +768,9 @@ if ($compose) {
my $tpl_sender = $sender || $repoauthor || $repocommitter || '';
my $tpl_subject = $initial_subject || '';
my $tpl_reply_to = $initial_reply_to || '';
+ my $tpl_quote = $message_quoted &&
+ "\nGIT: Please, trim down irrelevant sections in the quoted message\n".
+ "GIT: to keep your email concise.\n" . $message_quoted || '';
print $c <<EOT1, Git::prefix_lines("GIT: ", __ <<EOT2), <<EOT3;
From $tpl_sender # This line is ignored.
@@ -756,7 +784,7 @@ EOT2
From: $tpl_sender
Subject: $tpl_subject
In-Reply-To: $tpl_reply_to
-
+$tpl_quote
EOT3
for my $f (@files) {
print $c get_patch_subject($f);
@@ -821,9 +849,53 @@ EOT3
$compose = -1;
}
} elsif ($annotate) {
- do_edit(@files);
+ if ($quote_email) {
+ my $quote_email_filename = ($repo ?
+ tempfile(".gitsendemail.msg.XXXXXX",
+ DIR => $repo->repo_path()) :
+ tempfile(".gitsendemail.msg.XXXXXX",
+ DIR => "."))[1];
+
+ # Insertion in a temporary file to keep the original file clean
+ # in case of cancellation/error.
+ do_insert_quoted_message($quote_email_filename, $files[0]);
+
+ my $tmp = $files[0];
+ $files[0] = $quote_email_filename;
+
+ do_edit(@files);
+
+ # Erase the original patch if the edition went well
+ move($quote_email_filename, $tmp);
+ $files[0] = $tmp;
+ } else {
+ do_edit(@files);
+ }
}
+sub do_insert_quoted_message {
+ my $tmp_file = shift;
+ my $original_file = shift;
+
+ open my $c, "<", $original_file
+ or die "Failed to open $original_file: " . $!;
+
+ open my $c2, ">", $tmp_file
+ or die "Failed to open $tmp_file: " . $!;
+
+ # Insertion after the triple-dash
+ while (<$c>) {
+ print $c2 $_;
+ last if (/^---$/);
+ }
+ print $c2 $message_quoted;
+ while (<$c>) {
+ print $c2 $_;
+ }
+
+ close $c;
+ close $c2;
+}
sub ask {
my ($prompt, %arg) = @_;
my $valid_re = $arg{valid_re};
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index ce12a1164..7c29c829d 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -1941,7 +1941,7 @@ test_expect_success $PREREQ 'Fields with --quote-email are correct' '
--quote-email=email \
--from="Example <nobody@example.com>" \
--smtp-server="$(pwd)/fake.sendmail" \
- -1 \
+ -2 \
2>errors &&
grep "From: Example <nobody@example.com>" msgtxt1 &&
grep "In-Reply-To: <author_123456@example.com>" msgtxt1 &&
@@ -1961,6 +1961,17 @@ test_expect_success $PREREQ 'Fields with --quote-email are correct' '
echo "$ref_adr" | grep -v "References: <author_123456@example.com>"
'
+test_expect_success $PREREQ 'correct quoted message with --quote-email' '
+ msg_quoted=$(grep -A 3 "^---$" msgtxt1) &&
+ echo "$msg_quoted" | grep "On Sat, 12 Jun 2010 15:53:58 +0200, author@example.com wrote:" &&
+ echo "$msg_quoted" | grep "> Have you seen my previous email?" &&
+ echo "$msg_quoted" | grep ">> Previous content"
+'
+
+test_expect_success $PREREQ 'second patch body is not modified by --quote-email' '
+ ! grep "Have you seen my previous email?" msgtxt2
+'
+
test_expect_success $PREREQ 'Fields with --quote-email and --compose are correct' '
clean_fake_sendmail &&
git send-email \
@@ -2000,4 +2011,10 @@ test_expect_success $PREREQ 'Re: written only once with --quote-email and --comp
grep "Subject: Re: subject goes here" msgtxt3
'
+test_expect_success $PREREQ 'correct quoted message with --quote-email and --compose' '
+ grep "> On Sat, 12 Jun 2010 15:53:58 +0200, author@example.com wrote:" msgtxt3 &&
+ grep ">> Have you seen my previous email?" msgtxt3 &&
+ grep ">>> Previous content" msgtxt3
+'
+
test_done
--
2.14.2
next prev parent reply other threads:[~2017-10-30 22:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-30 22:34 [PATCH 0/2] New send-email option --quote-email Payre Nathan
2017-10-30 22:34 ` [PATCH 1/2] quote-email populates the fields Payre Nathan
2017-11-01 2:44 ` Junio C Hamano
2017-11-09 8:49 ` Nathan PAYRE
[not found] ` <607ed87207454d1098484b0ffbc6916f@BPMBX2013-01.univ-lyon1.fr>
2017-11-01 11:04 ` Matthieu Moy
2017-11-01 18:12 ` Stefan Beller
2017-10-30 22:34 ` Payre Nathan [this message]
2017-11-01 6:40 ` [PATCH 2/2] send-email: quote-email quotes the message body Junio C Hamano
[not found] ` <0db6387ef95b4fafbd70068be9e4f7c5@BPMBX2013-01.univ-lyon1.fr>
2017-11-01 11:12 ` Matthieu Moy
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=20171030223444.5052-3-nathan.payre@etu.univ-lyon1.fr \
--to=second.payre@gmail.com \
--cc=daniel.bensoussan--bohm@etu.univ-lyon1.fr \
--cc=git@vger.kernel.org \
--cc=matthieu.moy@univ-lyon1.fr \
--cc=timothee.albertin@etu.univ-lyon1.fr \
--cc=tom.russello@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).