diff --git a/app/controllers/mailbox.go b/app/controllers/mailbox.go index 44265e9..d7cd5d2 100644 --- a/app/controllers/mailbox.go +++ b/app/controllers/mailbox.go @@ -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) +} diff --git a/app/inbucket/datastore.go b/app/inbucket/datastore.go index 7b19d55..42e99d8 100644 --- a/app/inbucket/datastore.go +++ b/app/inbucket/datastore.go @@ -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 { diff --git a/app/views/Mailbox/Index.html b/app/views/Mailbox/Index.html index e1aae1f..a4e8c67 100644 --- a/app/views/Mailbox/Index.html +++ b/app/views/Mailbox/Index.html @@ -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) diff --git a/conf/routes b/conf/routes index e6154b9..9c5a041 100644 --- a/conf/routes +++ b/conf/routes @@ -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