Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow processing when domains do not have SPF configured #35

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ Once you have correctly configured Mandrill, you can go ahead and delete this co

[Adding Routes]: http://help.mandrill.com/entries/21699367-Inbound-Email-Processing-Overview

#### Allowing domains without SPF configured
Sometimes, due to circumstances outside our control, a domain may not have SPF set up. In those cases, you can set the adapter to pass results to your email processor.

```
Griddler::Mandrill::Adapter.allow_spf_none = true
```


## Credits

Griddler::Mandrill was extracted from Griddler by [Stafford Brunk](https://github.com/wingrunr21).
Expand Down
21 changes: 20 additions & 1 deletion lib/griddler/mandrill/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,33 @@ def initialize(params)
@params = params
end

def self.allow_spf_none?
@allow_spf_none || false
end

def allow_spf_none?
self.class.allow_spf_none?
end

def self.allow_spf_none=(allow_spf_none)
@allow_spf_none = allow_spf_none
end

def self.normalize_params(params)
adapter = new(params)
adapter.normalize_params
end

def event_passes_spf?(event)
event[:spf].present? &&
((event[:spf][:result] == 'pass' || event[:spf][:result] == 'neutral') ||
(allow_spf_none? && event[:spf][:result] == 'none'))
end

def normalize_params
events.select do |event|
event[:spf].present? && (event[:spf][:result] == 'pass' || event[:spf][:result] == 'neutral')
event_passes_spf?(event)

end.map do |event|
{
to: recipients(:to, event),
Expand Down
27 changes: 27 additions & 0 deletions spec/griddler/mandrill/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,33 @@
end
end

describe 'when the spf record is none' do
before do
@params = params_hash
@params.first[:msg][:spf] = { result: 'none', detail: '' }
end

it 'does not include the emails without spf results by default' do
params = default_params(@params)
normalized_params = Griddler::Mandrill::Adapter.normalize_params(params)
expect(normalized_params).to be_empty
end

context 'when the adapter is configured to allow none' do
before do
Griddler::Mandrill::Adapter.allow_spf_none = true
end
after do
Griddler::Mandrill::Adapter.allow_spf_none = false
end
it 'includes the message' do
params = default_params(@params)
normalized_params = Griddler::Mandrill::Adapter.normalize_params(params)
expect(normalized_params).not_to be_empty
end
end
end

describe 'when the spf record is softfail' do
before do
@params = params_hash
Expand Down