all repos — mdawh @ 3466f295e7b32f26e711ced85dcd3f7ee6f8b3cd

An MDA that creates a webhook on recieval of mail

Decode From header
Anirudh Oppiliappan x@icyphox.sh
Mon, 20 Sep 2021 21:13:08 +0530
commit

3466f295e7b32f26e711ced85dcd3f7ee6f8b3cd

parent

7214a5cce2a9cc6bcaaa13e1cbb98ca4f6fb19ad

1 files changed, 18 insertions(+), 1 deletions(-)

jump to
M main.gomain.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 {