Skip to content

Commit

Permalink
Reorganize code
Browse files Browse the repository at this point in the history
  • Loading branch information
Xpl0itU committed Sep 10, 2023
1 parent de09541 commit 8aafdcd
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import (
"github.com/joho/godotenv"
)

type MailFilter struct {
Mail string `json:"mail"`
Subject string `json:"subject"`
FailIfFound bool `json:"fail_if_found"`
HourThreshold int `json:"hour_threshold"`
Comment string `json:"comment"`
FailIfNotFound bool `json:"fail_if_not_found"`
}

func main() {
err := godotenv.Load()
if err != nil {
Expand All @@ -32,15 +41,6 @@ func main() {
}
}

type MailFilter struct {
Mail string `json:"mail"`
Subject string `json:"subject"`
FailIfFound bool `json:"fail_if_found"`
HourThreshold int `json:"hour_threshold"`
Comment string `json:"comment"`
FailIfNotFound bool `json:"fail_if_not_found"`
}

func checkEmailsWithFilters(filters []MailFilter, server, email, password, mailOkFolder, mailFailedFolder string) error {
anyErrors := false
c, err := connectToIMAP(server, email, password)
Expand Down Expand Up @@ -69,14 +69,14 @@ func checkEmailsWithFilters(filters []MailFilter, server, email, password, mailO
}

if filter.FailIfFound {
if err := moveMessages(c, messages, mailFailedFolder); err != nil {
if err := c.Move(messages, mailFailedFolder); err != nil {
log.Println(err)
} else {
log.Printf("Moved messages to %s\n", mailFailedFolder)
}
anyErrors = true
} else {
if err := moveMessages(c, messages, mailOkFolder); err != nil {
if err := c.Move(messages, mailOkFolder); err != nil {
log.Println(err)
} else {
log.Printf("Moved messages to %s\n", mailOkFolder)
Expand Down Expand Up @@ -127,11 +127,3 @@ func searchEmails(c *client.Client, filter MailFilter) (*imap.SeqSet, error) {

return messages, nil
}

func moveMessages(c *client.Client, messages *imap.SeqSet, folderName string) error {
err := c.Move(messages, folderName)
if err != nil {
return err
}
return nil
}

0 comments on commit 8aafdcd

Please sign in to comment.