Skip to content

Commit

Permalink
Merge pull request #3 from karashiiro/fix/junk-mail
Browse files Browse the repository at this point in the history
Receive junk emails
  • Loading branch information
karashiiro authored May 10, 2022
2 parents c300fc4 + f174237 commit 58ea8bd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
OPERATOR_SMTP_SERVER: ${OPERATOR_SMTP_SERVER}
OPERATOR_IMAP_SERVER: ${OPERATOR_IMAP_SERVER}
OPERATOR_INBOX: ${OPERATOR_INBOX}
OPERATOR_JUNK: ${OPERATOR_JUNK}
OPERATOR_POSTGRES: postgres
depends_on:
- postgres
34 changes: 25 additions & 9 deletions pkg/inbox/receive-emails.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ type ReceiveEmailsJob struct {
}

func (j *ReceiveEmailsJob) Execute() {
auth := eazye.MailboxInfo{
Host: os.Getenv("OPERATOR_IMAP_SERVER"),
TLS: true,
User: os.Getenv("OPERATOR_EMAIL"),
Pwd: os.Getenv("OPERATOR_PASSWORD"),
Folder: os.Getenv("OPERATOR_INBOX"),
}

log.Println("Fetching unread operator emails")
emails, err := eazye.GetUnread(auth, true, false)
emails, err := getEmails(os.Getenv("OPERATOR_INBOX"))
if err != nil {
log.Printf("Failed to get incoming emails: %v\n", err)
}

junkEmails, err := getEmails(os.Getenv("OPERATOR_JUNK"))
if err != nil {
log.Printf("Failed to get incoming junk emails: %v\n", err)
}

emails = append(emails, junkEmails...)

newReaders := make([]*ReaderInfo, 0)
updatedReaders := make([]*ReaderInfo, 0)
unsubscribers := make([]string, 0)
Expand Down Expand Up @@ -108,3 +107,20 @@ func (j *ReceiveEmailsJob) Key() int {
h.Write([]byte(j.Description()))
return int(h.Sum32())
}

func getEmails(mailbox string) ([]eazye.Email, error) {
auth := eazye.MailboxInfo{
Host: os.Getenv("OPERATOR_IMAP_SERVER"),
TLS: true,
User: os.Getenv("OPERATOR_EMAIL"),
Pwd: os.Getenv("OPERATOR_PASSWORD"),
Folder: mailbox,
}

emails, err := eazye.GetUnread(auth, true, false)
if err != nil {
return nil, err
}

return emails, nil
}
2 changes: 2 additions & 0 deletions pkg/reports/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type ReportJob struct {
}

func (j *ReportJob) Execute() {
log.Println("Checking plugin pull requests and subscribers")

// Process all open pull requests
reportTemplates, err := GetPlogonReportTemplates()
if err != nil {
Expand Down

0 comments on commit 58ea8bd

Please sign in to comment.