Added SetDateWithValue() as well as Reset() to Msg

This commit is contained in:
Winni Neessen 2022-03-14 11:50:36 +01:00
parent bc5e6cfb95
commit 3e43819b57
Signed by: wneessen
GPG key ID: 385AC9889632126E

15
msg.go
View file

@ -315,6 +315,11 @@ func (m *Msg) SetDate() {
m.SetHeader(HeaderDate, ts)
}
// SetDateWithValue sets the Date genHeader field to the provided time in a valid format
func (m *Msg) SetDateWithValue(t time.Time) {
m.SetHeader(HeaderDate, t.Format(time.RFC1123Z))
}
// SetImportance sets the Msg Importance/Priority header to given Importance
func (m *Msg) SetImportance(i Importance) {
if i == ImportanceNormal {
@ -411,6 +416,16 @@ func (m *Msg) EmbedReader(n string, r io.Reader, o ...FileOption) {
m.embeds = m.appendFile(m.embeds, fileFromReader(n, r), o...)
}
// Reset resets all headers, body parts and attachments/embeds of the Msg
// It leaves already set encodings, charsets, boundaries, etc. as is
func (m *Msg) Reset() {
m.addrHeader = make(map[AddrHeader][]*mail.Address)
m.attachments = nil
m.embeds = nil
m.genHeader = make(map[Header][]string)
m.parts = nil
}
// Write writes the formated Msg into a give io.Writer
func (m *Msg) Write(w io.Writer) (int64, error) {
mw := &msgWriter{w: w}