diff --git a/README.md b/README.md index 4b368be..1bad6dd 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ gem install mailgun-ruby Gemfile: ```ruby -gem 'mailgun-ruby', '~>1.2.3' +gem 'mailgun-ruby', '~>1.2.4' ``` Usage diff --git a/lib/mailgun/client.rb b/lib/mailgun/client.rb index b25557d..940ac3c 100755 --- a/lib/mailgun/client.rb +++ b/lib/mailgun/client.rb @@ -64,6 +64,8 @@ def self.deliveries # containing required parameters for the requested resource. # @return [Mailgun::Response] A Mailgun::Response object. def send_message(working_domain, data) + fail ParameterError.new('Missing working domain', working_domain) unless working_domain + if test_mode? then Mailgun::Client.deliveries << data return Response.from_hash( diff --git a/lib/mailgun/messages/message_builder.rb b/lib/mailgun/messages/message_builder.rb index a45cafc..562b4f9 100644 --- a/lib/mailgun/messages/message_builder.rb +++ b/lib/mailgun/messages/message_builder.rb @@ -270,8 +270,12 @@ def set_custom_data(name, data) # @return [void] def variable(name, data) fail(Mailgun::ParameterError, 'Variable name must be specified') if name.to_s.empty? - jsondata = make_json data - set_single("v:#{name}", jsondata) + begin + jsondata = make_json data + set_single("v:#{name}", jsondata) + rescue Mailgun::ParameterError + set_single("v:#{name}", data) + end end # Add custom parameter to the message. A custom parameter is any parameter that diff --git a/lib/mailgun/version.rb b/lib/mailgun/version.rb index ac8a140..08091cf 100644 --- a/lib/mailgun/version.rb +++ b/lib/mailgun/version.rb @@ -1,4 +1,4 @@ # It's the version. Yeay! module Mailgun - VERSION = '1.2.3' + VERSION = '1.2.4' end diff --git a/lib/railgun/mailer.rb b/lib/railgun/mailer.rb index b13a129..446fee2 100644 --- a/lib/railgun/mailer.rb +++ b/lib/railgun/mailer.rb @@ -11,7 +11,7 @@ module Railgun class Mailer # List of the headers that will be ignored when copying headers from `mail.header_fields` - IGNORED_HEADERS = %w[ to from subject reply-to ] + IGNORED_HEADERS = %w[ to from subject reply-to mime-version ] # [Hash] config -> # Requires *at least* `api_key` and `domain` keys. diff --git a/lib/railgun/railtie.rb b/lib/railgun/railtie.rb index 3c91a35..a8b7107 100644 --- a/lib/railgun/railtie.rb +++ b/lib/railgun/railtie.rb @@ -2,8 +2,9 @@ module Railgun class Railtie < ::Rails::Railtie - config.before_configuration do - ActionMailer::Base.add_delivery_method :mailgun, Railgun::Mailer + ActiveSupport.on_load(:action_mailer) do + add_delivery_method :mailgun, Railgun::Mailer + ActiveSupport.run_load_hooks(:mailgun_mailer, Railgun::Mailer) end end end diff --git a/spec/unit/messages/message_builder_spec.rb b/spec/unit/messages/message_builder_spec.rb index fb2810a..e35e1ce 100644 --- a/spec/unit/messages/message_builder_spec.rb +++ b/spec/unit/messages/message_builder_spec.rb @@ -567,9 +567,13 @@ expect(@mb_obj.message["v:my-data"]).to be_kind_of(String) expect(@mb_obj.message["v:my-data"].to_s).to eq('{"key":"value"}') end - it 'throws an exception on broken JSON.' do - data = 'This is some crappy JSON.' - expect {@mb_obj.variable('my-data', data)}.to raise_error(Mailgun::ParameterError) + it 'accepts string values' do + data = 'String Value.' + + @mb_obj.variable('my-data', data) + + expect(@mb_obj.message["v:my-data"]).to be_kind_of(String) + expect(@mb_obj.message["v:my-data"].to_s).to eq('String Value.') end end diff --git a/spec/unit/railgun/mailer_spec.rb b/spec/unit/railgun/mailer_spec.rb index 3476354..525bb1c 100644 --- a/spec/unit/railgun/mailer_spec.rb +++ b/spec/unit/railgun/mailer_spec.rb @@ -191,6 +191,19 @@ def message_with_attachment(address, subject) expect(body['h:reply-to']).to eq('dude@example.com.au') end + it 'ignores `mime-version` in headers' do + message = UnitTestMailer.plain_message('test@example.org', '', { + 'mime-version' => '1.0', + }) + message.mailgun_headers = { + 'Mime-Version' => '1.1', + } + message.headers({'MIME-VERSION' => '1.2'}) + + body = Railgun.transform_for_mailgun(message) + expect(body).not_to include('h:mime-version') + end + it 'treats `headers()` names as case-insensitve' do message = UnitTestMailer.plain_message('test@example.org', '', { 'X-BIG-VALUE' => 1,