diff options
author | Simon Ser <contact@emersion.fr> | 2019-12-16 17:45:20 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-12-16 17:45:20 +0100 |
commit | a425e17b0eda3dd7e961127670a46a3b3b2c3d19 (patch) | |
tree | c0aa6f119e4a3f989384089ec327f37b494e3281 /plugins | |
parent | 1841609fbc7a16a657e530e0a208419af7791bd0 (diff) | |
download | alps-a425e17b0eda3dd7e961127670a46a3b3b2c3d19.tar.gz alps-a425e17b0eda3dd7e961127670a46a3b3b2c3d19.zip |
Add button to delete message
Maybe we should add a confirmation step in the future.
References: https://todo.sr.ht/~sircmpwn/koushin/36
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/base/handlers.go | 41 | ||||
-rw-r--r-- | plugins/base/plugin.go | 2 | ||||
-rw-r--r-- | plugins/base/public/message.html | 4 |
3 files changed, 47 insertions, 0 deletions
diff --git a/plugins/base/handlers.go b/plugins/base/handlers.go index d77cd4a..c36cfa7 100644 --- a/plugins/base/handlers.go +++ b/plugins/base/handlers.go @@ -338,3 +338,44 @@ func handleMove(ectx echo.Context) error { return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", to)) } + +func handleDelete(ectx echo.Context) error { + ctx := ectx.(*koushin.Context) + + mboxName, uid, err := parseMboxAndUid(ctx.Param("mbox"), ctx.Param("uid")) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, err) + } + + err = ctx.Session.DoIMAP(func(c *imapclient.Client) error { + if err := ensureMailboxSelected(c, mboxName); err != nil { + return err + } + + var seqSet imap.SeqSet + seqSet.AddNum(uid) + + item := imap.FormatFlagsOp(imap.AddFlags, true) + flags := []interface{}{imap.DeletedFlag} + if err := c.UidStore(&seqSet, item, flags, nil); err != nil { + return fmt.Errorf("failed to add deleted flag: %v", err) + } + + if err := c.Expunge(nil); err != nil { + return fmt.Errorf("failed to expunge mailbox: %v", err) + } + + // Deleting a message invalidates our cached message count + // TODO: listen to async updates instead + if _, err := c.Select(mboxName, false); err != nil { + return fmt.Errorf("failed to select mailbox: %v", err) + } + + return nil + }) + if err != nil { + return err + } + + return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", mboxName)) +} diff --git a/plugins/base/plugin.go b/plugins/base/plugin.go index 7eaf00c..1cee571 100644 --- a/plugins/base/plugin.go +++ b/plugins/base/plugin.go @@ -47,5 +47,7 @@ func init() { p.POST("/message/:mbox/:uid/move", handleMove) + p.POST("/message/:mbox/:uid/delete", handleDelete) + koushin.RegisterPlugin(p.Plugin()) } diff --git a/plugins/base/public/message.html b/plugins/base/public/message.html index 2a0ab71..11afa73 100644 --- a/plugins/base/public/message.html +++ b/plugins/base/public/message.html @@ -26,6 +26,10 @@ <input type="submit" value="Move"> </form> +<form method="post" action="{{.Message.Uid}}/delete"> + <input type="submit" value="Delete"> +</form> + {{define "message-part-tree"}} {{/* nested templates can't access the parent's context */}} {{$ = index . 0}} |