imapclient: parse fetch attribute "internaldate" as time.Time instead of keeping it as string

similar to the SAVEDATE fetch attribute implemented recently.
This commit is contained in:
Mechiel Lukkien 2025-02-19 23:01:23 +01:00
parent 02c4715724
commit 6ed97469b7
No known key found for this signature in database
3 changed files with 9 additions and 3 deletions

View File

@ -688,7 +688,10 @@ func (c *Conn) xmsgatt1() FetchAttr {
case "INTERNALDATE": case "INTERNALDATE":
c.xspace() 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": case "SAVEDATE":
c.xspace() c.xspace()

View File

@ -455,7 +455,10 @@ type Address struct {
} }
// "INTERNALDATE" fetch response. // "INTERNALDATE" fetch response.
type FetchInternalDate string // todo: parsed time type FetchInternalDate struct {
Date time.Time
}
func (f FetchInternalDate) Attr() string { return "INTERNALDATE" } func (f FetchInternalDate) Attr() string { return "INTERNALDATE" }
// "SAVEDATE" fetch response. ../rfc/8514:265 // "SAVEDATE" fetch response. ../rfc/8514:265

View File

@ -23,7 +23,7 @@ func TestFetch(t *testing.T) {
tc.client.Select("inbox") tc.client.Select("inbox")
uid1 := imapclient.FetchUID(1) uid1 := imapclient.FetchUID(1)
date1 := imapclient.FetchInternalDate("16-Nov-2022 10:01:00 +0100") date1 := imapclient.FetchInternalDate{received}
rfcsize1 := imapclient.FetchRFC822Size(len(exampleMsg)) rfcsize1 := imapclient.FetchRFC822Size(len(exampleMsg))
env1 := imapclient.FetchEnvelope{ env1 := imapclient.FetchEnvelope{
Date: "Mon, 7 Feb 1994 21:52:25 -0800", Date: "Mon, 7 Feb 1994 21:52:25 -0800",