Skip to content

Commit 6ed9746

Browse files
committed
imapclient: parse fetch attribute "internaldate" as time.Time instead of keeping it as string
similar to the SAVEDATE fetch attribute implemented recently.
1 parent 02c4715 commit 6ed9746

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

imapclient/parse.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,10 @@ func (c *Conn) xmsgatt1() FetchAttr {
688688

689689
case "INTERNALDATE":
690690
c.xspace()
691-
return FetchInternalDate(c.xquoted()) // todo: parsed time
691+
s := c.xquoted()
692+
v, err := time.Parse("_2-Jan-2006 15:04:05 -0700", s)
693+
c.xcheckf(err, "parsing internaldate")
694+
return FetchInternalDate{v}
692695

693696
case "SAVEDATE":
694697
c.xspace()

imapclient/protocol.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ type Address struct {
455455
}
456456

457457
// "INTERNALDATE" fetch response.
458-
type FetchInternalDate string // todo: parsed time
458+
type FetchInternalDate struct {
459+
Date time.Time
460+
}
461+
459462
func (f FetchInternalDate) Attr() string { return "INTERNALDATE" }
460463

461464
// "SAVEDATE" fetch response. ../rfc/8514:265

imapserver/fetch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestFetch(t *testing.T) {
2323
tc.client.Select("inbox")
2424

2525
uid1 := imapclient.FetchUID(1)
26-
date1 := imapclient.FetchInternalDate("16-Nov-2022 10:01:00 +0100")
26+
date1 := imapclient.FetchInternalDate{received}
2727
rfcsize1 := imapclient.FetchRFC822Size(len(exampleMsg))
2828
env1 := imapclient.FetchEnvelope{
2929
Date: "Mon, 7 Feb 1994 21:52:25 -0800",

0 commit comments

Comments
 (0)