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

@protontech/mimemessage

v1.1.4

Published

MIME messages for JavaScript (RFC 2045 & 2046)

Downloads

1,329

Readme

mimemessage.js

MIME messages for JavaScript (RFC 2045 & 2046).

Suitable for parsing and generating MIME messages, allowing access to headers and body, including multipart messages such as:

From: Nathaniel Borenstein <[email protected]>
To: Ned Freed <[email protected]>
Date: Sun, 21 Mar 1993 23:56:48 -0800 (PST)
Subject: Sample message
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="simple boundary"

--simple boundary

This is implicitly typed plain US-ASCII text.
It does NOT end with a linebreak.
--simple boundary
Content-type: text/plain; charset=us-ascii

This is explicitly typed plain US-ASCII text.
It DOES end with a linebreak.

--simple boundary--

NOTE: This library is not intended for mail parsing (there are tons of MIME related Node libraries for that). In fact, it does not deal with encodings different that UTF-8. The purpose of this library is to be used in pure browser/Node environments in which MIME messages are useful to transmit data.

Installation

npm:

$ npm install mimemessage --save

And then:

var mimemessage = require('mimemessage');

Browserified library

The browserified version of the library at dist/mimemessage.js exposes the global window.mimemessage module.

<script type='text/javascript' src='js/mimemessage.js'></script>

Usage Example

Let's build a complex multipart MIME message with the following content:

  • An HTML body.
  • An alternate plain text for those non HTML capable clients.
  • An attached PNG image named "mypicture.png" encoded in Base64.
var mimemessage = require('mimemessage');
var msg, alternateEntity, htmlEntity, plainEntity, pngEntity;

// Build the top-level multipart MIME message.
msg = mimemessage.factory({
    contentType: 'multipart/mixed',
    body: []
});
msg.header('Message-ID', '<1234qwerty>');

// Build the multipart/alternate MIME entity containing both the HTML and plain text entities.
alternateEntity = mimemessage.factory({
    contentType: 'multipart/alternate',
    body: []
});

// Build the HTML MIME entity.
htmlEntity = mimemessage.factory({
    contentType: 'text/html;charset=utf-8',
    body: '<p>This is the <strong>HTML</strong> version of the message.</p>'
});

// Build the plain text MIME entity.
plainEntity = mimemessage.factory({
    body: 'This is the plain text version of the message.'
});

// Build the PNG MIME entity.
pngEntity = mimemessage.factory({
    contentType: 'image/png',
    contentTransferEncoding: 'base64',
    body: 'fVkVvYassFAAAABQAAAAIAAAAbWltZXR5cG=='
});
pngEntity.header('Content-Disposition', 'attachment ;filename="mypicture.png"');

// Add both the HTML and plain text entities to the multipart/alternate entity.
alternateEntity.body.push(htmlEntity);
alternateEntity.body.push(plainEntity);

// Add the multipart/alternate entity to the top-level MIME message.
msg.body.push(alternateEntity);

// Add the PNG entity to the top-level MIME message.
msg.body.push(pngEntity);

By calling msg.toString() it produces the following MIME formatted string:

Content-Type: multipart/mixed;boundary=92ckNGfS
Message-Id: <1234qwerty>

--92ckNGfS
Content-Type: multipart/alternate;boundary=EVGuDPPT

--EVGuDPPT
Content-Type: text/html;charset=utf-8

<p>This is the <strong>HTML</strong> version of the message.</p>
--EVGuDPPT
Content-Type: text/plain;charset=utf-8

This is the plain text version of the message.
--EVGuDPPT--
--92ckNGfS
Content-Type: image/png
Content-Transfer-Encoding: base64
Content-Disposition: attachment ;filename="mypicture.png"

fVkVvYassFAAAABQAAAAIAAAAbWltZXR5cG==
--92ckNGfS--

Documentation

You can read the full API documentation in the docs folder.

Tests

Run once,

$ npm test

Watch mode:

$ npm run test -- -w

Debugging

The library includes the Node debug module. In order to enable debugging:

In Node set the DEBUG=mimemessage* environment variable before running the application, or set it at the top of the script:

process.env.DEBUG = 'mimemessage*';

In the browser run mimemessage.debug.enable('mimemessage*'); and reload the page. Note that the debugging settings are stored into the browser LocalStorage. To disable it run mimemessage.debug.disable('mimemessage*');.

You can also set the envia the console, ex:

DEBUG=mimemessage:* npm run test -- -w

Author

Iñaki Baz Castillo Kay Lukas ProtonMail team

License

MIT :)