From aab04672f8c78fe782a7d9e52f8eeac78bbbc90b Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Fri, 4 Oct 2024 20:39:14 +0200 Subject: [PATCH] Rename DSN type variable for clarity Renamed the variable from `dsnrntype` to `dsnRcptNotifyType` to improve code readability and ensure clarity regarding its purpose. Also updated corresponding comments and test cases to reflect this change. --- client.go | 22 +++++++++++++--------- client_test.go | 18 +++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/client.go b/client.go index 48d36dd..45ccf0c 100644 --- a/client.go +++ b/client.go @@ -106,20 +106,24 @@ type ( // dialContextFunc is the DialContextFunc that is used by the Client to connect to the SMTP server. dialContextFunc DialContextFunc - // dsnReturnType defines the DSNMailReturnOption in case DSN is enabled - dsnReturnType DSNMailReturnOption + // dsnRcptNotifyType represents the different types of notifications for DSN (Delivery Status Notifications) + // receipts. + dsnRcptNotifyType []string - // dsnrntype defines the DSNRcptNotifyOption in case DSN is enabled - dsnrntype []string + // dsnReturnType specifies the type of Delivery Status Notification (DSN) that should be requested for an + // email. + dsnReturnType DSNMailReturnOption // fallbackPort is used as an alternative port number in case the primary port is unavailable or // fails to bind. + // + // The fallbackPort is only used in combination with SetTLSPortPolicy and SetSSLPort correspondingly. fallbackPort int - // HELO/EHLO string for the greeting the target SMTP server + // helo is the hostname used in the HELO/EHLO greeting, that is sent to the target SMTP server. helo string - // Hostname of the target SMTP server to connect to + // host is the hostname of the SMTP server we are connecting to. host string // isEncrypted indicates if a Client connection is encrypted or not @@ -399,7 +403,7 @@ func WithDSN() Option { return func(c *Client) error { c.requestDSN = true c.dsnReturnType = DSNMailReturnFull - c.dsnrntype = []string{string(DSNRcptNotifyFailure), string(DSNRcptNotifySuccess)} + c.dsnRcptNotifyType = []string{string(DSNRcptNotifyFailure), string(DSNRcptNotifySuccess)} return nil } } @@ -452,7 +456,7 @@ func WithDSNRcptNotifyType(opts ...DSNRcptNotifyOption) Option { } c.requestDSN = true - c.dsnrntype = rcptOpts + c.dsnRcptNotifyType = rcptOpts return nil } } @@ -892,7 +896,7 @@ func (c *Client) sendSingleMsg(message *Msg) error { rcptSendErr := &SendError{affectedMsg: message} rcptSendErr.errlist = make([]error, 0) rcptSendErr.rcpt = make([]string, 0) - rcptNotifyOpt := strings.Join(c.dsnrntype, ",") + rcptNotifyOpt := strings.Join(c.dsnRcptNotifyType, ",") c.smtpClient.SetDSNRcptNotifyOption(rcptNotifyOpt) for _, rcpt := range rcpts { if err = c.smtpClient.Rcpt(rcpt); err != nil { diff --git a/client_test.go b/client_test.go index 47ffab8..1539426 100644 --- a/client_test.go +++ b/client_test.go @@ -490,13 +490,13 @@ func TestWithDSN(t *testing.T) { t.Errorf("WithDSN failed. c.dsnReturnType expected to be: %s, got: %s", DSNMailReturnFull, c.dsnReturnType) } - if c.dsnrntype[0] != string(DSNRcptNotifyFailure) { - t.Errorf("WithDSN failed. c.dsnrntype[0] expected to be: %s, got: %s", DSNRcptNotifyFailure, - c.dsnrntype[0]) + if c.dsnRcptNotifyType[0] != string(DSNRcptNotifyFailure) { + t.Errorf("WithDSN failed. c.dsnRcptNotifyType[0] expected to be: %s, got: %s", DSNRcptNotifyFailure, + c.dsnRcptNotifyType[0]) } - if c.dsnrntype[1] != string(DSNRcptNotifySuccess) { - t.Errorf("WithDSN failed. c.dsnrntype[1] expected to be: %s, got: %s", DSNRcptNotifySuccess, - c.dsnrntype[1]) + if c.dsnRcptNotifyType[1] != string(DSNRcptNotifySuccess) { + t.Errorf("WithDSN failed. c.dsnRcptNotifyType[1] expected to be: %s, got: %s", DSNRcptNotifySuccess, + c.dsnRcptNotifyType[1]) } } @@ -547,11 +547,11 @@ func TestWithDSNRcptNotifyType(t *testing.T) { t.Errorf("failed to create new client: %s", err) return } - if len(c.dsnrntype) <= 0 && !tt.sf { + if len(c.dsnRcptNotifyType) <= 0 && !tt.sf { t.Errorf("WithDSNRcptNotifyType failed. Expected at least one DSNRNType but got none") } - if !tt.sf && c.dsnrntype[0] != tt.want { - t.Errorf("WithDSNRcptNotifyType failed. Expected %s, got: %s", tt.want, c.dsnrntype[0]) + if !tt.sf && c.dsnRcptNotifyType[0] != tt.want { + t.Errorf("WithDSNRcptNotifyType failed. Expected %s, got: %s", tt.want, c.dsnRcptNotifyType[0]) } }) }