Repository: emersion/go-smtp
Pull request #145 (2021-07-15 11:12:10)

Change smtp.MailOptions to a pointer
Pass a pointer instead of the struct copy.
Will require a corresponding change in https://github.com/emersion/go-smtp-proxy

kayrus: I'm also thinking of parsing the from and rcpt emails via https://pkg.go.dev/net/mail#ParseAddress and return an error, if parsing is failed. Therefore we can pass a `*mail.Address` pointer to `Mail` and `Rcpt` methods instead of the strings.
foxcpp: > 
> 
> I'm also thinking of parsing the from and rcpt emails via https://pkg.go.dev/net/mail#ParseAddress and return an error, if parsing is failed. Therefore we can pass a `*mail.Address` pointer to `Mail` and `Rcpt` methods instead of the strings.

NACK, mail.Address is for RFC 5322 header values, not SMTP envelope. What mail.Address represents and what mail.ParseAddress would accept is invalid for SMTP.
foxcpp: Wondering why this is not merged yet. Since we are breaking stuff all around we can probably merge this too.
@kayrus, can you rebase your PR on master?
emersion: Acked-by me
kayrus: rebased

Patch:
diff --git a/backend.go b/backend.go
index e4de6af..9885d8e 100644
--- a/backend.go
+++ b/backend.go
@@ -72,7 +72,7 @@ type Session interface {
 	AuthPlain(username, password string) error
 
 	// Set return path for currently processed message.
-	Mail(from string, opts MailOptions) error
+	Mail(from string, opts *MailOptions) error
 	// Add recipient for currently processed message.
 	Rcpt(to string) error
 	// Set currently processed message contents and send it.
diff --git a/backendutil/transform.go b/backendutil/transform.go
index 55a7da2..aae0ab8 100755
--- a/backendutil/transform.go
+++ b/backendutil/transform.go
@@ -37,7 +37,7 @@ func (s *transformSession) AuthPlain(username, password string) error {
 	return s.Session.AuthPlain(username, password)
 }
 
-func (s *transformSession) Mail(from string, opts smtp.MailOptions) error {
+func (s *transformSession) Mail(from string, opts *smtp.MailOptions) error {
 	if s.be.TransformMail != nil {
 		var err error
 		from, err = s.be.TransformMail(from)
diff --git a/cmd/smtp-debug-server/main.go b/cmd/smtp-debug-server/main.go
index 8c4c65b..38d0a90 100644
--- a/cmd/smtp-debug-server/main.go
+++ b/cmd/smtp-debug-server/main.go
@@ -27,7 +27,7 @@ func (s *session) AuthPlain(username, password string) error {
 	return nil
 }
 
-func (s *session) Mail(from string, opts smtp.MailOptions) error {
+func (s *session) Mail(from string, opts *smtp.MailOptions) error {
 	return nil
 }
 
diff --git a/conn.go b/conn.go
index 526c3c3..ff497d3 100644
--- a/conn.go
+++ b/conn.go
@@ -321,7 +321,7 @@ func (c *Conn) handleMail(arg string) {
 	}
 	from = strings.Trim(from, "<>")
 
-	opts := MailOptions{}
+	opts := &MailOptions{}
 
 	c.binarymime = false
 	// This is where the Conn may put BODY=8BITMIME, but we already


Test patch:
diff --git a/backendutil/transform_test.go b/backendutil/transform_test.go
index 5a85865..471bfc1 100755
--- a/backendutil/transform_test.go
+++ b/backendutil/transform_test.go
@@ -56,7 +56,7 @@ func (s *session) AuthPlain(username, password string) error {
 	return nil
 }
 
-func (s *session) Mail(from string, opts smtp.MailOptions) error {
+func (s *session) Mail(from string, opts *smtp.MailOptions) error {
 	if s.backend.userErr != nil {
 		return s.backend.userErr
 	}
diff --git a/example_test.go b/example_test.go
index 65a829b..89d09f8 100644
--- a/example_test.go
+++ b/example_test.go
@@ -108,7 +108,7 @@ func (s *Session) AuthPlain(username, password string) error {
 	return nil
 }
 
-func (s *Session) Mail(from string, opts smtp.MailOptions) error {
+func (s *Session) Mail(from string, opts *smtp.MailOptions) error {
 	log.Println("Mail from:", from)
 	return nil
 }
diff --git a/server_test.go b/server_test.go
index 09a0e22..48cdb12 100644
--- a/server_test.go
+++ b/server_test.go
@@ -17,7 +17,7 @@ type message struct {
 	From string
 	To   []string
 	Data []byte
-	Opts smtp.MailOptions
+	Opts *smtp.MailOptions
 }
 
 type backend struct {
@@ -79,7 +79,7 @@ func (s *session) Logout() error {
 	return nil
 }
 
-func (s *session) Mail(from string, opts smtp.MailOptions) error {
+func (s *session) Mail(from string, opts *smtp.MailOptions) error {
 	if s.backend.userErr != nil {
 		return s.backend.userErr
 	}