nodemailer / mailparser

Decode mime formatted e-mails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

date parsing failure in 3.3.2

msimerson opened this issue · comments

expected

A typical Date header in an email will parse to a corresponding Date() object.

actual

The Date header in an email parses to new Date() (aka, now)

example date header that fails:

Date: Sun, 1 Dec 2013 08:00:17 +0000 (GMT)

more details

The date parsing failure issue goes away when I pin to 3.3.1 or previous.

tbh I was not able to reproduce it with your sample Date header:

const {simpleParser} = require('mailparser');

simpleParser(`From: andris@kreata.ee
To: andris.reinman@gmail.com
Subject: test
Date: Sun, 8 Jan 2017 20:37:44 +0200

Hello world!
`).then(parsed=>console.log(parsed.date));
// -> "2017-01-08T18:37:44.000Z"

In 3.3.2 I switched to use any-date-parser module for date parsing which might have caused these issues you have.

To kind of revert that change but still be able to process these non-standard dates that any-date-parser is able to process I created a new release v3.3.3 where:

  • First regular new Date(datestr) is used
  • If it fails then fallback to anyDateParser.fromString(datestr)
  • If it still fails then fallback to current time

Could you try it if v3.3.3 fixes your issues. And maybe try that test case above to see why it runs on my system but fails on yours?

Yes, 3.3.3 resolves the issue.

This issue surfaced in one of my (alas: private) test suites running in GitHub Actions. It's nothing special, I parse a very standard RFC 822 email Date header. I couldn't repeat it locally until I found the issue was in mailparser 3.3.2. In the open PR, I added a variety of "in the wild" observed email date header formats. Date() seems to do a better job of parsing them than anyDateParser.