merge v0.23.0-rc changes

This commit is contained in:
Gani Georgiev
2024-09-29 19:23:19 +03:00
parent ad92992324
commit 844f18cac3
753 changed files with 85141 additions and 63396 deletions
+32 -30
View File
@@ -7,43 +7,27 @@ import (
"strings"
"github.com/domodwyer/mailyak/v3"
"github.com/pocketbase/pocketbase/tools/hook"
"github.com/pocketbase/pocketbase/tools/security"
)
var _ Mailer = (*SmtpClient)(nil)
var _ Mailer = (*SMTPClient)(nil)
const (
SmtpAuthPlain = "PLAIN"
SmtpAuthLogin = "LOGIN"
SMTPAuthPlain = "PLAIN"
SMTPAuthLogin = "LOGIN"
)
// Deprecated: Use directly the SmtpClient struct literal.
//
// NewSmtpClient creates new SmtpClient with the provided configuration.
func NewSmtpClient(
host string,
port int,
username string,
password string,
tls bool,
) *SmtpClient {
return &SmtpClient{
Host: host,
Port: port,
Username: username,
Password: password,
Tls: tls,
}
}
// SmtpClient defines a SMTP mail client structure that implements
// SMTPClient defines a SMTP mail client structure that implements
// `mailer.Mailer` interface.
type SmtpClient struct {
Host string
type SMTPClient struct {
onSend *hook.Hook[*SendEvent]
TLS bool
Port int
Host string
Username string
Password string
Tls bool
// SMTP auth method to use
// (if not explicitly set, defaults to "PLAIN")
@@ -56,12 +40,30 @@ type SmtpClient struct {
LocalName string
}
// Send implements `mailer.Mailer` interface.
func (c *SmtpClient) Send(m *Message) error {
// OnSend implements [mailer.SendInterceptor] interface.
func (c *SMTPClient) OnSend() *hook.Hook[*SendEvent] {
if c.onSend == nil {
c.onSend = &hook.Hook[*SendEvent]{}
}
return c.onSend
}
// Send implements [mailer.Mailer] interface.
func (c *SMTPClient) Send(m *Message) error {
if c.onSend != nil {
return c.onSend.Trigger(&SendEvent{Message: m}, func(e *SendEvent) error {
return c.send(e.Message)
})
}
return c.send(m)
}
func (c *SMTPClient) send(m *Message) error {
var smtpAuth smtp.Auth
if c.Username != "" || c.Password != "" {
switch c.AuthMethod {
case SmtpAuthLogin:
case SMTPAuthLogin:
smtpAuth = &smtpLoginAuth{c.Username, c.Password}
default:
smtpAuth = smtp.PlainAuth("", c.Username, c.Password, c.Host)
@@ -70,7 +72,7 @@ func (c *SmtpClient) Send(m *Message) error {
// create mail instance
var yak *mailyak.MailYak
if c.Tls {
if c.TLS {
var tlsErr error
yak, tlsErr = mailyak.NewWithTLS(fmt.Sprintf("%s:%d", c.Host, c.Port), smtpAuth, nil)
if tlsErr != nil {