properly update mailbox, fixes #9
This commit is contained in:
14
bot/bot.go
14
bot/bot.go
@@ -78,20 +78,6 @@ func (b *Bot) Start(statusMsg string) error {
|
||||
return b.lp.Start(statusMsg)
|
||||
}
|
||||
|
||||
// GetMappings returns mapping of mailbox = room
|
||||
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
|
||||
}
|
||||
|
||||
return roomID, ok
|
||||
}
|
||||
|
||||
// Stop the bot
|
||||
func (b *Bot) Stop() {
|
||||
err := b.lp.GetClient().SetPresence(event.PresenceOffline)
|
||||
|
||||
@@ -256,11 +256,16 @@ func (b *Bot) setOption(ctx context.Context, name, value string) {
|
||||
return
|
||||
}
|
||||
|
||||
old := cfg.Get(name)
|
||||
cfg.Set(name, value)
|
||||
|
||||
if name == optionMailbox {
|
||||
value = fmt.Sprintf("%s@%s", value, b.domain)
|
||||
cfg.Set(optionOwner, evt.Sender.String())
|
||||
if old != "" {
|
||||
b.rooms.Delete(old)
|
||||
}
|
||||
b.rooms.Store(value, evt.RoomID)
|
||||
value = fmt.Sprintf("%s@%s", value, b.domain)
|
||||
}
|
||||
|
||||
err = b.setSettings(evt.RoomID, cfg)
|
||||
|
||||
19
bot/email.go
19
bot/email.go
@@ -43,6 +43,25 @@ func email2content(email *utils.Email, cfg settings, threadID id.EventID) *event
|
||||
return &content
|
||||
}
|
||||
|
||||
// GetMapping returns mapping of mailbox = room
|
||||
func (b *Bot) GetMapping(mailbox string) (id.RoomID, bool) {
|
||||
b.rooms.Range(func(key, value any) bool {
|
||||
b.log.Debug("MAPPING %v=%v", key, value)
|
||||
|
||||
return true
|
||||
})
|
||||
v, ok := b.rooms.Load(mailbox)
|
||||
if !ok {
|
||||
return "", ok
|
||||
}
|
||||
roomID, ok := v.(id.RoomID)
|
||||
if !ok {
|
||||
return "", ok
|
||||
}
|
||||
|
||||
return roomID, ok
|
||||
}
|
||||
|
||||
// Send email to matrix room
|
||||
func (b *Bot) Send(ctx context.Context, email *utils.Email) error {
|
||||
roomID, ok := b.GetMapping(utils.Mailbox(email.To))
|
||||
|
||||
Reference in New Issue
Block a user