Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 5020650

Browse files
committed
Rescue Mail::AddressList parse errors
If a malformed email address makes it's way to normalize_params it currently explodes resulting in a 500 which Sendgrid retries. If a few of these come in per day the resulting errors snowball pretty quickly. The email will never properly parse, of course so retrying is futile.
1 parent 7a1bad3 commit 5020650

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/griddler/sendgrid/adapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def normalize_params
3131

3232
def recipients(key)
3333
Mail::AddressList.new(params[key] || '').addresses
34+
rescue Mail::Field::IncompleteParseError
35+
[]
3436
end
3537

3638
def get_bcc

spec/griddler/sendgrid/adapter_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@
145145
normalize_params(params)[:charsets].should eq({})
146146
end
147147

148+
it 'does not explode if address is not parseable' do
149+
params = default_params.merge(cc: '"Closing Bracket Missing For Some Reason" <[email protected]')
150+
151+
normalize_params(params)[:cc].should eq([])
152+
end
153+
148154
it 'defaults charsets to an empty hash if it is not specified in params' do
149155
params = default_params.except(:charsets)
150156
normalize_params(params)[:charsets].should eq({})

0 commit comments

Comments
 (0)