expose security and spam options

This commit is contained in:
Aine
2022-10-07 23:24:59 +03:00
parent 70ef60c934
commit 6f8e850103
3 changed files with 103 additions and 10 deletions

View File

@@ -143,6 +143,46 @@ func (b *Bot) initCommands() commandList {
sanitizer: utils.SanitizeBoolString, sanitizer: utils.SanitizeBoolString,
allowed: b.allowOwner, 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 {allowed: b.allowAdmin}, // delimiter
{ {
key: botOptionUsers, key: botOptionUsers,

View File

@@ -13,16 +13,21 @@ const acRoomSettingsKey = "cc.etke.postmoogle.settings"
// option keys // option keys
const ( const (
roomOptionOwner = "owner" roomOptionOwner = "owner"
roomOptionMailbox = "mailbox" roomOptionMailbox = "mailbox"
roomOptionNoSend = "nosend" roomOptionNoSend = "nosend"
roomOptionNoSender = "nosender" roomOptionNoSender = "nosender"
roomOptionNoRecipient = "norecipient" roomOptionNoRecipient = "norecipient"
roomOptionNoSubject = "nosubject" roomOptionNoSubject = "nosubject"
roomOptionNoHTML = "nohtml" roomOptionNoHTML = "nohtml"
roomOptionNoThreads = "nothreads" roomOptionNoThreads = "nothreads"
roomOptionNoFiles = "nofiles" roomOptionNoFiles = "nofiles"
roomOptionPassword = "password" roomOptionPassword = "password"
roomOptionSecuritySMTP = "security:smtp"
roomOptionSecurityEmail = "security:email"
roomOptionSpamEmails = "spam:emails"
roomOptionSpamHosts = "spam:hosts"
roomOptionSpamLocalparts = "spam:localparts"
) )
type roomSettings map[string]string type roomSettings map[string]string
@@ -77,6 +82,26 @@ func (s roomSettings) NoFiles() bool {
return utils.Bool(s.Get(roomOptionNoFiles)) 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 // ContentOptions converts room display settings to content options
func (s roomSettings) ContentOptions() *utils.ContentOptions { func (s roomSettings) ContentOptions() *utils.ContentOptions {
return &utils.ContentOptions{ return &utils.ContentOptions{

View File

@@ -33,3 +33,31 @@ func Bool(str string) bool {
func SanitizeBoolString(str string) string { func SanitizeBoolString(str string) string {
return strconv.FormatBool(Bool(str)) 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, ",")
}