Class: WhitelistMailProxy
- Inherits:
-
Object
- Object
- WhitelistMailProxy
- Defined in:
- lib/whitelist_mail_proxy.rb
Defined Under Namespace
Classes: BlockedDelivery, SettingsError
Instance Attribute Summary collapse
-
#delivery_method ⇒ Object
readonly
Returns the value of attribute delivery_method.
-
#domains ⇒ Object
readonly
Returns the value of attribute domains.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
Class Method Summary collapse
Instance Method Summary collapse
- #block_recipient?(string) ⇒ Boolean
- #deliver!(mail) ⇒ Object
-
#initialize(options) ⇒ WhitelistMailProxy
constructor
A new instance of WhitelistMailProxy.
- #whitelist_description ⇒ Object
Constructor Details
#initialize(options) ⇒ WhitelistMailProxy
Returns a new instance of WhitelistMailProxy.
8 9 10 11 12 13 14 15 |
# File 'lib/whitelist_mail_proxy.rb', line 8 def initialize() @delivery_method = [:delivery_method] @regexp = [:regexp] @domains = [:domain] && Array([:domain]) raise SettingsError, "you must specify config.action_mailer.whitelist_proxy_settings to contain a :delivery_method" unless @delivery_method raise SettingsError, "you must specify config.action_mailer.whitelist_proxy_settings to contain a :regexp or :domain" unless @regexp || @domains end |
Instance Attribute Details
#delivery_method ⇒ Object (readonly)
Returns the value of attribute delivery_method.
16 17 18 |
# File 'lib/whitelist_mail_proxy.rb', line 16 def delivery_method @delivery_method end |
#domains ⇒ Object (readonly)
Returns the value of attribute domains.
16 17 18 |
# File 'lib/whitelist_mail_proxy.rb', line 16 def domains @domains end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
16 17 18 |
# File 'lib/whitelist_mail_proxy.rb', line 16 def regexp @regexp end |
Class Method Details
.extract_email_address(recipient) ⇒ Object
eg.
"Matthew Rudy Jacobs"<[email protected]>
[email protected]
33 34 35 |
# File 'lib/whitelist_mail_proxy.rb', line 33 def self.extract_email_address(recipient) recipient.split("<").last.gsub(/>$/, "").strip end |
.extract_email_domain(recipient) ⇒ Object
37 38 39 |
# File 'lib/whitelist_mail_proxy.rb', line 37 def self.extract_email_domain(recipient) extract_email_address(recipient).split("@").last end |
Instance Method Details
#block_recipient?(string) ⇒ Boolean
41 42 43 |
# File 'lib/whitelist_mail_proxy.rb', line 41 def block_recipient?(string) block_by_regexp?(string) || block_by_domain?(string) end |
#deliver!(mail) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/whitelist_mail_proxy.rb', line 18 def deliver!(mail) blocked = mail.destinations.select do |destination| block_recipient?(destination) end if blocked.any? raise BlockedDelivery.new("cannot send to #{blocked.inspect}, whitelist is #{whitelist_description}") else real_delivery_method.deliver!(mail) end end |
#whitelist_description ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/whitelist_mail_proxy.rb', line 45 def whitelist_description bits = [] bits << "addresses LIKE #{regexp.inspect}" if self.regexp bits << "domains IN #{domains.inspect}" if self.domains bits.join(" OR ") end |