From e4daf0778dc4682405017a7cbdc593808257408f Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 30 Oct 2020 15:21:33 -0400 Subject: Implement mailbox deletion --- plugins/base/routes.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'plugins') diff --git a/plugins/base/routes.go b/plugins/base/routes.go index c031cb0..ecdfc1a 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -34,6 +34,9 @@ func registerRoutes(p *alps.GoPlugin) { p.GET("/new-mailbox", handleNewMailbox) p.POST("/new-mailbox", handleNewMailbox) + p.GET("/delete-mailbox/:mbox", handleDeleteMailbox) + p.POST("/delete-mailbox/:mbox", handleDeleteMailbox) + p.GET("/message/:mbox/:uid", func(ctx *alps.Context) error { return handleGetPart(ctx, false) }) @@ -303,6 +306,25 @@ func handleNewMailbox(ctx *alps.Context) error { }) } +func handleDeleteMailbox(ctx *alps.Context) error { + ibase, err := newIMAPBaseRenderData(ctx, alps.NewBaseRenderData(ctx)) + if err != nil { + return err + } + + mbox := ibase.Mailbox + ibase.BaseRenderData.WithTitle("Delete folder '" + mbox.Name + "'") + + if ctx.Request().Method == http.MethodPost { + ctx.Session.DoIMAP(func(c *imapclient.Client) error { + return c.Delete(mbox.Name) + }) + return ctx.Redirect(http.StatusFound, "/mailbox/INBOX") + } + + return ctx.Render(http.StatusOK, "delete-mailbox.html", ibase) +} + func handleLogin(ctx *alps.Context) error { username := ctx.FormValue("username") password := ctx.FormValue("password") -- cgit v1.2.3