rename local to incoming

This commit is contained in:
Aine
2022-09-23 10:33:25 +03:00
parent d50b79a801
commit 3f5a1cd915
5 changed files with 23 additions and 23 deletions

View File

@@ -46,8 +46,8 @@ func (b *Bot) GetMapping(mailbox string) (id.RoomID, bool) {
} }
// Send email to matrix room // Send email to matrix room
func (b *Bot) Send2Matrix(ctx context.Context, email *utils.Email, local bool) error { func (b *Bot) Send2Matrix(ctx context.Context, email *utils.Email, incoming bool) error {
roomID, ok := b.GetMapping(email.Mailbox(local)) roomID, ok := b.GetMapping(email.Mailbox(incoming))
if !ok { if !ok {
return errors.New("room not found") 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) 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") 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) b.sendFiles(ctx, roomID, email.Files, cfg.NoThreads(), threadID)
} }
if !local { if !incoming {
email.MessageID = fmt.Sprintf("<%s@%s>", eventID, b.domain) email.MessageID = fmt.Sprintf("<%s@%s>", eventID, b.domain)
return b.mta.Send(email.From, email.To, email.Compose(b.getBotSettings().DKIMPrivateKey())) return b.mta.Send(email.From, email.To, email.Compose(b.getBotSettings().DKIMPrivateKey()))
} }

View File

@@ -19,15 +19,15 @@ type msa struct {
mta utils.MTA mta utils.MTA
} }
func (m *msa) newSession(from string, local bool) *msasession { func (m *msa) newSession(from string, incoming bool) *msasession {
return &msasession{ return &msasession{
ctx: sentry.SetHubOnContext(context.Background(), sentry.CurrentHub().Clone()), ctx: sentry.SetHubOnContext(context.Background(), sentry.CurrentHub().Clone()),
mta: m.mta, mta: m.mta,
from: from, from: from,
local: local, incoming: incoming,
log: m.log, log: m.log,
bot: m.bot, bot: m.bot,
domain: m.domain, domain: m.domain,
} }
} }

View File

@@ -19,10 +19,10 @@ type msasession struct {
mta utils.MTA mta utils.MTA
domain string domain string
ctx context.Context ctx context.Context
local bool incoming bool
to string to string
from string from string
} }
func (s *msasession) Mail(from string, opts smtp.MailOptions) error { 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) { if !utils.AddressValid(from) {
return errors.New("please, provide email address") return errors.New("please, provide email address")
} }
if s.local { if s.incoming {
s.from = from s.from = from
s.log.Debug("mail from %s, options: %+v", from, opts) 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 { func (s *msasession) Rcpt(to string) error {
sentry.GetHubFromContext(s.ctx).Scope().SetTag("to", to) sentry.GetHubFromContext(s.ctx).Scope().SetTag("to", to)
if s.local { if s.incoming {
if utils.Hostname(to) != s.domain { if utils.Hostname(to) != s.domain {
s.log.Debug("wrong domain of %s", to) s.log.Debug("wrong domain of %s", to)
return smtp.ErrAuthRequired return smtp.ErrAuthRequired
@@ -90,7 +90,7 @@ func (s *msasession) Data(r io.Reader) error {
eml.HTML, eml.HTML,
files) files)
return s.bot.Send2Matrix(s.ctx, email, s.local) return s.bot.Send2Matrix(s.ctx, email, s.incoming)
} }
func (s *msasession) Reset() {} func (s *msasession) Reset() {}

View File

@@ -19,7 +19,7 @@ import (
type Bot interface { type Bot interface {
AllowAuth(string, string) bool AllowAuth(string, string) bool
GetMapping(string) (id.RoomID, 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) SetMTA(mta utils.MTA)
} }

View File

@@ -78,9 +78,9 @@ func NewEmail(messageID, inReplyTo, subject, from, to, text, html string, files
return email return email
} }
// Mailbox returns postmoogle's mailbox, parsing it from FROM (if local=false) or TO (local=true) // Mailbox returns postmoogle's mailbox, parsing it from FROM (if incoming=false) or TO (incoming=true)
func (e *Email) Mailbox(local bool) string { func (e *Email) Mailbox(incoming bool) string {
if local { if incoming {
return Mailbox(e.To) return Mailbox(e.To)
} }
return Mailbox(e.From) return Mailbox(e.From)