Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpl0itU committed Sep 9, 2023
1 parent 636de61 commit 5c8f4d3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import (
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
log.Fatalln("Error loading .env file")
}

filtersContents, err := os.ReadFile("filters.json")
if err != nil {
log.Fatal(err)
log.Fatalln(err)
}
var filters []MailFilter
if err := json.Unmarshal(filtersContents, &filters); err != nil {
log.Fatal(err)
log.Fatalln(err)
}

if err := checkEmailsWithFilters(filters, os.Getenv("SERVER"), os.Getenv("EMAIL"), os.Getenv("PASSWORD"), os.Getenv("MAIL_OK_FOLDER"), os.Getenv("MAIL_FAILED_FOLDER")); err != nil {
log.Fatal(err)
log.Fatalln(err)
}
}

Expand Down Expand Up @@ -81,15 +81,17 @@ func checkEmailsWithFilters(filters []MailFilter, server, email, password, mailO
if !okSet.Empty() {
if err := moveMessages(c, okSet, mailOkFolder); err != nil {
log.Println(err)
} else {
log.Printf("Moved messages to %s\n", mailOkFolder)
}
log.Printf("Moved messages to %s\n", mailOkFolder)
}

if !failedSet.Empty() {
if err := moveMessages(c, failedSet, mailFailedFolder); err != nil {
log.Println(err)
} else {
log.Printf("Moved messages to %s\n", mailFailedFolder)
}
log.Printf("Moved messages to %s\n", mailFailedFolder)
}

if anyErrors {
Expand Down

0 comments on commit 5c8f4d3

Please sign in to comment.