Skip to content
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ test/dummy/db/*.sqlite3-journal
test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache
**/.DS_Store
5 changes: 4 additions & 1 deletion app/mailers/ep_postmaster/postmaster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module EpPostmaster
class Postmaster < ::ActionMailer::Base

def bounced_email(options = {})
@to = MailgunPost.unfurl(options.fetch(:original_sender) { options.fetch(:reply_to) })
@to = Array.wrap(MailgunPost.unfurl(options.fetch(:original_sender) { options.fetch(:reply_to) }))
@to -= EpPostmaster.configuration.ignored_bounce_emails
return if @to.empty?

@recipient = options.fetch(:original_recipient)
@subject = options[:original_subject]
@error = options[:error]
Expand Down
3 changes: 2 additions & 1 deletion lib/ep_postmaster/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module EpPostmaster
class Configuration
attr_accessor :mailgun_api_key, :mailer_sender, :mailer_deliverer
attr_accessor :mailgun_api_key, :mailer_sender, :mailer_deliverer, :ignored_bounce_emails

def initialize
@mailgun_api_key = ""
@ignored_bounce_emails = []
self.mailer_deliverer = ->(message) { message.deliver_now }
self.bounced_email_handler = Class.new do
def self.handle_bounced_email!(*)
Expand Down
2 changes: 2 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
ruby = "3.4"
9 changes: 9 additions & 0 deletions test/unit/mailers/ep_postmaster/postmaster_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ class PostmasterTest < ActionMailer::TestCase
should "say something in the body of the email" do
assert_match "unable to deliver", mail.body.encoded
end

should "not send anything when the original sender is in a list of ignored addresses" do
EpPostmaster.configure { |config| config.ignored_bounce_emails = [ "sender@test.test" ] }
message = Postmaster.bounced_email(options).message
EpPostmaster.configure { |config| config.ignored_bounce_emails = [] }

assert message.is_a?(ActionMailer::Base::NullMail)

end
end

private
Expand Down