Skip to content

Commit

Permalink
Merge branch 'master' into datadog-log-formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
etlund authored Apr 4, 2024
2 parents 6bd302d + 05a2a3a commit 4194fca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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 or configured incorrectly.

If that is causing you to miss emails; you may configure the adapter to allow those results through to your applications email processor.
Expand All @@ -58,6 +59,8 @@ Griddler::Mandrill.spf_allow.add(:softfail)
# Allow messages from domains where SPF is failing
Griddler::Mandrill.spf_allow.add(:fail)
Griddler::Mandrill::Adapter.allow_spf_none = true
```

## Credits
Expand Down
20 changes: 19 additions & 1 deletion lib/griddler/mandrill/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,29 @@ 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.each do |event|
Rails.logger.warn(logger: "Griddler::Mandrill::Adapter",
Expand All @@ -29,7 +47,7 @@ def normalize_params
end

events.select do |event|
spf_filter.passes?(event)
event_passes_spf?(event)
end.map do |event|
{
to: recipients(:to, event),
Expand Down
4 changes: 2 additions & 2 deletions spec/griddler/mandrill/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@

context 'when the adapter is configured to allow none' do
before do
Griddler::Mandrill.spf_allow.add(:none)
Griddler::Mandrill::Adapter.allow_spf_none = true
end
after do
Griddler::Mandrill.spf_allow.delete(:none)
Griddler::Mandrill::Adapter.allow_spf_none = false
end
it 'includes the message' do
params = default_params(@params)
Expand Down

0 comments on commit 4194fca

Please sign in to comment.