From 3fb0b13a790b5374ebdb362b46040c820cf37bd9 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Tue, 25 Sep 2018 11:01:56 +0300 Subject: [PATCH] index List-ID headers --- lib/message-handler.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/message-handler.js b/lib/message-handler.js index b4b86b0c..aca5611d 100644 --- a/lib/message-handler.js +++ b/lib/message-handler.js @@ -14,7 +14,7 @@ const openpgp = require('openpgp'); const parseDate = require('../imap-core/lib/parse-date'); // 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', 'list-id']; openpgp.config.commentstring = 'Plaintext message encrypted by WildDuck Mail Server'; @@ -1218,6 +1218,18 @@ class MessageHandler { // store indexed value as lowercase for easier SEARCHing value = value.toLowerCase(); + switch (key) { + case 'list-id': + // only index the actual ID of the list + if (value.indexOf('<') >= 0) { + let m = value.match(/<([^>]+)/); + if (m && m[1] && m[1].trim()) { + value = m[1].trim(); + } + } + break; + } + // trim long values as mongodb indexed fields can not be too long if (Buffer.byteLength(key, 'utf-8') >= 255) { key = Buffer.from(key)