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