Skip to contentSkip to conversation

mailinfo: support format=flowed

PATCH In review René Scharfe 3 participants 4 messages Aug 25, 2018 – Sep 4, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mailinfo: support format=flowed

Add best-effort support for patches sent using format=flowed (RFC 3676). Remove leading spaces ("unstuff"), remove soft line breaks (indicated by space + newline), but leave the signature separator (dash dash space newline) alone.

Warn in git am when encountering a format=flowed patch, because any trailing spaces would most probably be lost, as the sending MUA is encouraged to remove them when preparing the email.

Provide a test patch formatted by Mozilla Thunderbird 60 using its default configuration. It reuses the contents of the file mailinfo.c before and after this patch.

---
A test for DelSp=yes would be nice (in a separate patch; this one is quite big already), but I don't know how to create one.

 builtin/am.c                |    4 +
 mailinfo.c                  |   64 +-
 mailinfo.h                  |    2 +
 t/t4256-am-format-flowed.sh |   19 +
 t/t4256/1/mailinfo.c        | 1245 +++++++++++++++++++++++++++++++++++
 t/t4256/1/mailinfo.c.orig   | 1185 +++++++++++++++++++++++++++++++++
 t/t4256/1/patch             |  129 ++++
 7 files changed, 2646 insertions(+), 2 deletions(-)
 create mode 100755 t/t4256-am-format-flowed.sh
 create mode 100644 t/t4256/1/mailinfo.c
 create mode 100644 t/t4256/1/mailinfo.c.orig
 create mode 100644 t/t4256/1/patch
builtin/am.c +4 -0
index 9f7ecf6ecb..2a7341cf48 100644
@@ -1244,6 +1244,10 @@ static int parse_mail(struct am_state *state, const char *mail)
 	fclose(mi.input);
 	fclose(mi.output);
 
+	if (mi.format_flowed)
+		warning(_("Patch sent with format=flowed; "
+			  "space at the end of lines might be lost."));
+
 	/* Extract message and author information */
 	fp = xfopen(am_path(state, "info"), "r");
 	while (!strbuf_getline_lf(&sb, fp)) {
mailinfo.c +62 -2

99 lines not on this page · raw message

mailinfo.h +2 -0
index 766c03dd1d..6830e1e625 100644
@@ -22,6 +22,8 @@ struct mailinfo {
 	struct strbuf *content[MAX_BOUNDARIES];
 	struct strbuf **content_top;
 	struct strbuf charset;
+	unsigned int format_flowed:1;
+	unsigned int delsp:1;
 	char *message_id;
 	enum  {
 		TE_DONTCARE, TE_QP, TE_BASE64
t/t4256-am-format-flowed.sh new file +19 -0
new file mode 100755
index 0000000000..6340310e9a
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+test_description='test format=flowed support of git am'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	cp "$TEST_DIRECTORY/t4256/1/mailinfo.c.orig" mailinfo.c &&
+	git add mailinfo.c &&
+	git commit -m initial
+'
+
+test_expect_success 'am with format=flowed' '
+	git am <"$TEST_DIRECTORY/t4256/1/patch" >stdout 2>stderr &&
+	test_i18ngrep "warning: Patch sent with format=flowed" stderr &&
+	test_cmp "$TEST_DIRECTORY/t4256/1/mailinfo.c" mailinfo.c
+'
+
+test_done
t/t4256/1/mailinfo.c new file +1245 -0

1,245 lines not on this page · raw message

t/t4256/1/mailinfo.c.orig new file +1185 -0

1,185 lines not on this page · raw message

t/t4256/1/patch new file +129 -0

129 lines not on this page · raw message

Signature · 1 line
2.18.0
#1 lore raw
Quoted 8 lines · René Scharfe

Add best-effort support for patches sent using format=flowed (RFC 3676). Remove leading spaces ("unstuff"), remove soft line breaks (indicated by space + newline), but leave the signature separator (dash dash space newline) alone.

Warn in git am when encountering a format=flowed patch, because any trailing spaces would most probably be lost, as the sending MUA is encouraged to remove them when preparing the email.

The warning is a very good idea, but I wonder if it is loud enough when mixed with other noise (e.g. "--whitespace=warn" for a short series, or patch titles when applying a very long series).

Lossage of trailing spaces may even be a feature (just joking), when the project policy makes it OK to use "am --whitespace=fix". I usually use "am --whitespace=fix" but I used "am --whitespace=warn" while applying this patch to preserve lines that begin with "SP SP HT" in the sample patch.

#2 lore raw
In reply to René Scharfe

Hi,

Quoted 6 lines · René Scharfe
 builtin/am.c                |    4 +
 mailinfo.c                  |   64 +-
 mailinfo.h                  |    2 +
 t/t4256-am-format-flowed.sh |   19 +
 t/t4256/1/mailinfo.c        | 1245 +++++++++++++++++++++++++++++++++++
 t/t4256/1/mailinfo.c.orig   | 1185 +++++++++++++++++++++++++++++++++

This mailinfo.c.orig file appears to have been lost when applying the patch to git.git, resulting in test failures:

 $ ./t4256-am-format-flowed.sh -v -i
 Initialized empty Git repository in git/t/trash directory.t4256-am-format-flowed/.git/
 expecting success: 
        cp "$TEST_DIRECTORY/t4256/1/mailinfo.c.orig" mailinfo.c &&
        git add mailinfo.c &&
        git commit -m initial

cp: cannot stat 'git/t/t4256/1/mailinfo.c.orig': No such file or directory not ok 1 - setup
#

 #               cp "$TEST_DIRECTORY/t4256/1/mailinfo.c.orig" mailinfo.c &&
 #               git add mailinfo.c &&
 #               git commit -m initial

#

Known issue?

Thanks,
Jonathan

#3 lore raw
Quoted 22 lines · Jonathan Nieder
Quoted 6 lines · René Scharfe
 builtin/am.c                |    4 +
 mailinfo.c                  |   64 +-
 mailinfo.h                  |    2 +
 t/t4256-am-format-flowed.sh |   19 +
 t/t4256/1/mailinfo.c        | 1245 +++++++++++++++++++++++++++++++++++
 t/t4256/1/mailinfo.c.orig   | 1185 +++++++++++++++++++++++++++++++++

This mailinfo.c.orig file appears to have been lost when applying the patch to git.git, resulting in test failures:

 $ ./t4256-am-format-flowed.sh -v -i
 Initialized empty Git repository in git/t/trash directory.t4256-am-format-flowed/.git/
 expecting success: 
        cp "$TEST_DIRECTORY/t4256/1/mailinfo.c.orig" mailinfo.c &&
        git add mailinfo.c &&
        git commit -m initial

cp: cannot stat 'git/t/t4256/1/mailinfo.c.orig': No such file or directory not ok 1 - setup
#

Quoted 6 lines
 #               cp "$TEST_DIRECTORY/t4256/1/mailinfo.c.orig" mailinfo.c &&
 #               git add mailinfo.c &&
 #               git commit -m initial

#

Known issue?

My bad: this was operator error:

 $ git status -s
  D t/t4256/1/mailinfo.c.orig

The issue was that I ran dh_clean, which removed the .orig file. I'll fix the issue on my side. Sorry for the false alarm.

Sincerely,
Jonathan