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

View File

@ -208,9 +208,10 @@ func (msg *Message) GetBodyWriter(contentType string) io.Writer {
// A File represents a file that can be attached or embedded in an email.
type File struct {
Name string
MimeType string
Content []byte
Name string
MimeType string
Content []byte
ContentID string
}
// 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.SetHeader("From", "from@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.SetBody("text/plain", "Test")
@ -355,7 +357,7 @@ func TestEmbedded(t *testing.T) {
"--_BOUNDARY_1_\r\n" +
"Content-Type: image/jpeg; name=\"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" +
"\r\n" +
base64.StdEncoding.EncodeToString([]byte("Content 1")) + "\r\n" +