all repos — mdawh @ 79d17abbef465ffe9f521da316b5902f17d10242

An MDA that creates a webhook on recieval of mail

Clean up logging etc.
Anirudh Oppiliappan x@icyphox.sh
Mon, 13 Sep 2021 14:33:41 +0530
commit

79d17abbef465ffe9f521da316b5902f17d10242

parent

0ff2bd53b5bc2ea01735370c0f61c9598e7c3e11

2 files changed, 7 insertions(+), 8 deletions(-)

jump to
M .gitignore.gitignore

@@ -1,2 +1,3 @@

mdawh *mail +*.log
M main.gomain.go

@@ -5,7 +5,6 @@ "bufio"

"bytes" "encoding/json" "io" - "io/ioutil" "log" "net/http" "os"

@@ -14,13 +13,11 @@

"github.com/emersion/go-message/mail" ) -type P map[string]string - type Mail struct { From string Date string ReplyTo string - Parts []P + Parts map[string]string } func makeReq(j []byte) {

@@ -54,6 +51,7 @@ if err != nil {

log.Fatal(err) } + parts := make(map[string]string) for { p, err := mr.NextPart() if err == io.EOF {

@@ -64,13 +62,13 @@ }

switch h := p.Header.(type) { case *mail.InlineHeader: ct := strings.Split(p.Header.Get("Content-Type"), ";")[0] - b, _ := ioutil.ReadAll(p.Body) - part := P{ct: string(b)} - newmail.Parts = append(newmail.Parts, part) + b, _ := io.ReadAll(p.Body) + parts[ct] = string(b) + newmail.Parts = parts case *mail.AttachmentHeader: filename, _ := h.Filename() - log.Printf("Got attachment: %v\n", filename) + log.Printf("got attachment: %v\n", filename) } }