mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-24 22:50:49 +01:00
Refactor variable names in client_119.go
Updated variable names in the client_119.go file to enhance readability and clarity. This observes best practices for naming conventions in Go, producing cleaner code that's easier to maintain and troubleshoot. Changes primarily consist of replacing abbreviations with full descriptive names.
This commit is contained in:
parent
21d7b367bd
commit
d85c12220a
1 changed files with 62 additions and 62 deletions
124
client_119.go
124
client_119.go
|
@ -10,33 +10,33 @@ package mail
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
// Send sends out the mail message
|
// Send sends out the mail message
|
||||||
func (c *Client) Send(ml ...*Msg) error {
|
func (c *Client) Send(messages ...*Msg) error {
|
||||||
if cerr := c.checkConn(); cerr != nil {
|
if cerr := c.checkConn(); cerr != nil {
|
||||||
return &SendError{Reason: ErrConnCheck, errlist: []error{cerr}, isTemp: isTempError(cerr)}
|
return &SendError{Reason: ErrConnCheck, errlist: []error{cerr}, isTemp: isTempError(cerr)}
|
||||||
}
|
}
|
||||||
var errs []*SendError
|
var errs []*SendError
|
||||||
for _, m := range ml {
|
for _, message := range messages {
|
||||||
m.sendError = nil
|
message.sendError = nil
|
||||||
if m.encoding == NoEncoding {
|
if message.encoding == NoEncoding {
|
||||||
if ok, _ := c.smtpClient.Extension("8BITMIME"); !ok {
|
if ok, _ := c.smtpClient.Extension("8BITMIME"); !ok {
|
||||||
se := &SendError{Reason: ErrNoUnencoded, isTemp: false}
|
sendErr := &SendError{Reason: ErrNoUnencoded, isTemp: false}
|
||||||
m.sendError = se
|
message.sendError = sendErr
|
||||||
errs = append(errs, se)
|
errs = append(errs, sendErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f, err := m.GetSender(false)
|
from, err := message.GetSender(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
se := &SendError{Reason: ErrGetSender, errlist: []error{err}, isTemp: isTempError(err)}
|
sendErr := &SendError{Reason: ErrGetSender, errlist: []error{err}, isTemp: isTempError(err)}
|
||||||
m.sendError = se
|
message.sendError = sendErr
|
||||||
errs = append(errs, se)
|
errs = append(errs, sendErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rl, err := m.GetRecipients()
|
rcpts, err := message.GetRecipients()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
se := &SendError{Reason: ErrGetRcpts, errlist: []error{err}, isTemp: isTempError(err)}
|
sendErr := &SendError{Reason: ErrGetRcpts, errlist: []error{err}, isTemp: isTempError(err)}
|
||||||
m.sendError = se
|
message.sendError = sendErr
|
||||||
errs = append(errs, se)
|
errs = append(errs, sendErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,88 +45,88 @@ func (c *Client) Send(ml ...*Msg) error {
|
||||||
c.smtpClient.SetDSNMailReturnOption(string(c.dsnmrtype))
|
c.smtpClient.SetDSNMailReturnOption(string(c.dsnmrtype))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := c.smtpClient.Mail(f); err != nil {
|
if err = c.smtpClient.Mail(from); err != nil {
|
||||||
se := &SendError{Reason: ErrSMTPMailFrom, errlist: []error{err}, isTemp: isTempError(err)}
|
sendErr := &SendError{Reason: ErrSMTPMailFrom, errlist: []error{err}, isTemp: isTempError(err)}
|
||||||
if reserr := c.smtpClient.Reset(); reserr != nil {
|
if resetSendErr := c.smtpClient.Reset(); resetSendErr != nil {
|
||||||
se.errlist = append(se.errlist, reserr)
|
sendErr.errlist = append(sendErr.errlist, resetSendErr)
|
||||||
}
|
}
|
||||||
m.sendError = se
|
message.sendError = sendErr
|
||||||
errs = append(errs, se)
|
errs = append(errs, sendErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
failed := false
|
failed := false
|
||||||
rse := &SendError{}
|
rcptSendErr := &SendError{}
|
||||||
rse.errlist = make([]error, 0)
|
rcptSendErr.errlist = make([]error, 0)
|
||||||
rse.rcpt = make([]string, 0)
|
rcptSendErr.rcpt = make([]string, 0)
|
||||||
rno := strings.Join(c.dsnrntype, ",")
|
rcptNotifyOpt := strings.Join(c.dsnrntype, ",")
|
||||||
c.smtpClient.SetDSNRcptNotifyOption(rno)
|
c.smtpClient.SetDSNRcptNotifyOption(rcptNotifyOpt)
|
||||||
for _, r := range rl {
|
for _, rcpt := range rcpts {
|
||||||
if err := c.smtpClient.Rcpt(r); err != nil {
|
if err = c.smtpClient.Rcpt(rcpt); err != nil {
|
||||||
rse.Reason = ErrSMTPRcptTo
|
rcptSendErr.Reason = ErrSMTPRcptTo
|
||||||
rse.errlist = append(rse.errlist, err)
|
rcptSendErr.errlist = append(rcptSendErr.errlist, err)
|
||||||
rse.rcpt = append(rse.rcpt, r)
|
rcptSendErr.rcpt = append(rcptSendErr.rcpt, rcpt)
|
||||||
rse.isTemp = isTempError(err)
|
rcptSendErr.isTemp = isTempError(err)
|
||||||
failed = true
|
failed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if failed {
|
if failed {
|
||||||
if reserr := c.smtpClient.Reset(); reserr != nil {
|
if resetSendErr := c.smtpClient.Reset(); resetSendErr != nil {
|
||||||
rse.errlist = append(rse.errlist, err)
|
rcptSendErr.errlist = append(rcptSendErr.errlist, err)
|
||||||
}
|
}
|
||||||
m.sendError = rse
|
message.sendError = rcptSendErr
|
||||||
errs = append(errs, rse)
|
errs = append(errs, rcptSendErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w, err := c.smtpClient.Data()
|
writer, err := c.smtpClient.Data()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
se := &SendError{Reason: ErrSMTPData, errlist: []error{err}, isTemp: isTempError(err)}
|
sendErr := &SendError{Reason: ErrSMTPData, errlist: []error{err}, isTemp: isTempError(err)}
|
||||||
m.sendError = se
|
message.sendError = sendErr
|
||||||
errs = append(errs, se)
|
errs = append(errs, sendErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
_, err = m.WriteTo(w)
|
_, err = message.WriteTo(writer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
se := &SendError{Reason: ErrWriteContent, errlist: []error{err}, isTemp: isTempError(err)}
|
sendErr := &SendError{Reason: ErrWriteContent, errlist: []error{err}, isTemp: isTempError(err)}
|
||||||
m.sendError = se
|
message.sendError = sendErr
|
||||||
errs = append(errs, se)
|
errs = append(errs, sendErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
m.isDelivered = true
|
message.isDelivered = true
|
||||||
|
|
||||||
if err := w.Close(); err != nil {
|
if err = writer.Close(); err != nil {
|
||||||
se := &SendError{Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err)}
|
sendErr := &SendError{Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err)}
|
||||||
m.sendError = se
|
message.sendError = sendErr
|
||||||
errs = append(errs, se)
|
errs = append(errs, sendErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.Reset(); err != nil {
|
if err = c.Reset(); err != nil {
|
||||||
se := &SendError{Reason: ErrSMTPReset, errlist: []error{err}, isTemp: isTempError(err)}
|
sendErr := &SendError{Reason: ErrSMTPReset, errlist: []error{err}, isTemp: isTempError(err)}
|
||||||
m.sendError = se
|
message.sendError = sendErr
|
||||||
errs = append(errs, se)
|
errs = append(errs, sendErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := c.checkConn(); err != nil {
|
if err = c.checkConn(); err != nil {
|
||||||
se := &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)}
|
sendErr := &SendError{Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err)}
|
||||||
m.sendError = se
|
message.sendError = sendErr
|
||||||
errs = append(errs, se)
|
errs = append(errs, sendErr)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
if len(errs) > 1 {
|
if len(errs) > 1 {
|
||||||
re := &SendError{Reason: ErrAmbiguous}
|
returnErr := &SendError{Reason: ErrAmbiguous}
|
||||||
for i := range errs {
|
for i := range errs {
|
||||||
re.errlist = append(re.errlist, errs[i].errlist...)
|
returnErr.errlist = append(returnErr.errlist, errs[i].errlist...)
|
||||||
re.rcpt = append(re.rcpt, errs[i].rcpt...)
|
returnErr.rcpt = append(returnErr.rcpt, errs[i].rcpt...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We assume that the isTemp flag from the last error we received should be the
|
// We assume that the isTemp flag from the last error we received should be the
|
||||||
// indicator for the returned isTemp flag as well
|
// indicator for the returned isTemp flag as well
|
||||||
re.isTemp = errs[len(errs)-1].isTemp
|
returnErr.isTemp = errs[len(errs)-1].isTemp
|
||||||
|
|
||||||
return re
|
return returnErr
|
||||||
}
|
}
|
||||||
return errs[0]
|
return errs[0]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue