mikedilger / email-format

Email data structure and builder for streaming emails
Apache License 2.0
17 stars 5 forks source link

Parsing a RFC2822 date from Chrono #20

Closed eminence closed 7 years ago

eminence commented 7 years ago

Chrono's to_rfc2822 method will return a date string like the following:

Fri,  8 Sep 2017 20:46:39 +0000

This is unparseable by email-format, seemingly because the single digit (8) for the day-of-month:

thread 'main' panicked at 'called Result::unwrap() on an Err value: "DateTime" Not Found', src\libcore\result.rs:906:4

I've been reading RFC2822, and do be honest I can't tell if a single-digit field is allowed. Do you think this is a email-format parsing problem? Or a Chrono formatting problem?

eminence commented 7 years ago

After a little more research, the day field is defined as (via RFC2822 section 3.3):

day             =   ([FWS] 1*2DIGIT FWS) / obs-day

I had to look up this notational format in RFC 2234 to find that it means this:

The operator "*" preceding an element indicates repetition. The full
   form is:

        <a>*<b>element

   where <a> and <b> are optional decimal values, indicating at least
   <a> and at most <b> occurrences of element.

So RFC2822 (and RFC5322) allow for a single-digit date.

mikedilger commented 7 years ago

Aha! I was reading that ABNF as if 2DIGIT was a single token, and so there could be only a single 2DIGIT. I will make the change.

eminence commented 7 years ago

I just put together a quick PR for this issue, if you want it