From 41a52c1eca09defd5edc72521cae280b32304c38 Mon Sep 17 00:00:00 2001 From: Aine Date: Fri, 26 Aug 2022 15:56:25 +0300 Subject: [PATCH] add 'nohtml' option, fixes #5 --- bot/bot.go | 2 +- bot/command.go | 8 ++++++++ bot/data.go | 1 + bot/settings.go | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bot/bot.go b/bot/bot.go index c0e3b33..61dbed4 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -103,7 +103,7 @@ func (b *Bot) Send(ctx context.Context, email *utils.Email) error { text.WriteString(email.Subject) text.WriteString("\n\n") } - if email.HTML != "" { + if email.HTML != "" && !settings.NoHTML() { text.WriteString(format.HTMLToMarkdown(email.HTML)) } else { text.WriteString(email.Text) diff --git a/bot/command.go b/bot/command.go index 1c399bb..2b11cea 100644 --- a/bot/command.go +++ b/bot/command.go @@ -64,6 +64,13 @@ var ( optionNoSubject, ), }, + { + key: optionNoHTML, + description: fmt.Sprintf( + "Get or set `%s` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails)", + optionNoHTML, + ), + }, } // sanitizers is map of option name => sanitizer function @@ -71,6 +78,7 @@ var ( optionMailbox: utils.Mailbox, optionNoSender: utils.SanitizeBoolString, optionNoSubject: utils.SanitizeBoolString, + optionNoHTML: utils.SanitizeBoolString, } ) diff --git a/bot/data.go b/bot/data.go index c79b5c4..74f1b8a 100644 --- a/bot/data.go +++ b/bot/data.go @@ -24,6 +24,7 @@ const ( optionMailbox = "mailbox" optionNoSender = "nosender" optionNoSubject = "nosubject" + optionNoHTML = "nohtml" ) var migrations = []string{} diff --git a/bot/settings.go b/bot/settings.go index fd7fe82..fe3055f 100644 --- a/bot/settings.go +++ b/bot/settings.go @@ -60,6 +60,10 @@ func (s settings) NoSubject() bool { return utils.Bool(s.Get(optionNoSubject)) } +func (s settings) NoHTML() bool { + return utils.Bool(s.Get(optionNoHTML)) +} + // Set option func (s settings) Set(key, value string) { s[strings.ToLower(strings.TrimSpace(key))] = value