Compare commits

..

No commits in common. "e808e0b972ef61d243282e70cc10e16dfe4399fd" and "d7b32480fdeb0d2607c076c1e4e7399c178813c7" have entirely different histories.

4 changed files with 791 additions and 1984 deletions

View file

@ -1261,13 +1261,14 @@ func (c *Client) sendSingleMsg(message *Msg) error {
affectedMsg: message, affectedMsg: message,
} }
} }
message.isDelivered = true
if err = writer.Close(); err != nil { if err = writer.Close(); err != nil {
return &SendError{ return &SendError{
Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err), Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err),
affectedMsg: message, affectedMsg: message,
} }
} }
message.isDelivered = true
if err = c.Reset(); err != nil { if err = c.Reset(); err != nil {
return &SendError{ return &SendError{

View file

@ -3527,9 +3527,6 @@ func parseJSONLog(t *testing.T, buf *bytes.Buffer) logData {
func testMessage(t *testing.T) *Msg { func testMessage(t *testing.T) *Msg {
t.Helper() t.Helper()
message := NewMsg() message := NewMsg()
if message == nil {
t.Fatal("failed to create new message")
}
if err := message.From(TestSenderValid); err != nil { if err := message.From(TestSenderValid); err != nil {
t.Errorf("failed to set sender address: %s", err) t.Errorf("failed to set sender address: %s", err)
} }

40
msg.go
View file

@ -847,16 +847,7 @@ func (m *Msg) CcIgnoreInvalid(rcpts ...string) {
// References: // References:
// - https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.3 // - https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.3
func (m *Msg) CcFromString(rcpts string) error { func (m *Msg) CcFromString(rcpts string) error {
src := strings.Split(rcpts, ",") return m.Cc(strings.Split(rcpts, ",")...)
var dst []string
for _, address := range src {
address = strings.TrimSpace(address)
if address == "" {
continue
}
dst = append(dst, address)
}
return m.Cc(dst...)
} }
// Bcc sets one or more "BCC" (blind carbon copy) addresses in the mail body for the Msg. // Bcc sets one or more "BCC" (blind carbon copy) addresses in the mail body for the Msg.
@ -942,16 +933,7 @@ func (m *Msg) BccIgnoreInvalid(rcpts ...string) {
// References: // References:
// - https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.3 // - https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.3
func (m *Msg) BccFromString(rcpts string) error { func (m *Msg) BccFromString(rcpts string) error {
src := strings.Split(rcpts, ",") return m.Bcc(strings.Split(rcpts, ",")...)
var dst []string
for _, address := range src {
address = strings.TrimSpace(address)
if address == "" {
continue
}
dst = append(dst, address)
}
return m.Bcc(dst...)
} }
// ReplyTo sets the "Reply-To" address for the Msg, specifying where replies should be sent. // ReplyTo sets the "Reply-To" address for the Msg, specifying where replies should be sent.
@ -1087,7 +1069,8 @@ func (m *Msg) SetBulk() {
// - https://datatracker.ietf.org/doc/html/rfc5322#section-3.3 // - https://datatracker.ietf.org/doc/html/rfc5322#section-3.3
// - https://datatracker.ietf.org/doc/html/rfc1123 // - https://datatracker.ietf.org/doc/html/rfc1123
func (m *Msg) SetDate() { func (m *Msg) SetDate() {
m.SetDateWithValue(time.Now()) now := time.Now().Format(time.RFC1123Z)
m.SetGenHeader(HeaderDate, now)
} }
// SetDateWithValue sets the "Date" header for the Msg using the provided time value in a valid RFC 1123 format. // SetDateWithValue sets the "Date" header for the Msg using the provided time value in a valid RFC 1123 format.
@ -1187,9 +1170,6 @@ func (m *Msg) IsDelivered() bool {
// References: // References:
// - https://datatracker.ietf.org/doc/html/rfc8098 // - https://datatracker.ietf.org/doc/html/rfc8098
func (m *Msg) RequestMDNTo(rcpts ...string) error { func (m *Msg) RequestMDNTo(rcpts ...string) error {
if m.genHeader == nil {
m.genHeader = make(map[Header][]string)
}
var addresses []string var addresses []string
for _, addrVal := range rcpts { for _, addrVal := range rcpts {
address, err := mail.ParseAddress(addrVal) address, err := mail.ParseAddress(addrVal)
@ -1198,7 +1178,9 @@ func (m *Msg) RequestMDNTo(rcpts ...string) error {
} }
addresses = append(addresses, address.String()) addresses = append(addresses, address.String())
} }
m.genHeader[HeaderDispositionNotificationTo] = addresses if _, ok := m.genHeader[HeaderDispositionNotificationTo]; ok {
m.genHeader[HeaderDispositionNotificationTo] = addresses
}
return nil return nil
} }
@ -1237,11 +1219,11 @@ func (m *Msg) RequestMDNAddTo(rcpt string) error {
return fmt.Errorf(errParseMailAddr, rcpt, err) return fmt.Errorf(errParseMailAddr, rcpt, err)
} }
var addresses []string var addresses []string
if current, ok := m.genHeader[HeaderDispositionNotificationTo]; ok { addresses = append(addresses, m.genHeader[HeaderDispositionNotificationTo]...)
addresses = current
}
addresses = append(addresses, address.String()) addresses = append(addresses, address.String())
m.genHeader[HeaderDispositionNotificationTo] = addresses if _, ok := m.genHeader[HeaderDispositionNotificationTo]; ok {
m.genHeader[HeaderDispositionNotificationTo] = addresses
}
return nil return nil
} }

File diff suppressed because it is too large Load diff