Selaa lähdekoodia

Add button to delete message

Maybe we should add a confirmation step in the future.

References: https://todo.sr.ht/~sircmpwn/koushin/36
master
Simon Ser 4 vuotta sitten
vanhempi
commit
a425e17b0e
No known key found for this signature in database GPG Key ID: FDE7BE0E88F5E48
3 muutettua tiedostoa jossa 47 lisäystä ja 0 poistoa
  1. +41
    -0
      plugins/base/handlers.go
  2. +2
    -0
      plugins/base/plugin.go
  3. +4
    -0
      plugins/base/public/message.html

+ 41
- 0
plugins/base/handlers.go Näytä tiedosto

@@ -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))
}

+ 2
- 0
plugins/base/plugin.go Näytä tiedosto

@@ -47,5 +47,7 @@ func init() {

p.POST("/message/:mbox/:uid/move", handleMove)

p.POST("/message/:mbox/:uid/delete", handleDelete)

koushin.RegisterPlugin(p.Plugin())
}

+ 4
- 0
plugins/base/public/message.html Näytä tiedosto

@@ -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}}


Ladataan…
Peruuta
Tallenna