Clean up logging etc.
Anirudh Oppiliappan x@icyphox.sh
Mon, 13 Sep 2021 14:33:41 +0530
2 files changed,
7 insertions(+),
8 deletions(-)
M
main.go
→
main.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) } }