From b607d5fa7d0482b49509b866299551e786abe68c Mon Sep 17 00:00:00 2001 From: Eric Pinzur Date: Wed, 10 Jun 2015 16:10:29 -0500 Subject: [PATCH] Parser: fixed exception when parsing invalid bodystructure --- lib/Parser.js | 2 +- test/test-parse-bodystructure.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Parser.js b/lib/Parser.js index d6d673e..a38da29 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -499,7 +499,7 @@ function parseBodyStructure(cur, literals, prefix, partID) { }; } else { // type information for malformed multipart body - part = { type: cur[0].toLowerCase(), params: null }; + part = { type: cur[0] ? cur[0].toLowerCase() : null, params: null }; cur.splice(1, 0, null); ++partLen; next = 2; diff --git a/test/test-parse-bodystructure.js b/test/test-parse-bodystructure.js index ae826ef..3edf0aa 100644 --- a/test/test-parse-bodystructure.js +++ b/test/test-parse-bodystructure.js @@ -35,6 +35,17 @@ var assert = require('assert'), ], what: 'RFC3501 example #1' }, + { source: 'NIL NIL ("CHARSET" "GB2312") NIL NIL NIL 176 NIL NIL NIL', + expected: [ { type: null, + params: null, + disposition: null, + language: [ 'CHARSET', 'GB2312' ], + location: null, + extensions: null + } + ], + what: 'Issue 477' + }, { source: '"TEXT" "PLAIN" ("CHARSET" "US-ASCII") NIL NIL "7BIT" 3028 92', expected: [ { partID: '1', type: 'text',