diff options
Diffstat (limited to 'notifications.go')
-rw-r--r-- | notifications.go | 64 |
1 files changed, 52 insertions, 12 deletions
diff --git a/notifications.go b/notifications.go index beb9b3f..d4b9715 100644 --- a/notifications.go +++ b/notifications.go @@ -15,7 +15,15 @@ type NotificationMail interface { GetHeaders() map[string]string } +type VoterMail interface { + GetData() interface{} + GetTemplate() string + GetSubject() string + GetRecipient() (string, string) +} + var notifyMail = make(chan NotificationMail, 1) +var voterMail = make(chan VoterMail, 1) var quitMailNotifier = make(chan int) func CloseMailNotifier() { @@ -46,6 +54,24 @@ func MailNotifier() { if err := d.DialAndSend(m); err != nil { logger.Println("ERROR sending mail:", err) } + case notification := <-voterMail: + mailText, err := buildMail(notification.GetTemplate(), notification.GetData()) + if err != nil { + logger.Println("ERROR building mail:", err) + continue + } + + m := gomail.NewMessage() + m.SetHeader("From", config.ReminderSenderAddress) + address, name := notification.GetRecipient() + m.SetAddressHeader("To", address, name) + m.SetHeader("Subject", notification.GetSubject()) + m.SetBody("text/plain", mailText.String()) + + d := gomail.NewDialer(config.MailServer.Host, config.MailServer.Port, "", "") + if err := d.DialAndSend(m); err != nil { + logger.Println("ERROR sending mail:", err) + } case <-quitMailNotifier: fmt.Println("Ending mail notifier") return @@ -78,9 +104,7 @@ func (n *NotificationClosedDecision) GetData() interface{} { }{&n.decision, &n.voteSums} } -func (n *NotificationClosedDecision) GetTemplate() string { - return "closed_motion_mail.txt" -} +func (n *NotificationClosedDecision) GetTemplate() string { return "closed_motion_mail.txt" } func (n *NotificationClosedDecision) GetSubject() string { return fmt.Sprintf("Re: %s - %s - finalised", n.decision.Tag, n.decision.Title) @@ -106,9 +130,7 @@ func (n *NotificationCreateMotion) GetData() interface{} { }{&n.decision, n.voter.Name, voteURL, unvotedURL} } -func (n *NotificationCreateMotion) GetTemplate() string { - return "create_motion_mail.txt" -} +func (n *NotificationCreateMotion) GetTemplate() string { return "create_motion_mail.txt" } func (n *NotificationCreateMotion) GetSubject() string { return fmt.Sprintf("%s - %s", n.decision.Tag, n.decision.Title) @@ -134,9 +156,7 @@ func (n *NotificationUpdateMotion) GetData() interface{} { }{&n.decision, n.voter.Name, voteURL, unvotedURL} } -func (n *NotificationUpdateMotion) GetTemplate() string { - return "update_motion_mail.txt" -} +func (n *NotificationUpdateMotion) GetTemplate() string { return "update_motion_mail.txt" } func (n *NotificationUpdateMotion) GetSubject() string { return fmt.Sprintf("Re: %s - %s", n.decision.Tag, n.decision.Title) @@ -158,9 +178,7 @@ func (n *NotificationWithDrawMotion) GetData() interface{} { }{&n.decision, n.voter.Name} } -func (n *NotificationWithDrawMotion) GetTemplate() string { - return "withdraw_motion_mail.txt" -} +func (n *NotificationWithDrawMotion) GetTemplate() string { return "withdraw_motion_mail.txt" } func (n *NotificationWithDrawMotion) GetSubject() string { return fmt.Sprintf("Re: %s - %s - withdrawn", n.decision.Tag, n.decision.Title) @@ -169,3 +187,25 @@ func (n *NotificationWithDrawMotion) GetSubject() string { func (n *NotificationWithDrawMotion) GetHeaders() map[string]string { return map[string]string{"References": fmt.Sprintf("<%s>", n.decision.Tag)} } + +type RemindVoterNotification struct { + voter Voter + decisions []Decision +} + +func (n *RemindVoterNotification) GetData() interface{} { + return struct { + Decisions []Decision + Name string + BaseURL string + }{n.decisions, n.voter.Name, config.BaseURL} +} + +func (n *RemindVoterNotification) GetTemplate() string { return "remind_voter_mail.txt" } + +func (n *RemindVoterNotification) GetSubject() string { return "Outstanding CAcert board votes" } + +func (n *RemindVoterNotification) GetRecipient() (address string, name string) { + address, name = n.voter.Reminder, n.voter.Name + return +} |