diff --git a/themes/bootstrap/templates/_base.html b/themes/bootstrap/templates/_base.html
index e7be06b..83c5e42 100644
--- a/themes/bootstrap/templates/_base.html
+++ b/themes/bootstrap/templates/_base.html
@@ -69,9 +69,9 @@
- {{with .ctx.Session.Flashes "errors"}}
-
-
Please fix the following errors and resubmit:
-
- {{range .}}
- - {{.}}
- {{end}}
-
-
- {{end}}
Select a message at left, or enter a different username into the box on upper right.
diff --git a/webui/mailbox_controller.go b/webui/mailbox_controller.go
index a1273c1..35126db 100644
--- a/webui/mailbox_controller.go
+++ b/webui/mailbox_controller.go
@@ -17,14 +17,12 @@ func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context)
// Form values must be validated manually
name := req.FormValue("name")
selected := req.FormValue("id")
-
if len(name) == 0 {
ctx.Session.AddFlash("Account name is required", "errors")
_ = ctx.Session.Save(req, w)
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
return nil
}
-
name, err = smtpd.ParseMailboxName(name)
if err != nil {
ctx.Session.AddFlash(err.Error(), "errors")
@@ -32,17 +30,19 @@ func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context)
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
return nil
}
-
// Remember this mailbox was visited
RememberMailbox(ctx, name)
+ // Get flash messages, save session
+ errorFlash := ctx.Session.Flashes("errors")
if err = ctx.Session.Save(req, w); err != nil {
return err
}
-
+ // Render template
return httpd.RenderTemplate("mailbox/index.html", w, map[string]interface{}{
- "ctx": ctx,
- "name": name,
- "selected": selected,
+ "ctx": ctx,
+ "errorFlash": errorFlash,
+ "name": name,
+ "selected": selected,
})
}
@@ -57,7 +57,7 @@ func MailboxLink(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
return nil
}
-
+ // Build redirect
uri := fmt.Sprintf("%s?name=%s&id=%s", httpd.Reverse("MailboxIndex"), name, id)
http.Redirect(w, req, uri, http.StatusSeeOther)
return nil
@@ -81,7 +81,7 @@ func MailboxList(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (
return fmt.Errorf("Failed to get messages for %v: %v", name, err)
}
log.Tracef("Got %v messsages", len(messages))
-
+ // Render partial template
return httpd.RenderPartial("mailbox/_list.html", w, map[string]interface{}{
"ctx": ctx,
"name": name,
@@ -115,10 +115,9 @@ func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (
if err != nil {
return fmt.Errorf("ReadBody(%q) failed: %v", id, err)
}
-
body := template.HTML(httpd.TextToHTML(mime.Text))
htmlAvailable := mime.HTML != ""
-
+ // Render partial template
return httpd.RenderPartial("mailbox/_show.html", w, map[string]interface{}{
"ctx": ctx,
"name": name,
@@ -156,7 +155,7 @@ func MailboxHTML(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (
if err != nil {
return fmt.Errorf("ReadBody(%q) failed: %v", id, err)
}
-
+ // Render partial template
w.Header().Set("Content-Type", "text/html; charset=UTF-8")
return httpd.RenderPartial("mailbox/_html.html", w, map[string]interface{}{
"ctx": ctx,
@@ -193,7 +192,7 @@ func MailboxSource(w http.ResponseWriter, req *http.Request, ctx *httpd.Context)
if err != nil {
return fmt.Errorf("ReadRaw(%q) failed: %v", id, err)
}
-
+ // Output message source
w.Header().Set("Content-Type", "text/plain")
if _, err := io.WriteString(w, *raw); err != nil {
return err
@@ -221,7 +220,6 @@ func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
return nil
}
-
mb, err := ctx.DataStore.MailboxFor(name)
if err != nil {
// This doesn't indicate not found, likely an IO error
@@ -247,7 +245,7 @@ func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.
return nil
}
part := body.Attachments[num]
-
+ // Output attachment
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", "attachment")
if _, err := io.Copy(w, part); err != nil {
@@ -275,7 +273,6 @@ func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.Cont
http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther)
return nil
}
-
mb, err := ctx.DataStore.MailboxFor(name)
if err != nil {
// This doesn't indicate not found, likely an IO error
@@ -301,7 +298,7 @@ func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.Cont
return nil
}
part := body.Attachments[num]
-
+ // Output attachment
w.Header().Set("Content-Type", part.ContentType)
if _, err := io.Copy(w, part); err != nil {
return err
diff --git a/webui/root_controller.go b/webui/root_controller.go
index ef156be..a8e404c 100644
--- a/webui/root_controller.go
+++ b/webui/root_controller.go
@@ -16,17 +16,30 @@ func RootIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (er
if err != nil {
return fmt.Errorf("Failed to load greeting: %v", err)
}
-
+ // Get flash messages, save session
+ errorFlash := ctx.Session.Flashes("errors")
+ if err = ctx.Session.Save(req, w); err != nil {
+ return err
+ }
+ // Render template
return httpd.RenderTemplate("root/index.html", w, map[string]interface{}{
- "ctx": ctx,
- "greeting": template.HTML(string(greeting)),
+ "ctx": ctx,
+ "errorFlash": errorFlash,
+ "greeting": template.HTML(string(greeting)),
})
}
// RootMonitor serves the Inbucket monitor page
func RootMonitor(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) {
+ // Get flash messages, save session
+ errorFlash := ctx.Session.Flashes("errors")
+ if err = ctx.Session.Save(req, w); err != nil {
+ return err
+ }
+ // Render template
return httpd.RenderTemplate("root/monitor.html", w, map[string]interface{}{
- "ctx": ctx,
+ "ctx": ctx,
+ "errorFlash": errorFlash,
})
}
@@ -38,8 +51,15 @@ func RootStatus(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (e
config.GetPOP3Config().IP4port)
webListener := fmt.Sprintf("%s:%d", config.GetWebConfig().IP4address.String(),
config.GetWebConfig().IP4port)
+ // Get flash messages, save session
+ errorFlash := ctx.Session.Flashes("errors")
+ if err = ctx.Session.Save(req, w); err != nil {
+ return err
+ }
+ // Render template
return httpd.RenderTemplate("root/status.html", w, map[string]interface{}{
"ctx": ctx,
+ "errorFlash": errorFlash,
"version": config.Version,
"buildDate": config.BuildDate,
"smtpListener": smtpListener,