Decode From header
Anirudh Oppiliappan x@icyphox.sh
Mon, 20 Sep 2021 21:13:08 +0530
1 files changed,
18 insertions(+),
1 deletions(-)
jump to
M
main.go
→
main.go
@@ -6,6 +6,7 @@ "bytes"
"encoding/json" "io" "log" + "mime" "net/http" "os" "strings"@@ -32,6 +33,17 @@ }
defer res.Body.Close() } +// Decodes a RFC 2047 encoded word. +func decode(s string) (string, error) { + dec := mime.WordDecoder{} + header, err := dec.DecodeHeader(s) + if err != nil { + return "", err + } + + return header, nil +} + func main() { f, err := os.OpenFile("mdawh.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil {@@ -45,7 +57,12 @@ mr, err := mail.CreateReader(r)
m := Mail{} m.Date = mr.Header.Get("Date") - m.From = mr.Header.Get("From") + from, err := decode(mr.Header.Get("From")) + if err != nil { + m.From = mr.Header.Get("From") + } else { + m.From = from + } m.ReplyTo = mr.Header.Get("Reply-To") if err != nil {