From 18d4c34f7091603042ca880e0a7bf90223a1e650 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Thu, 6 Apr 2017 16:30:23 +0300 Subject: [PATCH] do not store multipart bodies or zero length bodies as attachments --- imap-core/lib/indexer/indexer.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imap-core/lib/indexer/indexer.js b/imap-core/lib/indexer/indexer.js index 241fb167..4476bdfb 100644 --- a/imap-core/lib/indexer/indexer.js +++ b/imap-core/lib/indexer/indexer.js @@ -302,6 +302,7 @@ class Indexer { let disposition = (parsedDisposition && parsedDisposition.value || '').toLowerCase().trim() || false; let isInlineText = false; + let isMultipart = contentType.split('/')[0] === 'multipart'; // If the current node is HTML or Plaintext then allow larger content included in the mime tree // Also decode text/html value @@ -352,7 +353,7 @@ class Indexer { } // remove attachments and very large text nodes from the mime tree - if (node.body && (!isInlineText || node.size > 300 * 1024)) { + if (!isMultipart && node.body && node.body.length && (!isInlineText || node.size > 300 * 1024)) { let attachmentId = new ObjectID(); let fileName = (node.parsedHeader['content-disposition'] && node.parsedHeader['content-disposition'].params && node.parsedHeader['content-disposition'].params.filename) || (node.parsedHeader['content-type'] && node.parsedHeader['content-type'].params && node.parsedHeader['content-type'].params.name) || false; @@ -393,7 +394,7 @@ class Indexer { }); // do not include text content, multipart elements and embedded messages in the attachment list - if (!isInlineText && contentType.split('/')[0] !== 'multipart' && !(contentType === 'message/rfc822' && (!disposition || disposition === 'inline'))) { + if (!isInlineText && !(contentType === 'message/rfc822' && (!disposition || disposition === 'inline'))) { // list in the attachments array response.attachments.push({ id: attachmentId,