Skip to content

Commit 2217dec

Browse files
committed
interceptor before normalizing so we can use the rich user info before it gets stripped by the formatter
1 parent 8ed3680 commit 2217dec

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/bamboo/mailer.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ defmodule Bamboo.Mailer do
203203

204204
@doc false
205205
def deliver_now(adapter, email, config, opts) do
206-
with {:ok, email} <- validate_and_normalize(email, adapter),
207-
%Bamboo.Email{blocked: false} = email <- apply_interceptors(email, config) do
206+
with %Bamboo.Email{blocked: false} = email <- apply_interceptors(email, config),
207+
{:ok, email} <- validate_and_normalize(email, adapter) do
208208
if empty_recipients?(email) do
209209
debug_unsent(email)
210210

@@ -244,8 +244,8 @@ defmodule Bamboo.Mailer do
244244

245245
@doc false
246246
def deliver_later(adapter, email, config) do
247-
with {:ok, email} <- validate_and_normalize(email, adapter),
248-
%Bamboo.Email{blocked: false} = email <- apply_interceptors(email, config) do
247+
with %Bamboo.Email{blocked: false} = email <- apply_interceptors(email, config),
248+
{:ok, email} <- validate_and_normalize(email, adapter) do
249249
if empty_recipients?(email) do
250250
debug_unsent(email)
251251
else

test/support/deny_list_interceptor.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ defmodule Bamboo.DenyListInterceptor do
33

44
@deny_list ["blocked@blocked.com"]
55

6-
def call(email) do
7-
if Enum.any?(email.to, &(elem(&1, 1) in @deny_list)) do
6+
def call(%{to: recipients} = email) when is_list(recipients) do
7+
if Enum.any?(recipients, &(&1 in @deny_list)) do
88
Bamboo.Email.block(email)
99
else
1010
email
1111
end
1212
end
13+
14+
def call(%{to: recipient} = email) when recipient in @deny_list do
15+
Bamboo.Email.block(email)
16+
end
17+
18+
def call(email) do
19+
email
20+
end
1321
end

0 commit comments

Comments
 (0)