"mime"
"net/textproto"
"strings"
+ "sync"
"time"
"unicode/utf8"
)
// Layouts suitable for passing to time.Parse.
// These are tried in order.
-var dateLayouts []string
+var (
+ dateLayoutsBuildOnce sync.Once
+ dateLayouts []string
+)
-func init() {
+func buildDateLayouts() {
// Generate layouts based on RFC 5322, section 3.3.
dows := [...]string{"", "Mon, "} // day-of-week
// ParseDate parses an RFC 5322 date string.
func ParseDate(date string) (time.Time, error) {
+ dateLayoutsBuildOnce.Do(buildDateLayouts)
for _, layout := range dateLayouts {
t, err := time.Parse(layout, date)
if err == nil {