initial, rought, not-user-friendly support for multi-domain setup
This commit is contained in:
@@ -73,7 +73,14 @@ func (b *Bot) allowSend(actorID id.UserID, targetRoomID id.RoomID) bool {
|
||||
|
||||
// AllowAuth check if SMTP login (email) and password are valid
|
||||
func (b *Bot) AllowAuth(email, password string) bool {
|
||||
if !strings.HasSuffix(email, "@"+b.domain) {
|
||||
var suffix bool
|
||||
for _, domain := range b.domains {
|
||||
if strings.HasSuffix(email, "@"+domain) {
|
||||
suffix = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !suffix {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
16
bot/bot.go
16
bot/bot.go
@@ -19,7 +19,7 @@ import (
|
||||
// Bot represents matrix bot
|
||||
type Bot struct {
|
||||
prefix string
|
||||
domain string
|
||||
domains []string
|
||||
allowedUsers []*regexp.Regexp
|
||||
allowedAdmins []*regexp.Regexp
|
||||
commands commandList
|
||||
@@ -36,16 +36,16 @@ func New(
|
||||
lp *linkpearl.Linkpearl,
|
||||
log *logger.Logger,
|
||||
prefix string,
|
||||
domain string,
|
||||
domains []string,
|
||||
admins []string,
|
||||
) (*Bot, error) {
|
||||
b := &Bot{
|
||||
prefix: prefix,
|
||||
domain: domain,
|
||||
rooms: sync.Map{},
|
||||
log: log,
|
||||
lp: lp,
|
||||
mu: map[id.RoomID]*sync.Mutex{},
|
||||
prefix: prefix,
|
||||
domains: domains,
|
||||
rooms: sync.Map{},
|
||||
log: log,
|
||||
lp: lp,
|
||||
mu: map[id.RoomID]*sync.Mutex{},
|
||||
}
|
||||
users, err := b.initBotUsers()
|
||||
if err != nil {
|
||||
|
||||
@@ -262,7 +262,7 @@ func (b *Bot) sendIntroduction(ctx context.Context, roomID id.RoomID) {
|
||||
msg.WriteString(" SOME_INBOX` command.\n")
|
||||
|
||||
msg.WriteString("You will then be able to send emails to `SOME_INBOX@")
|
||||
msg.WriteString(b.domain)
|
||||
msg.WriteString(b.domains[0])
|
||||
msg.WriteString("` and have them appear in this room.")
|
||||
|
||||
b.SendNotice(ctx, roomID, msg.String())
|
||||
@@ -301,7 +301,7 @@ func (b *Bot) sendHelp(ctx context.Context) {
|
||||
msg.WriteString(value)
|
||||
if cmd.key == roomOptionMailbox {
|
||||
msg.WriteString("@")
|
||||
msg.WriteString(b.domain)
|
||||
msg.WriteString(b.domains[0])
|
||||
}
|
||||
msg.WriteString("`)")
|
||||
}
|
||||
@@ -358,8 +358,8 @@ func (b *Bot) runSend(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
from := mailbox + "@" + b.domain
|
||||
ID := fmt.Sprintf("<%s@%s>", evt.ID, b.domain)
|
||||
from := mailbox + "@" + b.domains[0]
|
||||
ID := fmt.Sprintf("<%s@%s>", evt.ID, b.domains[0])
|
||||
for _, to := range tos {
|
||||
data := utils.
|
||||
NewEmail(ID, "", subject, from, to, body, "", nil).
|
||||
|
||||
@@ -55,7 +55,7 @@ func (b *Bot) sendMailboxes(ctx context.Context) {
|
||||
msg.WriteString("* `")
|
||||
msg.WriteString(mailbox)
|
||||
msg.WriteString("@")
|
||||
msg.WriteString(b.domain)
|
||||
msg.WriteString(b.domains[0])
|
||||
msg.WriteString("` by ")
|
||||
msg.WriteString(cfg.Owner())
|
||||
msg.WriteString("\n")
|
||||
@@ -202,5 +202,5 @@ func (b *Bot) runCatchAll(ctx context.Context, commandSlice []string) {
|
||||
return
|
||||
}
|
||||
|
||||
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("Catch-all is set to: `%s@%s`.", mailbox, b.domain))
|
||||
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("Catch-all is set to: `%s@%s`.", mailbox, b.domains[0]))
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func (b *Bot) getOption(ctx context.Context, name string) {
|
||||
}
|
||||
|
||||
if name == roomOptionMailbox {
|
||||
value = value + "@" + b.domain
|
||||
value = value + "@" + b.domains[0]
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("`%s` of this room is `%s`\n"+
|
||||
@@ -85,7 +85,7 @@ func (b *Bot) setOption(ctx context.Context, name, value string) {
|
||||
if name == roomOptionMailbox {
|
||||
existingID, ok := b.getMapping(value)
|
||||
if ok && existingID != "" && existingID != evt.RoomID {
|
||||
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("Mailbox `%s@%s` already taken, kupo", value, b.domain))
|
||||
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf("Mailbox `%s@%s` already taken, kupo", value, b.domains[0]))
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (b *Bot) setOption(ctx context.Context, name, value string) {
|
||||
b.rooms.Delete(old)
|
||||
}
|
||||
b.rooms.Store(value, evt.RoomID)
|
||||
value = fmt.Sprintf("%s@%s", value, b.domain)
|
||||
value = fmt.Sprintf("%s@%s", value, b.domains[0])
|
||||
}
|
||||
|
||||
err = b.setRoomSettings(evt.RoomID, cfg)
|
||||
|
||||
@@ -112,7 +112,7 @@ func (b *Bot) Send2Matrix(ctx context.Context, email *utils.Email, incoming bool
|
||||
}
|
||||
|
||||
if !incoming {
|
||||
email.MessageID = fmt.Sprintf("<%s@%s>", eventID, b.domain)
|
||||
email.MessageID = fmt.Sprintf("<%s@%s>", eventID, b.domains[0])
|
||||
return b.mta.Send(email.From, email.To, email.Compose(b.getBotSettings().DKIMPrivateKey()))
|
||||
}
|
||||
return nil
|
||||
@@ -167,7 +167,7 @@ func (b *Bot) Send2Email(ctx context.Context, to, subject, body string) error {
|
||||
if mailbox == "" {
|
||||
return fmt.Errorf("mailbox not configured, kupo")
|
||||
}
|
||||
from := mailbox + "@" + b.domain
|
||||
from := mailbox + "@" + b.domains[0]
|
||||
pTo, pInReplyTo, pSubject := b.getParentEmail(evt)
|
||||
inReplyTo = pInReplyTo
|
||||
if pTo != "" && to == "" {
|
||||
@@ -189,7 +189,7 @@ func (b *Bot) Send2Email(ctx context.Context, to, subject, body string) error {
|
||||
}
|
||||
}
|
||||
|
||||
ID := evt.ID.String()[1:] + "@" + b.domain
|
||||
ID := evt.ID.String()[1:] + "@" + b.domains[0]
|
||||
data := utils.
|
||||
NewEmail(ID, inReplyTo, subject, from, to, body, "", nil).
|
||||
Compose(b.getBotSettings().DKIMPrivateKey())
|
||||
|
||||
Reference in New Issue
Block a user