Merge branch 'fix-time' of https://github.com/EdwinLove/parsemail into EdwinLove-fix-time
diff --git a/parsemail.go b/parsemail.go
index 1cde6c8..3011f96 100644
--- a/parsemail.go
+++ b/parsemail.go
@@ -390,12 +390,19 @@
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
}
diff --git a/parsemail_test.go b/parsemail_test.go
index 944c0b7..17ae024 100644
--- a/parsemail_test.go
+++ b/parsemail_test.go
@@ -294,6 +294,42 @@
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: "john.q.public@example.com",
+ },
+ },
+ to: []mail.Address{
+ {
+ Name: "Mary Smith",
+ Address: "mary@x.test",
+ },
+ {
+ Name: "",
+ Address: "jdoe@example.org",
+ },
+ {
+ Name: "Who?",
+ Address: "one@y.test",
+ },
+ },
+ cc: []mail.Address{
+ {
+ Name: "",
+ Address: "boss@nil.test",
+ },
+ {
+ Name: "Giant; \"Big\" Box",
+ Address: "sysservices@example.net",
+ },
+ },
+ messageID: "5678.21-Nov-1997@example.com",
+ date: parseDate("Tue, 01 Jul 2003 10:52:37 +0200"),
+ textBody: `Hi everyone.`,
+ },
}
for index, td := range testData {
@@ -678,6 +714,16 @@
Hi everyone.
`
+var rfc5322exampleA12WithTimezone = `From: "Joe Q. Public" <john.q.public@example.com>
+To: Mary Smith <mary@x.test>, jdoe@example.org, Who? <one@y.test>
+Cc: <boss@nil.test>, "Giant; \"Big\" Box" <sysservices@example.net>
+Date: Tue, 1 Jul 2003 10:52:37 +0200 (GMT)
+Message-ID: <5678.21-Nov-1997@example.com>
+
+Hi everyone.
+`
+
+
//todo: not yet implemented in net/mail
//once there is support for this, add it
var rfc5322exampleA13 = `From: Pete <pete@silly.example>