Skip to content

Commit

Permalink
eml_unpack_attachments: replace email parsing library
Browse files Browse the repository at this point in the history
  • Loading branch information
dezeroku committed Oct 2, 2024
1 parent 1d140e6 commit fe4d297
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
8 changes: 6 additions & 2 deletions eml_unpack_attachments/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
12 changes: 8 additions & 4 deletions eml_unpack_attachments/go.sum
Original file line number Diff line number Diff line change
@@ -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=
18 changes: 8 additions & 10 deletions eml_unpack_attachments/main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit fe4d297

Please sign in to comment.