aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-12-16 17:25:53 +0100
committerSimon Ser <contact@emersion.fr>2019-12-16 17:25:53 +0100
commit1841609fbc7a16a657e530e0a208419af7791bd0 (patch)
tree0d6211103711187e62a12a4acc4b1ec04f05f687 /plugins
parenta061e85f006bd26f81668107e396d0357f665ce9 (diff)
downloadalps-1841609fbc7a16a657e530e0a208419af7791bd0.tar.gz
alps-1841609fbc7a16a657e530e0a208419af7791bd0.zip
Add form to move messages
References: https://todo.sr.ht/~sircmpwn/koushin/36
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/handlers.go46
-rw-r--r--plugins/base/plugin.go2
-rw-r--r--plugins/base/public/message.html10
3 files changed, 56 insertions, 2 deletions
diff --git a/plugins/base/handlers.go b/plugins/base/handlers.go
index 8e9971a..d77cd4a 100644
--- a/plugins/base/handlers.go
+++ b/plugins/base/handlers.go
@@ -12,6 +12,7 @@ import (
"git.sr.ht/~emersion/koushin"
"github.com/emersion/go-imap"
imapclient "github.com/emersion/go-imap/client"
+ imapmove "github.com/emersion/go-imap-move"
"github.com/emersion/go-message"
"github.com/emersion/go-smtp"
"github.com/labstack/echo/v4"
@@ -120,6 +121,7 @@ func handleLogout(ectx echo.Context) error {
type MessageRenderData struct {
koushin.RenderData
+ Mailboxes []*imap.MailboxInfo
Mailbox *imap.MailboxStatus
Message *IMAPMessage
Body string
@@ -138,14 +140,20 @@ func handleGetPart(ctx *koushin.Context, raw bool) error {
return echo.NewHTTPError(http.StatusBadRequest, err)
}
+ var mailboxes []*imap.MailboxInfo
var msg *IMAPMessage
var part *message.Entity
var mbox *imap.MailboxStatus
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
var err error
- msg, part, err = getMessagePart(c, mboxName, uid, partPath)
+ if mailboxes, err = listMailboxes(c); err != nil {
+ return err
+ }
+ if msg, part, err = getMessagePart(c, mboxName, uid, partPath); err != nil {
+ return err
+ }
mbox = c.Mailbox()
- return err
+ return nil
})
if err != nil {
return err
@@ -187,6 +195,7 @@ func handleGetPart(ctx *koushin.Context, raw bool) error {
return ctx.Render(http.StatusOK, "message.html", &MessageRenderData{
RenderData: *koushin.NewRenderData(ctx),
+ Mailboxes: mailboxes,
Mailbox: mbox,
Message: msg,
Body: body,
@@ -296,3 +305,36 @@ func handleCompose(ectx echo.Context) error {
Message: &msg,
})
}
+
+func handleMove(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)
+ }
+
+ to := ctx.FormValue("to")
+
+ err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
+ mc := imapmove.NewClient(c)
+
+ if err := ensureMailboxSelected(c, mboxName); err != nil {
+ return err
+ }
+
+ var seqSet imap.SeqSet
+ seqSet.AddNum(uid)
+ if err := mc.UidMoveWithFallback(&seqSet, to); err != nil {
+ return fmt.Errorf("failed to move message: %v", err)
+ }
+
+ // TODO: get the UID of the message in the destination mailbox with UIDPLUS
+ return nil
+ })
+ if err != nil {
+ return err
+ }
+
+ return ctx.Redirect(http.StatusFound, fmt.Sprintf("/mailbox/%v", to))
+}
diff --git a/plugins/base/plugin.go b/plugins/base/plugin.go
index 7c2aeaf..7eaf00c 100644
--- a/plugins/base/plugin.go
+++ b/plugins/base/plugin.go
@@ -45,5 +45,7 @@ func init() {
p.GET("/message/:mbox/:uid/reply", handleCompose)
p.POST("/message/:mbox/:uid/reply", handleCompose)
+ p.POST("/message/:mbox/:uid/move", handleMove)
+
koushin.RegisterPlugin(p.Plugin())
}
diff --git a/plugins/base/public/message.html b/plugins/base/public/message.html
index 729937d..2a0ab71 100644
--- a/plugins/base/public/message.html
+++ b/plugins/base/public/message.html
@@ -16,6 +16,16 @@
{{end}}
</h2>
+<form method="post" action="{{.Message.Uid}}/move">
+ <label for="move-to">Move to:</label>
+ <select name="to" id="move-to">
+ {{range .Mailboxes}}
+ <option {{if eq .Name $.Mailbox.Name}}selected{{end}}>{{.Name}}</option>
+ {{end}}
+ </select>
+ <input type="submit" value="Move">
+</form>
+
{{define "message-part-tree"}}
{{/* nested templates can't access the parent's context */}}
{{$ = index . 0}}