go-gomail / gomail

The best way to send emails in Go.
MIT License
4.32k stars 572 forks source link

Header Order #64

Open isaldana opened 8 years ago

isaldana commented 8 years ago

When constructing -> parsing -> re-constructing a message it is difficult to re-create the same message since message.WriteTo() iterates through a map and the order of headers is random. In some instances the order of the headers matters such as DKIM and Received headers. Would you be interested in a PR to support this? If so, I see it two ways:

1) Use a slice instead of a map (like attachments) to preserve order. Unfortunately, message.SetHeaders signature will change.

2) Change the type of header from map[string][]string to something like map[string]*hValue where hValue is something like:

type hValue struct {
    values []string
    order int
}

order increments each time a header gets added. Then message.WriteTo will sort headers by order when writing headers.

Let me know what you think, thanks.

namsral commented 7 years ago

I came here to suggest something similar as I'd like gomail to support deterministic messages.

wkhere commented 7 years ago

Yep, very good idea.

Cycl0pe commented 6 years ago

Awesome Idea!