How to use the mailsplit.Splitter function in mailsplit

To help you get started, we’ve selected a few mailsplit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Helpmonks / haraka-plugin-mongodb / email_body_utility.js View on Github external
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;'
github Criptext / Criptext-Email-React-Client / electron_app / src / ExternalEmailParser.js View on Github external
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);
  });

mailsplit

Split email messages into an object stream

(MIT OR EUPL-1.1+)
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis

Popular mailsplit functions

Similar packages