From: Kevin Daudt <me@ikke.info>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Kevin Daudt <me@ikke.info>
Subject: [RFC 0/1] mailinfo: de-quote quoted-pair in header fields
Date: Wed, 14 Sep 2016 01:46:12 +0200 [thread overview]
Message-ID: <20160913234612.22806-2-me@ikke.info> (raw)
In-Reply-To: <20160913234612.22806-1-me@ikke.info>
rfc2822 has provisions for quoted strings in structured header fields,
but also allows for escaping these with so-called quoted-pairs.
git currently does not do anything with this at all, and verbatim takes
over the field body.
Make sure to properly dequote these quoted-strings and comments.
Signed-off-by: Kevin Daudt <me@ikke.info>
---
mailinfo.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
t/t5100-mailinfo.sh | 5 +++++
t/t5100/quoted-pair.expect | 5 +++++
t/t5100/quoted-pair.in | 9 +++++++++
t/t5100/quoted-pair.info | 5 +++++
5 files changed, 70 insertions(+)
create mode 100644 t/t5100/quoted-pair.expect
create mode 100644 t/t5100/quoted-pair.in
create mode 100644 t/t5100/quoted-pair.info
diff --git a/mailinfo.c b/mailinfo.c
index e19abe3..3b7ae8a 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -445,6 +445,51 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
mi->input_error = -1;
}
+static int unescape_quoted_pair(struct mailinfo *mi, struct strbuf *line)
+{
+ struct strbuf outbuf = STRBUF_INIT;
+ const char *in = line->buf;
+ int c, skip=0;
+ char escape_context=0;
+
+ while ((c = *in++) != 0) {
+ if (!skip) {
+ switch (c) {
+ case '"':
+ if (!escape_context)
+ escape_context = '"';
+ else if (escape_context == '"')
+ escape_context = 0;
+ break;
+ case '\\':
+ if (escape_context) {
+ skip = 1;
+ continue;
+ }
+ break;
+ case '(':
+ if (!escape_context)
+ escape_context = '(';
+ break;
+ case ')':
+ if (escape_context == '(')
+ escape_context = 0;
+ break;
+ }
+ } else {
+ skip = 0;
+ }
+
+ strbuf_addch(&outbuf, c);
+ }
+
+ strbuf_reset(line);
+ strbuf_addbuf(line, &outbuf);
+
+ return 0;
+
+}
+
static int check_header(struct mailinfo *mi,
const struct strbuf *line,
struct strbuf *hdr_data[], int overwrite)
@@ -461,6 +506,7 @@ static int check_header(struct mailinfo *mi,
*/
strbuf_add(&sb, line->buf + len + 2, line->len - len - 2);
decode_header(mi, &sb);
+ unescape_quoted_pair(mi, &sb);
handle_header(&hdr_data[i], &sb);
ret = 1;
goto check_header_out;
diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh
index 1a5a546..2be61bf 100755
--- a/t/t5100-mailinfo.sh
+++ b/t/t5100-mailinfo.sh
@@ -142,4 +142,9 @@ test_expect_success 'mailinfo unescapes with --mboxrd' '
test_cmp expect mboxrd/msg
'
+test_expect_success 'mailinfo unescapes rfc2822 quoted-pair' '
+ git mailinfo /dev/null /dev/null <"$TEST_DIRECTORY"/t5100/quoted-pair.in >"$TEST_DIRECTORY"/t5100/quoted-pair.info &&
+ test_cmp "$TEST_DIRECTORY"/t5100/quoted-pair.expect "$TEST_DIRECTORY"/t5100/quoted-pair.info
+'
+
test_done
diff --git a/t/t5100/quoted-pair.expect b/t/t5100/quoted-pair.expect
new file mode 100644
index 0000000..9fe72e9
--- /dev/null
+++ b/t/t5100/quoted-pair.expect
@@ -0,0 +1,5 @@
+Author: "Author "The Author" Name"
+Email: somebody@example.com
+Subject: testing quoted-pair
+Date: Sun, 25 May 2008 00:38:18 -0700
+
diff --git a/t/t5100/quoted-pair.in b/t/t5100/quoted-pair.in
new file mode 100644
index 0000000..e2e627a
--- /dev/null
+++ b/t/t5100/quoted-pair.in
@@ -0,0 +1,9 @@
+From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
+From: "Author \"The Author\" Name" <somebody@example.com>
+Date: Sun, 25 May 2008 00:38:18 -0700
+Subject: [PATCH] testing quoted-pair
+
+
+
+---
+patch
diff --git a/t/t5100/quoted-pair.info b/t/t5100/quoted-pair.info
new file mode 100644
index 0000000..9fe72e9
--- /dev/null
+++ b/t/t5100/quoted-pair.info
@@ -0,0 +1,5 @@
+Author: "Author "The Author" Name"
+Email: somebody@example.com
+Subject: testing quoted-pair
+Date: Sun, 25 May 2008 00:38:18 -0700
+
--
2.10.0.rc2
next prev parent reply other threads:[~2016-09-13 23:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-12 20:10 git-am includes escape characters from 'From' field Swift Geek
2016-09-13 15:26 ` Jeff King
2016-09-13 23:46 ` [RFC 0/1] de-quote quoted-strings in mailinfo Kevin Daudt
2016-09-13 23:46 ` Kevin Daudt [this message]
2016-09-14 0:04 ` [RFC 0/1] mailinfo: de-quote quoted-pair in header fields Junio C Hamano
2016-09-14 4:58 ` Kevin Daudt
2016-09-14 5:09 ` Jeff King
2016-09-14 5:54 ` Junio C Hamano
2016-09-14 16:03 ` Kevin Daudt
2016-09-14 17:43 ` Junio C Hamano
2016-09-14 19:17 ` Jeff King
2016-09-14 19:30 ` Junio C Hamano
2016-09-14 19:38 ` Jeff King
2016-09-15 5:15 ` Kevin Daudt
2016-09-15 7:18 ` Jeff King
2016-09-14 5:13 ` Jeff King
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=20160913234612.22806-2-me@ikke.info \
--to=me@ikke.info \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kevin@lists.ikke.info \
/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).