Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const _getRfc822HtmlAndTextBody = function(body, callback) {
var rfc_body_info = { 'html' : '', 'text' : '' };
var rfc_822_node = _getFirstNodeOfType(body, 'message/rfc822');
let splitter = new Splitter();
// handle parsed data
splitter.on('data', data => {
switch (data.type) {
case 'node':
var headers = data.getHeaders().toString('utf8').split(' ');
var content_type_index = headers.indexOf('Content-Type:');
// if we have a content_type, then the next index is the value
var content_type = content_type_index > -1 ? headers[content_type_index+1] : null;
// if we've encountered either content type, set it to collect the result
collect_html = content_type === 'text/html;'
collect_text = content_type === 'text/plain;'
const getHeadersFromEmailFile = pathtoemail => {
const Splitter = require('mailsplit').Splitter;
const splitter = new Splitter();
const emailFileStream = fs.createReadStream(pathtoemail);
let headers;
let isFirst = true;
return new Promise(resolve => {
splitter.on('data', data => {
if (data.type === 'node' && isFirst) {
headers = `${data.getHeaders()}`;
isFirst = false;
}
});
splitter.on('error', () =>
resolve({ error: true, message: `Failed to split file: ${pathtoemail}` })
);
splitter.on('end', () => resolve({ error: false, message: headers }));
emailFileStream.pipe(splitter);
});