It is now possible to set the Content-ID of embeded files

Closes #20.
This commit is contained in:
Alexandre Cesaro 2015-02-18 20:46:05 +01:00
parent de623e612d
commit 6805982221
3 changed files with 13 additions and 6 deletions

View File

@ -126,8 +126,12 @@ func (w *messageWriter) addFiles(files []*File, isAttachment bool) {
h["Content-Disposition"] = []string{"attachment; filename=\"" + f.Name + "\""} h["Content-Disposition"] = []string{"attachment; filename=\"" + f.Name + "\""}
} else { } else {
h["Content-Disposition"] = []string{"inline; filename=\"" + f.Name + "\""} h["Content-Disposition"] = []string{"inline; filename=\"" + f.Name + "\""}
if f.ContentID != "" {
h["Content-ID"] = []string{"<" + f.ContentID + ">"}
} else {
h["Content-ID"] = []string{"<" + f.Name + ">"} h["Content-ID"] = []string{"<" + f.Name + ">"}
} }
}
w.write(h, f.Content, Base64) w.write(h, f.Content, Base64)
} }

View File

@ -211,6 +211,7 @@ type File struct {
Name string Name string
MimeType string MimeType string
Content []byte Content []byte
ContentID string
} }
// OpenFile opens a file on disk to create a gomail.File. // OpenFile opens a file on disk to create a gomail.File.

View File

@ -336,7 +336,9 @@ 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("image1.jpg", []byte("Content 1"))) f := CreateFile("image1.jpg", []byte("Content 1"))
f.ContentID = "test-content-id"
msg.Embed(f)
msg.Embed(CreateFile("image2.jpg", []byte("Content 2"))) msg.Embed(CreateFile("image2.jpg", []byte("Content 2")))
msg.SetBody("text/plain", "Test") msg.SetBody("text/plain", "Test")
@ -355,7 +357,7 @@ func TestEmbedded(t *testing.T) {
"--_BOUNDARY_1_\r\n" + "--_BOUNDARY_1_\r\n" +
"Content-Type: image/jpeg; name=\"image1.jpg\"\r\n" + "Content-Type: image/jpeg; name=\"image1.jpg\"\r\n" +
"Content-Disposition: inline; filename=\"image1.jpg\"\r\n" + "Content-Disposition: inline; filename=\"image1.jpg\"\r\n" +
"Content-ID: <image1.jpg>\r\n" + "Content-ID: <test-content-id>\r\n" +
"Content-Transfer-Encoding: base64\r\n" + "Content-Transfer-Encoding: base64\r\n" +
"\r\n" + "\r\n" +
base64.StdEncoding.EncodeToString([]byte("Content 1")) + "\r\n" + base64.StdEncoding.EncodeToString([]byte("Content 1")) + "\r\n" +