mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
Basic HTML email rendering
Messages with a MIME text/html MIME part will now be displayed with an `HTML` button above them that will open another window and render the HTML when clicked. There is no sanitization performed, and inline attachment display is not support. This closes #2
This commit is contained in:
@@ -3,6 +3,7 @@ package controllers
|
|||||||
import (
|
import (
|
||||||
"github.com/jhillyerd/inbucket/app/inbucket"
|
"github.com/jhillyerd/inbucket/app/inbucket"
|
||||||
"github.com/robfig/revel"
|
"github.com/robfig/revel"
|
||||||
|
"html/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Mailbox struct {
|
type Mailbox struct {
|
||||||
@@ -69,9 +70,10 @@ func (c Mailbox) Show(name string, id string) rev.Result {
|
|||||||
return c.RenderError(err)
|
return c.RenderError(err)
|
||||||
}
|
}
|
||||||
body := mime.Text
|
body := mime.Text
|
||||||
|
htmlAvailable := mime.Html != ""
|
||||||
|
|
||||||
c.Response.Out.Header().Set("Expires", "-1")
|
c.Response.Out.Header().Set("Expires", "-1")
|
||||||
return c.Render(name, message, body)
|
return c.Render(name, message, body, htmlAvailable)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Mailbox) Delete(name string, id string) rev.Result {
|
func (c Mailbox) Delete(name string, id string) rev.Result {
|
||||||
@@ -97,9 +99,41 @@ func (c Mailbox) Delete(name string, id string) rev.Result {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return c.RenderError(err)
|
return c.RenderError(err)
|
||||||
}
|
}
|
||||||
|
c.Response.Out.Header().Set("Expires", "-1")
|
||||||
return c.RenderText("OK")
|
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 {
|
func (c Mailbox) Source(name string, id string) rev.Result {
|
||||||
c.Validation.Required(name).Message("Account name is required")
|
c.Validation.Required(name).Message("Account name is required")
|
||||||
c.Validation.Required(id).Message("Message ID is required")
|
c.Validation.Required(id).Message("Message ID is required")
|
||||||
|
|||||||
1
app/views/Mailbox/Html.html
Normal file
1
app/views/Mailbox/Html.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{{.body}}
|
||||||
@@ -44,6 +44,12 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function htmlView(id) {
|
||||||
|
window.open('/mailbox/html/{{$name}}/' + id, '_blank',
|
||||||
|
'width=800,height=600,' +
|
||||||
|
'menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes')
|
||||||
|
}
|
||||||
|
|
||||||
function messageSource(id) {
|
function messageSource(id) {
|
||||||
window.open('/mailbox/source/{{$name}}/' + id, '_blank',
|
window.open('/mailbox/source/{{$name}}/' + id, '_blank',
|
||||||
'width=800,height=600,' +
|
'width=800,height=600,' +
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<div id="emailActions">
|
<div id="emailActions">
|
||||||
<a href="javascript:deleteMessage('{{.message.Id}}');">Delete</a>
|
<a href="javascript:deleteMessage('{{.message.Id}}');">Delete</a>
|
||||||
<a href="javascript:messageSource('{{.message.Id}}');">Source</a>
|
<a href="javascript:messageSource('{{.message.Id}}');">Source</a>
|
||||||
|
{{if .htmlAvailable}}
|
||||||
|
<a href="javascript:htmlView('{{.message.Id}}');">HTML</a>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
<table id="emailHeader">
|
<table id="emailHeader">
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ GET /mailbox Mailbox.Index
|
|||||||
GET /mailbox/list/{name} Mailbox.List
|
GET /mailbox/list/{name} Mailbox.List
|
||||||
GET /mailbox/show/{name}/{id} Mailbox.Show
|
GET /mailbox/show/{name}/{id} Mailbox.Show
|
||||||
GET /mailbox/source/{name}/{id} Mailbox.Source
|
GET /mailbox/source/{name}/{id} Mailbox.Source
|
||||||
|
GET /mailbox/html/{name}/{id} Mailbox.Html
|
||||||
POST /mailbox/delete/{name}/{id} Mailbox.Delete
|
POST /mailbox/delete/{name}/{id} Mailbox.Delete
|
||||||
|
|
||||||
# Ignore favicon requests
|
# Ignore favicon requests
|
||||||
|
|||||||
Reference in New Issue
Block a user