From 5fe8603506b4e2f773b933b2d5b47b22cb4a8f84 Mon Sep 17 00:00:00 2001 From: Aine Date: Sat, 19 Nov 2022 17:09:24 +0200 Subject: [PATCH] add `nocc` option --- README.md | 1 + bot/command.go | 9 +++++++++ bot/settings_room.go | 6 ++++++ email/email.go | 6 +++++- email/options.go | 1 + 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e66550..f46bd9c 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ If you want to change them - check available options in the help message (`!pm h * **!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) * **!pm nosubject** - Get or set `nosubject` of the room (`true` - hide email subject; `false` - show email subject) * **!pm nohtml** - Get or set `nohtml` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails) * **!pm nothreads** - Get or set `nothreads` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads) diff --git a/bot/command.go b/bot/command.go index 8233ef3..965017e 100644 --- a/bot/command.go +++ b/bot/command.go @@ -121,6 +121,15 @@ func (b *Bot) initCommands() commandList { sanitizer: utils.SanitizeBoolString, allowed: b.allowOwner, }, + { + key: roomOptionNoCC, + description: fmt.Sprintf( + "Get or set `%s` of the room (`true` - hide CC; `false` - show CC)", + roomOptionNoCC, + ), + sanitizer: utils.SanitizeBoolString, + allowed: b.allowOwner, + }, { key: roomOptionNoSubject, description: fmt.Sprintf( diff --git a/bot/settings_room.go b/bot/settings_room.go index 54359c7..bd62091 100644 --- a/bot/settings_room.go +++ b/bot/settings_room.go @@ -18,6 +18,7 @@ const ( roomOptionMailbox = "mailbox" roomOptionDomain = "domain" roomOptionNoSend = "nosend" + roomOptionNoCC = "nocc" roomOptionNoSender = "nosender" roomOptionNoRecipient = "norecipient" roomOptionNoSubject = "nosubject" @@ -62,6 +63,10 @@ func (s roomSettings) NoSend() bool { return utils.Bool(s.Get(roomOptionNoSend)) } +func (s roomSettings) NoCC() bool { + return utils.Bool(s.Get(roomOptionNoCC)) +} + func (s roomSettings) NoSender() bool { return utils.Bool(s.Get(roomOptionNoSender)) } @@ -146,6 +151,7 @@ func (s roomSettings) migrateSpamlistSettings() { // ContentOptions converts room display settings to content options func (s roomSettings) ContentOptions() *email.ContentOptions { return &email.ContentOptions{ + CC: !s.NoCC(), HTML: !s.NoHTML(), Sender: !s.NoSender(), Recipient: !s.NoRecipient(), diff --git a/email/email.go b/email/email.go index b54ecbd..026d76f 100644 --- a/email/email.go +++ b/email/email.go @@ -107,7 +107,11 @@ func (e *Email) Content(threadID id.EventID, options *ContentOptions) *event.Con text.WriteString(" ➡️ ") text.WriteString(e.To) } - if options.Sender || options.Recipient { + if options.CC && e.CC != "" { + text.WriteString("\ncc: ") + text.WriteString(e.CC) + } + if options.Sender || options.Recipient || options.CC { text.WriteString("\n\n") } if options.Subject && threadID == "" { diff --git a/email/options.go b/email/options.go index d7744a0..522ece8 100644 --- a/email/options.go +++ b/email/options.go @@ -10,6 +10,7 @@ type IncomingFilteringOptions interface { // ContentOptions represents settings that specify how an email is to be converted to a Matrix message type ContentOptions struct { // On/Off + CC bool Sender bool Recipient bool Subject bool