npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@u22n/mailtools

v0.1.2

Published

Processes HTML email for display. Extracts quotations and more. Successor to tempo-email-parser.

Downloads

217

Readme

@u22n/mailtools

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

Features

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

Usage

import { parseMessage } from '@u22n/mailtools';
import type { ParseMessageOptions } from '@u22n/mailtools';

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

const parsedEmail = parseMessage(emailHtml);

Options

// All options default to false.
const parseOptions: ParseMessageOptions = {
  /** Remove quotations. Only affects the result messageHtml */
  cleanQuotations: false,
  /** Remove and return signatures. Only affects the result messageHtml */
  cleanSignatures: false,
  /** Automatically convert text links to anchor tags */
  autolink: false,
  /** Fix broken links and add the href to the title tag */
  enhanceLinks: false,
  /** Specific viewport to enforce. For example "<meta name="viewport" content="width=device-width">" */
  forceViewport: false,
  /** Replace remote images with a transparent image, and replace other remote URLs with '#' */
  noRemoteContent: false,
  /** Replace remote content with custom URLs */
  remoteContentReplacements: {} as ReplacementOptions,
  /** Append the given style to the HTML <head> */
  includeStyle: false,
  /** Remove specific styles that could affect the rendering of the html */
  /** true = remove 'background-color', 'font-family', 'font-size'. */
  /** otherwise pass in an string array of styles to remove */
  cleanStyles: false
};

Outputs

const {
	/** The original complete message. */
  completeHtml: string;
  /** The body of the message, stripped from secondary information */
  parsedMessageHtml: string;
  /** True if a quote was found and stripped */
  didFindQuotation: boolean | null;
  /** True if a signature was found and stripped */
  didFindSignature: boolean | null;
  /** The signature in plain text */
  foundSignaturePlainText: string | null;
  /** The signature in HTML */
  foundSignatureHtml: string | null;
} = parseMessage(emailHtml, parseOptions);

Other

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

const withLinks = linkify(messageHtml);

const noRemoteContent = blockRemoteContent(
  messageHtml,
  remoteContentReplacements
);

Development

Playground

We have included a playground for local testing of functionality and features.

Edit the email html in playground/index.ts and run with pnpm run start.

The output will be logged to the console.

Tests

pnpm run test

The main function parseMessage 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.

pnpm 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 pnpm 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.

History

@u22n/mailtools is a modified and more feature filled version of tempo-email-parser.

We picked up on tempo-email-parser which was not being maintained any more and updated it to modern tooling and dependencies. We are using this package at uninbox.com, everyone is free to use as they want and need.

Limitations

Its nearly impossible to parse every kind of outlook emails. We have implemented some measures to be able to parse them but we are not able to parse certain kind of signatures from them. Its totally impossible for us to parse them with out using some kind of LLM. Thats also might not be accurate.

We have covered major providers like gmail, newer outlook clients, proton mail and a few others.

You can help us improve this package by testing your email clients and signatures at https://tools.unin.sh and report in the built-in feedback system.

License

This package is licensed under the MIT License. Please see the LICENSE file for more information.