mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 13:50:49 +01:00
Merge pull request #88 from james-d-elliott/feat-without-noop
feat: without noop option
This commit is contained in:
commit
f454ae8c41
2 changed files with 41 additions and 2 deletions
20
client.go
20
client.go
|
@ -96,6 +96,9 @@ type Client struct {
|
|||
// enc indicates if a Client connection is encrypted or not
|
||||
enc bool
|
||||
|
||||
// noNoop indicates the Noop is to be skipped
|
||||
noNoop bool
|
||||
|
||||
// HELO/EHLO string for the greeting the target SMTP server
|
||||
helo string
|
||||
|
||||
|
@ -366,6 +369,15 @@ func WithDSNRcptNotifyType(rno ...DSNRcptNotifyOption) Option {
|
|||
}
|
||||
}
|
||||
|
||||
// WithoutNoop disables the Client Noop check during connections. This is primarily for servers which delay responses
|
||||
// to SMTP commands that are not the AUTH command. For example Microsoft Exchange's Tarpit.
|
||||
func WithoutNoop() Option {
|
||||
return func(c *Client) error {
|
||||
c.noNoop = true
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// TLSPolicy returns the currently set TLSPolicy as string
|
||||
func (c *Client) TLSPolicy() string {
|
||||
return c.tlspolicy.String()
|
||||
|
@ -517,9 +529,13 @@ func (c *Client) checkConn() error {
|
|||
if c.co == nil {
|
||||
return ErrNoActiveConnection
|
||||
}
|
||||
if err := c.sc.Noop(); err != nil {
|
||||
return ErrNoActiveConnection
|
||||
|
||||
if !c.noNoop {
|
||||
if err := c.sc.Noop(); err != nil {
|
||||
return ErrNoActiveConnection
|
||||
}
|
||||
}
|
||||
|
||||
if err := c.co.SetDeadline(time.Now().Add(c.cto)); err != nil {
|
||||
return ErrDeadlineExtendFailed
|
||||
}
|
||||
|
|
|
@ -103,6 +103,8 @@ func TestNewClientWithOptions(t *testing.T) {
|
|||
{"WithDSNMailReturnType() wrong option", WithDSNMailReturnType("FAIL"), true},
|
||||
{"WithDSNRcptNotifyType()", WithDSNRcptNotifyType(DSNRcptNotifySuccess), false},
|
||||
{"WithDSNRcptNotifyType() wrong option", WithDSNRcptNotifyType("FAIL"), true},
|
||||
{"WithoutNoop()", WithoutNoop(), false},
|
||||
|
||||
{
|
||||
"WithDSNRcptNotifyType() NEVER combination",
|
||||
WithDSNRcptNotifyType(DSNRcptNotifySuccess, DSNRcptNotifyNever), true,
|
||||
|
@ -461,6 +463,27 @@ func TestWithDSNRcptNotifyType(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestWithoutNoop tests the WithoutNoop method for the Client object
|
||||
func TestWithoutNoop(t *testing.T) {
|
||||
c, err := NewClient(DefaultHost, WithoutNoop())
|
||||
if err != nil {
|
||||
t.Errorf("failed to create new client: %s", err)
|
||||
return
|
||||
}
|
||||
if !c.noNoop {
|
||||
t.Errorf("WithoutNoop failed. c.noNoop expected to be: %t, got: %t", true, c.noNoop)
|
||||
}
|
||||
|
||||
c, err = NewClient(DefaultHost)
|
||||
if err != nil {
|
||||
t.Errorf("failed to create new client: %s", err)
|
||||
return
|
||||
}
|
||||
if c.noNoop {
|
||||
t.Errorf("WithoutNoop failed. c.noNoop expected to be: %t, got: %t", false, c.noNoop)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSetSMTPAuthCustom tests the SetSMTPAuthCustom method for the Client object
|
||||
func TestSetSMTPAuthCustom(t *testing.T) {
|
||||
tests := []struct {
|
||||
|
|
Loading…
Reference in a new issue