From 622f00fe063c454b4080ad47e8732bd0e9848e82 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 16 Dec 2019 13:07:35 +0100 Subject: Replace Session.ConnectSMTP with Session.DoSMTP This gives more flexibility in Session for optimizations, e.g. keep the SMTP connection around for some time if possible. --- plugins/base/handlers.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'plugins/base') diff --git a/plugins/base/handlers.go b/plugins/base/handlers.go index c96dabf..d0ba9ba 100644 --- a/plugins/base/handlers.go +++ b/plugins/base/handlers.go @@ -13,6 +13,7 @@ import ( "github.com/emersion/go-imap" imapclient "github.com/emersion/go-imap/client" "github.com/emersion/go-message" + "github.com/emersion/go-smtp" "github.com/labstack/echo/v4" ) @@ -257,7 +258,9 @@ func handleCompose(ectx echo.Context) error { msg.Text = ctx.FormValue("text") msg.InReplyTo = ctx.FormValue("in_reply_to") - c, err := ctx.Session.ConnectSMTP() + err := ctx.Session.DoSMTP(func(c *smtp.Client) error { + return sendMessage(c, &msg) + }) if err != nil { if _, ok := err.(koushin.AuthError); ok { return echo.NewHTTPError(http.StatusForbidden, err) @@ -265,14 +268,6 @@ func handleCompose(ectx echo.Context) error { return err } - if err := sendMessage(c, &msg); err != nil { - return err - } - - if err := c.Quit(); err != nil { - return fmt.Errorf("QUIT failed: %v", err) - } - // TODO: append to IMAP Sent mailbox return ctx.Redirect(http.StatusFound, "/mailbox/INBOX") -- cgit v1.2.3