mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-20 19:17:01 +00:00
Add a controller to view list mailbox contents, view individual
messages.
This commit is contained in:
60
app/controllers/mailbox.go
Normal file
60
app/controllers/mailbox.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/jhillyerd/inbucket/app/inbucket"
|
||||
"github.com/robfig/revel"
|
||||
)
|
||||
|
||||
type Mailbox struct {
|
||||
*rev.Controller
|
||||
}
|
||||
|
||||
func (c Mailbox) Index(name string) rev.Result {
|
||||
return c.Redirect("/mailbox/list/%v", name)
|
||||
}
|
||||
|
||||
func (c Mailbox) List(name string) rev.Result {
|
||||
title := fmt.Sprintf("Mailbox for %v", name)
|
||||
|
||||
ds := inbucket.NewDataStore()
|
||||
mb, err := ds.MailboxFor(name)
|
||||
if err != nil {
|
||||
rev.ERROR.Printf(err.Error())
|
||||
c.Flash.Error(err.Error())
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
messages, err := mb.GetMessages()
|
||||
if err != nil {
|
||||
rev.ERROR.Printf(err.Error())
|
||||
c.Flash.Error(err.Error())
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
rev.INFO.Printf("Got %v messsages", len(messages))
|
||||
|
||||
return c.Render(title, name, messages)
|
||||
}
|
||||
|
||||
func (c Mailbox) Show(name string, id string) rev.Result {
|
||||
ds := inbucket.NewDataStore()
|
||||
mb, err := ds.MailboxFor(name)
|
||||
if err != nil {
|
||||
rev.ERROR.Printf(err.Error())
|
||||
c.Flash.Error(err.Error())
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
message, err := mb.GetMessage(id)
|
||||
if err != nil {
|
||||
rev.ERROR.Printf(err.Error())
|
||||
c.Flash.Error(err.Error())
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
_, body, err := message.ReadBody()
|
||||
if err != nil {
|
||||
rev.ERROR.Printf(err.Error())
|
||||
c.Flash.Error(err.Error())
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
|
||||
return c.Render(name, message, body)
|
||||
}
|
||||
Reference in New Issue
Block a user