fuck
sophuwu sophie@skisiel.com
Sat, 20 Jul 2024 15:13:03 +0200
M
go.sum
→
go.sum
@@ -2,3 +2,5 @@ github.com/DusanKasan/parsemail v1.2.0 h1:CrzTL1nuPLxB41aO4zE/Tzc9GVD8jjifUftlbTKQQl4=
github.com/DusanKasan/parsemail v1.2.0/go.mod h1:B9lfMbpVe4DMqPImAOCGti7KEwasnRTrKKn66iQefVs= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
M
parse.go
→
parse.go
@@ -5,7 +5,6 @@ "bytes"
"crypto/sha1" "encoding/base32" "fmt" - "github.com/DusanKasan/parsemail" "github.com/andybalholm/brotli" "mime" "net/mail"@@ -29,6 +28,7 @@ var email bytes.Buffer
if _, err := email.ReadFrom(os.Stdin); err != nil { os.Exit(1) } + meta, err := GenerateMeta(email) if err != nil { os.Exit(1)@@ -50,7 +50,6 @@ d = time.Now().Local()
} return d.UTC().Unix() } - func ShaHash(b []byte) string { h := sha1.New() h.Write(b)@@ -72,18 +71,16 @@ }
} }(mime.WordDecoder{}) - // e, err := mail.ReadMessage(&email) - e, err := parsemail.Parse(&email) + e, err := mail.ReadMessage(bytes.NewReader(email.Bytes())) if err != nil { - fmt.Println("Error parsing email: ", err) return em, err } em.To = func() string { - if len(e.To) > 0 { - return e.To[0].String() + if len(e.Header.Get("To")) > 0 { + return e.Header.Get("To") } - if e.Header.Get("X-Original-To") != "" { + if len(e.Header.Get("X-Original-To")) > 2 { return e.Header.Get("X-Original-To") } if e.Header.Get("Delivered-To") != "" {@@ -93,8 +90,8 @@ return "Unknown Recipient"
}() decode(&em.To) em.From = func() string { - if len(e.From) > 0 { - return e.From[0].String() + if len(e.Header.Get("From")) > 0 { + return e.Header.Get("From") } if len(e.Header.Get("Return-Path")) > 2 { return e.Header.Get("Return-Path")