diff --git a/README.md b/README.md
index 17a5ec7..f1bfee6 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,7 @@ so you can use it to send emails from your apps and scripts as well.
- [x] SMTP server (you can use Postmoogle as general purpose SMTP server to send emails from your scripts or apps)
- [x] Send a message to matrix room with special format to send a new email, even to multiple email addresses at once
- [x] Reply to matrix thread sends reply into email thread
+- [x] Email signatures
## Configuration
@@ -120,6 +121,7 @@ If you want to change them - check available options in the help message (`!pm h
> The following section is visible to the mailbox owners only
+* **`!pm signature`** - Get or set signature of the room (markdown supported)
* **`!pm nosend`** - Get or set `nosend` of the room (`true` - disable email sending; `false` - enable email sending)
* **`!pm noreplies`** - Get or set `noreplies` of the room (`true` - ignore matrix replies; `false` - parse matrix replies)
* **`!pm nosender`** - Get or set `nosender` of the room (`true` - hide email sender; `false` - show email sender)
diff --git a/bot/command.go b/bot/command.go
index 2ee2361..69c0367 100644
--- a/bot/command.go
+++ b/bot/command.go
@@ -99,6 +99,12 @@ func (b *Bot) initCommands() commandList {
allowed: b.allowOwner,
},
{allowed: b.allowOwner, description: "mailbox options"}, // delimiter
+ {
+ key: config.RoomSignature,
+ description: "Get or set signature of the room (markdown supported)",
+ sanitizer: func(s string) string { return s },
+ allowed: b.allowOwner,
+ },
{
key: config.RoomNoSend,
description: fmt.Sprintf(
@@ -523,6 +529,14 @@ func (b *Bot) runSend(ctx context.Context) {
htmlBody = format.RenderMarkdown(body, true, true).FormattedBody
}
+ signature := format.RenderMarkdown(cfg.Signature(), true, true)
+ if signature.Body != "" {
+ body += "\n\n---\n" + signature.Body
+ if htmlBody != "" {
+ htmlBody += "
" + signature.FormattedBody
+ }
+ }
+
tos := strings.Split(to, ",")
// validate first
for _, to := range tos {
diff --git a/bot/command_owner.go b/bot/command_owner.go
index e79b3bd..0e2696b 100644
--- a/bot/command_owner.go
+++ b/bot/command_owner.go
@@ -84,7 +84,7 @@ func (b *Bot) getOption(ctx context.Context, name string) {
b.SendNotice(ctx, evt.RoomID, msg)
}
-//nolint:gocognit
+//nolint:gocognit // TODO
func (b *Bot) setOption(ctx context.Context, name, value string) {
cmd := b.commands.get(name)
if cmd != nil && cmd.sanitizer != nil {
@@ -119,6 +119,14 @@ func (b *Bot) setOption(ctx context.Context, name, value string) {
}
}
+ if name == config.RoomSignature {
+ value = strings.Join(b.parseCommand(evt.Content.AsMessage().Body, false)[1:], " ")
+ }
+
+ if value == "reset" {
+ value = ""
+ }
+
old := cfg.Get(name)
cfg.Set(name, value)
diff --git a/bot/config/room.go b/bot/config/room.go
index 0539559..0531f28 100644
--- a/bot/config/room.go
+++ b/bot/config/room.go
@@ -29,6 +29,7 @@ const (
RoomNoFiles = "nofiles"
RoomNoInlines = "noinlines"
RoomPassword = "password"
+ RoomSignature = "signature"
RoomSpamcheckDKIM = "spamcheck:dkim"
RoomSpamcheckSMTP = "spamcheck:smtp"
RoomSpamcheckSPF = "spamcheck:spf"
@@ -66,6 +67,10 @@ func (s Room) Password() string {
return s.Get(RoomPassword)
}
+func (s Room) Signature() string {
+ return s.Get(RoomSignature)
+}
+
func (s Room) NoSend() bool {
return utils.Bool(s.Get(RoomNoSend))
}
diff --git a/bot/email.go b/bot/email.go
index 126c890..3401767 100644
--- a/bot/email.go
+++ b/bot/email.go
@@ -158,6 +158,8 @@ func (b *Bot) IncomingEmail(ctx context.Context, email *email.Email) error {
}
// SendEmailReply sends replies from matrix thread to email thread
+//
+//nolint:gocognit // TODO
func (b *Bot) SendEmailReply(ctx context.Context) {
evt := eventFromContext(ctx)
if !b.allowSend(evt.Sender, evt.RoomID) {
@@ -194,10 +196,17 @@ func (b *Bot) SendEmailReply(ctx context.Context) {
if meta.Subject == "" {
meta.Subject = strings.SplitN(content.Body, "\n", 1)[0]
}
+ signature := format.RenderMarkdown(cfg.Signature(), true, true)
body := content.Body
+ if signature.Body != "" {
+ body += "\n\n---\n" + signature.Body
+ }
var htmlBody string
if !cfg.NoHTML() {
htmlBody = content.FormattedBody
+ if htmlBody != "" && signature.FormattedBody != "" {
+ htmlBody += "
" + signature.FormattedBody
+ }
}
meta.MessageID = email.MessageID(evt.ID, meta.FromDomain)