Merge branch 'main' into feature/145_add-eml-parser-to-generate-msg-from-eml-files

This commit is contained in:
Winni Neessen 2024-01-25 11:21:38 +01:00
commit f7ba3a1d02
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D
5 changed files with 18 additions and 3 deletions

View file

@ -9,9 +9,9 @@ freebsd_task:
- name: FreeBSD 13.2 - name: FreeBSD 13.2
freebsd_instance: freebsd_instance:
image_family: freebsd-13-2 image_family: freebsd-13-2
- name: FreeBSD 12.4 - name: FreeBSD 14.0
freebsd_instance: freebsd_instance:
image_family: freebsd-12-4 image_family: freebsd-14-0
env: env:
TEST_ALLOW_SEND: 0 TEST_ALLOW_SEND: 0

View file

@ -91,6 +91,7 @@ func (c *Client) Send(ml ...*Msg) error {
errs = append(errs, se) errs = append(errs, se)
continue continue
} }
m.isDelivered = true
if err := w.Close(); err != nil { if err := w.Close(); err != nil {
se := &SendError{Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err)} se := &SendError{Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err)}

View file

@ -88,6 +88,7 @@ func (c *Client) Send(ml ...*Msg) (rerr error) {
rerr = errors.Join(rerr, m.sendError) rerr = errors.Join(rerr, m.sendError)
continue continue
} }
m.isDelivered = true
if err := w.Close(); err != nil { if err := w.Close(); err != nil {
m.sendError = &SendError{Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err)} m.sendError = &SendError{Reason: ErrSMTPDataClose, errlist: []error{err}, isTemp: isTempError(err)}

View file

@ -763,6 +763,9 @@ func TestClient_DialSendClose(t *testing.T) {
if err := c.Close(); err != nil { if err := c.Close(); err != nil {
t.Errorf("Close() failed: %s", err) t.Errorf("Close() failed: %s", err)
} }
if !m.IsDelivered() {
t.Errorf("message should be delivered but is indicated no to")
}
} }
// TestClient_DialAndSendWithContext tests the DialAndSendWithContext() method of Client // TestClient_DialAndSendWithContext tests the DialAndSendWithContext() method of Client
@ -1134,7 +1137,9 @@ func TestClient_DialAndSendWithContext_withSendError(t *testing.T) {
} }
if se.IsTemp() { if se.IsTemp() {
t.Errorf("expected permanent error but IsTemp() returned true") t.Errorf("expected permanent error but IsTemp() returned true")
return }
if m.IsDelivered() {
t.Errorf("message is indicated to be delivered but shouldn't")
} }
} }

8
msg.go
View file

@ -94,6 +94,9 @@ type Msg struct {
// genHeader is a slice of strings that the different generic mail Header fields // genHeader is a slice of strings that the different generic mail Header fields
genHeader map[Header][]string genHeader map[Header][]string
// isDelivered signals if a message has been delivered or not
isDelivered bool
// middlewares is the list of middlewares to apply to the Msg before sending in FIFO order // middlewares is the list of middlewares to apply to the Msg before sending in FIFO order
middlewares []Middleware middlewares []Middleware
@ -507,6 +510,11 @@ func (m *Msg) SetUserAgent(a string) {
m.SetGenHeader(HeaderXMailer, a) m.SetGenHeader(HeaderXMailer, a)
} }
// IsDelivered will return true if the Msg has been successfully delivered
func (m *Msg) IsDelivered() bool {
return m.isDelivered
}
// RequestMDNTo adds the Disposition-Notification-To header to request a MDN from the receiving end // RequestMDNTo adds the Disposition-Notification-To header to request a MDN from the receiving end
// as described in RFC8098. It allows to provide a list recipient addresses. // as described in RFC8098. It allows to provide a list recipient addresses.
// Address validation is performed // Address validation is performed