mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 13:50:49 +01:00
Refactor variable names in SMTP client code
Improved variable names in the SMTP client code to make them more expressive and descriptive. Also corrected several code comments to enhance clarity. These changes are intended to increase code readability and maintainability and have been implemented throughout the client_119.go and client.go files for consistency in naming conventions.
This commit is contained in:
parent
e1098091c3
commit
f18335fa1d
1 changed files with 17 additions and 17 deletions
34
client.go
34
client.go
|
@ -649,18 +649,18 @@ func (c *Client) Reset() error {
|
||||||
|
|
||||||
// DialAndSend establishes a connection to the SMTP server with a
|
// DialAndSend establishes a connection to the SMTP server with a
|
||||||
// default context.Background and sends the mail
|
// default context.Background and sends the mail
|
||||||
func (c *Client) DialAndSend(ml ...*Msg) error {
|
func (c *Client) DialAndSend(messages ...*Msg) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
return c.DialAndSendWithContext(ctx, ml...)
|
return c.DialAndSendWithContext(ctx, messages...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialAndSendWithContext establishes a connection to the SMTP server with a
|
// DialAndSendWithContext establishes a connection to the SMTP server with a
|
||||||
// custom context and sends the mail
|
// custom context and sends the mail
|
||||||
func (c *Client) DialAndSendWithContext(ctx context.Context, ml ...*Msg) error {
|
func (c *Client) DialAndSendWithContext(ctx context.Context, messages ...*Msg) error {
|
||||||
if err := c.DialWithContext(ctx); err != nil {
|
if err := c.DialWithContext(ctx); err != nil {
|
||||||
return fmt.Errorf("dial failed: %w", err)
|
return fmt.Errorf("dial failed: %w", err)
|
||||||
}
|
}
|
||||||
if err := c.Send(ml...); err != nil {
|
if err := c.Send(messages...); err != nil {
|
||||||
return fmt.Errorf("send failed: %w", err)
|
return fmt.Errorf("send failed: %w", err)
|
||||||
}
|
}
|
||||||
if err := c.Close(); err != nil {
|
if err := c.Close(); err != nil {
|
||||||
|
@ -700,21 +700,21 @@ func (c *Client) tls() error {
|
||||||
return ErrNoActiveConnection
|
return ErrNoActiveConnection
|
||||||
}
|
}
|
||||||
if !c.useSSL && c.tlspolicy != NoTLS {
|
if !c.useSSL && c.tlspolicy != NoTLS {
|
||||||
est := false
|
hasStartTLS := false
|
||||||
st, _ := c.smtpClient.Extension("STARTTLS")
|
extension, _ := c.smtpClient.Extension("STARTTLS")
|
||||||
if c.tlspolicy == TLSMandatory {
|
if c.tlspolicy == TLSMandatory {
|
||||||
est = true
|
hasStartTLS = true
|
||||||
if !st {
|
if !extension {
|
||||||
return fmt.Errorf("STARTTLS mode set to: %q, but target host does not support STARTTLS",
|
return fmt.Errorf("STARTTLS mode set to: %q, but target host does not support STARTTLS",
|
||||||
c.tlspolicy)
|
c.tlspolicy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.tlspolicy == TLSOpportunistic {
|
if c.tlspolicy == TLSOpportunistic {
|
||||||
if st {
|
if extension {
|
||||||
est = true
|
hasStartTLS = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if est {
|
if hasStartTLS {
|
||||||
if err := c.smtpClient.StartTLS(c.tlsconfig); err != nil {
|
if err := c.smtpClient.StartTLS(c.tlsconfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -730,29 +730,29 @@ func (c *Client) auth() error {
|
||||||
return fmt.Errorf("failed to authenticate: %w", err)
|
return fmt.Errorf("failed to authenticate: %w", err)
|
||||||
}
|
}
|
||||||
if c.smtpAuth == nil && c.smtpAuthType != "" {
|
if c.smtpAuth == nil && c.smtpAuthType != "" {
|
||||||
sa, sat := c.smtpClient.Extension("AUTH")
|
hasSMTPAuth, smtpAuthType := c.smtpClient.Extension("AUTH")
|
||||||
if !sa {
|
if !hasSMTPAuth {
|
||||||
return fmt.Errorf("server does not support SMTP AUTH")
|
return fmt.Errorf("server does not support SMTP AUTH")
|
||||||
}
|
}
|
||||||
|
|
||||||
switch c.smtpAuthType {
|
switch c.smtpAuthType {
|
||||||
case SMTPAuthPlain:
|
case SMTPAuthPlain:
|
||||||
if !strings.Contains(sat, string(SMTPAuthPlain)) {
|
if !strings.Contains(smtpAuthType, string(SMTPAuthPlain)) {
|
||||||
return ErrPlainAuthNotSupported
|
return ErrPlainAuthNotSupported
|
||||||
}
|
}
|
||||||
c.smtpAuth = smtp.PlainAuth("", c.user, c.pass, c.host)
|
c.smtpAuth = smtp.PlainAuth("", c.user, c.pass, c.host)
|
||||||
case SMTPAuthLogin:
|
case SMTPAuthLogin:
|
||||||
if !strings.Contains(sat, string(SMTPAuthLogin)) {
|
if !strings.Contains(smtpAuthType, string(SMTPAuthLogin)) {
|
||||||
return ErrLoginAuthNotSupported
|
return ErrLoginAuthNotSupported
|
||||||
}
|
}
|
||||||
c.smtpAuth = smtp.LoginAuth(c.user, c.pass, c.host)
|
c.smtpAuth = smtp.LoginAuth(c.user, c.pass, c.host)
|
||||||
case SMTPAuthCramMD5:
|
case SMTPAuthCramMD5:
|
||||||
if !strings.Contains(sat, string(SMTPAuthCramMD5)) {
|
if !strings.Contains(smtpAuthType, string(SMTPAuthCramMD5)) {
|
||||||
return ErrCramMD5AuthNotSupported
|
return ErrCramMD5AuthNotSupported
|
||||||
}
|
}
|
||||||
c.smtpAuth = smtp.CRAMMD5Auth(c.user, c.pass)
|
c.smtpAuth = smtp.CRAMMD5Auth(c.user, c.pass)
|
||||||
case SMTPAuthXOAUTH2:
|
case SMTPAuthXOAUTH2:
|
||||||
if !strings.Contains(sat, string(SMTPAuthXOAUTH2)) {
|
if !strings.Contains(smtpAuthType, string(SMTPAuthXOAUTH2)) {
|
||||||
return ErrXOauth2AuthNotSupported
|
return ErrXOauth2AuthNotSupported
|
||||||
}
|
}
|
||||||
c.smtpAuth = smtp.XOAuth2Auth(c.user, c.pass)
|
c.smtpAuth = smtp.XOAuth2Auth(c.user, c.pass)
|
||||||
|
|
Loading…
Reference in a new issue