diff --git a/README.md b/README.md index d26da0c..c55dacf 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,8 @@ If you want to change them - check available options in the help message (`!pm h --- +* **!pm nosend** - Get or set `nosend` of the room (`true` - disable email sending; `false` - enable email sending) +* **!pm noreplies** - Get or set `noreplies` of the room (`true` - ignore matrix replies; `false` - parse matrix replies) * **!pm nosender** - Get or set `nosender` of the room (`true` - hide email sender; `false` - show email sender) * **!pm norecipient** - Get or set `norecipient` of the room (`true` - hide recipient; `false` - show recipient) * **!pm nocc** - Get or set `nocc` of the room (`true` - hide CC; `false` - show CC) diff --git a/bot/access.go b/bot/access.go index 2782de4..d779023 100644 --- a/bot/access.go +++ b/bot/access.go @@ -73,6 +73,20 @@ func (b *Bot) allowSend(actorID id.UserID, targetRoomID id.RoomID) bool { return !cfg.NoSend() } +func (b *Bot) allowReply(actorID id.UserID, targetRoomID id.RoomID) bool { + if !b.allowUsers(actorID) { + return false + } + + cfg, err := b.cfg.GetRoom(targetRoomID) + if err != nil { + b.Error(sentry.SetHubOnContext(context.Background(), sentry.CurrentHub()), targetRoomID, "failed to retrieve settings: %v", err) + return false + } + + return !cfg.NoReplies() +} + func (b *Bot) isReserved(mailbox string) bool { for _, reserved := range b.mbxc.Reserved { if mailbox == reserved { diff --git a/bot/command.go b/bot/command.go index 3104d54..646e1b6 100644 --- a/bot/command.go +++ b/bot/command.go @@ -104,6 +104,15 @@ func (b *Bot) initCommands() commandList { sanitizer: utils.SanitizeBoolString, allowed: b.allowOwner, }, + { + key: config.RoomNoReplies, + description: fmt.Sprintf( + "Get or set `%s` of the room (`true` - ignore matrix replies; `false` - parse matrix replies)", + config.RoomNoReplies, + ), + sanitizer: utils.SanitizeBoolString, + allowed: b.allowOwner, + }, { key: config.RoomNoSender, description: fmt.Sprintf( diff --git a/bot/config/room.go b/bot/config/room.go index 92e60b3..fd55b88 100644 --- a/bot/config/room.go +++ b/bot/config/room.go @@ -19,6 +19,7 @@ const ( RoomMailbox = "mailbox" RoomDomain = "domain" RoomNoSend = "nosend" + RoomNoReplies = "noreplies" RoomNoCC = "nocc" RoomNoSender = "nosender" RoomNoRecipient = "norecipient" @@ -69,6 +70,10 @@ func (s Room) NoSend() bool { return utils.Bool(s.Get(RoomNoSend)) } +func (s Room) NoReplies() bool { + return utils.Bool(s.Get(RoomNoReplies)) +} + func (s Room) NoCC() bool { return utils.Bool(s.Get(RoomNoCC)) } diff --git a/bot/email.go b/bot/email.go index 40f09b7..35aed13 100644 --- a/bot/email.go +++ b/bot/email.go @@ -146,6 +146,9 @@ func (b *Bot) SendEmailReply(ctx context.Context) { if !b.allowSend(evt.Sender, evt.RoomID) { return } + if !b.allowReply(evt.Sender, evt.RoomID) { + return + } cfg, err := b.cfg.GetRoom(evt.RoomID) if err != nil { b.Error(ctx, evt.RoomID, "cannot retrieve room settings: %v", err) diff --git a/smtp/manager.go b/smtp/manager.go index 3c5749b..518d276 100644 --- a/smtp/manager.go +++ b/smtp/manager.go @@ -145,11 +145,16 @@ func (m *Manager) Start() error { // Stop SMTP server func (m *Manager) Stop() { - m.fsw.Stop() - err := m.smtp.Close() + err := m.fsw.Stop() + if err != nil { + m.log.Error("cannot stop filesystem watcher properly: %v", err) + } + + err = m.smtp.Close() if err != nil { m.log.Error("cannot stop SMTP server properly: %v", err) } + m.log.Info("SMTP server has been stopped") }