iBet uBet web content aggregator. Adding the entire web to your favor.
iBet uBet web content aggregator. Adding the entire web to your favor.



Link to original content: http://github.com/go-mail/mail/pull/62
Make encodeHeader return a new array by Emile-Filteau · Pull Request #62 · go-mail/mail · GitHub
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{"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 Emile-Filteau force-pushed the return_new_encoded_header_array branch from 8a0fb54 to 8f3f176 Compare November 1, 2019 17:36
@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 Emile-Filteau force-pushed the return_new_encoded_header_array branch from 2482a33 to 7d16daf Compare November 4, 2019 15:24
@Emile-Filteau Emile-Filteau force-pushed the return_new_encoded_header_array branch from 7d16daf to feff2ea Compare November 4, 2019 15:31
@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