add !pm signature option
This commit is contained in:
@@ -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] 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] 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] Reply to matrix thread sends reply into email thread
|
||||||
|
- [x] Email signatures
|
||||||
|
|
||||||
## Configuration
|
## 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
|
> 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 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 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)
|
* **`!pm nosender`** - Get or set `nosender` of the room (`true` - hide email sender; `false` - show email sender)
|
||||||
|
|||||||
@@ -99,6 +99,12 @@ func (b *Bot) initCommands() commandList {
|
|||||||
allowed: b.allowOwner,
|
allowed: b.allowOwner,
|
||||||
},
|
},
|
||||||
{allowed: b.allowOwner, description: "mailbox options"}, // delimiter
|
{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,
|
key: config.RoomNoSend,
|
||||||
description: fmt.Sprintf(
|
description: fmt.Sprintf(
|
||||||
@@ -523,6 +529,14 @@ func (b *Bot) runSend(ctx context.Context) {
|
|||||||
htmlBody = format.RenderMarkdown(body, true, true).FormattedBody
|
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 += "<br><hr><br>" + signature.FormattedBody
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tos := strings.Split(to, ",")
|
tos := strings.Split(to, ",")
|
||||||
// validate first
|
// validate first
|
||||||
for _, to := range tos {
|
for _, to := range tos {
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ func (b *Bot) getOption(ctx context.Context, name string) {
|
|||||||
b.SendNotice(ctx, evt.RoomID, msg)
|
b.SendNotice(ctx, evt.RoomID, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gocognit
|
//nolint:gocognit // TODO
|
||||||
func (b *Bot) setOption(ctx context.Context, name, value string) {
|
func (b *Bot) setOption(ctx context.Context, name, value string) {
|
||||||
cmd := b.commands.get(name)
|
cmd := b.commands.get(name)
|
||||||
if cmd != nil && cmd.sanitizer != nil {
|
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)
|
old := cfg.Get(name)
|
||||||
cfg.Set(name, value)
|
cfg.Set(name, value)
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const (
|
|||||||
RoomNoFiles = "nofiles"
|
RoomNoFiles = "nofiles"
|
||||||
RoomNoInlines = "noinlines"
|
RoomNoInlines = "noinlines"
|
||||||
RoomPassword = "password"
|
RoomPassword = "password"
|
||||||
|
RoomSignature = "signature"
|
||||||
RoomSpamcheckDKIM = "spamcheck:dkim"
|
RoomSpamcheckDKIM = "spamcheck:dkim"
|
||||||
RoomSpamcheckSMTP = "spamcheck:smtp"
|
RoomSpamcheckSMTP = "spamcheck:smtp"
|
||||||
RoomSpamcheckSPF = "spamcheck:spf"
|
RoomSpamcheckSPF = "spamcheck:spf"
|
||||||
@@ -66,6 +67,10 @@ func (s Room) Password() string {
|
|||||||
return s.Get(RoomPassword)
|
return s.Get(RoomPassword)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s Room) Signature() string {
|
||||||
|
return s.Get(RoomSignature)
|
||||||
|
}
|
||||||
|
|
||||||
func (s Room) NoSend() bool {
|
func (s Room) NoSend() bool {
|
||||||
return utils.Bool(s.Get(RoomNoSend))
|
return utils.Bool(s.Get(RoomNoSend))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,6 +158,8 @@ func (b *Bot) IncomingEmail(ctx context.Context, email *email.Email) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SendEmailReply sends replies from matrix thread to email thread
|
// SendEmailReply sends replies from matrix thread to email thread
|
||||||
|
//
|
||||||
|
//nolint:gocognit // TODO
|
||||||
func (b *Bot) SendEmailReply(ctx context.Context) {
|
func (b *Bot) SendEmailReply(ctx context.Context) {
|
||||||
evt := eventFromContext(ctx)
|
evt := eventFromContext(ctx)
|
||||||
if !b.allowSend(evt.Sender, evt.RoomID) {
|
if !b.allowSend(evt.Sender, evt.RoomID) {
|
||||||
@@ -194,10 +196,17 @@ func (b *Bot) SendEmailReply(ctx context.Context) {
|
|||||||
if meta.Subject == "" {
|
if meta.Subject == "" {
|
||||||
meta.Subject = strings.SplitN(content.Body, "\n", 1)[0]
|
meta.Subject = strings.SplitN(content.Body, "\n", 1)[0]
|
||||||
}
|
}
|
||||||
|
signature := format.RenderMarkdown(cfg.Signature(), true, true)
|
||||||
body := content.Body
|
body := content.Body
|
||||||
|
if signature.Body != "" {
|
||||||
|
body += "\n\n---\n" + signature.Body
|
||||||
|
}
|
||||||
var htmlBody string
|
var htmlBody string
|
||||||
if !cfg.NoHTML() {
|
if !cfg.NoHTML() {
|
||||||
htmlBody = content.FormattedBody
|
htmlBody = content.FormattedBody
|
||||||
|
if htmlBody != "" && signature.FormattedBody != "" {
|
||||||
|
htmlBody += "<br><hr><br>" + signature.FormattedBody
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.MessageID = email.MessageID(evt.ID, meta.FromDomain)
|
meta.MessageID = email.MessageID(evt.ID, meta.FromDomain)
|
||||||
|
|||||||
Reference in New Issue
Block a user