From 6ed97469b76fbc34a53c0819f21e0203bcf2cc42 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Wed, 19 Feb 2025 23:01:23 +0100 Subject: [PATCH] imapclient: parse fetch attribute "internaldate" as time.Time instead of keeping it as string similar to the SAVEDATE fetch attribute implemented recently. --- imapclient/parse.go | 5 ++++- imapclient/protocol.go | 5 ++++- imapserver/fetch_test.go | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/imapclient/parse.go b/imapclient/parse.go index 2ff069f..f7e37f3 100644 --- a/imapclient/parse.go +++ b/imapclient/parse.go @@ -688,7 +688,10 @@ func (c *Conn) xmsgatt1() FetchAttr { case "INTERNALDATE": c.xspace() - return FetchInternalDate(c.xquoted()) // todo: parsed time + s := c.xquoted() + v, err := time.Parse("_2-Jan-2006 15:04:05 -0700", s) + c.xcheckf(err, "parsing internaldate") + return FetchInternalDate{v} case "SAVEDATE": c.xspace() diff --git a/imapclient/protocol.go b/imapclient/protocol.go index 58ce3d9..55ecb60 100644 --- a/imapclient/protocol.go +++ b/imapclient/protocol.go @@ -455,7 +455,10 @@ type Address struct { } // "INTERNALDATE" fetch response. -type FetchInternalDate string // todo: parsed time +type FetchInternalDate struct { + Date time.Time +} + func (f FetchInternalDate) Attr() string { return "INTERNALDATE" } // "SAVEDATE" fetch response. ../rfc/8514:265 diff --git a/imapserver/fetch_test.go b/imapserver/fetch_test.go index 732b463..6f5b52a 100644 --- a/imapserver/fetch_test.go +++ b/imapserver/fetch_test.go @@ -23,7 +23,7 @@ func TestFetch(t *testing.T) { tc.client.Select("inbox") uid1 := imapclient.FetchUID(1) - date1 := imapclient.FetchInternalDate("16-Nov-2022 10:01:00 +0100") + date1 := imapclient.FetchInternalDate{received} rfcsize1 := imapclient.FetchRFC822Size(len(exampleMsg)) env1 := imapclient.FetchEnvelope{ Date: "Mon, 7 Feb 1994 21:52:25 -0800",