rename local to incoming
This commit is contained in:
@@ -46,8 +46,8 @@ func (b *Bot) GetMapping(mailbox string) (id.RoomID, bool) {
|
||||
}
|
||||
|
||||
// Send email to matrix room
|
||||
func (b *Bot) Send2Matrix(ctx context.Context, email *utils.Email, local bool) error {
|
||||
roomID, ok := b.GetMapping(email.Mailbox(local))
|
||||
func (b *Bot) Send2Matrix(ctx context.Context, email *utils.Email, incoming bool) error {
|
||||
roomID, ok := b.GetMapping(email.Mailbox(incoming))
|
||||
if !ok {
|
||||
return errors.New("room not found")
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (b *Bot) Send2Matrix(ctx context.Context, email *utils.Email, local bool) e
|
||||
b.Error(ctx, roomID, "cannot get settings: %v", err)
|
||||
}
|
||||
|
||||
if !local && cfg.NoSend() {
|
||||
if !incoming && cfg.NoSend() {
|
||||
return errors.New("that mailbox is receive-only")
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func (b *Bot) Send2Matrix(ctx context.Context, email *utils.Email, local bool) e
|
||||
b.sendFiles(ctx, roomID, email.Files, cfg.NoThreads(), threadID)
|
||||
}
|
||||
|
||||
if !local {
|
||||
if !incoming {
|
||||
email.MessageID = fmt.Sprintf("<%s@%s>", eventID, b.domain)
|
||||
return b.mta.Send(email.From, email.To, email.Compose(b.getBotSettings().DKIMPrivateKey()))
|
||||
}
|
||||
|
||||
16
smtp/msa.go
16
smtp/msa.go
@@ -19,15 +19,15 @@ type msa struct {
|
||||
mta utils.MTA
|
||||
}
|
||||
|
||||
func (m *msa) newSession(from string, local bool) *msasession {
|
||||
func (m *msa) newSession(from string, incoming bool) *msasession {
|
||||
return &msasession{
|
||||
ctx: sentry.SetHubOnContext(context.Background(), sentry.CurrentHub().Clone()),
|
||||
mta: m.mta,
|
||||
from: from,
|
||||
local: local,
|
||||
log: m.log,
|
||||
bot: m.bot,
|
||||
domain: m.domain,
|
||||
ctx: sentry.SetHubOnContext(context.Background(), sentry.CurrentHub().Clone()),
|
||||
mta: m.mta,
|
||||
from: from,
|
||||
incoming: incoming,
|
||||
log: m.log,
|
||||
bot: m.bot,
|
||||
domain: m.domain,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ type msasession struct {
|
||||
mta utils.MTA
|
||||
domain string
|
||||
|
||||
ctx context.Context
|
||||
local bool
|
||||
to string
|
||||
from string
|
||||
ctx context.Context
|
||||
incoming bool
|
||||
to string
|
||||
from string
|
||||
}
|
||||
|
||||
func (s *msasession) Mail(from string, opts smtp.MailOptions) error {
|
||||
@@ -30,7 +30,7 @@ func (s *msasession) Mail(from string, opts smtp.MailOptions) error {
|
||||
if !utils.AddressValid(from) {
|
||||
return errors.New("please, provide email address")
|
||||
}
|
||||
if s.local {
|
||||
if s.incoming {
|
||||
s.from = from
|
||||
s.log.Debug("mail from %s, options: %+v", from, opts)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func (s *msasession) Mail(from string, opts smtp.MailOptions) error {
|
||||
func (s *msasession) Rcpt(to string) error {
|
||||
sentry.GetHubFromContext(s.ctx).Scope().SetTag("to", to)
|
||||
|
||||
if s.local {
|
||||
if s.incoming {
|
||||
if utils.Hostname(to) != s.domain {
|
||||
s.log.Debug("wrong domain of %s", to)
|
||||
return smtp.ErrAuthRequired
|
||||
@@ -90,7 +90,7 @@ func (s *msasession) Data(r io.Reader) error {
|
||||
eml.HTML,
|
||||
files)
|
||||
|
||||
return s.bot.Send2Matrix(s.ctx, email, s.local)
|
||||
return s.bot.Send2Matrix(s.ctx, email, s.incoming)
|
||||
}
|
||||
|
||||
func (s *msasession) Reset() {}
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
type Bot interface {
|
||||
AllowAuth(string, string) bool
|
||||
GetMapping(string) (id.RoomID, bool)
|
||||
Send2Matrix(ctx context.Context, email *utils.Email, local bool) error
|
||||
Send2Matrix(ctx context.Context, email *utils.Email, incoming bool) error
|
||||
SetMTA(mta utils.MTA)
|
||||
}
|
||||
|
||||
|
||||
@@ -78,9 +78,9 @@ func NewEmail(messageID, inReplyTo, subject, from, to, text, html string, files
|
||||
return email
|
||||
}
|
||||
|
||||
// Mailbox returns postmoogle's mailbox, parsing it from FROM (if local=false) or TO (local=true)
|
||||
func (e *Email) Mailbox(local bool) string {
|
||||
if local {
|
||||
// Mailbox returns postmoogle's mailbox, parsing it from FROM (if incoming=false) or TO (incoming=true)
|
||||
func (e *Email) Mailbox(incoming bool) string {
|
||||
if incoming {
|
||||
return Mailbox(e.To)
|
||||
}
|
||||
return Mailbox(e.From)
|
||||
|
||||
Reference in New Issue
Block a user