send multipart email with both html and plaintext by default, closes #22
This commit is contained in:
@@ -17,7 +17,6 @@ const (
|
||||
commandHelp = "help"
|
||||
commandStop = "stop"
|
||||
commandSend = "send"
|
||||
commandSendHTML = "send:html"
|
||||
commandDKIM = "dkim"
|
||||
commandCatchAll = botOptionCatchAll
|
||||
commandUsers = botOptionUsers
|
||||
@@ -68,11 +67,6 @@ func (b *Bot) initCommands() commandList {
|
||||
description: "Send email",
|
||||
allowed: b.allowSend,
|
||||
},
|
||||
{
|
||||
key: commandSendHTML,
|
||||
description: "Send email, converting markdown to HTML",
|
||||
allowed: b.allowSend,
|
||||
},
|
||||
{allowed: b.allowOwner}, // delimiter
|
||||
// options commands
|
||||
{
|
||||
@@ -273,9 +267,7 @@ func (b *Bot) handleCommand(ctx context.Context, evt *event.Event, commandSlice
|
||||
case commandStop:
|
||||
b.runStop(ctx)
|
||||
case commandSend:
|
||||
b.runSend(ctx, false)
|
||||
case commandSendHTML:
|
||||
b.runSend(ctx, true)
|
||||
b.runSend(ctx)
|
||||
case commandDKIM:
|
||||
b.runDKIM(ctx, commandSlice)
|
||||
case commandUsers:
|
||||
@@ -386,30 +378,27 @@ func (b *Bot) sendHelp(ctx context.Context) {
|
||||
b.SendNotice(ctx, evt.RoomID, msg.String())
|
||||
}
|
||||
|
||||
func (b *Bot) runSend(ctx context.Context, html bool) {
|
||||
func (b *Bot) runSend(ctx context.Context) {
|
||||
evt := eventFromContext(ctx)
|
||||
if !b.allowSend(evt.Sender, evt.RoomID) {
|
||||
return
|
||||
}
|
||||
subcommand := "send"
|
||||
if html {
|
||||
subcommand = "send:html"
|
||||
}
|
||||
commandSlice := b.parseCommand(evt.Content.AsMessage().Body, false)
|
||||
to, subject, body, err := utils.ParseSend(commandSlice)
|
||||
if err == utils.ErrInvalidArgs {
|
||||
b.SendNotice(ctx, evt.RoomID, fmt.Sprintf(
|
||||
"Usage:\n"+
|
||||
"```\n"+
|
||||
"%s %s someone@example.com\n"+
|
||||
"%s send someone@example.com\n"+
|
||||
"Subject goes here on a line of its own\n"+
|
||||
"Email content goes here\n"+
|
||||
"on as many lines\n"+
|
||||
"as you want.\n"+
|
||||
"```",
|
||||
b.prefix, subcommand))
|
||||
b.prefix))
|
||||
return
|
||||
}
|
||||
htmlBody := format.RenderMarkdown(body, true, true).FormattedBody
|
||||
|
||||
cfg, err := b.getRoomSettings(evt.RoomID)
|
||||
if err != nil {
|
||||
@@ -432,11 +421,6 @@ func (b *Bot) runSend(ctx context.Context, html bool) {
|
||||
}
|
||||
}
|
||||
|
||||
var htmlBody string
|
||||
if html {
|
||||
htmlBody = format.RenderMarkdown(body, true, true).FormattedBody
|
||||
}
|
||||
|
||||
b.lock(evt.RoomID.String())
|
||||
defer b.unlock(evt.RoomID.String())
|
||||
|
||||
@@ -445,7 +429,7 @@ func (b *Bot) runSend(ctx context.Context, html bool) {
|
||||
ID := utils.MessageID(evt.ID, domain)
|
||||
for _, to := range tos {
|
||||
email := utils.NewEmail(ID, "", " "+ID, subject, from, to, body, htmlBody, nil)
|
||||
data := email.Compose(html, b.getBotSettings().DKIMPrivateKey())
|
||||
data := email.Compose(b.getBotSettings().DKIMPrivateKey())
|
||||
queued, err := b.Sendmail(evt.ID, from, to, data)
|
||||
if queued {
|
||||
b.log.Error("cannot send email: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user