mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
@@ -3,6 +3,7 @@ package web
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jhillyerd/inbucket/log"
|
"github.com/jhillyerd/inbucket/log"
|
||||||
|
"github.com/jhillyerd/inbucket/smtpd"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -30,6 +31,7 @@ type JsonMessageBody struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
||||||
|
// Form values must be validated manually
|
||||||
name := req.FormValue("name")
|
name := req.FormValue("name")
|
||||||
selected := req.FormValue("id")
|
selected := req.FormValue("id")
|
||||||
|
|
||||||
@@ -39,6 +41,8 @@ func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *Context) (err e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name = smtpd.ParseMailboxName(name)
|
||||||
|
|
||||||
return RenderTemplate("mailbox/index.html", w, map[string]interface{}{
|
return RenderTemplate("mailbox/index.html", w, map[string]interface{}{
|
||||||
"ctx": ctx,
|
"ctx": ctx,
|
||||||
"name": name,
|
"name": name,
|
||||||
@@ -47,7 +51,8 @@ func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *Context) (err e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MailboxLink(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
func MailboxLink(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
||||||
name := ctx.Vars["name"]
|
// Don't have to validate these aren't empty, Gorilla returns 404
|
||||||
|
name := smtpd.ParseMailboxName(ctx.Vars["name"])
|
||||||
id := ctx.Vars["id"]
|
id := ctx.Vars["id"]
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s?name=%s&id=%s", reverse("MailboxIndex"), name, id)
|
uri := fmt.Sprintf("%s?name=%s&id=%s", reverse("MailboxIndex"), name, id)
|
||||||
@@ -57,7 +62,7 @@ func MailboxLink(w http.ResponseWriter, req *http.Request, ctx *Context) (err er
|
|||||||
|
|
||||||
func MailboxList(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
func MailboxList(w http.ResponseWriter, req *http.Request, ctx *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
|
||||||
name := ctx.Vars["name"]
|
name := smtpd.ParseMailboxName(ctx.Vars["name"])
|
||||||
|
|
||||||
mb, err := ctx.DataStore.MailboxFor(name)
|
mb, err := ctx.DataStore.MailboxFor(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -93,7 +98,7 @@ func MailboxList(w http.ResponseWriter, req *http.Request, ctx *Context) (err er
|
|||||||
|
|
||||||
func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *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
|
||||||
name := ctx.Vars["name"]
|
name := smtpd.ParseMailboxName(ctx.Vars["name"])
|
||||||
id := ctx.Vars["id"]
|
id := ctx.Vars["id"]
|
||||||
|
|
||||||
mb, err := ctx.DataStore.MailboxFor(name)
|
mb, err := ctx.DataStore.MailboxFor(name)
|
||||||
@@ -145,7 +150,7 @@ func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *Context) (err er
|
|||||||
|
|
||||||
func MailboxPurge(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
func MailboxPurge(w http.ResponseWriter, req *http.Request, ctx *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
|
||||||
name := ctx.Vars["name"]
|
name := smtpd.ParseMailboxName(ctx.Vars["name"])
|
||||||
|
|
||||||
mb, err := ctx.DataStore.MailboxFor(name)
|
mb, err := ctx.DataStore.MailboxFor(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -167,7 +172,7 @@ func MailboxPurge(w http.ResponseWriter, req *http.Request, ctx *Context) (err e
|
|||||||
|
|
||||||
func MailboxHtml(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
func MailboxHtml(w http.ResponseWriter, req *http.Request, ctx *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
|
||||||
name := ctx.Vars["name"]
|
name := smtpd.ParseMailboxName(ctx.Vars["name"])
|
||||||
id := ctx.Vars["id"]
|
id := ctx.Vars["id"]
|
||||||
|
|
||||||
mb, err := ctx.DataStore.MailboxFor(name)
|
mb, err := ctx.DataStore.MailboxFor(name)
|
||||||
@@ -194,7 +199,7 @@ func MailboxHtml(w http.ResponseWriter, req *http.Request, ctx *Context) (err er
|
|||||||
|
|
||||||
func MailboxSource(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
func MailboxSource(w http.ResponseWriter, req *http.Request, ctx *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
|
||||||
name := ctx.Vars["name"]
|
name := smtpd.ParseMailboxName(ctx.Vars["name"])
|
||||||
id := ctx.Vars["id"]
|
id := ctx.Vars["id"]
|
||||||
|
|
||||||
mb, err := ctx.DataStore.MailboxFor(name)
|
mb, err := ctx.DataStore.MailboxFor(name)
|
||||||
@@ -217,7 +222,7 @@ func MailboxSource(w http.ResponseWriter, req *http.Request, ctx *Context) (err
|
|||||||
|
|
||||||
func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *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
|
||||||
name := ctx.Vars["name"]
|
name := smtpd.ParseMailboxName(ctx.Vars["name"])
|
||||||
id := ctx.Vars["id"]
|
id := ctx.Vars["id"]
|
||||||
numStr := ctx.Vars["num"]
|
numStr := ctx.Vars["num"]
|
||||||
num, err := strconv.ParseUint(numStr, 10, 32)
|
num, err := strconv.ParseUint(numStr, 10, 32)
|
||||||
@@ -254,7 +259,7 @@ func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *Contex
|
|||||||
|
|
||||||
func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *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
|
||||||
name := ctx.Vars["name"]
|
name := smtpd.ParseMailboxName(ctx.Vars["name"])
|
||||||
id := ctx.Vars["id"]
|
id := ctx.Vars["id"]
|
||||||
numStr := ctx.Vars["num"]
|
numStr := ctx.Vars["num"]
|
||||||
num, err := strconv.ParseUint(numStr, 10, 32)
|
num, err := strconv.ParseUint(numStr, 10, 32)
|
||||||
@@ -290,7 +295,7 @@ func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *Context) (
|
|||||||
|
|
||||||
func MailboxDelete(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) {
|
func MailboxDelete(w http.ResponseWriter, req *http.Request, ctx *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
|
||||||
name := ctx.Vars["name"]
|
name := smtpd.ParseMailboxName(ctx.Vars["name"])
|
||||||
id := ctx.Vars["id"]
|
id := ctx.Vars["id"]
|
||||||
|
|
||||||
mb, err := ctx.DataStore.MailboxFor(name)
|
mb, err := ctx.DataStore.MailboxFor(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user