From 70ef60c93425375595c9649b2f858e5ccc95bf31 Mon Sep 17 00:00:00 2001 From: Aine Date: Fri, 7 Oct 2022 23:07:57 +0300 Subject: [PATCH] add 'norecipient' room option, closes #35 --- README.md | 1 + bot/command.go | 9 +++++++++ bot/settings_room.go | 32 +++++++++++++++++++------------- utils/email.go | 16 +++++++++++----- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e75764f..903153c 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,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 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 d933775..fc92b5b 100644 --- a/bot/command.go +++ b/bot/command.go @@ -98,6 +98,15 @@ func (b *Bot) initCommands() commandList { sanitizer: utils.SanitizeBoolString, allowed: b.allowOwner, }, + { + key: roomOptionNoRecipient, + description: fmt.Sprintf( + "Get or set `%s` of the room (`true` - hide recipient; `false` - show recipient)", + roomOptionNoRecipient, + ), + sanitizer: utils.SanitizeBoolString, + allowed: b.allowOwner, + }, { key: roomOptionNoSubject, description: fmt.Sprintf( diff --git a/bot/settings_room.go b/bot/settings_room.go index 619d70f..7870aa7 100644 --- a/bot/settings_room.go +++ b/bot/settings_room.go @@ -13,15 +13,16 @@ const acRoomSettingsKey = "cc.etke.postmoogle.settings" // option keys const ( - roomOptionOwner = "owner" - roomOptionMailbox = "mailbox" - roomOptionNoSend = "nosend" - roomOptionNoSender = "nosender" - 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" ) type roomSettings map[string]string @@ -56,6 +57,10 @@ func (s roomSettings) NoSender() bool { return utils.Bool(s.Get(roomOptionNoSender)) } +func (s roomSettings) NoRecipient() bool { + return utils.Bool(s.Get(roomOptionNoRecipient)) +} + func (s roomSettings) NoSubject() bool { return utils.Bool(s.Get(roomOptionNoSubject)) } @@ -75,10 +80,11 @@ func (s roomSettings) NoFiles() bool { // ContentOptions converts room display settings to content options func (s roomSettings) ContentOptions() *utils.ContentOptions { return &utils.ContentOptions{ - HTML: !s.NoHTML(), - Sender: !s.NoSender(), - Subject: !s.NoSubject(), - Threads: !s.NoThreads(), + HTML: !s.NoHTML(), + Sender: !s.NoSender(), + Recipient: !s.NoRecipient(), + Subject: !s.NoSubject(), + Threads: !s.NoThreads(), FromKey: eventFromKey, SubjectKey: eventSubjectKey, diff --git a/utils/email.go b/utils/email.go index 02a9593..b415929 100644 --- a/utils/email.go +++ b/utils/email.go @@ -35,10 +35,11 @@ type Email struct { // ContentOptions represents settings that specify how an email is to be converted to a Matrix message type ContentOptions struct { // On/Off - Sender bool - Subject bool - HTML bool - Threads bool + Sender bool + Recipient bool + Subject bool + HTML bool + Threads bool // Keys MessageIDKey string @@ -92,7 +93,12 @@ func (e *Email) Content(threadID id.EventID, options *ContentOptions) *event.Con if options.Sender { text.WriteString("From: ") text.WriteString(e.From) - text.WriteString("\n\n") + text.WriteString("\n") + } + if options.Recipient { + text.WriteString("To: ") + text.WriteString(e.To) + text.WriteString("\n") } if options.Subject { text.WriteString("# ")