Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/griddler/mailgun/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'],
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion spec/griddler/mailgun/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
expect(normalized_params[:to]).to eq ['johndoe@example.com']
end

it "handles downcased params" do
downcased = {
to: "John Doe <johndoe@example.com>"
}
normalized_params = Griddler::Mailgun::Adapter.normalize_params(downcased)
expect(normalized_params[:to]).to eq ["John Doe <johndoe@example.com>"]
end

it 'handles message-headers' do
params = default_params.merge(
'message-headers' => '[["NotCc", "emily@example.mailgun.org"], ["Reply-To", "mail2@example.mailgun.org"]]'
Expand Down Expand Up @@ -174,7 +182,6 @@ def default_params
"To"=>"John Doe <johndoe@example.com>, Jane Doe <janedoe@example.com>",
"body-html"=>"<div dir=\"ltr\">And attachments. Two of them. An image and a text file.</div>\r\n",
"body-plain"=>"And attachments. Two of them. An image and a text file.\r\n",
"from"=>"Jon Snow <jon@example.com>",
"recipient"=>"johndoe@example.com",
"sender"=>"jon@example.com",
"stripped-html"=>"<div dir=\"ltr\">And attachments. Two of them. An image and a text file.</div>\r\n",
Expand Down