google mail API [[[WIP]]]
This commit is contained in:
41
googleapi/attachment.go
Normal file
41
googleapi/attachment.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package googleapi
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type MailAttachment struct {
|
||||
IsInline bool
|
||||
ContentType *string
|
||||
Filename *string
|
||||
Data []byte
|
||||
}
|
||||
|
||||
func (a MailAttachment) dump() []string {
|
||||
res := make([]string, 0, 4)
|
||||
|
||||
if a.ContentType != nil {
|
||||
res = append(res, "Content-Type: "+*a.ContentType+"; charset=UTF-8")
|
||||
}
|
||||
|
||||
res = append(res, "Content-Transfer-Encoding: base64")
|
||||
|
||||
if a.IsInline {
|
||||
if a.Filename != nil {
|
||||
res = append(res, fmt.Sprintf("Content-Disposition: inline;filename=\"%s\"", *a.Filename))
|
||||
} else {
|
||||
res = append(res, "Content-Disposition: inline")
|
||||
}
|
||||
} else {
|
||||
if a.Filename != nil {
|
||||
res = append(res, fmt.Sprintf("Content-Disposition: attachment;filename=\"%s\"", *a.Filename))
|
||||
} else {
|
||||
res = append(res, "Content-Disposition: attachment")
|
||||
}
|
||||
}
|
||||
|
||||
res = append(res, base64.URLEncoding.EncodeToString(a.Data))
|
||||
|
||||
return res
|
||||
}
|
Reference in New Issue
Block a user