diff --git a/client_119.go b/client_119.go deleted file mode 100644 index 8b2e35a..0000000 --- a/client_119.go +++ /dev/null @@ -1,79 +0,0 @@ -// SPDX-FileCopyrightText: The go-mail Authors -// -// SPDX-License-Identifier: MIT - -//go:build !go1.20 -// +build !go1.20 - -package mail - -import ( - "errors" - - "github.com/wneessen/go-mail/smtp" -) - -// SendWithSMTPClient attempts to send one or more Msg using a provided smtp.Client with an -// established connection to the SMTP server. If the smtp.Client has no active connection to -// the server, SendWithSMTPClient will fail with an error. For each of the provided Msg, it -// will associate a SendError with the Msg in case of a transmission or delivery error. -// -// This method first checks for an active connection to the SMTP server. If the connection is -// not valid, it returns a SendError. It then iterates over the provided messages, attempting -// to send each one. If an error occurs during sending, the method records the error and -// associates it with the corresponding Msg. If multiple errors are encountered, it aggregates -// them into a single SendError to be returned. -// -// Parameters: -// - client: A pointer to the smtp.Client that holds the connection to the SMTP server -// - messages: A variadic list of pointers to Msg objects to be sent. -// -// Returns: -// - An error that represents the sending result, which may include multiple SendErrors if -// any occurred; otherwise, returns nil. -func (c *Client) SendWithSMTPClient(client *smtp.Client, messages ...*Msg) error { - escSupport := false - if client != nil { - escSupport, _ = client.Extension("ENHANCEDSTATUSCODES") - } - if err := c.checkConn(client); err != nil { - return &SendError{ - Reason: ErrConnCheck, errlist: []error{err}, isTemp: isTempError(err), - errcode: errorCode(err), enhancedStatusCode: enhancedStatusCode(err, escSupport), - } - } - var errs []*SendError - for id, message := range messages { - if message == nil { - continue - } - if sendErr := c.sendSingleMsg(client, message); sendErr != nil { - messages[id].sendError = sendErr - - var msgSendErr *SendError - if errors.As(sendErr, &msgSendErr) { - errs = append(errs, msgSendErr) - } - } - } - - if len(errs) > 0 { - if len(errs) > 1 { - returnErr := &SendError{Reason: ErrAmbiguous} - for i := range errs { - returnErr.errlist = append(returnErr.errlist, errs[i].errlist...) - returnErr.rcpt = append(returnErr.rcpt, errs[i].rcpt...) - } - - // We assume that the error codes and flags from the last error we received should be the - // indicator for the returned isTemp flag as well - returnErr.isTemp = errs[len(errs)-1].isTemp - returnErr.errcode = errs[len(errs)-1].errcode - returnErr.enhancedStatusCode = errs[len(errs)-1].enhancedStatusCode - - return returnErr - } - return errs[0] - } - return nil -} diff --git a/go.mod b/go.mod index 5707e58..f098250 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,6 @@ module github.com/wneessen/go-mail -go 1.16 +go 1.20 require golang.org/x/text v0.22.0 diff --git a/go.sum b/go.sum index 27dd6ca..a81672a 100644 --- a/go.sum +++ b/go.sum @@ -1,62 +1,2 @@ -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/msg_totmpfile.go b/msg_totmpfile.go index e178414..a56b0ef 100644 --- a/msg_totmpfile.go +++ b/msg_totmpfile.go @@ -2,9 +2,6 @@ // // SPDX-License-Identifier: MIT -//go:build go1.17 -// +build go1.17 - package mail import ( diff --git a/msg_totmpfile_116.go b/msg_totmpfile_116.go deleted file mode 100644 index 84717bf..0000000 --- a/msg_totmpfile_116.go +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-FileCopyrightText: The go-mail Authors -// -// SPDX-License-Identifier: MIT - -//go:build !go1.17 -// +build !go1.17 - -package mail - -import ( - "fmt" - "io/ioutil" -) - -// WriteToTempFile creates a temporary file and writes the Msg content to this file. -// -// This method generates a temporary file with a ".eml" extension, writes the Msg to it, and returns the -// filename of the created temporary file. -// -// Returns: -// - A string representing the filename of the temporary file. -// - An error if the file creation or writing process fails. -func (m *Msg) WriteToTempFile() (string, error) { - f, err := ioutil.TempFile("", "go-mail_*.eml") - if err != nil { - return "", fmt.Errorf("failed to create output file: %w", err) - } - defer func() { _ = f.Close() }() - return f.Name(), m.WriteToFile(f.Name()) -} diff --git a/smtp/auth_cram_md5.go b/smtp/auth_cram_md5.go index 3b49374..c0bd250 100644 --- a/smtp/auth_cram_md5.go +++ b/smtp/auth_cram_md5.go @@ -11,9 +11,6 @@ // // SPDX-License-Identifier: BSD-3-Clause AND MIT -//go:build go1.19 -// +build go1.19 - package smtp import ( diff --git a/smtp/auth_cram_md5_118.go b/smtp/auth_cram_md5_118.go deleted file mode 100644 index 17cb2b6..0000000 --- a/smtp/auth_cram_md5_118.go +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2010 The Go Authors. All rights reserved. -// SPDX-FileCopyrightText: Copyright (c) The go-mail Authors -// -// Original net/smtp code from the Go stdlib by the Go Authors. -// Use of this source code is governed by a BSD-style -// LICENSE file that can be found in this directory. -// -// go-mail specific modifications by the go-mail Authors. -// Licensed under the MIT License. -// See [PROJECT ROOT]/LICENSES directory for more information. -// -// SPDX-License-Identifier: BSD-3-Clause AND MIT - -//go:build !go1.19 -// +build !go1.19 - -package smtp - -import ( - "crypto/hmac" - "crypto/md5" - "fmt" -) - -// cramMD5Auth is the type that satisfies the Auth interface for the "SMTP CRAM_MD5" auth -type cramMD5Auth struct { - username, secret string -} - -// CRAMMD5Auth returns an [Auth] that implements the CRAM-MD5 authentication -// mechanism as defined in RFC 2195. -// The returned Auth uses the given username and secret to authenticate -// to the server using the challenge-response mechanism. -func CRAMMD5Auth(username, secret string) Auth { - return &cramMD5Auth{username, secret} -} - -func (a *cramMD5Auth) Start(_ *ServerInfo) (string, []byte, error) { - return "CRAM-MD5", nil, nil -} - -// Backport of: https://github.com/golang/go/commit/58158e990f272774e615c9abd8662bf0198c29aa#diff-772fc9f5d0c86f26e35158fb3e7a71a4967d18b4ec23a5dbb60781ab0babf426 -// to guarantee backwards compatibility with Go 1.16-1.18 -func (a *cramMD5Auth) Next(fromServer []byte, more bool) ([]byte, error) { - if more { - d := hmac.New(md5.New, []byte(a.secret)) - d.Write(fromServer) - s := make([]byte, 0, d.Size()) - return []byte(fmt.Sprintf("%s %x", a.username, d.Sum(s))), nil - } - return nil, nil -} diff --git a/smtp/smtp_ehlo.go b/smtp/smtp_ehlo.go index 68192c0..1d029b3 100644 --- a/smtp/smtp_ehlo.go +++ b/smtp/smtp_ehlo.go @@ -11,9 +11,6 @@ // // SPDX-License-Identifier: BSD-3-Clause AND MIT -//go:build go1.18 -// +build go1.18 - package smtp import "strings" diff --git a/smtp/smtp_ehlo_117.go b/smtp/smtp_ehlo_117.go deleted file mode 100644 index f94683d..0000000 --- a/smtp/smtp_ehlo_117.go +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2010 The Go Authors. All rights reserved. -// SPDX-FileCopyrightText: Copyright (c) The go-mail Authors -// -// Original net/smtp code from the Go stdlib by the Go Authors. -// Use of this source code is governed by a BSD-style -// LICENSE file that can be found in this directory. -// -// go-mail specific modifications by the go-mail Authors. -// Licensed under the MIT License. -// See [PROJECT ROOT]/LICENSES directory for more information. -// -// SPDX-License-Identifier: BSD-3-Clause AND MIT - -//go:build !go1.18 -// +build !go1.18 - -package smtp - -import "strings" - -// ehlo sends the EHLO (extended hello) greeting to the server. It -// should be the preferred greeting for servers that support it. -// -// Backport of: https://github.com/golang/go/commit/4d8db00641cc9ff4f44de7df9b8c4f4a4f9416ee#diff-4f6f6bdb9891d4dd271f9f31430420a2e44018fe4ee539576faf458bebb3cee4 -// to guarantee backwards compatibility with Go 1.16/1.17 -func (c *Client) ehlo() error { - _, msg, err := c.cmd(250, "EHLO %s", c.localName) - if err != nil { - return err - } - - c.mutex.Lock() - defer c.mutex.Unlock() - ext := make(map[string]string) - extList := strings.Split(msg, "\n") - if len(extList) > 1 { - extList = extList[1:] - for _, line := range extList { - args := strings.SplitN(line, " ", 2) - if len(args) > 1 { - ext[args[0]] = args[1] - } else { - ext[args[0]] = "" - } - } - } - if mechs, ok := ext["AUTH"]; ok { - c.auth = strings.Split(mechs, " ") - } - c.ext = ext - return err -}