diff --git a/lib/griddler/mailgun/adapter.rb b/lib/griddler/mailgun/adapter.rb index de98a25..7e54936 100644 --- a/lib/griddler/mailgun/adapter.rb +++ b/lib/griddler/mailgun/adapter.rb @@ -4,7 +4,7 @@ class Adapter attr_reader :params def initialize(params) - @params = params + @params = params.transform_keys(&:downcase) end def self.normalize_params(params) @@ -16,7 +16,7 @@ def normalize_params { to: to_recipients, cc: cc_recipients, - bcc: Array.wrap(param_or_header(:Bcc)), + bcc: Array.wrap(param_or_header(:bcc)), from: determine_sender, subject: params[:subject], text: params['body-plain'], @@ -34,23 +34,23 @@ def normalize_params private def determine_sender - sender = param_or_header(:From) + sender = param_or_header(:from) sender ||= params[:sender] end def to_recipients - to_emails = param_or_header(:To) + to_emails = param_or_header(:to) to_emails ||= params[:recipient] to_emails.split(',').map(&:strip) end def cc_recipients - cc = param_or_header(:Cc) || '' + cc = param_or_header(:cc) || "" cc.split(',').map(&:strip) end def headers - @headers ||= extract_headers + @headers ||= extract_headers.transform_keys(&:downcase) end def extract_headers diff --git a/spec/griddler/mailgun/adapter_spec.rb b/spec/griddler/mailgun/adapter_spec.rb index bf78fb9..57d188b 100644 --- a/spec/griddler/mailgun/adapter_spec.rb +++ b/spec/griddler/mailgun/adapter_spec.rb @@ -78,6 +78,14 @@ expect(normalized_params[:to]).to eq ['johndoe@example.com'] end + it "handles downcased params" do + downcased = { + to: "John Doe " + } + normalized_params = Griddler::Mailgun::Adapter.normalize_params(downcased) + expect(normalized_params[:to]).to eq ["John Doe "] + end + it 'handles message-headers' do params = default_params.merge( 'message-headers' => '[["NotCc", "emily@example.mailgun.org"], ["Reply-To", "mail2@example.mailgun.org"]]' @@ -174,7 +182,6 @@ def default_params "To"=>"John Doe , Jane Doe ", "body-html"=>"
And attachments. Two of them. An image and a text file.
\r\n", "body-plain"=>"And attachments. Two of them. An image and a text file.\r\n", - "from"=>"Jon Snow ", "recipient"=>"johndoe@example.com", "sender"=>"jon@example.com", "stripped-html"=>"
And attachments. Two of them. An image and a text file.
\r\n",