mirror of
https://github.com/mjl-/mox.git
synced 2025-01-14 01:06:27 +03:00
when a message contains a date that we cannon marhsal to json, adjust the date
found a message with a 24 hour time zone offset, which Go's json package cannot marshal. in that case, we adjust the date to utc.
This commit is contained in:
parent
5817e87a32
commit
7facf9d446
2 changed files with 13 additions and 0 deletions
|
@ -356,6 +356,18 @@ func parseHeader(r io.Reader) (textproto.MIMEHeader, error) {
|
||||||
|
|
||||||
func parseEnvelope(h mail.Header) (*Envelope, error) {
|
func parseEnvelope(h mail.Header) (*Envelope, error) {
|
||||||
date, _ := h.Date()
|
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{
|
env := &Envelope{
|
||||||
date,
|
date,
|
||||||
h.Get("Subject"),
|
h.Get("Subject"),
|
||||||
|
|
|
@ -300,6 +300,7 @@ type Message struct {
|
||||||
// ParsedBuf message structure. Currently saved as JSON of message.Part because bstore
|
// 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
|
// cannot yet store recursive types. Created when first needed, and saved in the
|
||||||
// database.
|
// database.
|
||||||
|
// todo: once replaced with non-json storage, remove date fixup in ../message/part.go.
|
||||||
ParsedBuf []byte
|
ParsedBuf []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue