diff --git a/pkg/rest/apiv1_controller.go b/pkg/rest/apiv1_controller.go index 8250fa3..84ceba6 100644 --- a/pkg/rest/apiv1_controller.go +++ b/pkg/rest/apiv1_controller.go @@ -65,15 +65,16 @@ func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *web.Context) ( attachments := make([]*model.JSONMessageAttachmentV1, len(attachParts)) for i, part := range attachParts { content := part.Content - var checksum = md5.Sum(content) + // Example URL: http://localhost/serve/mailbox/swaks/0001/attach/0/favicon.png + link := "http://" + req.Host + "/serve/mailbox/" + name + "/" + id + "/attach/" + + strconv.Itoa(i) + "/" + part.FileName + checksum := md5.Sum(content) attachments[i] = &model.JSONMessageAttachmentV1{ - 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[:]), + ContentType: part.ContentType, + FileName: part.FileName, + DownloadLink: link, + ViewLink: link, + MD5: hex.EncodeToString(checksum[:]), } } return web.RenderJSON(w, diff --git a/pkg/rest/apiv1_controller_test.go b/pkg/rest/apiv1_controller_test.go index efb0936..8444edc 100644 --- a/pkg/rest/apiv1_controller_test.go +++ b/pkg/rest/apiv1_controller_test.go @@ -196,6 +196,10 @@ func TestRestMessage(t *testing.T) { "From": []string{"noreply@inbucket.org"}, }, }, + Attachments: []*enmime.Part{{ + FileName: "favicon.png", + ContentType: "image/png", + }}, }, ) mm.AddMessage("good", msg1) @@ -231,6 +235,10 @@ func TestRestMessage(t *testing.T) { decodedStringEquals(t, result, "header/To/[0]", "fred@fish.com") decodedStringEquals(t, result, "header/To/[1]", "keyword@nsa.gov") decodedStringEquals(t, result, "header/From/[0]", "noreply@inbucket.org") + decodedStringEquals(t, result, "attachments/[0]/filename", "favicon.png") + decodedStringEquals(t, result, "attachments/[0]/content-type", "image/png") + decodedStringEquals(t, result, "attachments/[0]/download-link", "http://localhost/serve/mailbox/good/0001/attach/0/favicon.png") + decodedStringEquals(t, result, "attachments/[0]/view-link", "http://localhost/serve/mailbox/good/0001/attach/0/favicon.png") if t.Failed() { // Wait for handler to finish logging