add catch-all mailbox, closes #25

This commit is contained in:
Aine
2022-10-04 21:45:52 +03:00
parent 4c6b7c2c1a
commit d6b6a5dc44
5 changed files with 69 additions and 2 deletions

View File

@@ -31,12 +31,12 @@ func (b *Bot) SetMTA(mta utils.MTA) {
b.mta = mta
}
// GetMapping returns mapping of mailbox = room
func (b *Bot) GetMapping(mailbox string) (id.RoomID, bool) {
func (b *Bot) getMapping(mailbox string) (id.RoomID, bool) {
v, ok := b.rooms.Load(mailbox)
if !ok {
return "", ok
}
roomID, ok := v.(id.RoomID)
if !ok {
return "", ok
@@ -45,6 +45,20 @@ func (b *Bot) GetMapping(mailbox string) (id.RoomID, bool) {
return roomID, ok
}
// GetMapping returns mapping of mailbox = room
func (b *Bot) GetMapping(mailbox string) (id.RoomID, bool) {
roomID, ok := b.getMapping(mailbox)
if !ok {
catchAll := b.getBotSettings().CatchAll()
if catchAll == "" {
return roomID, ok
}
return b.getMapping(catchAll)
}
return roomID, ok
}
// Send email to matrix room
func (b *Bot) Send2Matrix(ctx context.Context, email *utils.Email, incoming bool) error {
roomID, ok := b.GetMapping(email.Mailbox(incoming))