griddler-mailgun
griddler-mailgun copied to clipboard
Multiple Received headers
I noticed an issue when email has multiple "Received" headers.
The extract_headers method
https://github.com/bradpauly/griddler-mailgun/blob/master/lib%2Fgriddler%2Fmailgun%2Fadapter.rb#L51
i.e. the line
parsed_headers.each{ |h| extracted_headers[h[0]] = h[1] }
overrides the "Received" header x times and return only the last one.
I could submit a PR, just need your opinion on this.
@janvarljen Thanks for pointing that out. Do you have a solution in mind? I'd have to look more closely at what Griddler is expecting from us to make sure it would work.
I think we have two solutions: concatenate strings or build an array. Both ways have pros and cons.
If we concatenate strings we can always expect the same data type -> String but we lose the ability to differentiate multiple headers (it gets mashed into one String).
If we build arrays we can differentiate multiple headers but the problem is how to decide which header should be an array and which not.
I prefer the array what and probably the best way to do it is:
- rfc2822 https://tools.ietf.org/html/rfc2822#section-3.6 defines number of times each field may occur in the header
- fields with max 1 -> Strings
- fields with unlimited max -> Arrays
I was using griddler-mandrill before switching to mailgun and header['Received'] was always an array (even with only one item). This way we can ensure compatibility between adapters (I had to rewrite my email_processor to make it work correctly)
Also I think we need a good readme section describing headers section.
This sounds like a good approach. I also agree that there should be better documentation about the headers. The way they are handled is a little confusing. Thanks for taking the time to make a clear proposal.