Class: MailAllowlist

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_allowlist.rb,
lib/mail_allowlist/version.rb

Overview

Filter mails with a specific allowlist of e-mailaddresses and only leaves those in the ‘to’.

Constant Summary collapse

VERSION =
'2.0.0'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allowlist, fallback = nil) ⇒ MailAllowlist

Returns a new instance of MailAllowlist.

Parameters:

  • allowlist (Array<String>, #include?)
  • fallback (String) (defaults to: nil)


10
11
12
13
# File 'lib/mail_allowlist.rb', line 10

def initialize(allowlist, fallback = nil)
  @allowlist = allowlist
  @fallback = fallback
end

Instance Attribute Details

#allowlistObject (readonly)

Returns the value of attribute allowlist.



6
7
8
# File 'lib/mail_allowlist.rb', line 6

def allowlist
  @allowlist
end

#fallbackObject (readonly)

Returns the value of attribute fallback.



6
7
8
# File 'lib/mail_allowlist.rb', line 6

def fallback
  @fallback
end

Instance Method Details

#delivering_email(mail) ⇒ Object



15
16
17
18
# File 'lib/mail_allowlist.rb', line 15

def delivering_email(mail)
  mail.to = mail.to.select { |recipient| allowlisted?(recipient) }
  mail.to = [fallback] unless mail.to.any?
end