Handle time strings with timezone suffix
diff --git a/parsemail.go b/parsemail.go
index 996e357..d526dd7 100644
--- a/parsemail.go
+++ b/parsemail.go
@@ -9,6 +9,7 @@
"mime"
"mime/multipart"
"net/mail"
+ "regexp"
"strings"
"time"
)
@@ -375,6 +376,8 @@
return
}
+var timezoneRegex = regexp.MustCompile(` \([A-Za-z0-9]+\)$`)
+
func (hp headerParser) parseTime(s string) (t time.Time) {
if hp.err != nil || s == "" {
return
@@ -385,6 +388,8 @@
return t
}
+ s = timezoneRegex.ReplaceAllString(s, "")
+
t, hp.err = time.Parse("Mon, 2 Jan 2006 15:04:05 -0700", s)
return
diff --git a/parsemail_test.go b/parsemail_test.go
index 809aad8..9d6e4d3 100644
--- a/parsemail_test.go
+++ b/parsemail_test.go
@@ -597,7 +597,7 @@
var rfc5322exampleA12 = `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
+Date: Tue, 1 Jul 2003 10:52:37 +0200 (GMT)
Message-ID: <5678.21-Nov-1997@example.com>
Hi everyone.