griddler-mailgun 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35285f68548904ddab1f410fce0f047ab4681e5c
4
- data.tar.gz: fae1d9a3d9b469dd0b020f098fa97647cd2f8ae3
3
+ metadata.gz: 2377ee3b434c8ed1763841a6158052ef0d5cdfcd
4
+ data.tar.gz: 3138c2e3d6962b70aa89c2df0e262ef74eea0bb2
5
5
  SHA512:
6
- metadata.gz: 61908cb6d794afd73bd556a43bcba8ed64265d1e44f824595d4d9d39097ce6058746c17b6bf2837b460ebed945b1ab3054da3a6967975a1463a92923b2521b25
7
- data.tar.gz: 756b89b4186b0b117e8fd41b605ef1d18d47d20f9fb893b8e8eacb9ff0f2a401ce56c443fd0b07217610ad945ace8c088904a06ae9aad8f0ffc4ed2553528989
6
+ metadata.gz: 082e170f993d4f7751361d33f5bb6ff211612ddb6d957675fdda01f8c922d48b88ff3833fa9517de0ff7d90eede0dc53451e9dbf0371ad81237e845a10122fde
7
+ data.tar.gz: 0a2a0956210186cb7d228f8b6fec99d2d83f37a0a1439d418a90fca09b639ef3f07a444fe8138c47cb286bfa82ba61276373417a4716a90c1a89baa6276f083d
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1.2
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'griddler', '1.0.0'
3
+ gem 'griddler', '1.1.0'
4
4
 
5
5
  gemspec
@@ -1,6 +1,8 @@
1
1
  module Griddler
2
2
  module Mailgun
3
3
  class Adapter
4
+ attr_reader :params
5
+
4
6
  def initialize(params)
5
7
  @params = params
6
8
  end
@@ -14,17 +16,17 @@ module Griddler
14
16
  {
15
17
  to: to_recipients,
16
18
  cc: cc_recipients,
19
+ bcc: Array.wrap(param_or_header(:Bcc)),
17
20
  from: determine_sender,
18
21
  subject: params[:subject],
19
22
  text: params['body-plain'],
20
23
  html: params['body-html'],
21
- attachments: attachment_files
24
+ attachments: attachment_files,
25
+ headers: serialized_headers
22
26
  }
23
27
  end
24
28
 
25
- private
26
-
27
- attr_reader :params
29
+ private
28
30
 
29
31
  def determine_sender
30
32
  sender = param_or_header(:From)
@@ -55,6 +57,18 @@ module Griddler
55
57
  ActiveSupport::HashWithIndifferentAccess.new(extracted_headers)
56
58
  end
57
59
 
60
+ def serialized_headers
61
+
62
+ # Griddler expects unparsed headers to pass to ActionMailer, which will manually
63
+ # unfold, split on line-endings, and parse into individual fields.
64
+ #
65
+ # Mailgun already provides fully-parsed headers in JSON -- so we're reconstructing
66
+ # fake headers here for now, until we can find a better way to pass the parsed
67
+ # headers directly to Griddler
68
+
69
+ headers.to_a.collect { |header| "#{header[0]}: #{header[1]}" }.join("\n")
70
+ end
71
+
58
72
  def param_or_header(key)
59
73
  if params[key].present?
60
74
  params[key]
@@ -1,5 +1,5 @@
1
1
  module Griddler
2
2
  module Mailgun
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Griddler::Mailgun::Adapter do
4
4
  it 'registers itself with griddler' do
5
- Griddler.adapter_registry[:mailgun].should eq Griddler::Mailgun::Adapter
5
+ expect(Griddler.adapter_registry[:mailgun]).to eq Griddler::Mailgun::Adapter
6
6
  end
7
7
  end
8
8
 
@@ -27,12 +27,12 @@ describe Griddler::Mailgun::Adapter, '.normalize_params' do
27
27
  )
28
28
 
29
29
  normalized_params = Griddler::Mailgun::Adapter.normalize_params(params)
30
- normalized_params[:attachments].should eq [upload_1, upload_2]
30
+ expect(normalized_params[:attachments]).to eq [upload_1, upload_2]
31
31
  end
32
32
 
33
33
  it 'has no attachments' do
34
34
  normalized_params = Griddler::Mailgun::Adapter.normalize_params(default_params)
35
- normalized_params[:attachments].should be_empty
35
+ expect(normalized_params[:attachments]).to be_empty
36
36
  end
37
37
 
38
38
  it 'gets sender from headers' do
@@ -69,6 +69,26 @@ describe Griddler::Mailgun::Adapter, '.normalize_params' do
69
69
  expect(normalized_params[:to]).to eq ['johndoe@example.com']
70
70
  end
71
71
 
72
+ it 'handles message-headers' do
73
+ params = default_params.merge(
74
+ 'message-headers' => '[["NotCc", "emily@example.mailgun.org"], ["Reply-To", "mail2@example.mailgun.org"]]'
75
+ )
76
+ normalized_params = Griddler::Mailgun::Adapter.normalize_params(params)
77
+ email = Griddler::Email.new(normalized_params)
78
+ expect(email.headers["Reply-To"]).to eq "mail2@example.mailgun.org"
79
+ end
80
+
81
+ it 'adds Bcc when it exists' do
82
+ params = default_params.merge('Bcc' => 'bcc@example.com')
83
+ normalized_params = Griddler::Mailgun::Adapter.normalize_params(params)
84
+ expect(normalized_params[:bcc]).to eq ['bcc@example.com']
85
+ end
86
+
87
+ it 'bcc is empty array when it missing' do
88
+ normalized_params = Griddler::Mailgun::Adapter.normalize_params(default_params)
89
+ expect(normalized_params[:bcc]).to eq []
90
+ end
91
+
72
92
  def upload_1
73
93
  @upload_1 ||= ActionDispatch::Http::UploadedFile.new(
74
94
  filename: 'photo1.jpg',
@@ -100,7 +120,7 @@ describe Griddler::Mailgun::Adapter, '.normalize_params' do
100
120
  end
101
121
 
102
122
  def short_params
103
- params = ActiveSupport::HashWithIndifferentAccess.new(
123
+ ActiveSupport::HashWithIndifferentAccess.new(
104
124
  {
105
125
  "from" => "Jon Snow <jon@example.com>",
106
126
  "recipient" => "johndoe@example.com",
@@ -110,7 +130,7 @@ describe Griddler::Mailgun::Adapter, '.normalize_params' do
110
130
  end
111
131
 
112
132
  def default_params
113
- params = ActiveSupport::HashWithIndifferentAccess.new(
133
+ ActiveSupport::HashWithIndifferentAccess.new(
114
134
  {
115
135
  "Cc"=>"Brandon Stark <brandon@example.com>, Arya Stark <arya@example.com>",
116
136
  "From"=>"Jon Snow <jon@example.com>",
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,6 @@ require 'active_support/core_ext/string'
5
5
  require 'active_support/core_ext/hash'
6
6
 
7
7
  RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
9
8
  config.run_all_when_everything_filtered = true
10
9
  config.order = 'random'
11
10
  config.include Griddler::Testing
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: griddler-mailgun
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Pauly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-01 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -103,3 +103,4 @@ test_files:
103
103
  - spec/fixtures/photo2.jpg
104
104
  - spec/griddler/mailgun/adapter_spec.rb
105
105
  - spec/spec_helper.rb
106
+ has_rdoc: