diff --git a/parsemail.go b/parsemail.go index 1cde6c8..3011f96 100644 --- a/parsemail.go +++ b/parsemail.go @@ -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 } 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 @@ 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: "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 @@ Message-ID: <5678.21-Nov-1997@example.com> Hi everyone. ` +var rfc5322exampleA12WithTimezone = `From: "Joe Q. Public" +To: Mary Smith , jdoe@example.org, Who? +Cc: , "Giant; \"Big\" Box" +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