git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "\"Alejandro R. Sedeño\"" <asedeno@MIT.EDU>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org, Michael J Gruber <git@drmicha.warpmail.net>,
	"Shawn O. Pearce" <spearce@spearce.org>
Subject: Re: [PATCH] git-svn: Add a svn-remote.<name>.pushurl config key
Date: Fri, 22 Apr 2011 15:11:46 -0400	[thread overview]
Message-ID: <4DB1D2F2.6040000@mit.edu> (raw)
In-Reply-To: <20110408224035.GB7343@sigill.intra.peff.net>

(Sorry I didn't chime in on this tangent. My life has been very busy since
Google finished acquiring ITA Software. At least it's a good kind of busy.
:) )

I'd be happy to see something like this get in. I've often noticed
git-send-email telling me that it couldn't parse an address out of my
signed-of-by lines, but I never stopped and took the time to look into it.

-Alejandro

On 04/08/2011 06:40 PM, Jeff King wrote:
> On Fri, Apr 08, 2011 at 03:25:09PM -0700, Junio C Hamano wrote:
> 
>> Jeff King <peff@peff.net> writes:
>>
>>> I disagree. Format-patch claims to make an mbox, so it should make one
>>> that is valid.
>>
>> OK.  That makes sense (even though I think it would make cutting and
>> pasting somewhat awkward).
> 
> Cutting and pasting is already potentially awkward, because we
> rfc2047-quote in format-patch, too. But we can still get away without
> quoting at all in regular "git log". The "Author:" lines, while
> rfc822-looking do not have to be real header lines, and we know that
> everything before the <> must be the name.
> 
> So I think this is the patch we want:
> 
> -- >8 --
> Subject: [PATCH] pretty: quote rfc822 specials in email addresses
> 
> If somebody has a name that includes an rfc822 special, we
> will output it literally in the "From:" header. This is
> usually OK, but certain characters (like ".") are supposed
> to be enclosed in double-quotes in a mail header.
> 
> In practice, whether this matters may depend on your MUA.
> Some MUAs will happily take in:
> 
>    From: Foo B. Bar <author@example.com>
> 
> without quotes, and properly quote the "." when they send
> the actual mail.  Others may not, or may screw up harder
> things like:
> 
>   From: Foo "The Baz" Bar <author@example.com>
> 
> For example, mutt will strip the quotes, thinking they are
> actual syntactic rfc822 quotes.
> 
> So let's quote properly, and then (if necessary) we still
> apply rfc2047 encoding on top of that, which should make all
> MUAs happy.
> 
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  pretty.c                |   61 ++++++++++++++++++++++++++++++++++++++++++++++-
>  t/t4014-format-patch.sh |   42 ++++++++++++++++++++++++++++++++
>  2 files changed, 102 insertions(+), 1 deletions(-)
> 
> diff --git a/pretty.c b/pretty.c
> index e1d8a8f..8345485 100644
> --- a/pretty.c
> +++ b/pretty.c
> @@ -208,6 +208,58 @@ int has_non_ascii(const char *s)
>  	return 0;
>  }
>  
> +static int is_rfc822_special(char ch)
> +{
> +	switch (ch) {
> +	case '(':
> +	case ')':
> +	case '<':
> +	case '>':
> +	case '[':
> +	case ']':
> +	case ':':
> +	case ';':
> +	case '@':
> +	case ',':
> +	case '.':
> +	case '"':
> +	case '\\':
> +		return 1;
> +	default:
> +		return 0;
> +	}
> +}
> +
> +static int has_rfc822_specials(const char *s, int len)
> +{
> +	int i;
> +	for (i = 0; i < len; i++)
> +		if (is_rfc822_special(s[i]))
> +			return 1;
> +	return 0;
> +}
> +
> +static void add_rfc822_quoted(struct strbuf *out, const char *s, int len)
> +{
> +	int i;
> +
> +	/* just a guess, we may have to also backslash-quote */
> +	strbuf_grow(out, len + 2);
> +
> +	strbuf_addch(out, '"');
> +	for (i = 0; i < len; i++) {
> +		switch (s[i]) {
> +		case '"':
> +		case '\\':
> +			strbuf_addch(out, '\\');
> +			/* fall through */
> +		default:
> +			strbuf_addch(out, s[i]);
> +		}
> +	}
> +	strbuf_addch(out, '"');
> +}
> +
>  static int is_rfc2047_special(char ch)
>  {
>  	return (non_ascii(ch) || (ch == '=') || (ch == '?') || (ch == '_'));
> @@ -293,7 +345,14 @@ void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
>  			name_tail--;
>  		display_name_length = name_tail - line;
>  		strbuf_addstr(sb, "From: ");
> -		add_rfc2047(sb, line, display_name_length, encoding);
> +		if (has_rfc822_specials(line, display_name_length)) {
> +			struct strbuf quoted = STRBUF_INIT;
> +			add_rfc822_quoted(&quoted, line, display_name_length);
> +			add_rfc2047(sb, quoted.buf, quoted.len, encoding);
> +			strbuf_release(&quoted);
> +		}
> +		else
> +			add_rfc2047(sb, line, display_name_length, encoding);
>  		strbuf_add(sb, name_tail, namelen - display_name_length);
>  		strbuf_addch(sb, '\n');
>  	} else {
> diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
> index c3cdb52..dd406c4 100755
> --- a/t/t4014-format-patch.sh
> +++ b/t/t4014-format-patch.sh
> @@ -793,4 +793,46 @@ test_expect_success 'format-patch wraps extremely long headers (rfc2047)' '
>  	test_cmp expect subject
>  '
>  
> +check_author() {
> +	echo content >>file &&
> +	git add file &&
> +	GIT_AUTHOR_NAME=$1 git commit -m author-check &&
> +	git format-patch --stdout -1 >patch &&
> +	grep ^From: patch >actual &&
> +	test_cmp expect actual
> +}
> +
> +cat >expect <<'EOF'
> +From: "Foo B. Bar" <author@example.com>
> +EOF
> +test_expect_success 'format-patch quotes dot in headers' '
> +	check_author "Foo B. Bar"
> +'
> +
> +cat >expect <<'EOF'
> +From: "Foo \"The Baz\" Bar" <author@example.com>
> +EOF
> +test_expect_success 'format-patch quotes double-quote in headers' '
> +	check_author "Foo \"The Baz\" Bar"
> +'
> +
> +cat >expect <<'EOF'
> +From: =?UTF-8?q?"F=C3=B6o=20B.=20Bar"?= <author@example.com>
> +EOF
> +test_expect_success 'rfc2047-encoded headers also double-quote 822 specials' '
> +	check_author "Föo B. Bar"
> +'
> +
> +cat >expect <<'EOF'
> +Subject: header with . in it
> +EOF
> +test_expect_success 'subject lines do not have 822 atom-quoting' '
> +	echo content >>file &&
> +	git add file &&
> +	git commit -m "header with . in it" &&
> +	git format-patch -k -1 --stdout >patch &&
> +	grep ^Subject: patch >actual &&
> +	test_cmp expect actual
> +'
> +
>  test_done

  parent reply	other threads:[~2011-04-22 19:11 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-04 19:09 [PATCHv2 0/2] a couple of git-svn patches Alejandro R. Sedeño
2011-04-04 19:09 ` [PATCH 1/2] git-svn: Fix the commit-url config to be the base url, just like the url config Alejandro R. Sedeño
2011-04-04 21:52   ` Eric Wong
2011-04-04 22:16     ` James Y Knight
2011-04-04 22:54       ` Eric Wong
2011-04-05 15:11         ` "Alejandro R. Sedeño"
2011-04-05 20:15           ` [PATCH] git-svn: Add a svn-remote.<name>.pushurl config key Alejandro R. Sedeño
2011-04-05 20:25             ` "Alejandro R. Sedeño"
2011-04-05 21:09               ` Eric Wong
2011-04-06 12:53               ` Michael J Gruber
2011-04-06 13:04                 ` "Alejandro R. Sedeño"
2011-04-06 13:12                   ` Michael J Gruber
2011-04-06 15:05               ` Alejandro R. Sedeño
2011-04-06 15:22                 ` Michael J Gruber
2011-04-06 15:34                   ` "Alejandro R. Sedeño"
2011-04-06 15:38                     ` Michael J Gruber
2011-04-08 14:57                 ` Alejandro R. Sedeño
2011-04-08 20:13                   ` Junio C Hamano
2011-04-08 20:25                     ` Michael J Gruber
2011-04-08 20:54                     ` Jeff King
     [not found]                       ` <7v4o6830cc.fsf@alter.siamese.dyndns.org>
2011-04-08 21:32                         ` Jeff King
2011-04-08 22:25                           ` Junio C Hamano
2011-04-08 22:40                             ` Jeff King
2011-04-08 22:43                               ` Jeff King
2011-04-22 19:11                               ` "Alejandro R. Sedeño" [this message]
2011-04-22 19:36                                 ` Jeff King
2011-04-22 19:40                                   ` "Alejandro R. Sedeño"
2011-04-09 22:47                   ` Eric Wong
2011-04-06 12:44             ` Michael J Gruber
2011-04-06 12:56               ` "Alejandro R. Sedeño"
2011-04-04 19:09 ` [PATCH 2/2] git-svn: Cache results of running the executable "git config" Alejandro R. Sedeño
2011-04-04 21:53   ` Eric Wong
     [not found]     ` <7voc4l5hm5.fsf@alter.siamese.dyndns.org>
2011-04-05  8:15       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DB1D2F2.6040000@mit.edu \
    --to=asedeno@mit.edu \
    --cc=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).