Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Add helper to make mail attachment headers

Kailash Nadhd390bc904c1c
diff --git a/messenger/messenger.go b/messenger/messenger.go
index 66b6e244..65772faa 100644
--- a/messenger/messenger.go
+++ b/messenger/messenger.go
@@ -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
+}