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

Re: [PATCH v2 3/5] mailinfo: skip quoted CR on user's wish

From
Junio C Hamano <gitster@pobox.com>
Date
May 5, 2021, 04:12 UTC
Message-ID
<xmqqeeel4y5f.fsf@gitster.g>
In-Reply-To
<3215ea95cf869c8495d95cfd774973c330c14d1d.1620148732.git.congdanhqx@gmail.com>
Đoàn Trần Công Danh  <congdanhqx@gmail.com> writes:
> Subject: Re: [PATCH v2 3/5] mailinfo: skip quoted CR on user's wish

Nothing wrong per-se, but "on user's wish" feel somewhat bizarre. Perhaps

    mailinfo: allow skipping quoted CR
or something along that line?
Show 25 quoted lines
> In previous change, we've turned on warning for quoted CR in base64
> encoded email. Despite those warnings are usually helpful for our users,
> they may expect quoted CR in their emails.
>
> Let's give them an option to turn off the warning completely.
>
> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
> ---
>  Documentation/git-mailinfo.txt | 18 +++++++++++++++++-
>  builtin/mailinfo.c             |  8 ++++++--
>  mailinfo.c                     | 21 ++++++++++++++++++++-
>  mailinfo.h                     |  8 ++++++++
>  t/t5100-mailinfo.sh            |  6 ++++--
>  5 files changed, 55 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/git-mailinfo.txt b/Documentation/git-mailinfo.txt
> index d343f040f5..c776b27515 100644
> --- a/Documentation/git-mailinfo.txt
> +++ b/Documentation/git-mailinfo.txt
> @@ -9,7 +9,7 @@ git-mailinfo - Extracts patch and authorship from a single e-mail message
>  SYNOPSIS
>  --------
>  [verse]
> -'git mailinfo' [-k|-b] [-u | --encoding=<encoding> | -n] [--[no-]scissors] <msg> <patch>
> +'git mailinfo' [-k|-b] [-u | --encoding=<encoding> | -n] [--[no-]scissors] [--quoted-cr=<action>] <msg> <patch>
This line is getting really crowded.  Perhaps it is time to do
	'git mailinfo' [<options>] <msg> <patch>

like other Git subcommands with too many options? Certainly it can be done after the dust settles from this entire series as a follow up clean-up patch.

Show 7 quoted lines
> @@ -89,6 +89,22 @@ This can be enabled by default with the configuration option mailinfo.scissors.
>  --no-scissors::
>  	Ignore scissors lines. Useful for overriding mailinfo.scissors settings.
>  
> +--quoted-cr=<action>::
> +	Action when processes email messages sent with base64 or
> +	quoted-printable encoding, and the decoded lines end with CR-LF
s/with CR-LF/with a CRLF/
Show 6 quoted lines
> +	instead of a simple LF.
> ++
> +The valid actions are:
> ++
> +--
> +*	`nowarn`: Git will do nothing with this action.
s/with this action./when such a CRLF is seen./ perhaps?
> +*	`warn`: Git will issue a warning for each message if such CR-LF is
s/such CR-LF/such a CRLF/
Show 10 quoted lines
> diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c
> index b309badce5..1d600263cb 100644
> --- a/builtin/mailinfo.c
> +++ b/builtin/mailinfo.c
> @@ -9,7 +9,7 @@
>  #include "mailinfo.h"
>  
>  static const char mailinfo_usage[] =
> -	"git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] <msg> <patch> < mail >info";
> +	"git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] [--quoted-cr=<action>] <msg> <patch> < mail >info";

It is surprising that we haven't switched this to parse_options(). It of course is outside the scope of this series, but from a cursory look of its option parsing loop, it looks like a trivial improvement to make.

Show 9 quoted lines
> @@ -43,7 +43,11 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
>  			mi.use_scissors = 0;
>  		else if (!strcmp(argv[1], "--no-inbody-headers"))
>  			mi.use_inbody_headers = 0;
> -		else
> +		else if (skip_prefix(argv[1], "--quoted-cr=", &str)) {
> +			mi.quoted_cr = mailinfo_parse_quoted_cr_action(str);
> +			if (mi.quoted_cr == quoted_cr_invalid_action)
> +				usage(mailinfo_usage);

This is not all that helpful, given that mailinfo_usage[] only says <action> without saying what the supported values are, and the message does not make it clear it was issued while looking at the --quoted-cr option.

At least, something like
			if (mi.quoted_cr == quoted_cr_invalid_action)
                        	die("--quoted-cr=%s: invalid action", str);

would be more palatable, but I wonder if mailinfo_parse_quoted_cr_action() should have an option to die with the list of actions it knows about in a message.

Show 11 quoted lines
> diff --git a/mailinfo.c b/mailinfo.c
> index 713567f84b..fe7ffd01d0 100644
> --- a/mailinfo.c
> +++ b/mailinfo.c
> @@ -1040,7 +1040,8 @@ static void handle_filter_flowed(struct mailinfo *mi, struct strbuf *line,
>  
>  static void summarize_quoted_cr(struct mailinfo *mi, int have_quoted_cr)
>  {
> -	if (have_quoted_cr)
> +	if (have_quoted_cr
> +	    && mi->quoted_cr == quoted_cr_warn)

Existing code in this file prefers to split a multi-line statement after sequence point like &&, ||, etc., not before.

Show 15 quoted lines
>  		warning("quoted CR detected");
>  }
>  
> @@ -1221,9 +1222,19 @@ int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
>  	return mi->input_error;
>  }
>  
> +enum quoted_cr_action mailinfo_parse_quoted_cr_action(const char *action)
> +{
> +	if (!strcmp(action, "nowarn"))
> +		return quoted_cr_nowarn;
> +	else if (!strcmp(action, "warn"))
> +		return quoted_cr_warn;
> +	return quoted_cr_invalid_action;
> +}
OK.
Show 18 quoted lines
>  static int git_mailinfo_config(const char *var, const char *value, void *mi_)
>  {
>  	struct mailinfo *mi = mi_;
> +	const char *str;
>  
>  	if (!starts_with(var, "mailinfo."))
>  		return git_default_config(var, value, NULL);
> @@ -1231,6 +1242,13 @@ static int git_mailinfo_config(const char *var, const char *value, void *mi_)
>  		mi->use_scissors = git_config_bool(var, value);
>  		return 0;
>  	}
> +	if (!strcmp(var, "mailinfo.quotedcr")) {
> +		git_config_string(&str, var, value);
> +		mi->quoted_cr = mailinfo_parse_quoted_cr_action(str);
> +		if (mi->quoted_cr == quoted_cr_invalid_action)
> +			die(_("bad action '%s' for '%s'"), str, var);
> +		free((void *)str);
> +	}

Here, it is more reasonable. It still does not say what actions are accepted, but at least the user learns where our displeasure comes from.

>  	/* perhaps others here */
>  	return 0;
>  }
Previous: Đoàn Trần Công DanhNext: Đoàn Trần Công Danh
Message 11 of 35 in “mailinfo: strip CR from base64/quoted-printable email”
  1. mailinfo: strip CR from base64/quoted-printable emailĐoàn Trần Công Danh, Apr 21, 2021
  2. Junio C HamanoApr 21, 2021
  3. brian m. carlsonApr 21, 2021
  4. Đoàn Trần Công DanhApr 21, 2021
  5. brian m. carlsonApr 22, 2021
  6. 0/5 Teach am/mailinfo to process quoted CRĐoàn Trần Công Danh, May 4, 2021
  7. 1/5 mailinfo: avoid magic number in option parsingĐoàn Trần Công Danh, May 4, 2021
  8. 2/5 mailinfo: warn if CR found in base64/quoted-printable emailĐoàn Trần Công Danh, May 4, 2021
  9. Junio C HamanoMay 5, 2021
  10. 3/5 mailinfo: skip quoted CR on user's wishĐoàn Trần Công Danh, May 4, 2021
  11. Junio C HamanoMay 5, 2021
  12. Đoàn Trần Công DanhMay 5, 2021
  13. 4/5 mailinfo: strip quoted CR on users' wishĐoàn Trần Công Danh, May 4, 2021
  14. Junio C HamanoMay 5, 2021
  15. 5/5 am: learn to process quoted lines that ends with CRLFĐoàn Trần Công Danh, May 4, 2021
  16. Junio C HamanoMay 5, 2021
  17. 0/6 Teach am/mailinfo to process quoted CRĐoàn Trần Công Danh, May 6, 2021
  18. 1/6 mailinfo: load default metainfo_charset lazilyĐoàn Trần Công Danh, May 6, 2021
  19. 2/6 mailinfo: stop parsing options manuallyĐoàn Trần Công Danh, May 6, 2021
  20. Junio C HamanoMay 8, 2021
  21. 3/6 mailinfo: warn if CR found in decoded base64/QP emailĐoàn Trần Công Danh, May 6, 2021
  22. Junio C HamanoMay 8, 2021
  23. 4/6 mailinfo: allow squelching quoted CR warningĐoàn Trần Công Danh, May 6, 2021
  24. 5/6 mailinfo: allow stripping quoted CR without warningĐoàn Trần Công Danh, May 6, 2021
  25. 6/6 am: learn to process quoted lines that ends with CRLFĐoàn Trần Công Danh, May 6, 2021
  26. Junio C HamanoMay 8, 2021
  27. 0/6 Teach am/mailinfo to process quoted CRĐoàn Trần Công Danh, May 9, 2021
  28. 1/6 mailinfo: load default metainfo_charset lazilyĐoàn Trần Công Danh, May 9, 2021
  29. 2/6 mailinfo: stop parsing options manuallyĐoàn Trần Công Danh, May 9, 2021
  30. 3/6 mailinfo: warn if CRLF found in decoded base64/QP emailĐoàn Trần Công Danh, May 9, 2021
  31. 4/6 mailinfo: allow squelching quoted CRLF warningĐoàn Trần Công Danh, May 9, 2021
  32. 5/6 mailinfo: allow stripping quoted CR without warningĐoàn Trần Công Danh, May 9, 2021
  33. 6/6 am: learn to process quoted lines that ends with CRLFĐoàn Trần Công Danh, May 9, 2021
  34. 2/6 mailinfo: stop parse options manuallyĐoàn Trần Công Danh, May 6, 2021
  35. Đoàn Trần Công DanhMay 6, 2021

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.