Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make encodeHeader return a new array #62

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from

Conversation

Emile-Filteau
Copy link

Problem

Arrays in Go are mutable. This method currently replaces all values passed to SetHeader by their encoded version.

This can be problematic in a scenario that the array passed to SetHeader is reused somewhere else in the code.

Ex :

rcptTo := []string{"alice@example.com, "bob@example.com"}

message := gomail.NewMessage()
message.SetHeader("To", rcptTo)
// ...
var buffer bytes.Buffer
message.WriteTo(&buffer)

mail.SendMail("myhost.com:25", nil, "postmaster@example.com", rcptTo, buffer.Bytes())

In the above example, the recipients passed to SendMail will be encoded and result in a 501 5.1.3 Bad recipient address syntax from any postfix server.

In my opinion, the expected behaviour of SetHeader is not to mutate the values passed as arguments.

Solution

The proposed change creates a new array of string of the same length as the header values passed in and fill it with the encoded values, therefore not touching the raw ones.

@Emile-Filteau
Copy link
Author

Not clear why CI is failing for Go 1.2, could it be that gimme stopped supporting 1.2 ?

@Emile-Filteau
Copy link
Author

@ivy you seem to be the "most recent" contributor (i know it's been a while). Can you take a look at this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant