nodemailer / mailparser

Decode mime formatted e-mails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I parse individual header values?

aguynamedben opened this issue · comments

Hi, I'm using the Gmail API and getting objects back that look like this: https://developers.google.com/gmail/api/v1/reference/users/messages#resource

The payload.headers field is an array containing

List of headers on this message part. For the top-level message part, representing the entire message payload, it will contain the standard RFC 2822 email headers such as To, From, and Subject.

I'm getting these header values using Google's JavaScript client, but I want to parse the To and From fields correctly. Is there a way I can use mailparser to parse just those values? I looked at the source code and from what I can tell mailparser is kind of all-or-nothing parsing given a mime formatted email.

Thanks for your help, this library look really helpful and well done.

You can parse messages with headers only.

const {simpleParser} = require('mailparser');
simpleParser(`From: user@example.com
Subject: hello world`).then(parsed=>{
    console.log(parsed);
});