mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-23 22:20:51 +01:00
Add EchoBuffer to serverProps for capturing SMTP data
Introduced a new io.Writer field `EchoBuffer` and its associated `BufferMutex` to `serverProps`. Updated relevant test code to write SMTP transaction data to `EchoBuffer` if it is set, ensuring thread safety with `BufferMutex`.
This commit is contained in:
parent
d30a4a73c6
commit
7ee4e47c8e
1 changed files with 23 additions and 0 deletions
|
@ -3665,6 +3665,8 @@ func testingKey(s string) string { return strings.ReplaceAll(s, "TESTING KEY", "
|
||||||
|
|
||||||
// serverProps represents the configuration properties for the SMTP server.
|
// serverProps represents the configuration properties for the SMTP server.
|
||||||
type serverProps struct {
|
type serverProps struct {
|
||||||
|
BufferMutex sync.RWMutex
|
||||||
|
EchoBuffer io.Writer
|
||||||
FailOnAuth bool
|
FailOnAuth bool
|
||||||
FailOnDataInit bool
|
FailOnDataInit bool
|
||||||
FailOnDataClose bool
|
FailOnDataClose bool
|
||||||
|
@ -3754,6 +3756,13 @@ func handleTestServerConnection(connection net.Conn, t *testing.T, props *server
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf("failed to write line: %s", err)
|
t.Logf("failed to write line: %s", err)
|
||||||
}
|
}
|
||||||
|
if props.EchoBuffer != nil {
|
||||||
|
props.BufferMutex.Lock()
|
||||||
|
if _, berr := props.EchoBuffer.Write([]byte(data + "\r\n")); berr != nil {
|
||||||
|
t.Errorf("failed write to echo buffer: %s", berr)
|
||||||
|
}
|
||||||
|
props.BufferMutex.Unlock()
|
||||||
|
}
|
||||||
_ = writer.Flush()
|
_ = writer.Flush()
|
||||||
}
|
}
|
||||||
writeOK := func() {
|
writeOK := func() {
|
||||||
|
@ -3770,6 +3779,13 @@ func handleTestServerConnection(connection net.Conn, t *testing.T, props *server
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
time.Sleep(time.Millisecond)
|
time.Sleep(time.Millisecond)
|
||||||
|
if props.EchoBuffer != nil {
|
||||||
|
props.BufferMutex.Lock()
|
||||||
|
if _, berr := props.EchoBuffer.Write([]byte(data)); berr != nil {
|
||||||
|
t.Errorf("failed write to echo buffer: %s", berr)
|
||||||
|
}
|
||||||
|
props.BufferMutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
var datastring string
|
var datastring string
|
||||||
data = strings.TrimSpace(data)
|
data = strings.TrimSpace(data)
|
||||||
|
@ -3830,6 +3846,13 @@ func handleTestServerConnection(connection net.Conn, t *testing.T, props *server
|
||||||
t.Logf("failed to read data from connection: %s", derr)
|
t.Logf("failed to read data from connection: %s", derr)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if props.EchoBuffer != nil {
|
||||||
|
props.BufferMutex.Lock()
|
||||||
|
if _, berr := props.EchoBuffer.Write([]byte(ddata)); berr != nil {
|
||||||
|
t.Errorf("failed write to echo buffer: %s", berr)
|
||||||
|
}
|
||||||
|
props.BufferMutex.Unlock()
|
||||||
|
}
|
||||||
ddata = strings.TrimSpace(ddata)
|
ddata = strings.TrimSpace(ddata)
|
||||||
if ddata == "." {
|
if ddata == "." {
|
||||||
if props.FailOnDataClose {
|
if props.FailOnDataClose {
|
||||||
|
|
Loading…
Reference in a new issue