Skip to content

Commit 2e8a54f

Browse files
authored
Merge pull request #22 from cph/add-bounce-ignore
Add bounce ignore config option
2 parents 82f461c + 8aaa140 commit 2e8a54f

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ test/dummy/db/*.sqlite3-journal
77
test/dummy/log/*.log
88
test/dummy/tmp/
99
test/dummy/.sass-cache
10+
**/.DS_Store

app/mailers/ep_postmaster/postmaster.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ module EpPostmaster
22
class Postmaster < ::ActionMailer::Base
33

44
def bounced_email(options = {})
5-
@to = MailgunPost.unfurl(options.fetch(:original_sender) { options.fetch(:reply_to) })
5+
@to = Array.wrap(MailgunPost.unfurl(options.fetch(:original_sender) { options.fetch(:reply_to) }))
6+
@to -= EpPostmaster.configuration.ignored_bounce_emails
7+
return if @to.empty?
8+
69
@recipient = options.fetch(:original_recipient)
710
@subject = options[:original_subject]
811
@error = options[:error]

lib/ep_postmaster/configuration.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
module EpPostmaster
22
class Configuration
3-
attr_accessor :mailgun_api_key, :mailer_sender, :mailer_deliverer
3+
attr_accessor :mailgun_api_key, :mailer_sender, :mailer_deliverer, :ignored_bounce_emails
44

55
def initialize
66
@mailgun_api_key = ""
7+
@ignored_bounce_emails = []
78
self.mailer_deliverer = ->(message) { message.deliver_now }
89
self.bounced_email_handler = Class.new do
910
def self.handle_bounced_email!(*)

mise.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tools]
2+
ruby = "3.4"

test/unit/mailers/ep_postmaster/postmaster_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ class PostmasterTest < ActionMailer::TestCase
4040
should "say something in the body of the email" do
4141
assert_match "unable to deliver", mail.body.encoded
4242
end
43+
44+
should "not send anything when the original sender is in a list of ignored addresses" do
45+
EpPostmaster.configure { |config| config.ignored_bounce_emails = [ "sender@test.test" ] }
46+
message = Postmaster.bounced_email(options).message
47+
EpPostmaster.configure { |config| config.ignored_bounce_emails = [] }
48+
49+
assert message.is_a?(ActionMailer::Base::NullMail)
50+
51+
end
4352
end
4453

4554
private

0 commit comments

Comments
 (0)