From 80bf776d0a4587c477bb8a248b9dbe1a31e74575 Mon Sep 17 00:00:00 2001 From: David Levine Date: Sun, 25 Nov 2012 09:06:20 -0600 Subject: [PATCH] In pick(1), attempt to decode each header field as if it were MIME encoded. --- test/pick/test-pick | 17 +++++++++++++++++ uip/picksbr.c | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/test/pick/test-pick b/test/pick/test-pick index 84eb18c..ac19783 100755 --- a/test/pick/test-pick +++ b/test/pick/test-pick @@ -244,5 +244,22 @@ echo 12 >"$expected" pick -subject 'multi-line header field' 12 >"$actual" 2>&1 check "$expected" "$actual" +# Test MIME-encoded header. +cat >"$MH_TEST_DIR/Mail/inbox/13" < +To: Some User +Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 13@test.nmh +Subject: =?us-ascii?q?=66=6f=6f?= + =?utf-8?q?=62=61=72?= + +This is message number 13, with MIME-encoded Subject "foobar". +EOF + +echo 13 >"$expected" + +pick -subject foobar 13 >"$actual" 2>&1 +check "$expected" "$actual" + exit $failed diff --git a/uip/picksbr.c b/uip/picksbr.c index 4895b23..91893e3 100644 --- a/uip/picksbr.c +++ b/uip/picksbr.c @@ -78,6 +78,7 @@ static struct swit parswit[] = { static char linebuf[LBSIZE + 1]; +static char decoded_linebuf[LBSIZE + 1]; /* the magic array for case-independence */ static unsigned char cc[] = { @@ -714,6 +715,13 @@ plist p1 = linebuf; p2 = n->n_expbuf; + /* Attempt to decode as a MIME header. If it's the last header, + body will be 1 and lf will be at least 1. */ + if ((body == 0 || lf > 0) && + decode_rfc2047 (linebuf, decoded_linebuf, sizeof decoded_linebuf)) { + p1 = decoded_linebuf; + } + if (n->n_circf) { if (advance (p1, p2)) return 1; -- 1.7.10.4