mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
e3528ff0b2
* feat: add default language to eventstore * feat: add secret generator configs events * feat: tests * feat: secret generators in eventstore * feat: secret generators in eventstore * feat: smtp config in eventstore * feat: smtp config in eventstore * feat: smtp config in eventstore * feat: smtp config in eventstore * feat: smtp config in eventstore * fix: migrations * fix migration version * fix test * feat: change secret generator type to enum * feat: change smtp attribute names * feat: change smtp attribute names * feat: remove engryption algorithms from command side * feat: remove engryption algorithms from command side * feat: smtp config * feat: smtp config * format smtp from header Co-authored-by: Livio Amstutz <livio.a@gmail.com>
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package messages
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/caos/zitadel/internal/notification/channels"
|
|
)
|
|
|
|
var (
|
|
isHTMLRgx = regexp.MustCompile(`.*<html.*>.*`)
|
|
lineBreak = "\r\n"
|
|
)
|
|
|
|
var _ channels.Message = (*Email)(nil)
|
|
|
|
type Email struct {
|
|
Recipients []string
|
|
BCC []string
|
|
CC []string
|
|
SenderEmail string
|
|
SenderName string
|
|
Subject string
|
|
Content string
|
|
}
|
|
|
|
func (msg *Email) GetContent() string {
|
|
headers := make(map[string]string)
|
|
from := msg.SenderEmail
|
|
if msg.SenderName != "" {
|
|
from = fmt.Sprintf("%s <%s>", msg.SenderName, msg.SenderEmail)
|
|
}
|
|
headers["From"] = from
|
|
headers["To"] = strings.Join(msg.Recipients, ", ")
|
|
headers["Cc"] = strings.Join(msg.CC, ", ")
|
|
|
|
message := ""
|
|
for k, v := range headers {
|
|
message += fmt.Sprintf("%s: %s"+lineBreak, k, v)
|
|
}
|
|
|
|
//default mime-type is html
|
|
mime := "MIME-version: 1.0;" + lineBreak + "Content-Type: text/html; charset=\"UTF-8\";" + lineBreak + lineBreak
|
|
if !isHTML(msg.Content) {
|
|
mime = "MIME-version: 1.0;" + lineBreak + "Content-Type: text/plain; charset=\"UTF-8\";" + lineBreak + lineBreak
|
|
}
|
|
subject := "Subject: " + msg.Subject + lineBreak
|
|
message += subject + mime + lineBreak + msg.Content
|
|
|
|
return message
|
|
}
|
|
|
|
func isHTML(input string) bool {
|
|
return isHTMLRgx.MatchString(input)
|
|
}
|