Skip to content

Commit

Permalink
Merge pull request #88 from james-d-elliott/feat-without-noop
Browse files Browse the repository at this point in the history
feat: without noop option
  • Loading branch information
wneessen committed Dec 26, 2022
2 parents e7b162a + 567276d commit f454ae8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
20 changes: 18 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
23 changes: 23 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f454ae8

Please sign in to comment.