all repos — mdawh @ 7214a5cce2a9cc6bcaaa13e1cbb98ca4f6fb19ad

An MDA that creates a webhook on recieval of mail

Dump the body as a whole if no Content-Type header
Anirudh Oppiliappan x@icyphox.sh
Fri, 17 Sep 2021 10:26:10 +0530
commit

7214a5cce2a9cc6bcaaa13e1cbb98ca4f6fb19ad

parent

f667d63d4c511a2a7b5cda7721e9d41aec12b749

1 files changed, 14 insertions(+), 8 deletions(-)

jump to
M main.gomain.go

@@ -17,6 +17,7 @@ type Mail struct {

From string Date string ReplyTo string + Body string Parts map[string]string }

@@ -42,10 +43,10 @@

r := bufio.NewReader(os.Stdin) mr, err := mail.CreateReader(r) - newmail := Mail{} - newmail.Date = mr.Header.Get("Date") - newmail.From = mr.Header.Get("From") - newmail.ReplyTo = mr.Header.Get("Reply-To") + m := Mail{} + m.Date = mr.Header.Get("Date") + m.From = mr.Header.Get("From") + m.ReplyTo = mr.Header.Get("Reply-To") if err != nil { log.Fatal(err)

@@ -62,9 +63,14 @@ }

switch h := p.Header.(type) { case *mail.InlineHeader: ct := strings.Split(p.Header.Get("Content-Type"), ";")[0] + // We didn't find any Content-Type header. b, _ := io.ReadAll(p.Body) - parts[ct] = string(b) - newmail.Parts = parts + if len(ct) == 0 { + m.Body = string(b) + } else { + parts[ct] = string(b) + m.Parts = parts + } case *mail.AttachmentHeader: filename, _ := h.Filename()

@@ -72,10 +78,10 @@ log.Printf("got attachment: %v\n", filename)

} } - j, err := json.Marshal(newmail) + j, err := json.Marshal(m) if err != nil { log.Fatal(err) } makeReq(j) - log.Printf("sent webhook: %v\n", newmail.From) + log.Printf("sent webhook: %v\n", m.From) }