diff --git a/message/part.go b/message/part.go index bac7bae..2f26ea0 100644 --- a/message/part.go +++ b/message/part.go @@ -356,6 +356,18 @@ func parseHeader(r io.Reader) (textproto.MIMEHeader, error) { func parseEnvelope(h mail.Header) (*Envelope, error) { date, _ := h.Date() + + // We currently marshal this field to JSON. But JSON cannot represent all + // time.Time. Time zone of 24:00 was seen in the wild. We won't try for extreme + // years, but we can readjust timezones. + // todo: remove this once we no longer store using json. + _, offset := date.Zone() + if date.Year() > 9999 { + date = time.Time{} + } else if offset <= -24*3600 || offset >= 24*3600 { + date = time.Unix(date.Unix(), 0).UTC() + } + env := &Envelope{ date, h.Get("Subject"), diff --git a/store/account.go b/store/account.go index 5b484e9..23b0b14 100644 --- a/store/account.go +++ b/store/account.go @@ -300,6 +300,7 @@ type Message struct { // ParsedBuf message structure. Currently saved as JSON of message.Part because bstore // cannot yet store recursive types. Created when first needed, and saved in the // database. + // todo: once replaced with non-json storage, remove date fixup in ../message/part.go. ParsedBuf []byte }