diff --git a/CHANGELOG.md b/CHANGELOG.md index 1540e81..4fd7c9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). domains. - Configurable support for identifying a mailbox by full email address instead of just the local part (username). +- Friendly URL support: `/` will redirect your browser to + that mailbox. ### Changed - Massive refactor of back-end code. Inbucket should now be both easier and diff --git a/cmd/inbucket/main.go b/cmd/inbucket/main.go index 1546d8f..30152c9 100644 --- a/cmd/inbucket/main.go +++ b/cmd/inbucket/main.go @@ -125,8 +125,8 @@ func main() { retentionScanner.Start() // Start HTTP server. web.Initialize(conf, shutdownChan, mmanager, msgHub) - webui.SetupRoutes(web.Router) rest.SetupRoutes(web.Router) + webui.SetupRoutes(web.Router) go web.Start(rootCtx) // Start POP3 server. pop3Server := pop3.New(conf.POP3, shutdownChan, store) diff --git a/pkg/webui/mailbox_controller.go b/pkg/webui/mailbox_controller.go index 199b5e4..71dbd42 100644 --- a/pkg/webui/mailbox_controller.go +++ b/pkg/webui/mailbox_controller.go @@ -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 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 diff --git a/pkg/webui/routes.go b/pkg/webui/routes.go index 1bbe888..d6da620 100644 --- a/pkg/webui/routes.go +++ b/pkg/webui/routes.go @@ -32,4 +32,6 @@ func SetupRoutes(r *mux.Router) { web.Handler(MailboxDownloadAttach)).Name("MailboxDownloadAttach").Methods("GET") r.Path("/mailbox/vattach/{name}/{id}/{num}/{file}").Handler( web.Handler(MailboxViewAttach)).Name("MailboxViewAttach").Methods("GET") + r.Path("/{name}").Handler( + web.Handler(MailboxIndexFriendly)).Name("MailboxListFriendly").Methods("GET") }