Skip to content

Commit

Permalink
Use ContentID if provided to lookup attachments (#103)
Browse files Browse the repository at this point in the history
File struct now has an optional ContentID field which if provided is
used to look up inline attachments in the body instead of Name.
  • Loading branch information
meain committed Mar 11, 2024
1 parent e26e0d1 commit 500bfa5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
type File struct {
// FilePath is the path of the file to attach.
FilePath string
// ContentID is the contentID of the attachment. Optional. Used instead of Name to look up inline attachment in the body if provided.
ContentID string
// Name is the name of file in attachment. Required for Data and B64Data. Optional for FilePath.
Name string
// MimeType of attachment. If empty then is obtained from Name (if not empty) or FilePath. If cannot obtained, application/octet-stream is set.
Expand Down
6 changes: 5 additions & 1 deletion message.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ func (msg *message) addFiles(files []*File, inline bool) {
header.Set("Content-Transfer-Encoding", encoding.string())
if inline {
header.Set("Content-Disposition", "inline;\n \tfilename=\""+encodeHeader(escapeQuotes(file.Name), msg.charset, 10)+`"`)
header.Set("Content-ID", "<"+msg.getCID(file.Name)+">")
if len(file.ContentID) > 0 {
header.Set("Content-ID", "<"+msg.getCID(file.ContentID)+">")
} else {
header.Set("Content-ID", "<"+msg.getCID(file.Name)+">")
}
} else {
header.Set("Content-Disposition", "attachment;\n \tfilename=\""+encodeHeader(escapeQuotes(file.Name), msg.charset, 10)+`"`)
}
Expand Down

0 comments on commit 500bfa5

Please sign in to comment.