diff --git a/bot/command.go b/bot/command.go index fc92b5b..df202d4 100644 --- a/bot/command.go +++ b/bot/command.go @@ -143,6 +143,46 @@ func (b *Bot) initCommands() commandList { sanitizer: utils.SanitizeBoolString, allowed: b.allowOwner, }, + {allowed: b.allowOwner}, // delimiter + { + key: roomOptionSecurityEmail, + description: "Enforce sender email address validation (`true` - enforce, `false` - disable)", + sanitizer: utils.SanitizeBoolString, + allowed: b.allowOwner, + }, + { + key: roomOptionSecuritySMTP, + description: "Enforce sender email SMTP check (`true` - enforce, `false` - disable)", + sanitizer: utils.SanitizeBoolString, + allowed: b.allowOwner, + }, + { + key: roomOptionSpamEmails, + description: fmt.Sprintf( + "Get or set `%s` of the room (comma-separated list)", + roomOptionSpamEmails, + ), + sanitizer: utils.SanitizeStringSlice, + allowed: b.allowOwner, + }, + { + key: roomOptionSpamHosts, + description: fmt.Sprintf( + "Get or set `%s` of the room (comma-separated list)", + roomOptionSpamHosts, + ), + sanitizer: utils.SanitizeStringSlice, + allowed: b.allowOwner, + }, + { + key: roomOptionSpamLocalparts, + description: fmt.Sprintf( + "Get or set `%s` of the room (comma-separated list)", + roomOptionSpamLocalparts, + ), + sanitizer: utils.SanitizeStringSlice, + allowed: b.allowOwner, + }, {allowed: b.allowAdmin}, // delimiter { key: botOptionUsers, diff --git a/bot/settings_room.go b/bot/settings_room.go index 7870aa7..57d57b9 100644 --- a/bot/settings_room.go +++ b/bot/settings_room.go @@ -13,16 +13,21 @@ const acRoomSettingsKey = "cc.etke.postmoogle.settings" // option keys const ( - roomOptionOwner = "owner" - roomOptionMailbox = "mailbox" - roomOptionNoSend = "nosend" - roomOptionNoSender = "nosender" - roomOptionNoRecipient = "norecipient" - roomOptionNoSubject = "nosubject" - roomOptionNoHTML = "nohtml" - roomOptionNoThreads = "nothreads" - roomOptionNoFiles = "nofiles" - roomOptionPassword = "password" + roomOptionOwner = "owner" + roomOptionMailbox = "mailbox" + roomOptionNoSend = "nosend" + roomOptionNoSender = "nosender" + roomOptionNoRecipient = "norecipient" + roomOptionNoSubject = "nosubject" + roomOptionNoHTML = "nohtml" + roomOptionNoThreads = "nothreads" + roomOptionNoFiles = "nofiles" + roomOptionPassword = "password" + roomOptionSecuritySMTP = "security:smtp" + roomOptionSecurityEmail = "security:email" + roomOptionSpamEmails = "spam:emails" + roomOptionSpamHosts = "spam:hosts" + roomOptionSpamLocalparts = "spam:localparts" ) type roomSettings map[string]string @@ -77,6 +82,26 @@ func (s roomSettings) NoFiles() bool { return utils.Bool(s.Get(roomOptionNoFiles)) } +func (s roomSettings) SecuritySMTP() bool { + return utils.Bool(s.Get(roomOptionSecuritySMTP)) +} + +func (s roomSettings) SecurityEmail() bool { + return utils.Bool(s.Get(roomOptionSecurityEmail)) +} + +func (s roomSettings) SpamEmails() []string { + return utils.StringSlice(s.Get(roomOptionSpamEmails)) +} + +func (s roomSettings) SpamHosts() []string { + return utils.StringSlice(s.Get(roomOptionSpamHosts)) +} + +func (s roomSettings) SpamLocalparts() []string { + return utils.StringSlice(s.Get(roomOptionSpamLocalparts)) +} + // ContentOptions converts room display settings to content options func (s roomSettings) ContentOptions() *utils.ContentOptions { return &utils.ContentOptions{ diff --git a/utils/utils.go b/utils/utils.go index 93271da..f49939a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -33,3 +33,31 @@ func Bool(str string) bool { func SanitizeBoolString(str string) string { return strconv.FormatBool(Bool(str)) } + +// StringSlice converts comma-separated string to slice +func StringSlice(str string) []string { + if str == "" { + return nil + } + + str = strings.TrimSpace(str) + if strings.IndexByte(str, ',') == -1 { + return []string{str} + } + + return strings.Split(str, ",") +} + +// SanitizeBoolString converts string to slice and back to string +func SanitizeStringSlice(str string) string { + parts := StringSlice(str) + if len(parts) == 0 { + return str + } + + for i, part := range parts { + parts[i] = strings.TrimSpace(part) + } + + return strings.Join(parts, ",") +}