action_recipient 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 200eadc692f55fd4253823211aad73f9da3ce764db8da5526101ba08792421a5
4
- data.tar.gz: 5e2de7f64a2fa5cc2b0e0eb1906f2e033e24b6e86ec089eebea5d072936017eb
3
+ metadata.gz: 8494299046a94fa75e5f75127e0c3854e0af1da065108c7d8c61c39be550e8af
4
+ data.tar.gz: a533cd9ad625688c008be2d95d6d493b57e4bc7c584d4168e58e87c999e4e74d
5
5
  SHA512:
6
- metadata.gz: 1d67685b2e4dec21fee76aa8566413d4eebf02b3c857a6993c5cfdb4dd82347851058c7e5dc8936a4bc14d062f7e9196c4ba9bfc31e8a8cabeac8a95bb34b2a5
7
- data.tar.gz: 9ffef13353d2a2e27a75c0185902937c0a7e5eb60f86204807487a64c4820a963ff08d825e7aeb590835a708adfeb9133f292b39aaea1393cb1aa7e650e8d876
6
+ metadata.gz: 491a5b5e79f2a6fe708239a1d89a4dc0d82ac4e92deac38bbb5f08993151e65f6777dc412d46e055c1cccac0c6d3c27ba880631f3bc0b5cbd154e2b5aff686d5
7
+ data.tar.gz: 8f2c371001d334168b1ee11622b4e1104b86ef51eb9e2a1859aaad7d12bf6704c13fbc82bcd29fd7dc1dfa7a0405c9d3abc413be7621538bae7206f4903b0b13
data/README.md CHANGED
@@ -46,7 +46,7 @@ if Rails.env.staging? # works only in staging environment
46
46
  ActionRecipient.configure do |config|
47
47
  config.format = 'your_address_to_redirect+%s@gmail.com'
48
48
 
49
- config.whitelist = [
49
+ config.whitelist.addresses = [
50
50
  'safe_address@example.com',
51
51
  'my_personal_adddress@example.com'
52
52
  ]
@@ -74,19 +74,29 @@ If you add **%s** in the format, it is automatically replaced with the original
74
74
 
75
75
  **DO NOT FORGET to specify a format**, otherwise your email addresses are not properly transformed, and your emails will not be successfully delivered.
76
76
 
77
- 2. you could also set a collection of whitelisted mails:
77
+ 2. you could also set a collection of whitelisted addresses and/or domains:
78
78
 
79
79
  ```ruby
80
80
  ActionRecipient.configure do |config|
81
- config.whitelist = [
81
+ config.whitelist.addresses = [
82
82
  'my_personal_address@example.com',
83
83
  'my_colleagues_address@example.com'
84
84
  ]
85
+
86
+ config.whitelist.domains = [
87
+ 'my_office_domain.com',
88
+ 'subdomain.my_office_domain.com'
89
+ ]
85
90
  end
86
91
  ```
87
92
 
88
93
  Whitelisted emails addresses are not overwritten, thus can be delivered as usual.
89
94
 
95
+ IMPORTANT:
96
+ With current version (version <~ 0.2.0) "domains" are the last part of email addresses after `@`, and matched with original email address literally on word-to-word basis.
97
+
98
+ So whitelisted domains such as `bar.com` does NOT whitelist emails to subdomains like `somebody@foo.bar.com` (therefore redirected).
99
+
90
100
  3. register ActionRecipient as the interceptor
91
101
 
92
102
  ```ruby
@@ -14,14 +14,30 @@ module ActionRecipient
14
14
  end
15
15
 
16
16
  class Configuration
17
- attr_writer :whitelist, :format
17
+ attr_writer :format
18
18
 
19
19
  def whitelist
20
- @whitelist ||= []
20
+ @whitelist ||= Whitelist.new
21
21
  end
22
22
 
23
23
  def format
24
24
  @format ||= '%s'
25
25
  end
26
+
27
+ class Whitelist
28
+ attr_writer :domains, :addresses
29
+
30
+ def [](key)
31
+ public_send(key) if %i[domains addresses].include? key
32
+ end
33
+
34
+ def domains
35
+ @domains ||= []
36
+ end
37
+
38
+ def addresses
39
+ @addresses ||= []
40
+ end
41
+ end
26
42
  end
27
43
  end
@@ -19,7 +19,7 @@ module ActionRecipient
19
19
  end
20
20
 
21
21
  def whitelisted?(email)
22
- whitelist.include? email
22
+ whitelist.addresses.include?(email) || whitelist.domains.include?(domain_for(email))
23
23
  end
24
24
 
25
25
  def whitelist
@@ -29,6 +29,10 @@ module ActionRecipient
29
29
  def format
30
30
  ActionRecipient.config.format
31
31
  end
32
+
33
+ def domain_for(email)
34
+ email.split('@').last
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -1,3 +1,3 @@
1
1
  module ActionRecipient
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_recipient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koji Onishi