From 9ca6ac4cdbec3d57068b490584d53f1755b3cc07 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Mon, 5 Jun 2017 16:40:48 +0300 Subject: [PATCH] v1.0.44 --- lib/message-handler.js | 15 +++++++++------ package.json | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/message-handler.js b/lib/message-handler.js index a8e9cea4..457830e7 100644 --- a/lib/message-handler.js +++ b/lib/message-handler.js @@ -13,6 +13,10 @@ const counters = require('./counters'); // how many modifications to cache before writing const BULK_BATCH_SIZE = 150; const SCHEMA_VERSION = '1.0'; +// how much plaintext to store. this is indexed with a fulltext index +const MAX_PLAINTEXT_CONTENT = 2 * 1024; +// how much HTML content to store. not indexed +const MAX_HTML_CONTENT = 300 * 1024; // index only the following headers for SEARCH const INDEXED_HEADERS = ['to', 'cc', 'subject', 'from', 'sender', 'reply-to', 'message-id', 'thread-index']; @@ -165,11 +169,10 @@ class MessageHandler { message.ha = false; } - let maxTextLength = 300 * 1024; - if (maildata.text) { message.text = maildata.text.replace(/\r\n/g, '\n').trim(); - message.text = message.text.length <= maxTextLength ? message.text : message.text.substr(0, maxTextLength); + // text is indexed with a fulltext index, so only store the beginning of it + message.text = message.text.length <= MAX_PLAINTEXT_CONTENT ? message.text : message.text.substr(0, MAX_PLAINTEXT_CONTENT); message.intro = message.text.replace(/\s+/g, ' ').trim(); if (message.intro.length > 128) { let intro = message.intro.substr(0, 128); @@ -185,16 +188,16 @@ class MessageHandler { let htmlSize = 0; message.html = maildata.html .map(html => { - if (htmlSize >= maxTextLength || !html) { + if (htmlSize >= MAX_HTML_CONTENT || !html) { return ''; } - if (htmlSize + Buffer.byteLength(html) <= maxTextLength) { + if (htmlSize + Buffer.byteLength(html) <= MAX_HTML_CONTENT) { htmlSize += Buffer.byteLength(html); return html; } - html = html.substr(0, htmlSize + Buffer.byteLength(html) - maxTextLength); + html = html.substr(0, htmlSize + Buffer.byteLength(html) - MAX_HTML_CONTENT); htmlSize += Buffer.byteLength(html); return html; }) diff --git a/package.json b/package.json index 73a4cfa7..0ba0f8ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wildduck", - "version": "1.0.43", + "version": "1.0.44", "description": "IMAP server built with Node.js and MongoDB", "main": "server.js", "scripts": {