aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2020-10-23 14:15:07 -0400
committerDrew DeVault <sir@cmpwn.com>2020-10-23 14:15:07 -0400
commitf97f38d4a9550bb15d39cfc05a3011e969927d22 (patch)
treeb755762ff994cfdc4a7ec3246f818c085be148f1 /plugins
parentb93b2bafa56ee79fa5d70b4c15901981215fa935 (diff)
downloadalps-f97f38d4a9550bb15d39cfc05a3011e969927d22.tar.gz
alps-f97f38d4a9550bb15d39cfc05a3011e969927d22.zip
Send outgoing emails asyncronously
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/routes.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/plugins/base/routes.go b/plugins/base/routes.go
index 3cad8da..7ba6253 100644
--- a/plugins/base/routes.go
+++ b/plugins/base/routes.go
@@ -2,6 +2,7 @@ package alpsbase
import (
"bytes"
+ "context"
"fmt"
"io"
"io/ioutil"
@@ -12,6 +13,7 @@ import (
"strings"
"git.sr.ht/~emersion/alps"
+ "git.sr.ht/~sircmpwn/dowork"
"github.com/emersion/go-imap"
imapmove "github.com/emersion/go-imap-move"
imapclient "github.com/emersion/go-imap/client"
@@ -408,9 +410,12 @@ type composeOptions struct {
// Send message, append it to the Sent mailbox, mark the original message as
// answered
func submitCompose(ctx *alps.Context, msg *OutgoingMessage, options *composeOptions) error {
- err := ctx.Session.DoSMTP(func(c *smtp.Client) error {
- return sendMessage(c, msg)
- })
+ task := work.NewTask(func(_ context.Context) error {
+ return ctx.Session.DoSMTP(func (c *smtp.Client) error {
+ return sendMessage(c, msg)
+ })
+ }).Retries(5)
+ err := ctx.Server.Queue.Enqueue(task)
if err != nil {
if _, ok := err.(alps.AuthError); ok {
return echo.NewHTTPError(http.StatusForbidden, err)