aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2020-10-30 13:41:25 -0400
committerDrew DeVault <sir@cmpwn.com>2020-10-30 13:41:25 -0400
commit417d9bbd646248daebde2ab0ccc2fcbcb8911426 (patch)
treeab3934a3809613f9ed411ca5ba67293e64796f67 /plugins
parent2bef9425fb249b015f6046b71f1d26cceda279d1 (diff)
downloadalps-417d9bbd646248daebde2ab0ccc2fcbcb8911426.tar.gz
alps-417d9bbd646248daebde2ab0ccc2fcbcb8911426.zip
Implement folder creation UI
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/routes.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/plugins/base/routes.go b/plugins/base/routes.go
index 7e30513..c031cb0 100644
--- a/plugins/base/routes.go
+++ b/plugins/base/routes.go
@@ -31,6 +31,9 @@ func registerRoutes(p *alps.GoPlugin) {
p.GET("/mailbox/:mbox", handleGetMailbox)
p.POST("/mailbox/:mbox", handleGetMailbox)
+ p.GET("/new-mailbox", handleNewMailbox)
+ p.POST("/new-mailbox", handleNewMailbox)
+
p.GET("/message/:mbox/:uid", func(ctx *alps.Context) error {
return handleGetPart(ctx, false)
})
@@ -259,6 +262,47 @@ func handleGetMailbox(ctx *alps.Context) error {
})
}
+type NewMailboxRenderData struct {
+ IMAPBaseRenderData
+ Error string
+}
+
+func handleNewMailbox(ctx *alps.Context) error {
+ ibase, err := newIMAPBaseRenderData(ctx, alps.NewBaseRenderData(ctx))
+ if err != nil {
+ return err
+ }
+ ibase.BaseRenderData.WithTitle("Create new folder")
+
+ if ctx.Request().Method == http.MethodPost {
+ name := ctx.FormValue("name")
+ if name == "" {
+ return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{
+ IMAPBaseRenderData: *ibase,
+ Error: "Name is required",
+ })
+ }
+
+ err := ctx.Session.DoIMAP(func(c *imapclient.Client) error {
+ return c.Create(name)
+ })
+
+ if err != nil {
+ return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{
+ IMAPBaseRenderData: *ibase,
+ Error: err.Error(),
+ })
+ }
+
+ return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%s", url.PathEscape(name)))
+ }
+
+ return ctx.Render(http.StatusOK, "new-mailbox.html", &NewMailboxRenderData{
+ IMAPBaseRenderData: *ibase,
+ Error: "",
+ })
+}
+
func handleLogin(ctx *alps.Context) error {
username := ctx.FormValue("username")
password := ctx.FormValue("password")