Gathering detailed insights and metrics for basic-postal-mime
Gathering detailed insights and metrics for basic-postal-mime
Gathering detailed insights and metrics for basic-postal-mime
Gathering detailed insights and metrics for basic-postal-mime
Email parser for browser and serverless environments
npm install basic-postal-mime
Typescript
Module System
Node Version
NPM Version
JavaScript (94.16%)
HTML (5.5%)
CSS (0.34%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
107 Commits
1 Branches
1 Contributors
Updated on Aug 19, 2024
Latest Version
2.2.7-a
Package Id
basic-postal-mime@2.2.7-a
Unpacked Size
136.81 kB
Size
32.04 kB
File Count
18
NPM Version
8.11.0
Node Version
16.15.1
Published on
Aug 19, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
6
Email parser for browser and serverless environments.
PostalMime can be run in the main web thread or from Web Workers. It can also be used in serverless functions.
[!TIP] PostalMime is developed by the makers of EmailEngine – a self-hosted email gateway that allows making REST requests against IMAP and SMTP servers. EmailEngine also sends webhooks whenever something changes on the registered accounts.
The source code is available on GitHub.
See this example.
First, install the module from npm:
$ npm install postal-mime
Next, import the PostalMime class into your script:
1import PostalMime from './node_modules/postal-mime/src/postal-mime.js';
Or when using it from a Node.js app or in a serverless function:
1import PostalMime from 'postal-mime';
PostalMime methods use Promises, so you need to wait using await
or the then()
method to get the response.
1import PostalMime from './node_modules/postal-mime/src/postal-mime.js'; 2 3const email = await PostalMime.parse(`Subject: My awesome email 🤓 4Content-Type: text/html; charset=utf-8 5 6<p>Hello world 😵💫</p>`); 7 8console.log(email.subject);
It is pretty much the same as in the browser.
1import PostalMime from 'postal-mime'; 2import util from 'node:util'; 3 4const email = await PostalMime.parse(`Subject: My awesome email 🤓 5Content-Type: text/html; charset=utf-8 6 7<p>Hello world 😵💫</p>`); 8 9console.log(util.inspect(email, false, 22, true));
Pretty much the same as in Node.js. Use message.raw
as the raw message for parsing.
1import PostalMime from 'postal-mime'; 2 3export default { 4 async email(message, env, ctx) { 5 const email = await PostalMime.parse(message.raw); 6 7 console.log('Subject: ', email.subject); 8 console.log('HTML: ', email.html); 9 console.log('Text: ', email.text); 10 } 11};
parse(email, options)
is a static class method used to parse emails.
1PostalMime.parse(email, options) -> Promise
Where:
false
). If set to true
, it treats Message/RFC822
attachments without a Content-Disposition declaration as attachments. By default, these messages are treated as inline values.This method parses an email message into a structured object with the following properties:
"dkim-signature"
.null
if disposition was not provided.Parse email address strings.
1addressParser(addressStr, opts) -> Array
Where:
true
, it ignores address groups and returns a flat array of addresses. By default (flatten
is false
), the result might include nested groups.The result is an array of objects:
flatten
is false
(the default) and the address string contains address group syntax.1import { addressParser } from 'postal-mime'; 2 3const addressStr = '=?utf-8?B?44Ko44Od44K544Kr44O844OJ?= <support@example.com>'; 4console.log(addressParser(addressStr)); 5// [ { name: 'エポスカード', address: 'support@example.com' } ]
Decode MIME encoded-words.
1decodeWords(encodedStr) -> String
Where:
The result is a Unicode string.
1import { decodeWords } from 'postal-mime'; 2 3const encodedStr = 'Hello, =?utf-8?B?44Ko44Od44K544Kr44O844OJ?='; 4console.log(decodeWords(encodedStr)); 5// Hello, エポスカード
© 2021-2024 Andris Reinman
postal-mime
is licensed under the MIT No Attribution license
No vulnerabilities found.
No security vulnerabilities found.