mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 07:47:32 +00:00
chore: move the go code into a subfolder
This commit is contained in:
75
apps/api/internal/notification/messages/email.go
Normal file
75
apps/api/internal/notification/messages/email.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package messages
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"mime"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/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
|
||||
ReplyToAddress string
|
||||
Subject string
|
||||
Content string
|
||||
TriggeringEventType eventstore.EventType
|
||||
}
|
||||
|
||||
func (msg *Email) GetContent() (string, error) {
|
||||
headers := make(map[string]string)
|
||||
from := msg.SenderEmail
|
||||
if msg.SenderName != "" {
|
||||
from = fmt.Sprintf("%s <%s>", bEncodeWord(msg.SenderName), msg.SenderEmail)
|
||||
}
|
||||
headers["From"] = from
|
||||
if msg.ReplyToAddress != "" {
|
||||
headers["Reply-to"] = msg.ReplyToAddress
|
||||
}
|
||||
headers["Return-Path"] = msg.SenderEmail
|
||||
headers["To"] = strings.Join(msg.Recipients, ", ")
|
||||
headers["Cc"] = strings.Join(msg.CC, ", ")
|
||||
headers["Date"] = time.Now().Format(time.RFC1123Z)
|
||||
|
||||
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: " + bEncodeWord(msg.Subject) + lineBreak
|
||||
message += subject + mime + lineBreak + msg.Content
|
||||
|
||||
return message, nil
|
||||
}
|
||||
|
||||
func (msg *Email) GetTriggeringEventType() eventstore.EventType {
|
||||
return msg.TriggeringEventType
|
||||
}
|
||||
|
||||
func isHTML(input string) bool {
|
||||
return isHTMLRgx.MatchString(input)
|
||||
}
|
||||
|
||||
// returns a RFC1342 "B" encoded string to allow non-ascii characters
|
||||
func bEncodeWord(word string) string {
|
||||
return mime.BEncoding.Encode("UTF-8", word)
|
||||
}
|
27
apps/api/internal/notification/messages/form.go
Normal file
27
apps/api/internal/notification/messages/form.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package messages
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/zitadel/schema"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/notification/channels"
|
||||
)
|
||||
|
||||
var _ channels.Message = (*Form)(nil)
|
||||
|
||||
type Form struct {
|
||||
Serializable any
|
||||
TriggeringEventType eventstore.EventType
|
||||
}
|
||||
|
||||
func (msg *Form) GetContent() (string, error) {
|
||||
values := make(url.Values)
|
||||
err := schema.NewEncoder().Encode(msg.Serializable, values)
|
||||
return values.Encode(), err
|
||||
}
|
||||
|
||||
func (msg *Form) GetTriggeringEventType() eventstore.EventType {
|
||||
return msg.TriggeringEventType
|
||||
}
|
24
apps/api/internal/notification/messages/json.go
Normal file
24
apps/api/internal/notification/messages/json.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package messages
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/notification/channels"
|
||||
)
|
||||
|
||||
var _ channels.Message = (*JSON)(nil)
|
||||
|
||||
type JSON struct {
|
||||
Serializable interface{}
|
||||
TriggeringEventType eventstore.EventType
|
||||
}
|
||||
|
||||
func (msg *JSON) GetContent() (string, error) {
|
||||
bytes, err := json.Marshal(msg.Serializable)
|
||||
return string(bytes), err
|
||||
}
|
||||
|
||||
func (msg *JSON) GetTriggeringEventType() eventstore.EventType {
|
||||
return msg.TriggeringEventType
|
||||
}
|
29
apps/api/internal/notification/messages/sms.go
Normal file
29
apps/api/internal/notification/messages/sms.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package messages
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/notification/channels"
|
||||
)
|
||||
|
||||
var _ channels.Message = (*SMS)(nil)
|
||||
|
||||
type SMS struct {
|
||||
SenderPhoneNumber string
|
||||
RecipientPhoneNumber string
|
||||
Content string
|
||||
TriggeringEventType eventstore.EventType
|
||||
|
||||
// VerificationID is set by the sender
|
||||
VerificationID *string
|
||||
InstanceID string
|
||||
JobID string
|
||||
UserID string
|
||||
}
|
||||
|
||||
func (msg *SMS) GetContent() (string, error) {
|
||||
return msg.Content, nil
|
||||
}
|
||||
|
||||
func (msg *SMS) GetTriggeringEventType() eventstore.EventType {
|
||||
return msg.TriggeringEventType
|
||||
}
|
Reference in New Issue
Block a user