Skip to content

Commit

Permalink
code writing and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
xboyi committed Dec 18, 2023
1 parent c1dc274 commit 77970e3
Show file tree
Hide file tree
Showing 8 changed files with 1,250 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
Package gomail basic jordan-wright/email wrapper
*/
package mail // import "github.com/miajio/goemail"
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/miajio/goemail

go 1.21.3
40 changes: 40 additions & 0 deletions mail/attachment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package mail

import (
"fmt"
"net/textproto"
)

// Attachment
// is email attachement param type
// Based on the mime/multipart.FileHeader struct
// Attachment contains the name, MIMEHeader, and content of the attachment in question
type Attachment struct {
FileName string // fileName
ContentType string // content type
Header textproto.MIMEHeader // header
Content []byte // content
HTMLRelated bool
}

func (at *Attachment) setDefaultHeaders() {
contentType := "application/octet-stream"
if len(at.ContentType) > 0 {
contentType = at.ContentType
}
at.Header.Set("Content-Type", contentType)

if len(at.Header.Get("Content-Disposition")) == 0 {
disposition := "attachment"
if at.HTMLRelated {
disposition = "inline"
}
at.Header.Set("Content-Disposition", fmt.Sprintf("%s;\r\n filename=\"%s\"", disposition, at.FileName))
}
if len(at.Header.Get("Content-ID")) == 0 {
at.Header.Set("Content-ID", fmt.Sprintf("<%s>", at.FileName))
}
if len(at.Header.Get("Content-Transfer-Encoding")) == 0 {
at.Header.Set("Content-Transfer-Encoding", "base64")
}
}
Loading

0 comments on commit 77970e3

Please sign in to comment.