From 42a486d2df9574ef0c44a94eabf8f605744ab945 Mon Sep 17 00:00:00 2001 From: Brian White Date: Sun, 17 Aug 2014 11:01:32 -0400 Subject: [PATCH] Parser: decode names in envelope --- lib/Parser.js | 22 ++++++++++++++-------- test/test-parse-envelope-addrs.js | 8 ++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/Parser.js b/lib/Parser.js index ad2d027..00e689e 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -588,13 +588,7 @@ function parseStructExtra(part, partLen, cur, next) { function parseFetchEnvelope(list) { return { date: new Date(list[0]), - subject: decodeWords(list[1], { - buffer: undefined, - encoding: undefined, - consecutive: false, - replaces: undefined, - curReplace: undefined - }), + subject: decodeWords(list[1]), from: parseEnvelopeAddresses(list[2]), sender: parseEnvelopeAddresses(list[3]), replyTo: parseEnvelopeAddresses(list[4]), @@ -627,7 +621,7 @@ function parseEnvelopeAddresses(list) { }; } else { // regular user address var info = { - name: addr[0], + name: decodeWords(addr[0]), mailbox: addr[2], host: addr[3] }; @@ -879,6 +873,18 @@ function qEncReplacer(match, byte) { } function decodeWords(str, state) { var pendoffset = -1; + + if (!state) { + state = { + buffer: undefined, + encoding: undefined, + consecutive: false, + replaces: undefined, + curReplace: undefined, + remainder: undefined + }; + } + state.replaces = []; var bytes, m, next, i, j, leni, lenj, seq, replaces = [], lastReplace = {}; diff --git a/test/test-parse-envelope-addrs.js b/test/test-parse-envelope-addrs.js index b31a235..25636ee 100644 --- a/test/test-parse-envelope-addrs.js +++ b/test/test-parse-envelope-addrs.js @@ -21,6 +21,14 @@ var assert = require('assert'), ], what: 'RFC3501 example #2' }, + { source: '("=?utf-8?Q?=C2=A9=C2=AEAZ=C2=A5?=" NIL "crazy" "example.org")', + expected: [ { name: '©®AZ¥', + mailbox: 'crazy', + host: 'example.org' + } + ], + what: 'Name with encoded word(s)' + }, { source: '(NIL NIL "imap" NIL)' + '(NIL NIL NIL NIL)', expected: [ { group: 'imap',