mirror of
https://github.com/jhillyerd/inbucket.git
synced 2026-01-07 19:57:06 +00:00
Add REST call for purging an entire mailbox
This commit is contained in:
@@ -94,6 +94,28 @@ func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *Context) (err er
|
||||
})
|
||||
}
|
||||
|
||||
func MailboxPurge(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
||||
// Don't have to validate these aren't empty, Gorilla returns 404
|
||||
name := ctx.Vars["name"]
|
||||
|
||||
mb, err := ctx.DataStore.MailboxFor(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("MailboxFor('%v'): %v", name, err)
|
||||
}
|
||||
if err := mb.Purge(); err != nil {
|
||||
return fmt.Errorf("Mailbox(%q) Purge: %v", name, err)
|
||||
}
|
||||
log.LogTrace("Purged mailbox for %q", name)
|
||||
|
||||
if ctx.IsJson {
|
||||
return RenderJson(w, "OK")
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
io.WriteString(w, "OK")
|
||||
return nil
|
||||
}
|
||||
|
||||
func MailboxHtml(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
||||
// Don't have to validate these aren't empty, Gorilla returns 404
|
||||
name := ctx.Vars["name"]
|
||||
|
||||
@@ -36,6 +36,7 @@ func setupRoutes(cfg config.WebConfig) {
|
||||
r.Path("/status").Handler(handler(RootStatus)).Name("RootStatus").Methods("GET")
|
||||
r.Path("/mailbox").Handler(handler(MailboxIndex)).Name("MailboxIndex").Methods("GET")
|
||||
r.Path("/mailbox/{name}").Handler(handler(MailboxList)).Name("MailboxList").Methods("GET")
|
||||
r.Path("/mailbox/{name}").Handler(handler(MailboxPurge)).Name("MailboxPurge").Methods("DELETE")
|
||||
r.Path("/mailbox/{name}/{id}").Handler(handler(MailboxShow)).Name("MailboxShow").Methods("GET")
|
||||
r.Path("/mailbox/{name}/{id}/html").Handler(handler(MailboxHtml)).Name("MailboxHtml").Methods("GET")
|
||||
r.Path("/mailbox/{name}/{id}/source").Handler(handler(MailboxSource)).Name("MailboxSource").Methods("GET")
|
||||
|
||||
Reference in New Issue
Block a user