mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
Add a view source button to see raw text of message
This commit is contained in:
@@ -78,3 +78,27 @@ func (c Mailbox) Delete(name string, id string) rev.Result {
|
||||
}
|
||||
return c.RenderText("OK")
|
||||
}
|
||||
|
||||
func (c Mailbox) Source(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)
|
||||
}
|
||||
raw, err := message.ReadRaw()
|
||||
if err != nil {
|
||||
rev.ERROR.Printf(err.Error())
|
||||
c.Flash.Error(err.Error())
|
||||
return c.Redirect(Application.Index)
|
||||
}
|
||||
|
||||
return c.RenderText(*raw)
|
||||
}
|
||||
|
||||
@@ -194,6 +194,22 @@ func (m *Message) ReadBody() (msg *mail.Message, body *string, err error) {
|
||||
return msg, &bodyString, err
|
||||
}
|
||||
|
||||
// ReadRaw opens the .raw portion of a Message and returns it as a string
|
||||
func (m *Message) ReadRaw() (raw *string, err error) {
|
||||
file, err := os.Open(m.rawPath())
|
||||
defer file.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reader := bufio.NewReader(file)
|
||||
bodyBytes, err := ioutil.ReadAll(reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bodyString := string(bodyBytes)
|
||||
return &bodyString, nil
|
||||
}
|
||||
|
||||
// Append data to a newly opened Message, this will fail on a pre-existing Message and
|
||||
// after Close() is called.
|
||||
func (m *Message) Append(data []byte) error {
|
||||
|
||||
@@ -45,7 +45,9 @@
|
||||
}
|
||||
|
||||
function messageSource(id) {
|
||||
alert('delete')
|
||||
window.open('/mailbox/source/{{$name}}/' + id, '_blank',
|
||||
'width=800,height=600,' +
|
||||
'location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no')
|
||||
}
|
||||
|
||||
$(document).ready(listInit)
|
||||
|
||||
@@ -7,6 +7,7 @@ GET /mailbox/{name} Mailbox.Index
|
||||
GET /mailbox Mailbox.Index
|
||||
GET /mailbox/list/{name} Mailbox.List
|
||||
GET /mailbox/show/{name}/{id} Mailbox.Show
|
||||
GET /mailbox/source/{name}/{id} Mailbox.Source
|
||||
POST /mailbox/delete/{name}/{id} Mailbox.Delete
|
||||
|
||||
# Ignore favicon requests
|
||||
|
||||
Reference in New Issue
Block a user