plugins/base: allow redirect param to be a form param

This commit is contained in:
Simon Ser 2020-03-27 10:27:37 +01:00
parent 9b804005b4
commit f6959346ee
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48

View file

@ -653,6 +653,13 @@ func handleEdit(ctx *koushin.Context) error {
return handleCompose(ctx, &msg, &composeOptions{Draft: &sourcePath}) 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 { func handleMove(ctx *koushin.Context) error {
mboxName, err := url.PathUnescape(ctx.Param("mbox")) mboxName, err := url.PathUnescape(ctx.Param("mbox"))
if err != nil { if err != nil {
@ -668,10 +675,7 @@ func handleMove(ctx *koushin.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, err) return echo.NewHTTPError(http.StatusBadRequest, err)
} }
to := ctx.FormValue("to") to := formOrQueryParam(ctx, "to")
if to == "" {
to = ctx.QueryParam("to")
}
if to == "" { if to == "" {
return echo.NewHTTPError(http.StatusBadRequest, "missing 'to' form parameter") return echo.NewHTTPError(http.StatusBadRequest, "missing 'to' form parameter")
} }
@ -696,7 +700,7 @@ func handleMove(ctx *koushin.Context) error {
return err 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, path)
} }
return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", url.PathEscape(to))) return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", url.PathEscape(to)))
@ -747,7 +751,7 @@ func handleDelete(ctx *koushin.Context) error {
return err 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, path)
} }
return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", url.PathEscape(mboxName))) return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", url.PathEscape(mboxName)))
@ -819,7 +823,7 @@ func handleSetFlags(ctx *koushin.Context) error {
return err 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, path)
} }
if len(uids) != 1 || (op == imap.RemoveFlags && len(flags) == 1 && flags[0] == imap.SeenFlag) { if len(uids) != 1 || (op == imap.RemoveFlags && len(flags) == 1 && flags[0] == imap.SeenFlag) {