Skip to content

Commit

Permalink
if message has html part, use intro from it
Browse files Browse the repository at this point in the history
  • Loading branch information
NickOvt committed Apr 12, 2024
1 parent c846b66 commit 52608f0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const parseDate = require('../imap-core/lib/parse-date');
const log = require('npmlog');
const packageData = require('../package.json');
const { SettingsHandler } = require('./settings-handler');
const { htmlToText } = require('html-to-text');

// index only the following headers for SEARCH
const INDEXED_HEADERS = ['to', 'cc', 'subject', 'from', 'sender', 'reply-to', 'message-id', 'thread-index', 'list-id', 'delivered-to'];
Expand Down Expand Up @@ -360,6 +361,30 @@ class MessageHandler {
return html;
})
.filter(html => html);

messageData.intro = htmlToText(messageData.html.join(''))
// assume we get the intro text from first 2 kB
.substr(0, 2 * 1024)
// remove markdown urls
.replace(/\[[^\]]*\]/g, ' ')
// remove quoted parts
// "> quote from previous message"
.replace(/^>.*$/gm, '')
// remove lines with repetetive chars
// "---------------------"
.replace(/^\s*(.)\1+\s*$/gm, '')
// join lines
.replace(/\s+/g, ' ')
.trim();

if (messageData.intro.length > 128) {
let intro = messageData.intro.substr(0, 128);
let lastSp = intro.lastIndexOf(' ');
if (lastSp > 0) {
intro = intro.substr(0, lastSp);
}
messageData.intro = intro + '…';
}
}

this.users.collection('users').findOneAndUpdate(
Expand Down

0 comments on commit 52608f0

Please sign in to comment.