plugins/base: add action param to handleSetFlags
This alows to add/remove flags instead of setting them.
This commit is contained in:
parent
feb8c7ac80
commit
fe73f2022c
2 changed files with 17 additions and 2 deletions
|
@ -450,7 +450,6 @@ func getMessagePart(conn *imapclient.Client, mboxName string, uid uint32, partPa
|
||||||
partHeaderSection.Path = partPath
|
partHeaderSection.Path = partPath
|
||||||
|
|
||||||
var partBodySection imap.BodySectionName
|
var partBodySection imap.BodySectionName
|
||||||
partBodySection.Peek = true
|
|
||||||
if len(partPath) > 0 {
|
if len(partPath) > 0 {
|
||||||
partBodySection.Specifier = imap.EntireSpecifier
|
partBodySection.Specifier = imap.EntireSpecifier
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -738,6 +738,18 @@ func handleSetFlags(ctx *koushin.Context) error {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "missing 'flags' form values")
|
return echo.NewHTTPError(http.StatusBadRequest, "missing 'flags' form values")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var op imap.FlagsOp
|
||||||
|
switch ctx.FormValue("action") {
|
||||||
|
case "", "set":
|
||||||
|
op = imap.SetFlags
|
||||||
|
case "add":
|
||||||
|
op = imap.AddFlags
|
||||||
|
case "remove":
|
||||||
|
op = imap.RemoveFlags
|
||||||
|
default:
|
||||||
|
return echo.NewHTTPError(http.StatusBadRequest, "invalid 'action' value")
|
||||||
|
}
|
||||||
|
|
||||||
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
|
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
|
||||||
if err := ensureMailboxSelected(c, mboxName); err != nil {
|
if err := ensureMailboxSelected(c, mboxName); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -751,7 +763,7 @@ func handleSetFlags(ctx *koushin.Context) error {
|
||||||
storeItems[i] = f
|
storeItems[i] = f
|
||||||
}
|
}
|
||||||
|
|
||||||
item := imap.FormatFlagsOp(imap.SetFlags, true)
|
item := imap.FormatFlagsOp(op, true)
|
||||||
if err := c.UidStore(&seqSet, item, storeItems, nil); err != nil {
|
if err := c.UidStore(&seqSet, item, storeItems, nil); err != nil {
|
||||||
return fmt.Errorf("failed to add deleted flag: %v", err)
|
return fmt.Errorf("failed to add deleted flag: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -762,6 +774,10 @@ func handleSetFlags(ctx *koushin.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if op == imap.RemoveFlags && len(flags) == 1 && flags[0] == "\\Seen" {
|
||||||
|
// Redirecting to the message view would mark the message as read again
|
||||||
|
return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", url.PathEscape(mboxName)))
|
||||||
|
}
|
||||||
return ctx.Redirect(http.StatusFound, fmt.Sprintf("/message/%v/%v", url.PathEscape(mboxName), uid))
|
return ctx.Redirect(http.StatusFound, fmt.Sprintf("/message/%v/%v", url.PathEscape(mboxName), uid))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue