Add ability to hide sender's email address (hide-sender-address setting)

The configuration setting is called `Hide*` instead of `Show*`, because
it's backward compatible with existing configuration settings.

This is useful for when you setup an email forwarding inbox and you're
always sending to it through the same email address. In that case, you
don't need to see the email address in each Matrix message.

In the future, another similar `bool` setting (`hide-subject`) will land,
which controls whether the email's subject is shown in the final message
or not. That setting can make use of most of the same setup (all of
`handleBooleanConfigurationKey`).
This commit is contained in:
Slavi Pantaleev
2022-08-23 18:18:06 +03:00
parent b8cb8196c2
commit 9f3aa3dd68
4 changed files with 124 additions and 9 deletions

View File

@@ -89,17 +89,24 @@ func (b *Bot) Send(ctx context.Context, from, to, subject, body string, files []
return errors.New("room not found")
}
settings, err := b.getSettings(ctx, roomID)
if err != nil {
return err
}
var text strings.Builder
text.WriteString("From: ")
text.WriteString(from)
text.WriteString("\n\n")
if !settings.HideSenderAddress {
text.WriteString("From: ")
text.WriteString(from)
text.WriteString("\n\n")
}
text.WriteString("# ")
text.WriteString(subject)
text.WriteString("\n\n")
text.WriteString(format.HTMLToMarkdown(body))
content := format.RenderMarkdown(text.String(), true, true)
_, err := b.lp.Send(roomID, content)
_, err = b.lp.Send(roomID, content)
if err != nil {
return err
}