Add helper to make mail attachment headers

This commit is contained in:
Kailash Nadh 2019-07-21 12:30:51 +05:30
parent 81fe874ee7
commit d390bc904c
1 changed files with 14 additions and 0 deletions

View File

@ -18,3 +18,17 @@ type Attachment struct {
Header textproto.MIMEHeader
Content []byte
}
// MakeAttachmentHeader is a helper function that returns a
// textproto.MIMEHeader tailored for attachments, primarily
// email. If no encoding is given, base64 is assumed.
func MakeAttachmentHeader(filename, encoding string) textproto.MIMEHeader {
if encoding == "" {
encoding = "base64"
}
h := textproto.MIMEHeader{}
h.Set("Content-Disposition", "attachment; filename="+filename)
h.Set("Content-Type", "application/json; name=\""+filename+"\"")
h.Set("Content-Transfer-Encoding", "base64")
return h
}