Skip to content

Date Issue #12

Description

@s2young

Love your module and have been using it for a while. In my app, very rarely, I have noticed messages come in sorted lower in date order than they should be.

I just received an email at 8am this morning, for example, but the parser gave it a timestamp of Friday night. I pulled the raw gmail api data for this email and noticed the 'x-received' header had the date I wanted - the date we actually received the email.

My suspicion is the sender drafted the email friday night, but hit Send on Monday morning. I threw together a crude bit of code to pull the date out of the 'x-received' header:

NOTE: this uses the parse method from the date-fns module.


let re: RegExp = new RegExp('(Mon|Tue|Wed|Thu|Fri|Sat|Sun)([^\(]*)\\(');
let matches: any[] = parsedMsg.headers['x-received'].match(re);
if (matches?.length) {
    let d: Date = parse(matches[0], 'EEE\, d LLL yyyy hh\:mm\:ss XX \(', new Date());
    if (d.toString() !== 'Invalid Date') {
        timestamp = d.valueOf();
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions