mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-13 03:29:46 +08:00
dce872fac8
- Bunyan logs json output, and added a stream to send our logs to cloudwatch - Replaces /all/ instances of console.log. Turned eslint rule back on, so we don't use console.log ever again. - Added npm scripts to view pretty logs
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
const mimelib = require('mimelib');
|
|
const SNIPPET_SIZE = 100
|
|
|
|
function Contact({name, address} = {}) {
|
|
return {
|
|
name,
|
|
email: address,
|
|
}
|
|
}
|
|
|
|
const extractContacts = (values) =>
|
|
(values || []).map(v => Contact(mimelib.parseAddresses(v).pop()))
|
|
|
|
function processMessage({message, logger}) {
|
|
if (message.snippet) {
|
|
// trim and clean snippet which is alreay present (from message plaintext)
|
|
message.snippet = message.snippet.replace(/[\n\r]/g, ' ').replace(/\s\s+/g, ' ')
|
|
const loc = message.snippet.indexOf(' ', SNIPPET_SIZE);
|
|
if (loc !== -1) {
|
|
message.snippet = message.snippet.substr(0, loc);
|
|
}
|
|
} else if (message.body) {
|
|
// create snippet from body, which is most likely html
|
|
// TODO: Fanciness
|
|
message.snippet = message.body.substr(0, Math.min(message.body.length, SNIPPET_SIZE));
|
|
} else {
|
|
logger.info("MessageProcessor: Parsing - Received message has no body or snippet.")
|
|
}
|
|
|
|
message.to = extractContacts(message.headers.to);
|
|
message.cc = extractContacts(message.headers.cc);
|
|
message.bcc = extractContacts(message.headers.bcc);
|
|
message.from = extractContacts(message.headers.from);
|
|
message.replyTo = extractContacts(message.headers['reply-to']);
|
|
|
|
return Promise.resolve(message);
|
|
}
|
|
|
|
module.exports = {
|
|
order: 0,
|
|
processMessage,
|
|
}
|