diff --git a/eml_unpack_attachments/go.mod b/eml_unpack_attachments/go.mod index 9d6b326..83c7390 100644 --- a/eml_unpack_attachments/go.mod +++ b/eml_unpack_attachments/go.mod @@ -3,8 +3,12 @@ module github.com/dezeroku/ses_local_email/eml_unpack_attachments go 1.23.1 require ( - github.com/DusanKasan/parsemail v1.2.0 github.com/fsnotify/fsnotify v1.7.0 + github.com/mnako/letters v0.2.2 ) -require golang.org/x/sys v0.4.0 // indirect +require ( + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/text v0.13.0 // indirect +) diff --git a/eml_unpack_attachments/go.sum b/eml_unpack_attachments/go.sum index 1840c75..7743dd1 100644 --- a/eml_unpack_attachments/go.sum +++ b/eml_unpack_attachments/go.sum @@ -1,6 +1,10 @@ -github.com/DusanKasan/parsemail v1.2.0 h1:CrzTL1nuPLxB41aO4zE/Tzc9GVD8jjifUftlbTKQQl4= -github.com/DusanKasan/parsemail v1.2.0/go.mod h1:B9lfMbpVe4DMqPImAOCGti7KEwasnRTrKKn66iQefVs= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/mnako/letters v0.2.2 h1:koVahnzazHIq3aQnjVZE5SBJ7ZG/mXK6uSM4Jh70Naw= +github.com/mnako/letters v0.2.2/go.mod h1:8DKs/xAQ9A7TP8zrLiZPvlrX5synZnvRyTT5Ja+QUK4= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= diff --git a/eml_unpack_attachments/main.go b/eml_unpack_attachments/main.go index 7462fed..64a2cb7 100644 --- a/eml_unpack_attachments/main.go +++ b/eml_unpack_attachments/main.go @@ -1,15 +1,14 @@ package main import ( - "bytes" "io/ioutil" "log" "os" "path" "strings" - "github.com/DusanKasan/parsemail" "github.com/fsnotify/fsnotify" + "github.com/mnako/letters" ) var ( @@ -49,19 +48,18 @@ func processNewFile(filename string, outputDirectory string) error { } defer reader.Close() - email, err := parsemail.Parse(reader) + email, err := letters.ParseEmail(reader) if err != nil { return err } - log.Printf("FROM: %s TO: %s SUBJECT: %s\n", email.From, email.To, email.Subject) - if len(email.Attachments) > 0 { + log.Printf("FROM: %s TO: %s SUBJECT: %s\n", email.Headers.From, email.Headers.To, email.Headers.Subject) + if len(email.AttachedFiles) > 0 { log.Print("Attachments:") - for _, a := range email.Attachments { - log.Print(a.Filename) - buf := new(bytes.Buffer) - buf.ReadFrom(a.Data) - err := os.WriteFile(path.Join(outputDirectory, a.Filename), buf.Bytes(), 0644) + for _, a := range email.AttachedFiles { + attachmentName := a.ContentType.Params["name"] + log.Print(attachmentName) + err := os.WriteFile(path.Join(outputDirectory, attachmentName), a.Data, 0644) if err != nil { return err }