From cd2ee868462e0912cfaf2cb857fe7cda2d8547da Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sun, 2 Oct 2022 12:25:49 +0200 Subject: [PATCH 1/2] Added GetGenHeader to the Msg to grant read access to set generic headers (e g. to use in Middlewares) --- msg.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/msg.go b/msg.go index e4ac4ad..029ae65 100644 --- a/msg.go +++ b/msg.go @@ -478,6 +478,11 @@ func (m *Msg) GetRecipients() ([]string, error) { return rl, nil } +// GetGenHeader returns the content of the requested generic header of the Msg +func (m *Msg) GetGenHeader(h Header) []string { + return m.genHeader[h] +} + // SetBodyString sets the body of the message. func (m *Msg) SetBodyString(ct ContentType, b string, o ...PartOption) { buf := bytes.NewBufferString(b) From da130c0222c0269da7365bc843d84530e1ad82da Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sun, 2 Oct 2022 12:30:08 +0200 Subject: [PATCH 2/2] Added test for Msg.GetGenHeader --- msg_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/msg_test.go b/msg_test.go index 9278f98..017c08e 100644 --- a/msg_test.go +++ b/msg_test.go @@ -2105,3 +2105,20 @@ func TestMsg_WriteToFile(t *testing.T) { t.Errorf("output file is expected to contain data but its size is zero") } } + +// TestMsg_GetGenHeader will test the GetGenHeader method of the Msg +func TestMsg_GetGenHeader(t *testing.T) { + m := NewMsg() + m.Subject("this is a test") + sa := m.GetGenHeader(HeaderSubject) + if len(sa) <= 0 { + t.Errorf("GetGenHeader on subject failed. Got empty slice") + return + } + if sa[0] == "" { + t.Errorf("GetGenHeader on subject failed. Got empty value") + } + if sa[0] != "this is a test" { + t.Errorf("GetGenHeader on subject failed. Expected: %q, got: %q", "this is a test", sa[0]) + } +}