Skip to content

Commit

Permalink
interceptor before normalizing so we can use the rich user info befor…
Browse files Browse the repository at this point in the history
…e it gets stripped by the formatter
  • Loading branch information
tarzan committed Dec 16, 2024
1 parent baadd4d commit 3e1ef7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/bamboo/mailer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ defmodule Bamboo.Mailer do

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

Expand Down Expand Up @@ -244,8 +244,8 @@ defmodule Bamboo.Mailer do

@doc false
def deliver_later(adapter, email, config) do
with {:ok, email} <- validate_and_normalize(email, adapter),
%Bamboo.Email{blocked: false} = email <- apply_interceptors(email, config) do
with %Bamboo.Email{blocked: false} = email <- apply_interceptors(email, config),
{:ok, email} <- validate_and_normalize(email, adapter) do
if empty_recipients?(email) do
debug_unsent(email)
else
Expand Down
12 changes: 10 additions & 2 deletions test/support/deny_list_interceptor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ defmodule Bamboo.DenyListInterceptor do

@deny_list ["[email protected]"]

def call(email) do
if Enum.any?(email.to, &(elem(&1, 1) in @deny_list)) do
def call(%{to: recipients} = email) when is_list(recipients) do
if Enum.any?(recipients, &(&1 in @deny_list)) do
Bamboo.Email.block(email)
else
email
end
end

def call(%{to: recipient} = email) when recipient in @deny_list do
Bamboo.Email.block(email)
end

def call(email) do
email
end
end

0 comments on commit 3e1ef7b

Please sign in to comment.