From f6959346ee75ba6aa97f86850bc222404372db38 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 27 Mar 2020 10:27:37 +0100 Subject: plugins/base: allow redirect param to be a form param --- plugins/base/routes.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'plugins/base') diff --git a/plugins/base/routes.go b/plugins/base/routes.go index 1ea611d..689fca4 100644 --- a/plugins/base/routes.go +++ b/plugins/base/routes.go @@ -653,6 +653,13 @@ func handleEdit(ctx *koushin.Context) error { return handleCompose(ctx, &msg, &composeOptions{Draft: &sourcePath}) } +func formOrQueryParam(ctx *koushin.Context, k string) string { + if v := ctx.FormValue(k); v != "" { + return v + } + return ctx.QueryParam(k) +} + func handleMove(ctx *koushin.Context) error { mboxName, err := url.PathUnescape(ctx.Param("mbox")) if err != nil { @@ -668,10 +675,7 @@ func handleMove(ctx *koushin.Context) error { return echo.NewHTTPError(http.StatusBadRequest, err) } - to := ctx.FormValue("to") - if to == "" { - to = ctx.QueryParam("to") - } + to := formOrQueryParam(ctx, "to") if to == "" { return echo.NewHTTPError(http.StatusBadRequest, "missing 'to' form parameter") } @@ -696,7 +700,7 @@ func handleMove(ctx *koushin.Context) error { return err } - if path := ctx.QueryParam("next"); path != "" { + if path := formOrQueryParam(ctx, "next"); path != "" { return ctx.Redirect(http.StatusFound, path) } return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", url.PathEscape(to))) @@ -747,7 +751,7 @@ func handleDelete(ctx *koushin.Context) error { return err } - if path := ctx.QueryParam("next"); path != "" { + if path := formOrQueryParam(ctx, "next"); path != "" { return ctx.Redirect(http.StatusFound, path) } return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", url.PathEscape(mboxName))) @@ -819,7 +823,7 @@ func handleSetFlags(ctx *koushin.Context) error { return err } - if path := ctx.QueryParam("next"); path != "" { + if path := formOrQueryParam(ctx, "next"); path != "" { return ctx.Redirect(http.StatusFound, path) } if len(uids) != 1 || (op == imap.RemoveFlags && len(flags) == 1 && flags[0] == imap.SeenFlag) { -- cgit v1.2.3