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 ++++++++++++++++++++++ themes/alps/assets/style.css | 10 ++++++++++ themes/alps/delete-mailbox.html | 24 ++++++++++++++++++++++++ themes/alps/messages-header.html | 6 ++++++ themes/alps/util.html | 14 +++++++------- 5 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 themes/alps/delete-mailbox.html 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") diff --git a/themes/alps/assets/style.css b/themes/alps/assets/style.css index 388f25f..8b80504 100644 --- a/themes/alps/assets/style.css +++ b/themes/alps/assets/style.css @@ -766,3 +766,13 @@ button:active, color: #ccc; background-color: #f8f8f8; } + +.alert { + padding: 0.5rem; + border: 1px solid transparent; + margin: 1rem 0; + background: #f8d7da; + color: #721c24; + border-color: #f5c6cb; + max-width: 600px; +} diff --git a/themes/alps/delete-mailbox.html b/themes/alps/delete-mailbox.html new file mode 100644 index 0000000..0429fe0 --- /dev/null +++ b/themes/alps/delete-mailbox.html @@ -0,0 +1,24 @@ +{{template "head.html" .}} +{{template "nav.html" .}} +{{template "util.html" .}} + +
+ {{ template "aside" . }} +
+
+
+

Delete "{{ .Mailbox.Name }}"?

+
+ Warning! This will permanently delete all messages + in "{{.Mailbox.Name}}". +
+
+ + Cancel +
+
+
+
+
+ +{{template "foot.html"}} diff --git a/themes/alps/messages-header.html b/themes/alps/messages-header.html index 13e4872..df70e06 100644 --- a/themes/alps/messages-header.html +++ b/themes/alps/messages-header.html @@ -26,6 +26,12 @@
Refresh
+ +
+ {{ if not (eq .Mailbox.Name "INBOX") }} + Delete folder + {{ end }} +