add catch-all mailbox, closes #25
This commit is contained in:
18
bot/email.go
18
bot/email.go
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user