mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 09:37:02 +00:00
webui: Friendly URL support for #73
This commit is contained in:
@@ -22,6 +22,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
domains.
|
domains.
|
||||||
- Configurable support for identifying a mailbox by full email address instead
|
- Configurable support for identifying a mailbox by full email address instead
|
||||||
of just the local part (username).
|
of just the local part (username).
|
||||||
|
- Friendly URL support: `<inbucket-url>/<mailbox>` will redirect your browser to
|
||||||
|
that mailbox.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Massive refactor of back-end code. Inbucket should now be both easier and
|
- Massive refactor of back-end code. Inbucket should now be both easier and
|
||||||
|
|||||||
@@ -125,8 +125,8 @@ func main() {
|
|||||||
retentionScanner.Start()
|
retentionScanner.Start()
|
||||||
// Start HTTP server.
|
// Start HTTP server.
|
||||||
web.Initialize(conf, shutdownChan, mmanager, msgHub)
|
web.Initialize(conf, shutdownChan, mmanager, msgHub)
|
||||||
webui.SetupRoutes(web.Router)
|
|
||||||
rest.SetupRoutes(web.Router)
|
rest.SetupRoutes(web.Router)
|
||||||
|
webui.SetupRoutes(web.Router)
|
||||||
go web.Start(rootCtx)
|
go web.Start(rootCtx)
|
||||||
// Start POP3 server.
|
// Start POP3 server.
|
||||||
pop3Server := pop3.New(conf.POP3, shutdownChan, store)
|
pop3Server := pop3.New(conf.POP3, shutdownChan, store)
|
||||||
|
|||||||
@@ -47,6 +47,21 @@ func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *web.Context) (e
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MailboxIndexFriendly handles pretty links to a particular mailbox. Renders a redirect
|
||||||
|
func MailboxIndexFriendly(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) {
|
||||||
|
name, err := ctx.Manager.MailboxForAddress(ctx.Vars["name"])
|
||||||
|
if err != nil {
|
||||||
|
ctx.Session.AddFlash(err.Error(), "errors")
|
||||||
|
_ = ctx.Session.Save(req, w)
|
||||||
|
http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Build redirect
|
||||||
|
uri := fmt.Sprintf("%s?name=%s", web.Reverse("MailboxIndex"), name)
|
||||||
|
http.Redirect(w, req, uri, http.StatusSeeOther)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// MailboxLink handles pretty links to a particular message. Renders a redirect
|
// MailboxLink handles pretty links to a particular message. Renders a redirect
|
||||||
func MailboxLink(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) {
|
func MailboxLink(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) {
|
||||||
// Don't have to validate these aren't empty, Gorilla returns 404
|
// Don't have to validate these aren't empty, Gorilla returns 404
|
||||||
|
|||||||
@@ -32,4 +32,6 @@ func SetupRoutes(r *mux.Router) {
|
|||||||
web.Handler(MailboxDownloadAttach)).Name("MailboxDownloadAttach").Methods("GET")
|
web.Handler(MailboxDownloadAttach)).Name("MailboxDownloadAttach").Methods("GET")
|
||||||
r.Path("/mailbox/vattach/{name}/{id}/{num}/{file}").Handler(
|
r.Path("/mailbox/vattach/{name}/{id}/{num}/{file}").Handler(
|
||||||
web.Handler(MailboxViewAttach)).Name("MailboxViewAttach").Methods("GET")
|
web.Handler(MailboxViewAttach)).Name("MailboxViewAttach").Methods("GET")
|
||||||
|
r.Path("/{name}").Handler(
|
||||||
|
web.Handler(MailboxIndexFriendly)).Name("MailboxListFriendly").Methods("GET")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user