diff --git a/msg.go b/msg.go index fb463c7..d644d0a 100644 --- a/msg.go +++ b/msg.go @@ -722,7 +722,7 @@ func (m *Msg) WriteTo(w io.Writer) (int64, error) { // the io.WriteTo interface but will skip the given Middleware func (m *Msg) WriteToSkipMiddleware(w io.Writer, mt MiddlewareType) (int64, error) { var omwl, mwl []Middleware - copy(omwl, m.middlewares) + omwl = m.middlewares for i := range m.middlewares { if m.middlewares[i].Type() == mt { continue diff --git a/msg_test.go b/msg_test.go index fc164d6..7fa7a05 100644 --- a/msg_test.go +++ b/msg_test.go @@ -1600,15 +1600,28 @@ func TestMsg_WriteToSkipMiddleware(t *testing.T) { wbuf := bytes.Buffer{} n, err := m.WriteToSkipMiddleware(&wbuf, "uppercase") if err != nil { - t.Errorf("WriteTo() failed: %s", err) + t.Errorf("WriteToSkipMiddleware() failed: %s", err) return } if n != int64(wbuf.Len()) { - t.Errorf("WriteTo() failed: expected written byte length: %d, got: %d", n, wbuf.Len()) + t.Errorf("WriteToSkipMiddleware() failed: expected written byte length: %d, got: %d", n, wbuf.Len()) } if !strings.Contains(wbuf.String(), "Subject: This is @ test") { t.Errorf("WriteToSkipMiddleware failed. Unable to find encoded subject") } + + wbuf2 := bytes.Buffer{} + n, err = m.WriteTo(&wbuf2) + if err != nil { + t.Errorf("WriteTo() failed: %s", err) + return + } + if n != int64(wbuf2.Len()) { + t.Errorf("WriteTo() failed: expected written byte length: %d, got: %d", n, wbuf2.Len()) + } + if !strings.Contains(wbuf2.String(), "Subject: THIS IS @ TEST") { + t.Errorf("WriteToSkipMiddleware failed. Unable to find encoded and upperchase subject") + } } // TestMsg_Write tests the Write() method of the Msg