Skip to content

Commit 3e43819

Browse files
author
Winni Neessen
committed
Added SetDateWithValue() as well as Reset() to Msg
1 parent bc5e6cf commit 3e43819

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

msg.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ func (m *Msg) SetDate() {
315315
m.SetHeader(HeaderDate, ts)
316316
}
317317

318+
// SetDateWithValue sets the Date genHeader field to the provided time in a valid format
319+
func (m *Msg) SetDateWithValue(t time.Time) {
320+
m.SetHeader(HeaderDate, t.Format(time.RFC1123Z))
321+
}
322+
318323
// SetImportance sets the Msg Importance/Priority header to given Importance
319324
func (m *Msg) SetImportance(i Importance) {
320325
if i == ImportanceNormal {
@@ -411,6 +416,16 @@ func (m *Msg) EmbedReader(n string, r io.Reader, o ...FileOption) {
411416
m.embeds = m.appendFile(m.embeds, fileFromReader(n, r), o...)
412417
}
413418

419+
// Reset resets all headers, body parts and attachments/embeds of the Msg
420+
// It leaves already set encodings, charsets, boundaries, etc. as is
421+
func (m *Msg) Reset() {
422+
m.addrHeader = make(map[AddrHeader][]*mail.Address)
423+
m.attachments = nil
424+
m.embeds = nil
425+
m.genHeader = make(map[Header][]string)
426+
m.parts = nil
427+
}
428+
414429
// Write writes the formated Msg into a give io.Writer
415430
func (m *Msg) Write(w io.Writer) (int64, error) {
416431
mw := &msgWriter{w: w}

0 commit comments

Comments
 (0)