Skip to content

Commit

Permalink
Merge branch 'EdwinLove-fix-time'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dusan Kasan authored and Dusan Kasan committed Apr 4, 2020
2 parents 28dfb22 + 88226cf commit 2d77617
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
15 changes: 11 additions & 4 deletions parsemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,19 @@ func (hp headerParser) parseTime(s string) (t time.Time) {
return
}

t, hp.err = time.Parse(time.RFC1123Z, s)
if hp.err == nil {
return t
formats := []string{
time.RFC1123Z,
"Mon, 2 Jan 2006 15:04:05 -0700",
time.RFC1123Z + " (MST)",
"Mon, 2 Jan 2006 15:04:05 -0700 (MST)",
}

t, hp.err = time.Parse("Mon, 2 Jan 2006 15:04:05 -0700", s)
for _, format := range formats {
t, hp.err = time.Parse(format, s)
if hp.err == nil {
return
}
}

return
}
Expand Down
46 changes: 46 additions & 0 deletions parsemail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,42 @@ So, "Hello".`,
date: parseDate("Fri, 02 May 2019 11:25:35 +0300"),
textBody: `plain text part`,
},
10: {
mailData: rfc5322exampleA12WithTimezone,
from: []mail.Address{
{
Name: "Joe Q. Public",
Address: "[email protected]",
},
},
to: []mail.Address{
{
Name: "Mary Smith",
Address: "[email protected]",
},
{
Name: "",
Address: "[email protected]",
},
{
Name: "Who?",
Address: "[email protected]",
},
},
cc: []mail.Address{
{
Name: "",
Address: "[email protected]",
},
{
Name: "Giant; \"Big\" Box",
Address: "[email protected]",
},
},
messageID: "[email protected]",
date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"),
textBody: `Hi everyone.`,
},
}

for index, td := range testData {
Expand Down Expand Up @@ -678,6 +714,16 @@ Message-ID: <[email protected]>
Hi everyone.
`

var rfc5322exampleA12WithTimezone = `From: "Joe Q. Public" <[email protected]>
To: Mary Smith <[email protected]>, [email protected], Who? <[email protected]>
Cc: <[email protected]>, "Giant; \"Big\" Box" <[email protected]>
Date: Tue, 1 Jul 2003 10:52:37 +0200 (GMT)
Message-ID: <[email protected]>
Hi everyone.
`


//todo: not yet implemented in net/mail
//once there is support for this, add it
var rfc5322exampleA13 = `From: Pete <[email protected]>
Expand Down

0 comments on commit 2d77617

Please sign in to comment.