rename internal thigs of smtp/
This commit is contained in:
22
smtp/msa.go
22
smtp/msa.go
@@ -14,35 +14,35 @@ import (
|
|||||||
type msa struct {
|
type msa struct {
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
domain string
|
domain string
|
||||||
client Client
|
bot Bot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *msa) newSession() *msasession {
|
func (m *msa) newSession() *msasession {
|
||||||
return &msasession{
|
return &msasession{
|
||||||
ctx: sentry.SetHubOnContext(context.Background(), sentry.CurrentHub().Clone()),
|
ctx: sentry.SetHubOnContext(context.Background(), sentry.CurrentHub().Clone()),
|
||||||
log: b.log,
|
log: m.log,
|
||||||
domain: b.domain,
|
bot: m.bot,
|
||||||
client: b.client,
|
domain: m.domain,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *msa) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error) {
|
func (m *msa) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error) {
|
||||||
return nil, smtp.ErrAuthUnsupported
|
return nil, smtp.ErrAuthUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *msa) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, error) {
|
func (m *msa) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, error) {
|
||||||
return b.newSession(), nil
|
return m.newSession(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(domain, port, loglevel string, maxSize int, client Client) error {
|
func Start(domain, port, loglevel string, maxSize int, bot Bot) error {
|
||||||
log := logger.New("smtp.", loglevel)
|
log := logger.New("smtp.", loglevel)
|
||||||
sender := NewMTA(loglevel)
|
sender := NewMTA(loglevel)
|
||||||
receiver := &msa{
|
receiver := &msa{
|
||||||
log: log,
|
log: log,
|
||||||
|
bot: bot,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
client: client,
|
|
||||||
}
|
}
|
||||||
receiver.client.SetMTA(sender)
|
receiver.bot.SetMTA(sender)
|
||||||
s := smtp.NewServer(receiver)
|
s := smtp.NewServer(receiver)
|
||||||
s.Addr = ":" + port
|
s.Addr = ":" + port
|
||||||
s.Domain = domain
|
s.Domain = domain
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import (
|
|||||||
|
|
||||||
type msasession struct {
|
type msasession struct {
|
||||||
log *logger.Logger
|
log *logger.Logger
|
||||||
|
bot Bot
|
||||||
domain string
|
domain string
|
||||||
client Client
|
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
to string
|
to string
|
||||||
@@ -37,7 +37,7 @@ func (s *msasession) Rcpt(to string) error {
|
|||||||
return smtp.ErrAuthRequired
|
return smtp.ErrAuthRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
_, ok := s.client.GetMapping(utils.Mailbox(to))
|
_, ok := s.bot.GetMapping(utils.Mailbox(to))
|
||||||
if !ok {
|
if !ok {
|
||||||
s.log.Debug("mapping for %s not found", to)
|
s.log.Debug("mapping for %s not found", to)
|
||||||
return smtp.ErrAuthRequired
|
return smtp.ErrAuthRequired
|
||||||
@@ -84,7 +84,7 @@ func (s *msasession) Data(r io.Reader) error {
|
|||||||
eml.HTML,
|
eml.HTML,
|
||||||
files)
|
files)
|
||||||
|
|
||||||
return s.client.Send2Matrix(s.ctx, email)
|
return s.bot.Send2Matrix(s.ctx, email)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *msasession) Reset() {}
|
func (s *msasession) Reset() {}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import (
|
|||||||
"gitlab.com/etke.cc/postmoogle/utils"
|
"gitlab.com/etke.cc/postmoogle/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client interface to send emails into matrix
|
// Bot interface to send emails into matrix
|
||||||
type Client interface {
|
type Bot interface {
|
||||||
GetMapping(string) (id.RoomID, bool)
|
GetMapping(string) (id.RoomID, bool)
|
||||||
Send2Matrix(ctx context.Context, email *utils.Email) error
|
Send2Matrix(ctx context.Context, email *utils.Email) error
|
||||||
SetMTA(mta utils.MTA)
|
SetMTA(mta utils.MTA)
|
||||||
|
|||||||
Reference in New Issue
Block a user