Skip to content

Commit 8152faa

Browse files
Merge pull request #18 from hooopo/master
ignore cc and bcc
2 parents a135f52 + fadd744 commit 8152faa

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ MailInterceptor::Interceptor.new({ forward_emails_to: ['intercepted_emails@bigbi
7979
'qa@bigbinary.com' })
8080
```
8181

82+
### ignore_bcc and ignore_cc
83+
84+
By default bcc and cc are ignored. You can set `:ignore_bcc` or `:ignore_cc` to `false`, if you don't want to ignore bcc or cc.
85+
8286
### Custom environment
8387

8488
By default all emails sent in non production environment are

lib/mail_interceptor.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44

55
module MailInterceptor
66
class Interceptor
7-
attr_accessor :deliver_emails_to, :forward_emails_to, :env
7+
attr_accessor :deliver_emails_to, :forward_emails_to, :env, :ignore_cc, :ignore_bcc
88

99
def initialize options = {}
1010
@deliver_emails_to = Array.wrap options[:deliver_emails_to]
1111
@forward_emails_to = options.fetch :forward_emails_to
12+
@ignore_cc = options.fetch :ignore_cc, true
13+
@ignore_bcc = options.fetch :ignore_bcc, true
1214
@env = options.fetch :env, InterceptorEnv.new
1315

1416
sanitize_forward_emails_to
1517
end
1618

1719
def delivering_email message
18-
message.to = normalize_recipients(message.to).flatten.uniq
20+
message.to = normalize_recipients(message.to).flatten.uniq
21+
message.cc = [] if ignore_cc
22+
message.bcc = [] if ignore_bcc
1923
end
2024

2125
private

test/mail_interceptor_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@ def test_error_if_forward_emails_to_is_empty
6161
assert_equal message, exception.message
6262
end
6363

64+
def test_default_ignore_bcc_and_cc
65+
interceptor = ::MailInterceptor::Interceptor.new env: env,
66+
forward_emails_to: 'test@example.com'
67+
@message.bcc = ['bcc@example.com']
68+
@message.cc = ['cc@example.com']
69+
interceptor.delivering_email @message
70+
assert_equal [], @message.bcc
71+
assert_equal [], @message.cc
72+
end
73+
74+
def test_do_not_ignore_bcc_or_cc
75+
interceptor = ::MailInterceptor::Interceptor.new env: env,
76+
forward_emails_to: 'test@example.com',
77+
ignore_bcc: false,
78+
ignore_cc: false
79+
@message.bcc = ['bcc@example.com']
80+
@message.cc = ['cc@example.com']
81+
interceptor.delivering_email @message
82+
assert_equal ['bcc@example.com'], @message.bcc
83+
assert_equal ['cc@example.com'], @message.cc
84+
end
85+
6486
private
6587

6688
def env(environment = 'test')

0 commit comments

Comments
 (0)