mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 01:57:02 +00:00
New directory layout - DOES NOT COMPILE
This commit is contained in:
31
web/app.go
Normal file
31
web/app.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/jhillyerd/inbucket/app/smtpd"
|
||||
"github.com/robfig/revel"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
*rev.Controller
|
||||
}
|
||||
|
||||
func (c Application) Index() rev.Result {
|
||||
return c.Render()
|
||||
}
|
||||
|
||||
type SmtpdPlugin struct {
|
||||
rev.EmptyPlugin
|
||||
server *smtpd.Server
|
||||
}
|
||||
|
||||
func (p SmtpdPlugin) OnAppStart() {
|
||||
domain := rev.Config.StringDefault("smtpd.domain", "localhost")
|
||||
port := rev.Config.IntDefault("smtpd.port", 2500)
|
||||
rev.INFO.Printf("SMTP Daemon plugin init {domain: %v, port: %v}", domain, port)
|
||||
p.server = smtpd.New(domain, port)
|
||||
go p.server.Start()
|
||||
}
|
||||
|
||||
func init() {
|
||||
rev.RegisterPlugin(SmtpdPlugin{})
|
||||
}
|
||||
19
web/helpers.go
Normal file
19
web/helpers.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/robfig/revel"
|
||||
"html/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rev.TRACE.Println("Registering helpers")
|
||||
rev.Funcs["friendlyTime"] = func(t time.Time) template.HTML {
|
||||
ty, tm, td := t.Date()
|
||||
ny, nm, nd := time.Now().Date()
|
||||
if (ty == ny) && (tm == nm) && (td == nd) {
|
||||
return template.HTML(t.Format("03:04:05 PM"))
|
||||
}
|
||||
return template.HTML(t.Format("Mon Jan 2, 2006"))
|
||||
}
|
||||
}
|
||||
163
web/mailbox.go
Normal file
163
web/mailbox.go
Normal file
@@ -0,0 +1,163 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/jhillyerd/inbucket/app/inbucket"
|
||||
"github.com/robfig/revel"
|
||||
"html/template"
|
||||
)
|
||||
|
||||
type Mailbox struct {
|
||||
*rev.Controller
|
||||
}
|
||||
|
||||
func (c Mailbox) Index(name string) rev.Result {
|
||||
c.Validation.Required(name).Message("Account name is required")
|
||||
|
||||
if c.Validation.HasErrors() {
|
||||
c.Validation.Keep()
|
||||
c.FlashParams()
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
|
||||
return c.Render(name)
|
||||
}
|
||||
|
||||
func (c Mailbox) List(name string) rev.Result {
|
||||
c.Validation.Required(name).Message("Account name is required")
|
||||
|
||||
if c.Validation.HasErrors() {
|
||||
c.Validation.Keep()
|
||||
c.FlashParams()
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
|
||||
ds := inbucket.NewDataStore()
|
||||
mb, err := ds.MailboxFor(name)
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
messages, err := mb.GetMessages()
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
rev.INFO.Printf("Got %v messsages", len(messages))
|
||||
|
||||
c.Response.Out.Header().Set("Expires", "-1")
|
||||
return c.Render(name, messages)
|
||||
}
|
||||
|
||||
func (c Mailbox) Show(name string, id string) rev.Result {
|
||||
c.Validation.Required(name).Message("Account name is required")
|
||||
c.Validation.Required(id).Message("Message ID is required")
|
||||
|
||||
if c.Validation.HasErrors() {
|
||||
c.Validation.Keep()
|
||||
c.FlashParams()
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
|
||||
ds := inbucket.NewDataStore()
|
||||
mb, err := ds.MailboxFor(name)
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
message, err := mb.GetMessage(id)
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
_, mime, err := message.ReadBody()
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
body := template.HTML(inbucket.TextToHtml(mime.Text))
|
||||
htmlAvailable := mime.Html != ""
|
||||
|
||||
c.Response.Out.Header().Set("Expires", "-1")
|
||||
return c.Render(name, message, body, htmlAvailable)
|
||||
}
|
||||
|
||||
func (c Mailbox) Delete(name string, id string) rev.Result {
|
||||
c.Validation.Required(name).Message("Account name is required")
|
||||
c.Validation.Required(id).Message("Message ID is required")
|
||||
|
||||
if c.Validation.HasErrors() {
|
||||
c.Validation.Keep()
|
||||
c.FlashParams()
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
|
||||
ds := inbucket.NewDataStore()
|
||||
mb, err := ds.MailboxFor(name)
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
message, err := mb.GetMessage(id)
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
err = message.Delete()
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
c.Response.Out.Header().Set("Expires", "-1")
|
||||
return c.RenderText("OK")
|
||||
}
|
||||
|
||||
func (c Mailbox) Html(name string, id string) rev.Result {
|
||||
c.Validation.Required(name).Message("Account name is required")
|
||||
c.Validation.Required(id).Message("Message ID is required")
|
||||
|
||||
if c.Validation.HasErrors() {
|
||||
c.Validation.Keep()
|
||||
c.FlashParams()
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
|
||||
ds := inbucket.NewDataStore()
|
||||
mb, err := ds.MailboxFor(name)
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
message, err := mb.GetMessage(id)
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
_, mime, err := message.ReadBody()
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
// Mark as safe to render HTML
|
||||
// TODO: It is not really safe to render, need to sanitize.
|
||||
body := template.HTML(mime.Html)
|
||||
|
||||
c.Response.Out.Header().Set("Expires", "-1")
|
||||
return c.Render(name, message, body)
|
||||
}
|
||||
|
||||
func (c Mailbox) Source(name string, id string) rev.Result {
|
||||
c.Validation.Required(name).Message("Account name is required")
|
||||
c.Validation.Required(id).Message("Message ID is required")
|
||||
|
||||
if c.Validation.HasErrors() {
|
||||
c.Validation.Keep()
|
||||
c.FlashParams()
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
|
||||
ds := inbucket.NewDataStore()
|
||||
mb, err := ds.MailboxFor(name)
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
message, err := mb.GetMessage(id)
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
raw, err := message.ReadRaw()
|
||||
if err != nil {
|
||||
return c.RenderError(err)
|
||||
}
|
||||
|
||||
c.Response.Out.Header().Set("Expires", "-1")
|
||||
return c.RenderText(*raw)
|
||||
}
|
||||
Reference in New Issue
Block a user