This commit is contained in:
Andris Reinman 2017-06-05 16:40:48 +03:00
parent fbdbc404c5
commit 9ca6ac4cdb
2 changed files with 10 additions and 7 deletions

View file

@ -13,6 +13,10 @@ const counters = require('./counters');
// how many modifications to cache before writing // how many modifications to cache before writing
const BULK_BATCH_SIZE = 150; const BULK_BATCH_SIZE = 150;
const SCHEMA_VERSION = '1.0'; 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 // index only the following headers for SEARCH
const INDEXED_HEADERS = ['to', 'cc', 'subject', 'from', 'sender', 'reply-to', 'message-id', 'thread-index']; const INDEXED_HEADERS = ['to', 'cc', 'subject', 'from', 'sender', 'reply-to', 'message-id', 'thread-index'];
@ -165,11 +169,10 @@ class MessageHandler {
message.ha = false; message.ha = false;
} }
let maxTextLength = 300 * 1024;
if (maildata.text) { if (maildata.text) {
message.text = maildata.text.replace(/\r\n/g, '\n').trim(); 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(); message.intro = message.text.replace(/\s+/g, ' ').trim();
if (message.intro.length > 128) { if (message.intro.length > 128) {
let intro = message.intro.substr(0, 128); let intro = message.intro.substr(0, 128);
@ -185,16 +188,16 @@ class MessageHandler {
let htmlSize = 0; let htmlSize = 0;
message.html = maildata.html message.html = maildata.html
.map(html => { .map(html => {
if (htmlSize >= maxTextLength || !html) { if (htmlSize >= MAX_HTML_CONTENT || !html) {
return ''; return '';
} }
if (htmlSize + Buffer.byteLength(html) <= maxTextLength) { if (htmlSize + Buffer.byteLength(html) <= MAX_HTML_CONTENT) {
htmlSize += Buffer.byteLength(html); htmlSize += Buffer.byteLength(html);
return 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); htmlSize += Buffer.byteLength(html);
return html; return html;
}) })

View file

@ -1,6 +1,6 @@
{ {
"name": "wildduck", "name": "wildduck",
"version": "1.0.43", "version": "1.0.44",
"description": "IMAP server built with Node.js and MongoDB", "description": "IMAP server built with Node.js and MongoDB",
"main": "server.js", "main": "server.js",
"scripts": { "scripts": {