The best way to parse dates from email

I am currently developing an application that can parse dates from email - like times and dates from email (similar to gmail).

I am currently doing this in php, but it is a little clunky.

What's the best language to do this and are there open source solutions out there?

+2


a source to share


3 answers


I think PHP is as capable as any other language. Can we see the code you are using so we can suggest improvements? I would use a regular expression ... you just need a good one that supports a variety of formats.



0


a source


What I am doing in my mail client is retrieving all tokens marked with spaces and then iterating over them with heuristics to decide how to classify each token. For example, if a token has a ":" character in it, then I consider it as a time that should be parsed as ##: ##: ##. If he has. or "-" treats it as a day / month / year combination and you have to decide which one ... can be any number of combinations. If the token starts with a letter (i.e. Isalpha (* string)), you are looking for the name of the month. If it's a number, it could be a day or a year ... decide by length and if you have a pre-existing day or year, etc. If the token starts with "-" or "+" then it is the timezone, parse accordingly.



It seems to work in the field pretty well, my email client has been around for about 10 years or so. My code is C ++, but you can write the same thing in PHP easily, it is not particularly language specific.

0


a source


if you mean the date it was sent (or received), you extract them from the message headers (for example, the "Date:" header) and they have a standard date format, see RFC 2822

Anyway, if you are using javamail (it is now open source) you can get the date sent with

Date sentDate = mail.getSentDate();

      

0


a source







All Articles