recipient_interceptor 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f74cc3d2d3870b44de76ddd8a972a7b4d004e6accb48e59f678913964fc34e7
4
- data.tar.gz: 693e37753d4dfd1decf906bdc4f5130eef84d5d42c5042425f2e952421cd4262
3
+ metadata.gz: 05054e20e0636b7e0ed92dc0af1ac23b884d70f210d2e214b6ced72845f934db
4
+ data.tar.gz: 98abb521569ecf525863342081b2c682133d99c35f659b564c9d8c1ab56798fd
5
5
  SHA512:
6
- metadata.gz: df47fd1c7e1637c8ebad24f7199f979796b6c94cfc305b76cd5f10e2fd1c2e3691136ae97098f1d918ee31e9574d43eb721624babfea363619c7bc91303ace70
7
- data.tar.gz: 74bda5ffcdb7027fed64065ebee0a9013ad3c4fa0c2b796689069a5c2228400adbc8cdcdd8abc2f41a68150a53423139e3ee60d169ce9056b54436207cf601e2
6
+ metadata.gz: 8251947adbc962c24d78941ea8dcdb54cfad7e0b68ef42d2a8039d897575ad77a2d16b644b62064cb553ba022abe860c9d49861fa60243c146ee7ff8427d0681
7
+ data.tar.gz: cabe6aec5167615c43a947f855a6fd478be28fba3d1fd13fbcd084d5c462a972dbf9dd72fb723d67b998235921102f09de33b80636112ca2aaecef459ed174d4
@@ -1,38 +1,29 @@
1
- require 'mail'
1
+ require "mail"
2
2
 
3
3
  class RecipientInterceptor
4
- def initialize(recipients, options = {})
5
- @recipients = normalize_to_array(recipients)
6
- @subject_prefix = options[:subject_prefix]
7
- end
8
-
9
- def delivering_email(message)
10
- add_custom_headers message
11
- add_subject_prefix message
12
- message.to = @recipients
13
- message.cc = nil if message.cc
14
- message.bcc = nil if message.bcc
15
- end
16
-
17
- private
18
-
19
- def normalize_to_array(recipients)
20
- if recipients.respond_to? :split
21
- recipients.split ','
4
+ def initialize(recipients, opts = {})
5
+ @recipients = if recipients.respond_to?(:split)
6
+ recipients.split(",")
22
7
  else
23
8
  recipients
24
9
  end
10
+
11
+ @subject_prefix = opts[:subject_prefix]
25
12
  end
26
13
 
27
- def add_subject_prefix(message)
28
- if @subject_prefix
29
- message.subject = "#{@subject_prefix} #{message.subject}"
14
+ def delivering_email(msg)
15
+ if @subject_prefix.respond_to?(:call)
16
+ msg.subject = "#{@subject_prefix.call(msg)} #{msg.subject}"
17
+ elsif @subject_prefix
18
+ msg.subject = "#{@subject_prefix} #{msg.subject}"
30
19
  end
31
- end
32
20
 
33
- def add_custom_headers(message)
34
- message.header['X-Intercepted-To'] = message.to || []
35
- message.header['X-Intercepted-Cc' ] = message.cc || []
36
- message.header['X-Intercepted-Bcc' ] = message.bcc || []
21
+ msg.header["X-Intercepted-To"] = msg.to || []
22
+ msg.header["X-Intercepted-Cc"] = msg.cc || []
23
+ msg.header["X-Intercepted-Bcc"] = msg.bcc || []
24
+
25
+ msg.to = @recipients
26
+ msg.cc = nil if msg.cc
27
+ msg.bcc = nil if msg.bcc
37
28
  end
38
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recipient_interceptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Croak
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-24 00:00:00.000000000 Z
11
+ date: 2021-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
27
  description: |2
56
28
  Use RecipientInterceptor when you don't want your Ruby program to
57
29
  accidentally send emails to addresses other than those on a whitelist
@@ -63,11 +35,10 @@ extensions: []
63
35
  extra_rdoc_files: []
64
36
  files:
65
37
  - lib/recipient_interceptor.rb
66
- - spec/recipient_interceptor_spec.rb
67
38
  homepage: http://github.com/croaky/recipient_interceptor
68
39
  licenses: []
69
40
  metadata: {}
70
- post_install_message:
41
+ post_install_message:
71
42
  rdoc_options: []
72
43
  require_paths:
73
44
  - lib
@@ -82,10 +53,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
53
  - !ruby/object:Gem::Version
83
54
  version: '0'
84
55
  requirements: []
85
- rubyforge_project:
86
- rubygems_version: 2.7.6
87
- signing_key:
56
+ rubygems_version: 3.2.11
57
+ signing_key:
88
58
  specification_version: 4
89
59
  summary: Intercept recipients when delivering email with the Mail gem.
90
- test_files:
91
- - spec/recipient_interceptor_spec.rb
60
+ test_files: []
@@ -1,112 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'lib', 'recipient_interceptor')
2
-
3
- describe RecipientInterceptor do
4
- before do
5
- Mail.defaults do
6
- delivery_method :test
7
- end
8
-
9
- module Mail
10
- @@delivery_interceptors = []
11
- end
12
- end
13
-
14
- it 'overrides to/cc/bcc fields' do
15
- Mail.register_interceptor RecipientInterceptor.new(recipient_string)
16
-
17
- response = deliver_mail
18
-
19
- expect(response.to).to eq [recipient_string]
20
- expect(response.cc).to eq nil
21
- expect(response.bcc).to eq nil
22
- end
23
-
24
- it 'overrides to/cc/bcc correctly even if they were already missing' do
25
- Mail.register_interceptor RecipientInterceptor.new(recipient_string)
26
-
27
- response = Mail.deliver do
28
- from 'original.from@example.com'
29
- to 'original.to@example.com'
30
- end
31
-
32
- expect(response.to).to eq [recipient_string]
33
- expect(response.cc).to eq nil
34
- expect(response.bcc).to eq nil
35
- end
36
-
37
- it 'copies original to/cc/bcc fields to custom headers' do
38
- Mail.register_interceptor RecipientInterceptor.new(recipient_string)
39
-
40
- response = deliver_mail
41
-
42
- expect(custom_header(response, 'X-Intercepted-To'))
43
- .to eq 'original.to@example.com'
44
- expect(custom_header(response, 'X-Intercepted-Cc'))
45
- .to eq 'original.cc@example.com'
46
- expect(custom_header(response, 'X-Intercepted-Bcc'))
47
- .to eq 'original.bcc@example.com'
48
- end
49
-
50
- it 'accepts an array of recipients' do
51
- Mail.register_interceptor RecipientInterceptor.new(recipient_array)
52
-
53
- response = deliver_mail
54
-
55
- expect(response.to).to eq recipient_array
56
- end
57
-
58
- it 'accepts a string of recipients' do
59
- Mail.register_interceptor RecipientInterceptor.new(recipient_string)
60
-
61
- response = deliver_mail
62
-
63
- expect(response.to).to eq [recipient_string]
64
- end
65
-
66
- it 'does not prefix subject by default' do
67
- Mail.register_interceptor RecipientInterceptor.new(recipient_string)
68
-
69
- response = deliver_mail
70
-
71
- expect(response.subject).to eq 'some subject'
72
- end
73
-
74
- it 'prefixes subject when given' do
75
- Mail.register_interceptor RecipientInterceptor.new(
76
- recipient_string,
77
- subject_prefix: '[STAGING]'
78
- )
79
-
80
- response = deliver_mail
81
-
82
- expect(response.subject).to eq '[STAGING] some subject'
83
- end
84
-
85
- def recipient_string
86
- 'staging@example.com'
87
- end
88
-
89
- def recipient_array
90
- ['one@example.com', 'two@example.com']
91
- end
92
-
93
- def deliver_mail
94
- Mail.deliver do
95
- from 'original.from@example.com'
96
- to 'original.to@example.com'
97
- cc 'original.cc@example.com'
98
- bcc 'original.bcc@example.com'
99
- subject 'some subject'
100
- end
101
- end
102
-
103
- def custom_header(response, name)
104
- header = response.header[name]
105
-
106
- if header.respond_to?(:map)
107
- header.map { |h| h.value.wrapped_string }
108
- else
109
- header.to_s
110
- end
111
- end
112
- end