summaryrefslogtreecommitdiff
path: root/actions.go
diff options
context:
space:
mode:
Diffstat (limited to 'actions.go')
-rw-r--r--actions.go36
1 files changed, 21 insertions, 15 deletions
diff --git a/actions.go b/actions.go
index a8e78fb..19e9bf3 100644
--- a/actions.go
+++ b/actions.go
@@ -4,9 +4,8 @@ import (
"bytes"
"fmt"
"github.com/Masterminds/sprig"
- "os"
- "text/template"
"gopkg.in/gomail.v2"
+ "text/template"
)
type templateBody string
@@ -89,7 +88,7 @@ func UpdateMotion(decision *Decision, voter *Voter) (err error) {
m := gomail.NewMessage()
m.SetHeader("From", config.NoticeSenderAddress)
m.SetHeader("To", config.BoardMailAddress)
- m.SetHeader("Subject", fmt.Sprintf("%s - %s", decision.Tag, decision.Title))
+ m.SetHeader("Subject", fmt.Sprintf("Re: %s - %s", decision.Tag, decision.Title))
m.SetHeader("References", fmt.Sprintf("<%s>", decision.Tag))
m.SetBody("text/plain", mailText.String())
@@ -102,24 +101,31 @@ func UpdateMotion(decision *Decision, voter *Voter) (err error) {
}
func WithdrawMotion(decision *Decision, voter *Voter) (err error) {
- // load template, fill name, tag, title, content
+ err = decision.UpdateStatus()
+
type mailContext struct {
*Decision
- Name string
- Sender string
- Recipient string
+ Name string
}
- context := mailContext{decision, voter.Name, config.NoticeSenderAddress, config.BoardMailAddress}
+ context := mailContext{decision, voter.Name}
- // fill withdraw_mail.txt
- t, err := template.New("withdraw_mail.txt").Funcs(
- sprig.GenericFuncMap()).ParseFiles("templates/withdraw_mail.txt")
+ mailText, err := buildMail("withdraw_motion_mail.txt", context)
if err != nil {
- logger.Fatal(err)
+ logger.Println("Error", err)
+ return
+ }
+
+ m := gomail.NewMessage()
+ m.SetHeader("From", config.NoticeSenderAddress)
+ m.SetHeader("To", config.BoardMailAddress)
+ m.SetHeader("Subject", fmt.Sprintf("Re: %s - %s - withdrawn", decision.Tag, decision.Title))
+ m.SetHeader("References", fmt.Sprintf("<%s>", decision.Tag))
+ 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)
}
- // TODO: send mail
- t.Execute(os.Stdout, context)
- // TODO: implement call decision.Close()
return
}