git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] send-email: fix In-Reply-To regression

From
Jay Soffian <jaysoffian@gmail.com>
Date
Feb 22, 2008, 00:16 UTC
Message-ID
<1203639364-91817-1-git-send-email-jaysoffian@gmail.com>
In-Reply-To
<76718490802211351n1f0a6c36nb84902a624ee2120@mail.gmail.com>
Fix a regression introduced by
1ca3d6e (send-email: squelch warning due to comparing undefined $_ to "")

where if the user was prompted for an initial In-Reply-To and didn't provide one, messages would be sent out with an invalid In-Reply-To of "<>"

Also add test cases for the regression and the fix. A small modification was needed to allow send-email to take its replies from stdin if the environment variable GIT_SEND_EMAIL_NOTTY is set.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---

An issue cropped up with testing the regression: it only occured if initial_reply_to was "", and the only way to do that is to respond to the Initial-Reply-To prompt with "\n". But send-email uses readline, which insists on /dev/tty.

So, I initially simulated the breakage by using --initial-reply-to=" ", but this isn't quite the same thing. However, it turns out this can also cause an invalid In-Reply-To, which wasn't fixed by Junio's suggestion of checking that initial_reply_to ne "". So I did a slightly different fix that handles initial_reply_to eq " ".

Anyway, back to testing the original problem. I didn't want to use expect or Expect.pm, so I made a small change to send-email where if GIT_SEND_EMAIL_NOTTY is set, it will read from stdin instead of /dev/tty.

But, I wonder if in the future we'll want to enhance the testing framework to be able to do expect-type stuff?

j.
 git-send-email.perl   |    9 ++++++---
 t/t9001-send-email.sh |   21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index ccb87a2..29b1105 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -170,7 +170,9 @@ my $envelope_sender;
 
 my $repo = Git->repository();
 my $term = eval {
-	new Term::ReadLine 'git-send-email';
+	$ENV{"GIT_SEND_EMAIL_NOTTY"}
+		? new Term::ReadLine 'git-send-email', \*STDIN, \*STDOUT
+		: new Term::ReadLine 'git-send-email';
 };
 if ($@) {
 	$term = new FakeTerm "$@: going non-interactive";
@@ -476,8 +478,9 @@ if ($thread && !defined $initial_reply_to && $prompting) {
 	$initial_reply_to = $_;
 }
 if (defined $initial_reply_to) {
-	$initial_reply_to =~ s/^\s*<?/</;
-	$initial_reply_to =~ s/>?\s*$/>/;
+	$initial_reply_to =~ s/^\s*<?//;
+	$initial_reply_to =~ s/>?\s*$//;
+	$initial_reply_to = "<$initial_reply_to>" if $initial_reply_to ne '';
 }
 
 if (!defined $smtp_server) {
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 08f7c3d..1422e9f 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -108,4 +108,25 @@ test_expect_success 'allow long lines with --no-validate' '
 		2>errors
 '
 
+test_expect_failure 'Invalid In-Reply-To' '
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--to=nobody@example.com \
+		--in-reply-to=" " \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		$patches
+		2>errors
+	! grep "^In-Reply-To: < *>" msgtxt
+'
+
+test_expect_success 'Valid In-Reply-To when prompting' '
+	(echo "From Example <from@example.com>"
+	 echo "To Example <to@example.com>"
+	 echo ""
+	) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		$patches 2>errors &&
+	! grep "^In-Reply-To: < *>" msgtxt
+'
+
 test_done
-- 
1.5.4.2.236.g77b4.dirty
Previous: Jay SoffianNext: Junio C Hamano
Message 9 of 14 in “git-send-email getting filtered as spam by vger.kernel.org”
  1. Len BrownFeb 21, 2008
  2. Len BrownFeb 21, 2008
  3. Uwe Kleine-KönigFeb 21, 2008
  4. Junio C HamanoFeb 21, 2008
  5. Mike HommeyFeb 21, 2008
  6. Jay SoffianFeb 21, 2008
  7. Mike HommeyFeb 21, 2008
  8. Jay SoffianFeb 21, 2008
  9. send-email: fix In-Reply-To regressionJay Soffian, Feb 22, 2008
  10. Junio C HamanoFeb 22, 2008
  11. Uwe Kleine-KönigFeb 27, 2008
  12. Junio C HamanoFeb 27, 2008
  13. Junio C HamanoFeb 21, 2008
  14. Len BrownFeb 23, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.