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

[PATCHv2] am: fix patch format detection for Thunderbird "Save As" emails

From
Stephen Boyd <bebarino@gmail.com>
Date
Dec 18, 2009, 21:34 UTC
Message-ID
<1261172078-9174-1-git-send-email-bebarino@gmail.com>
In-Reply-To
<7vtyvpcf36.fsf@alter.siamese.dyndns.org>

The patch detection wants to inspect all the headers of a rfc2822 message and ensure that they look like header field names. The headers are always separated from the message body with a blank line. When Thunderbird saves the message the blank line separating the headers from the body includes a CR. The patch detection is failing because a CRLF doesn't match /^$/. Fix this by allowing a CR to exist on the separating line.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
Changes since v1:
 - More portable code using tr (thanks Junio)
 - More portable testing by manually adding CRLFs
 git-am.sh     |    3 ++-
 t/t4150-am.sh |   24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index 4838cdb..9e64deb 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -204,7 +204,8 @@ check_patch_format () {
 			# discarding the indented remainder of folded lines,
 			# and see if it looks like that they all begin with the
 			# header field names...
-			sed -n -e '/^$/q' -e '/^[ 	]/d' -e p "$1" |
+			tr -d '\015' <"$1" |
+			sed -n -e '/^$/q' -e '/^[ 	]/d' -e p |
 			sane_egrep -v '^[!-9;-~]+:' >/dev/null ||
 			patch_format=mbox
 		fi
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 8296605..7b6269d 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -83,6 +83,21 @@ test_expect_success setup '
 		echo "X-Fake-Field: Line Three" &&
 		git format-patch --stdout first | sed -e "1d"
 	} > patch1.eml &&
+	{
+		echo "X-Fake-Field: Line One\015" &&
+		echo "X-Fake-Field: Line Two\015" &&
+		echo "X-Fake-Field: Line Three\015" &&
+		git format-patch --stdout first |
+		sed -e "1d" -e "3,\$d" | tr -d "\n" &&
+		echo "\015" &&
+		git format-patch --stdout first |
+		sed -e "1,2d" -e "4,\$d" | tr -d "\n" &&
+		echo "\015" &&
+		git format-patch --stdout first |
+		sed -e "1,3d" -e "5,\$d" | tr -d "\n" &&
+		echo "\015\n\015" &&
+		git format-patch --stdout first | sed -e "1,5d"
+	} > patch1-crlf.eml &&
 	sed -n -e "3,\$p" msg >file &&
 	git add file &&
 	test_tick &&
@@ -123,6 +138,15 @@ test_expect_success 'am applies patch e-mail not in a mbox' '
 	test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
 '
 
+test_expect_success 'am applies patch e-mail not in a mbox with CRLF' '
+	git checkout first &&
+	git am patch1-crlf.eml &&
+	! test -d .git/rebase-apply &&
+	test -z "$(git diff second)" &&
+	test "$(git rev-parse second)" = "$(git rev-parse HEAD)" &&
+	test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)"
+'
+
 GIT_AUTHOR_NAME="Another Thor"
 GIT_AUTHOR_EMAIL="a.thor@example.com"
 GIT_COMMITTER_NAME="Co M Miter"
-- 
1.6.6.rc3.1.g8df51
Previous: Junio C HamanoNext: Eric Blake
Message 3 of 16 in “am: fix patch format detection for Thunderbird "Save As" emails”
  1. am: fix patch format detection for Thunderbird "Save As" emailsStephen Boyd, Dec 17, 2009
  2. Junio C HamanoDec 18, 2009
  3. [PATCHv2] am: fix patch format detection for Thunderbird "Save As" emailsStephen Boyd, Dec 18, 2009
  4. Eric BlakeDec 18, 2009
  5. Stephen BoydDec 18, 2009
  6. Eric BlakeDec 18, 2009
  7. Stephen BoydDec 19, 2009
  8. Eric BlakeDec 19, 2009
  9. Stephen BoydDec 19, 2009
  10. Stephen BoydDec 19, 2009
  11. Junio C HamanoDec 19, 2009
  12. Stephen BoydDec 19, 2009
  13. Andreas SchwabDec 19, 2009
  14. Junio C HamanoDec 18, 2009
  15. Nanako ShiraishiJan 5, 2010
  16. Stephen BoydJan 21, 2010

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.