Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

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{"[email protected], "bob@example.com"}

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

mail.SendMail("myhost.com:25", nil, "[email protected]", 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant