Skip to content

Commit f1aa299

Browse files
sgngitster
authored andcommitted
mailinfo: allow squelching quoted CRLF warning
In previous change, Git starts to warn for quoted CRLF in decoded base64/QP email. Despite those warnings are usually helpful, quoted CRLF could be part of some users' workflow. Let's give them an option to turn off the warning completely. Signed-off-by: Đoàn Trần Công Danh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b68956 commit f1aa299

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

Documentation/git-mailinfo.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ git-mailinfo - Extracts patch and authorship from a single e-mail message
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git mailinfo' [-k|-b] [-u | --encoding=<encoding> | -n] [--[no-]scissors] <msg> <patch>
12+
'git mailinfo' [-k|-b] [-u | --encoding=<encoding> | -n]
13+
[--[no-]scissors] [--quoted-cr=<action>]
14+
<msg> <patch>
1315

1416

1517
DESCRIPTION
@@ -89,6 +91,22 @@ This can be enabled by default with the configuration option mailinfo.scissors.
8991
--no-scissors::
9092
Ignore scissors lines. Useful for overriding mailinfo.scissors settings.
9193

94+
--quoted-cr=<action>::
95+
Action when processes email messages sent with base64 or
96+
quoted-printable encoding, and the decoded lines end with a CRLF
97+
instead of a simple LF.
98+
+
99+
The valid actions are:
100+
+
101+
--
102+
* `nowarn`: Git will do nothing when such a CRLF is found.
103+
* `warn`: Git will issue a warning for each message if such a CRLF is
104+
found.
105+
--
106+
+
107+
The default action could be set by configuration option `mailinfo.quotedCR`.
108+
If no such configuration option has been set, `warn` will be used.
109+
92110
<msg>::
93111
The commit log message extracted from e-mail, usually
94112
except the title line which comes from e-mail Subject.

builtin/mailinfo.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ static int parse_opt_explicit_encoding(const struct option *opt,
3838
return 0;
3939
}
4040

41+
static int parse_opt_quoted_cr(const struct option *opt, const char *arg, int unset)
42+
{
43+
BUG_ON_OPT_NEG(unset);
44+
45+
if (mailinfo_parse_quoted_cr_action(arg, opt->value) != 0)
46+
return error(_("bad action '%s' for '%s'"), arg, "--quoted-cr");
47+
return 0;
48+
}
49+
4150
int cmd_mailinfo(int argc, const char **argv, const char *prefix)
4251
{
4352
struct metainfo_charset meta_charset;
@@ -61,6 +70,9 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
6170
N_("re-code metadata to this encoding"),
6271
PARSE_OPT_NONEG, parse_opt_explicit_encoding),
6372
OPT_BOOL(0, "scissors", &mi.use_scissors, N_("use scissors")),
73+
OPT_CALLBACK_F(0, "quoted-cr", &mi.quoted_cr, N_("<action>"),
74+
N_("action when quoted CR is found"),
75+
PARSE_OPT_NONEG, parse_opt_quoted_cr),
6476
OPT_HIDDEN_BOOL(0, "inbody-headers", &mi.use_inbody_headers,
6577
N_("use headers in message's body")),
6678
OPT_END()

mailinfo.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,8 @@ static void handle_filter_flowed(struct mailinfo *mi, struct strbuf *line,
10401040

10411041
static void summarize_quoted_cr(struct mailinfo *mi)
10421042
{
1043-
if (mi->have_quoted_cr)
1043+
if (mi->have_quoted_cr &&
1044+
mi->quoted_cr == quoted_cr_warn)
10441045
warning(_("quoted CRLF detected"));
10451046
}
10461047

@@ -1220,6 +1221,17 @@ int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
12201221
return mi->input_error;
12211222
}
12221223

1224+
int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action)
1225+
{
1226+
if (!strcmp(actionstr, "nowarn"))
1227+
*action = quoted_cr_nowarn;
1228+
else if (!strcmp(actionstr, "warn"))
1229+
*action = quoted_cr_warn;
1230+
else
1231+
return -1;
1232+
return 0;
1233+
}
1234+
12231235
static int git_mailinfo_config(const char *var, const char *value, void *mi_)
12241236
{
12251237
struct mailinfo *mi = mi_;
@@ -1230,6 +1242,11 @@ static int git_mailinfo_config(const char *var, const char *value, void *mi_)
12301242
mi->use_scissors = git_config_bool(var, value);
12311243
return 0;
12321244
}
1245+
if (!strcmp(var, "mailinfo.quotedcr")) {
1246+
if (mailinfo_parse_quoted_cr_action(value, &mi->quoted_cr) != 0)
1247+
return error(_("bad action '%s' for '%s'"), value, var);
1248+
return 0;
1249+
}
12331250
/* perhaps others here */
12341251
return 0;
12351252
}
@@ -1242,6 +1259,7 @@ void setup_mailinfo(struct mailinfo *mi)
12421259
strbuf_init(&mi->charset, 0);
12431260
strbuf_init(&mi->log_message, 0);
12441261
strbuf_init(&mi->inbody_header_accum, 0);
1262+
mi->quoted_cr = quoted_cr_warn;
12451263
mi->header_stage = 1;
12461264
mi->use_inbody_headers = 1;
12471265
mi->content_top = mi->content;

mailinfo.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
#define MAX_BOUNDARIES 5
77

8+
enum quoted_cr_action {
9+
quoted_cr_nowarn,
10+
quoted_cr_warn,
11+
};
12+
813
struct mailinfo {
914
FILE *input;
1015
FILE *output;
@@ -14,6 +19,7 @@ struct mailinfo {
1419
struct strbuf email;
1520
int keep_subject;
1621
int keep_non_patch_brackets_in_subject;
22+
int quoted_cr; /* enum quoted_cr_action */
1723
int add_message_id;
1824
int use_scissors;
1925
int use_inbody_headers;
@@ -40,6 +46,7 @@ struct mailinfo {
4046
int input_error;
4147
};
4248

49+
int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action);
4350
void setup_mailinfo(struct mailinfo *);
4451
int mailinfo(struct mailinfo *, const char *msg, const char *patch);
4552
void clear_mailinfo(struct mailinfo *);

t/t5100-mailinfo.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,11 @@ test_expect_success 'mailinfo warn CR in base64 encoded email' '
255255
check_quoted_cr_mail quoted-cr/0001 &&
256256
test_must_be_empty quoted-cr/0001.err &&
257257
check_quoted_cr_mail quoted-cr/0002 &&
258-
grep "quoted CRLF detected" quoted-cr/0002.err
258+
grep "quoted CRLF detected" quoted-cr/0002.err &&
259+
check_quoted_cr_mail quoted-cr/0001 --quoted-cr=nowarn &&
260+
test_must_be_empty quoted-cr/0001.err &&
261+
check_quoted_cr_mail quoted-cr/0002 --quoted-cr=nowarn &&
262+
test_must_be_empty quoted-cr/0002.err
259263
'
260264

261265
test_done

0 commit comments

Comments
 (0)