# tempo-email-parser

> Processes HTML email for display. Extracts quotations and more.

Latest version **0.7.7** (published 2021-09-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install tempo-email-parser
pnpm add tempo-email-parser
yarn add tempo-email-parser
bun add tempo-email-parser
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.7 |
| Published | 2021-09-29 |
| First published | 2021-09-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 53.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 137 |
| Maintainers | soreine |

## Links

- npm: https://www.npmjs.com/package/tempo-email-parser
- Repository: https://github.com/yourtempo/tempo-email-parser
- Homepage: https://github.com/yourtempo/tempo-email-parser#readme
- Issues: https://github.com/yourtempo/tempo-email-parser/issues
- npm.io page: https://npm.io/package/tempo-email-parser

## Dependencies (7)

- [regx](https://npm.io/package/regx.md) ^1.0.4
- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0-rc.3
- [autolinker](https://npm.io/package/autolinker.md) ^3.11.1
- [htmlparser2](https://npm.io/package/htmlparser2.md) ^6.0.1
- [@types/cheerio](https://npm.io/package/@types/cheerio.md) ^0.22.15
- [email-validator](https://npm.io/package/email-validator.md) ^2.0.4
- [is-valid-domain](https://npm.io/package/is-valid-domain.md) ^0.0.20

## Recent versions

- 0.7.7 (latest) — 2021-09-29
- 0.7.6 — 2021-09-22
- 0.7.5 — 2021-09-21

## README

# tempo-email-parser

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 inside a browser or Electron iframe for example.

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

## Usage

```ts
import prepareMessage, {
	blockRemoteContent,
	linkify,
} from 'tempo-email-parser';

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.

```js
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.

### Benchmarks

There are benchmarks to ensure the tool remains fast to not alter UI performance, and also to compare some external libraries. See the `benchmark` folder.

---
_Source: https://npm.io/package/tempo-email-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
