Socket
Socket
Sign inDemoInstall

tempo-message-splitter

Package Overview
Dependencies
19
Maintainers
4
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tempo-message-splitter

Processes HTML email for display. Extracts quotations and more.


Version published
Maintainers
4
Install size
8.21 MB
Created

Changelog

Source

[0.7.5] - 2021-03-30

  • #31 Automatically fix emails with a broken <head>.

Readme

Source

tempo-message-splitter

Parse and extract main message from an HTML email. Also runs several transformations to the email so that it can be displayed safely and correctly.

  • Extract quotations (replies), signatures
  • Remove scripts, trackers
  • Convert text links into anchor tags
  • Remove trailing whitespaces
  • Block remote content

Usage

import prepareMessage, {
	blockRemoteContent,
	linkify,
} from 'tempo-message-splitter';

const emailHtml = `
<div>Hello there</div>
`;

const remoteContentReplacements = {
	image: 'replacement-image-url', // Remote image URLs replacement. Default to 1x100 transparent image
	other: '#', // Other URLs replacements
};

// All options default to false.
const OPTIONS = {
	noQuotations: true,
	autolink: true,
	forceViewport: '<meta name="viewport" content="width=device-width" />',
	noRemoteContent: true,
	remoteContentReplacements,
	includeStyle: `
		.custom-style {
			color: red;
		}
	`,
};

const {
	// The extracted message
	messageHtml,
	// The whole message processed, including quotations and signature
	completeHtml,
	// Did we removed quotes or signature
	didFindQuotation,
} = prepareMessage(emailHtml, OPTIONS);

Autolinking and remote-content blocking are available as separate functions as well.

const withLinks = linkify(messageHtml);

const noRemoteContent = blockRemoteContent(
	messageHtml,
	remoteContentReplacements
);

Development

For tests

yarn run test

The main function prepareMessage has a list of fixtures used for tests. The input HTML are files named xxx.input.html. The expected outputs are named xxx.output-complete.html and xxx.output-message.html.

yarn run generate:fixtures

This script generates the respective outputs files for any .input.html file found without corresponding outputs.

To easily add a fixture from a real-world email, you can put the input HTML at /src/tests/prepareMessage/my-test.input.html, and then run yarn run generate:fixtures to generate the output files based on what prepareMessage produced. You now only have to check that the outputs look good and make adjustments if necessary.

FAQs

Last updated on 30 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc