diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-16 17:06:26 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-16 17:06:26 -0500 |
commit | 2b0bd61baca0d83b31dbea7a8e1a670d30a94a22 (patch) | |
tree | d07edbfa9e9ded23c00ac60832d0466829593a0d /textproto | |
parent | f9091033da16659b8aa23890b2294c42550e76b2 (diff) |
frontend: implement tag
Diffstat (limited to 'textproto')
-rw-r--r-- | textproto/types.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/textproto/types.go b/textproto/types.go index 2109517..9a1731b 100644 --- a/textproto/types.go +++ b/textproto/types.go @@ -2,10 +2,13 @@ package textproto import ( "fmt" + "strconv" "strings" "time" ) +// BUG(lukeshu): Only supports the "raw" date format (not "rfc2822" or +// "now") type UserTime struct { Name string Email string @@ -28,6 +31,45 @@ func (ut UserTime) String() string { } } +func ParseUserTime(str string) (UserTime, error) { + ret := UserTime{} + lt := strings.IndexAny(str, "<>") + if lt < 0 || str[lt] != '<' { + return ret, fmt.Errorf("Missing < in ident string: %v", str) + } + if lt > 0 { + if str[lt-1] != ' ' { + return ret, fmt.Errorf("Missing space before < in ident string: %v", str) + } + ret.Name = str[:lt-1] + } + gt := lt + 1 + strings.IndexAny(str[lt+1:], "<>") + if gt < lt+1 || str[gt] != '>' { + return ret, fmt.Errorf("Missing > in ident string: %v", str) + } + if str[gt+1] != ' ' { + return ret, fmt.Errorf("Missing space after > in ident string: %v", str) + } + ret.Email = str[lt+1 : gt] + + strWhen := str[gt+2:] + sp := strings.IndexByte(strWhen, ' ') + if sp < 0 { + return ret, fmt.Errorf("missing time zone in when: %v", str) + } + sec, err := strconv.ParseInt(strWhen[:sp], 10, 64) + if err != nil { + return ret, err + } + tzt, err := time.Parse("-0700", strWhen[sp+1:]) + if err != nil { + return ret, err + } + ret.Time = time.Unix(sec, 0).In(tzt.Location()) + + return ret, nil +} + type Mode uint32 // 18 bits var ( |