1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

Hide envelope, use Part.Content for #85

This commit is contained in:
James Hillyerd
2018-03-20 17:55:43 -07:00
parent 6d250a47b4
commit e7a86bd8f8
5 changed files with 65 additions and 36 deletions

View File

@@ -7,7 +7,6 @@ import (
"crypto/md5"
"encoding/hex"
"io/ioutil"
"strconv"
"github.com/jhillyerd/inbucket/pkg/log"
@@ -63,19 +62,20 @@ func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *web.Context) (
// This doesn't indicate empty, likely an IO error
return fmt.Errorf("GetMessage(%q) failed: %v", id, err)
}
mime := msg.Envelope
attachments := make([]*model.JSONMessageAttachmentV1, len(mime.Attachments))
for i, att := range mime.Attachments {
var content []byte
content, err = ioutil.ReadAll(att)
attachParts := msg.Attachments()
attachments := make([]*model.JSONMessageAttachmentV1, len(attachParts))
for i, part := range attachParts {
content := part.Content
var checksum = md5.Sum(content)
attachments[i] = &model.JSONMessageAttachmentV1{
ContentType: att.ContentType,
FileName: att.FileName,
DownloadLink: "http://" + req.Host + "/mailbox/dattach/" + name + "/" + id + "/" + strconv.Itoa(i) + "/" + att.FileName,
ViewLink: "http://" + req.Host + "/mailbox/vattach/" + name + "/" + id + "/" + strconv.Itoa(i) + "/" + att.FileName,
MD5: hex.EncodeToString(checksum[:]),
ContentType: part.ContentType,
FileName: part.FileName,
DownloadLink: "http://" + req.Host + "/mailbox/dattach/" + name + "/" + id + "/" +
strconv.Itoa(i) + "/" + part.FileName,
ViewLink: "http://" + req.Host + "/mailbox/vattach/" + name + "/" + id + "/" +
strconv.Itoa(i) + "/" + part.FileName,
MD5: hex.EncodeToString(checksum[:]),
}
}
@@ -88,10 +88,10 @@ func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *web.Context) (
Subject: msg.Subject,
Date: msg.Date,
Size: msg.Size,
Header: mime.Root.Header,
Header: msg.Header(),
Body: &model.JSONMessageBodyV1{
Text: mime.Text,
HTML: mime.HTML,
Text: msg.Text(),
HTML: msg.HTML(),
},
Attachments: attachments,
})

View File

@@ -172,8 +172,8 @@ func TestRestMessage(t *testing.T) {
}
// Test JSON message headers
msg1 := &message.Message{
Metadata: message.Metadata{
msg1 := message.New(
message.Metadata{
Mailbox: "good",
ID: "0001",
From: &mail.Address{Name: "", Address: "from1@host"},
@@ -181,7 +181,7 @@ func TestRestMessage(t *testing.T) {
Subject: "subject 1",
Date: time.Date(2012, 2, 1, 10, 11, 12, 253, time.FixedZone("PST", -800)),
},
Envelope: &enmime.Envelope{
&enmime.Envelope{
Text: "This is some text",
HTML: "This is some HTML",
Root: &enmime.Part{
@@ -191,7 +191,7 @@ func TestRestMessage(t *testing.T) {
},
},
},
}
)
mm.AddMessage("good", msg1)
// Check return code