Skip to content

transitive-bullshit/parse-email

Folders and files

NameName
Last commit message
Last commit date

Latest commit

904ce73 Β· Jul 11, 2020

History

7 Commits
May 9, 2018
May 9, 2018
May 9, 2018
May 9, 2018
May 9, 2018
May 9, 2018
May 9, 2018
Jul 11, 2020
Jul 11, 2020
Jul 11, 2020
Jul 11, 2020
May 9, 2018

Repository files navigation

parse-email

Parses mime-encoded email messages.

NPM Build Status JavaScript Style Guide

Install

npm install --save parse-email

Usage

const parse = require('parse-email')
const fs = require('fs')
const input = fs.readFileSync('./fixtures/0.txt', 'utf8')

parse(input)
  .then((email) => {
    console.log(email)
  })

Example parsed output:

{
  "attachments": [ ... ],
  "headers": { ... },
  "html": "<!DOCTYPE html>\n<html>...</html>",
  "text": "...",
  "textAsHtml": "<p>...</p>",
  "subject": "Example email subject",
  "date": "2018-05-09T14:17:02.000Z",
  "to": {
    "value": [
      {
        "address": "[email protected]",
        "name": "Travis Fischer"
      }
    ],
    "html": "<span class=\"mp_address_name\">Travis Fischer</span> &lt;<a href=\"mailto:[email protected]\" class=\"mp_address_email\">[email protected]</a>&gt;",
    "text": "Travis Fischer <[email protected]>"
  },
  "from": {
    "value": [
      {
        "address": "[email protected]",
        "name": "Bryant Nielson"
      }
    ],
    "html": "<span class=\"mp_address_name\">Bryant Nielson</span> &lt;<a href=\"mailto:[email protected]\" class=\"mp_address_email\">[email protected]</a>&gt;",
    "text": "Bryant Nielson <[email protected]>"
  },
  "messageId": "<01.B3.11399.xxxxxxxx@momentum1-mta1>"
}

API

parse(input)

Returns: Promise<Object>

Parses the given input string as a mime-encoded email.

input

Type: String Required

Mime-encoded email string to parse.

Related

License

Note: this module relies on @nodemailer/mailparser2 which has a more restrictive license.

MIT Β© Travis Fischer

Support my OSS work by following me on twitter twitter