From fd313e23b634795a97f264bfe1d2696b6a4e7d06 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 29 Nov 2023 17:26:47 +0100 Subject: [PATCH] Add checks for nil or empty Subject headers Added condition checks in `msg_test.go` for nil or empty Subject headers in the assigned functions. If the Subject is found to be nil or its length is less than 1, an empty string is now appended to prevent issues arising from null pointers or non-existent Subject headers in email messages. --- msg_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/msg_test.go b/msg_test.go index 14e5f18..b86be9f 100644 --- a/msg_test.go +++ b/msg_test.go @@ -216,6 +216,9 @@ func (mw uppercaseMiddleware) Handle(m *Msg) *Msg { if !ok { fmt.Println("can't find the subject header") } + if s == nil || len(s) < 1 { + s = append(s, "") + } m.Subject(strings.ToUpper(s[0])) return m } @@ -231,6 +234,9 @@ func (mw encodeMiddleware) Handle(m *Msg) *Msg { if !ok { fmt.Println("can't find the subject header") } + if s == nil || len(s) < 1 { + s = append(s, "") + } m.Subject(strings.Replace(s[0], "a", "@", -1)) return m }