aboutsummaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-05-06 10:50:18 -0700
committerJunio C Hamano <gitster@pobox.com>2011-05-06 10:50:18 -0700
commitace8ebbcf5f07a5519cbeb0ae0571d8b40222e34 (patch)
treecb7b4bf9560d6751816f1ac79caaccf27611aa25 /pretty.c
parent1273738f05dedc63865085deb5d1fb8816ff809c (diff)
parent4d03c18a3ea18138c24d379ccc25e219a36ca1ef (diff)
downloadgit-ace8ebbcf5f07a5519cbeb0ae0571d8b40222e34.tar.gz
git-ace8ebbcf5f07a5519cbeb0ae0571d8b40222e34.tar.xz
Merge branch 'jk/format-patch-quote-special-in-from'
* jk/format-patch-quote-special-in-from: pretty: quote rfc822 specials in email addresses Conflicts: pretty.c t/t4014-format-patch.sh
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/pretty.c b/pretty.c
index ba95de92c..dff5c8d18 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 == '_'));
@@ -294,7 +346,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)) {
+ add_rfc2047(sb, line, display_name_length, encoding);
+ } else {
+ struct strbuf quoted = STRBUF_INIT;
+ add_rfc822_quoted(&quoted, line, display_name_length);
+ add_rfc2047(sb, quoted.buf, quoted.len, encoding);
+ strbuf_release(&quoted);
+ }
for (final_line = 0; final_line < sb->len; final_line++)
if (sb->buf[sb->len - final_line - 1] == '\n')
break;