From 27d2ae8c8d54feec9683d08230631ec8e2235353 Mon Sep 17 00:00:00 2001 From: Brian White Date: Mon, 23 Jul 2012 08:39:02 -0400 Subject: [PATCH] Save message part's disposition type where available Closes #59 Thanks @asutherland --- lib/imap.parsers.js | 19 ++++++--- test/test-parse-fetch.js | 83 +++++++++++++++++++++++----------------- 2 files changed, 60 insertions(+), 42 deletions(-) diff --git a/lib/imap.parsers.js b/lib/imap.parsers.js index b942512..25099a1 100644 --- a/lib/imap.parsers.js +++ b/lib/imap.parsers.js @@ -202,15 +202,22 @@ exports.parseStructExtra = function(part, partLen, cur, next) { // e.g.: ['Foo', null] // ['Foo', ['Bar', 'Baz']] // ['Foo', ['Bar', 'Baz', 'Bam', 'Pow']] + var disposition = { type: null, params: null }; if (Array.isArray(cur[next])) { - part.disposition = {}; + disposition.type = cur[next][0]; if (Array.isArray(cur[next][1])) { + disposition.params = {}; for (var i=0,len=cur[next][1].length; i next) { diff --git a/test/test-parse-fetch.js b/test/test-parse-fetch.js index 3e9770a..0f9586d 100644 --- a/test/test-parse-fetch.js +++ b/test/test-parse-fetch.js @@ -53,6 +53,49 @@ var tests = { } ], + ['BODYSTRUCTURE (("text" "plain" ("charset" "us-ascii") NIL NIL "quoted-printable" 370 19 NIL NIL NIL NIL)("application" "pdf" ("x-mac-hide-extension" "yes" "x-unix-mode" "0644" "name" "filename.pdf") NIL NIL "base64" 2067794 NIL ("inline" ("filename" "filename.pdf")) NIL NIL) "mixed" ("boundary" "Apple-Mail=_801866EE-56A0-4F30-8DB3-2496094971D1") NIL NIL NIL)', + { structure: + [ { type: 'mixed', + params: { boundary: 'Apple-Mail=_801866EE-56A0-4F30-8DB3-2496094971D1' }, + + disposition: null, + language: null, + location: null + }, + [ { partID: '1', + type: 'text', + subtype: 'plain', + params: { charset: 'us-ascii' }, + id: null, + description: null, + encoding: 'quoted-printable', + size: 370, + lines: 19, + md5: null, + disposition: null, + language: null, + location: null + } ], + [ { partID: '2', + type: 'application', + subtype: 'pdf', + params: + { 'x-mac-hide-extension': 'yes', + 'x-unix-mode': '0644', + name: 'filename.pdf' }, + id: null, + description: null, + encoding: 'base64', + size: 2067794, + md5: null, + disposition: { type: 'inline', params: { filename: 'filename.pdf' } }, + language: null, + location: null + } ] + ] + } + ], + ['BODYSTRUCTURE (("TEXT" "PLAIN" ("CHARSET" "utf-8") NIL NIL "7BIT" 266 16 NIL ("INLINE" NIL) NIL)("TEXT" "HTML" ("CHARSET" "utf-8") NIL NIL "7BIT" 7343 65 NIL ("INLINE" NIL) NIL) "ALTERNATIVE" ("BOUNDARY" "--4c81da7e1fb95-MultiPart-Mime-Boundary") NIL NIL)', { structure: [ { type: 'alternative', @@ -70,7 +113,7 @@ var tests = { size: 266, lines: 16, md5: null, - disposition: { INLINE: null }, + disposition: { type: 'INLINE', params: null }, language: null } ], [ { partID: '2', @@ -83,7 +126,7 @@ var tests = { size: 7343, lines: 65, md5: null, - disposition: { INLINE: null }, + disposition: { type: 'INLINE', params: null }, language: null } ] ] @@ -175,51 +218,19 @@ var tests = { encoding: 'BASE64', size: 98, md5: null, - disposition: { filename: 'license' }, + disposition: { type: 'ATTACHMENT', params: { filename: 'license' } }, language: null } ] ] } ] - ], - - literals: [ - ['BODY[HEADER]', - 'Date: Wed, 17 Jul 1996 02:23:25 -0700 (PDT)\r\n\ -From: Terry Gray \r\n\ -Subject: IMAP4rev1 WG mtg summary and minutes\r\n\ -To: imap@cac.washington.edu\r\n\ -cc: minutes@CNRI.Reston.VA.US, John Klensin \r\n\ -Message-Id: \r\n\ -MIME-Version: 1.0\r\n\ -Content-Type: TEXT/PLAIN; CHARSET=US-ASCII\r\n\ -\r\n', - { headers: - { date: [ 'Wed, 17 Jul 1996 02:23:25 -0700 (PDT)' ], - from: [ 'Terry Gray ' ], - subject: [ 'IMAP4rev1 WG mtg summary and minutes' ], - to: [ 'imap@cac.washington.edu' ], - cc: [ 'minutes@CNRI.Reston.VA.US, John Klensin ' ], - 'message-id': [ '' ], - 'mime-version': [ '1.0' ], - 'content-type': [ 'TEXT/PLAIN; CHARSET=US-ASCII' ] - } - } - ] ] - }; var result; for (var i=0,len=tests.simple.length; i