Fixed a bug when embedding multiple files.

Closes #12.
This commit is contained in:
Alexandre Cesaro 2014-12-23 11:23:01 +01:00
parent b4e3113e2d
commit 512e469f62
2 changed files with 14 additions and 6 deletions

View File

@ -262,7 +262,7 @@ func (msg *Message) Embed(image ...*File) {
if msg.embedded == nil { if msg.embedded == nil {
msg.embedded = image msg.embedded = image
} else { } else {
msg.embedded = append(msg.attachments, image...) msg.embedded = append(msg.embedded, image...)
} }
} }

View File

@ -336,7 +336,8 @@ func TestEmbedded(t *testing.T) {
msg := NewMessage() msg := NewMessage()
msg.SetHeader("From", "from@example.com") msg.SetHeader("From", "from@example.com")
msg.SetHeader("To", "to@example.com") msg.SetHeader("To", "to@example.com")
msg.Embed(CreateFile("image.jpg", []byte("Content"))) msg.Embed(CreateFile("image1.jpg", []byte("Content 1")))
msg.Embed(CreateFile("image2.jpg", []byte("Content 2")))
msg.SetBody("text/plain", "Test") msg.SetBody("text/plain", "Test")
want := message{ want := message{
@ -352,12 +353,19 @@ func TestEmbedded(t *testing.T) {
"\r\n" + "\r\n" +
"Test\r\n" + "Test\r\n" +
"--_BOUNDARY_1_\r\n" + "--_BOUNDARY_1_\r\n" +
"Content-Type: image/jpeg; name=\"image.jpg\"\r\n" + "Content-Type: image/jpeg; name=\"image1.jpg\"\r\n" +
"Content-Disposition: inline; filename=\"image.jpg\"\r\n" + "Content-Disposition: inline; filename=\"image1.jpg\"\r\n" +
"Content-ID: <image.jpg>\r\n" + "Content-ID: <image1.jpg>\r\n" +
"Content-Transfer-Encoding: base64\r\n" + "Content-Transfer-Encoding: base64\r\n" +
"\r\n" + "\r\n" +
base64.StdEncoding.EncodeToString([]byte("Content")) + "\r\n" + base64.StdEncoding.EncodeToString([]byte("Content 1")) + "\r\n" +
"--_BOUNDARY_1_\r\n" +
"Content-Type: image/jpeg; name=\"image2.jpg\"\r\n" +
"Content-Disposition: inline; filename=\"image2.jpg\"\r\n" +
"Content-ID: <image2.jpg>\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"\r\n" +
base64.StdEncoding.EncodeToString([]byte("Content 2")) + "\r\n" +
"--_BOUNDARY_1_--\r\n", "--_BOUNDARY_1_--\r\n",
} }