Fix in the storage of the original Middleware

This commit is contained in:
Winni Neessen 2022-10-25 16:56:40 +02:00
parent 6f93e5835e
commit 2bd6851c78
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 16 additions and 3 deletions

2
msg.go
View file

@ -722,7 +722,7 @@ func (m *Msg) WriteTo(w io.Writer) (int64, error) {
// the io.WriteTo interface but will skip the given Middleware // the io.WriteTo interface but will skip the given Middleware
func (m *Msg) WriteToSkipMiddleware(w io.Writer, mt MiddlewareType) (int64, error) { func (m *Msg) WriteToSkipMiddleware(w io.Writer, mt MiddlewareType) (int64, error) {
var omwl, mwl []Middleware var omwl, mwl []Middleware
copy(omwl, m.middlewares) omwl = m.middlewares
for i := range m.middlewares { for i := range m.middlewares {
if m.middlewares[i].Type() == mt { if m.middlewares[i].Type() == mt {
continue continue

View file

@ -1600,15 +1600,28 @@ func TestMsg_WriteToSkipMiddleware(t *testing.T) {
wbuf := bytes.Buffer{} wbuf := bytes.Buffer{}
n, err := m.WriteToSkipMiddleware(&wbuf, "uppercase") n, err := m.WriteToSkipMiddleware(&wbuf, "uppercase")
if err != nil { if err != nil {
t.Errorf("WriteTo() failed: %s", err) t.Errorf("WriteToSkipMiddleware() failed: %s", err)
return return
} }
if n != int64(wbuf.Len()) { 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") { if !strings.Contains(wbuf.String(), "Subject: This is @ test") {
t.Errorf("WriteToSkipMiddleware failed. Unable to find encoded subject") 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 // TestMsg_Write tests the Write() method of the Msg