Files
golib/mail/tools.go
Nicolas JUHEL 2b42aa859d Add Packges:
- smtp : refactor smtp packgage and allow connection context for smtp
- mailer : add package for templating mail (using hermes lib)
- mail : add package to format mal with header to be send to smtp (using lib smple mail)

Add function in package :
- errors : add function to retireve a map of minimal error code and package path of the getMessage function
- version : add function to get root path of package (still existing but not return before this function)
- ioutils : add function to expand bytes.buffer as io.ReadCloser interface
2021-02-15 04:25:59 +01:00

53 lines
1.1 KiB
Go

package mail
import (
"bytes"
"encoding/base64"
"mime/quotedprintable"
"strings"
)
// base64Encode base64 encodes the provided text with line wrapping
func base64Encode(text []byte) []byte {
// create buffer
buf := new(bytes.Buffer)
// create base64 encoder that linewraps
encoder := base64.NewEncoder(base64.StdEncoding, &base64LineWrap{writer: buf})
// write the encoded text to buf
encoder.Write(text)
encoder.Close()
return buf.Bytes()
}
// qpEncode uses the quoted-printable encoding to encode the provided text
func qpEncode(text []byte) []byte {
// create buffer
buf := new(bytes.Buffer)
encoder := quotedprintable.NewWriter(buf)
encoder.Write(text)
encoder.Close()
return buf.Bytes()
}
func encodeHeader(text string, charset string, usedChars int) string {
// create buffer
buf := new(bytes.Buffer)
// encode
encoder := newEncoder(buf, charset, usedChars)
encoder.encode([]byte(text))
return buf.String()
}
func escapeQuotes(s string) string {
quoteEscaper := strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
return quoteEscaper.Replace(s)
}