git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Tom Russello <tom.russello@grenoble-inp.org>
To: git@vger.kernel.org
Cc: jordan.de-gea@grenoble-inp.org,
	erwan.mathoniere@grenoble-inp.org, matthieu.moy@grenoble-inp.fr,
	samuel.groot@grenoble-inp.org, e@80x24.org, aaron@schrab.com,
	gitster@pobox.com, Tom Russello <tom.russello@grenoble-inp.org>
Subject: [RFC-PATCH v2 2/2] send-email: quote-email quotes the message body
Date: Fri, 27 May 2016 19:11:42 +0200	[thread overview]
Message-ID: <1464369102-7551-3-git-send-email-tom.russello@grenoble-inp.org> (raw)
In-Reply-To: <1464369102-7551-1-git-send-email-tom.russello@grenoble-inp.org>

Take an email message file, parse it and quote the message body.

If `--compose` is set, then it will quote the message in the cover letter.
Otherwise, imply `--annotate` option and put the quoted message in the first
patch after the triple-dash.

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>
---
Currently, `send-email` without `--compose` implies `--annotate`. The
current behavior of `--annotate` is that changes made during edition are saved
in patch files.

Keeping that behavior when using `--quote-email` populates the patch file with
the quoted message body, and the patch is saved no matter what. If the user
closes his editor and then exits `send-email`, changes will be saved.

Should we keep the current behavior for the user, keeping the changes (including
the quoted message body) in the patch, or should we discard them?


changes since v1:
	- default behaviour of the option: it is now --annotate as one may not want
	  to send a cover letter for a single patch
	- "On [date], [original author] wrote:" is added before the quoted message
	- request to trim useless parts of the cited message when `--compose` is set
	- extra blank removed when the message quoted is empty

 Documentation/git-send-email.txt |  5 ++-
 git-send-email.perl              | 79 +++++++++++++++++++++++++++++++++++++---
 t/t9001-send-email.sh            |  6 +++
 3 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 2334d69..68bbb6c 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -109,7 +109,10 @@ is not set, this will be prompted for.
 --quote-email=<email_file>::
 	Reply to the given email and automatically populate the "To:", "Cc:" and
 	"In-Reply-To:" fields. If `--compose` is set, this will also fill the
-	subject field with "Re: [<email_file>'s subject]".
+	subject field with "Re: [<email_file>'s subject]" and quote the message body
+	of <email_file>. If `--compose` is not set, this will imply `--annotate`
+	option and will quote the message body of <email_file> after the triple-dash
+	in the first patch.
 
 --subject=<string>::
 	Specify the initial subject of the email thread.
diff --git a/git-send-email.perl b/git-send-email.perl
index 9df3dee..e73aa25 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(catfile);
+use File::Copy;
 use Error qw(:try);
 use Git;
 
@@ -55,8 +56,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> * Fill the fields "To:", "Cc:", "Subject:",
-                                     "In-Reply-To" appropriately.
+    --quote-email           <file> * Fill To:, Cc:, Subject:, In-Reply-To:
+                                     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.
@@ -642,11 +643,14 @@ if (@files) {
 	usage();
 }
 
+my $message_quoted;
 if ($quote_email) {
 	my $error = validate_patch($quote_email);
 	$error and die "fatal: $quote_email: $error\nwarning: no patches were sent\n";
 
 	my @header = ();
+	my $date;
+	my $recipient;
 
 	open my $fh, "<", $quote_email or die "can't open file $quote_email";
 
@@ -687,7 +691,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)) {
@@ -707,6 +712,8 @@ if ($quote_email) {
 				}
 			} elsif (/^Message-Id: (.*)/i) {
 				$initial_reply_to = $1;
+			} elsif (/^Date: (.*)/i) {
+				$date = $1;
 			}
 		} else {
 			# In the traditional
@@ -722,6 +729,23 @@ if ($quote_email) {
 			}
 		}
 	}
+
+	my $tpl_date = $date && "On $date, " || '';
+	$message_quoted = $tpl_date . $recipient . " wrote:\n";
+
+	# Quote the message body
+	while (<$fh>) {
+		# Only for files containing crlf line endings
+		s/\r//g;
+		my $space = "";
+		if (/^[^>]/) {
+			$space = " ";
+		}
+		$message_quoted .= ">" . $space . $_;
+	}
+	if (!$compose) {
+		$annotate = 1;
+	}
 }
 
 sub get_patch_subject {
@@ -749,6 +773,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 <<EOT;
 From $tpl_sender # This line is ignored.
@@ -760,7 +787,7 @@ GIT: Clear the body content if you don't wish to send a summary.
 From: $tpl_sender
 Subject: $tpl_subject
 In-Reply-To: $tpl_reply_to
-
+$tpl_quote
 EOT
 	for my $f (@files) {
 		print $c get_patch_subject($f);
@@ -825,9 +852,51 @@ EOT
 		$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];
+
+		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
+		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 389a54c..5ab7533 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -1916,6 +1916,12 @@ test_expect_success $PREREQ 'Fields with --quote-email are correct' '
 	echo "$cc_adr" | grep cc1@example.com
 '
 
+test_expect_success $PREREQ 'correct quoted message with --quote-email' '
+	grep "On Sat, 12 Jun 2010 15:53:58 +0200, author@example.com wrote:" msgtxt1 &&
+	grep "> Have you seen my previous email?" msgtxt1 &&
+	grep ">> Previous content" msgtxt1
+'
+
 test_expect_success $PREREQ 'Fields with --quote-email and --compose are correct' '
 	clean_fake_sendmail &&
 	git send-email \
-- 
2.8.2

  parent reply	other threads:[~2016-05-27 17:12 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   ` Tom Russello [this message]
2016-05-28 15:01     ` [RFC-PATCH v2 2/2] send-email: quote-email quotes the message body 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       ` [PATCH v3 5/6] send-email: --in-reply-to=<file> populates the fields Tom Russello
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=1464369102-7551-3-git-send-email-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).