Add comments

This commit is contained in:
kolaente 2021-02-07 16:46:53 +01:00
parent 8d3b9cd237
commit e41b596101
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 11 additions and 0 deletions

View File

@ -18,6 +18,7 @@ package notifications
import "code.vikunja.io/api/pkg/mail"
// Mail is a mail message
type Mail struct {
from string
to string
@ -29,38 +30,45 @@ type Mail struct {
outroLines []string
}
// NewMail creates a new mail object with a default greeting
func NewMail() *Mail {
return &Mail{
greeting: "Hi,",
}
}
// From sets the from name and email address
func (m *Mail) From(from string) *Mail {
m.from = from
return m
}
// To sets the recipient of the mail message
func (m *Mail) To(to string) *Mail {
m.to = to
return m
}
// Subject sets the subject of the mail message
func (m *Mail) Subject(subject string) *Mail {
m.subject = subject
return m
}
// Greeting sets the greeting of the mail message
func (m *Mail) Greeting(greeting string) *Mail {
m.greeting = greeting
return m
}
// Action sets any action a mail might have
func (m *Mail) Action(text, url string) *Mail {
m.actionText = text
m.actionURL = url
return m
}
// Line adds a line of text to the mail
func (m *Mail) Line(line string) *Mail {
if m.actionURL == "" {
m.introLines = append(m.introLines, line)
@ -72,6 +80,7 @@ func (m *Mail) Line(line string) *Mail {
return m
}
// SendMail passes the notification to the mailing queue for sending
func SendMail(m *Mail) error {
opts, err := RenderMail(m)
if err != nil {

View File

@ -85,6 +85,7 @@ const mailTemplateHTML = `
</html>
`
// RenderMail takes a precomposed mail message and renders it into a ready to send mail.Opts object
func RenderMail(m *Mail) (mailOpts *mail.Opts, err error) {
var htmlContent bytes.Buffer

View File

@ -16,6 +16,7 @@
package notifications
// Notification is a notification which can be sent via mail or db.
type Notification interface {
ToMail() *Mail
ToDB() interface{}