jhermsmeier/node-envelope

erroneous parsing of from field

Opened this issue · 2 comments

raw email:
From: "Almaifd, Tim" <T.Almaifd@redacted.com>

return:

from:
   [ { address: '"Almaifd', name: null },
     { address: 'T.Almaifd@redacted.com', name: ' Tim"' } ],

should be:

from: { address: 'T.Almaifd@redacted.com', name: 'Almaifd, Tim' },

I see the spec defines this field at https://tools.ietf.org/html/rfc5322#section-3.6.2 with the mailbox-list rule and its derivatives at https://tools.ietf.org/html/rfc5322#section-3.4 . Unless you were planning on hand-coding a parser for this, might you wish to use pegjs? It can be fairly easily to just define the grammar and get a parser built for it.

I should note that this module was never really intended to be strictly standards-compliant (for that, it's probably better to use https://github.com/ronomon/mime, for example) – I just built it to process large batches of emails (that have been through validating systems previously) fairly quickly.

I am open to the idea to turn Envelope into a standards-compliant MIME message decoder / encoder though, and I guess the people using this module wouldn't mind that either :)

Unless you were planning on hand-coding a parser for this, might you wish to use pegjs? It can be fairly easily to just define the grammar and get a parser built for it.

I would indeed hand-roll parsers for these things, parser-generators (like pegjs) are too much cruft & overhead in these cases.