recipient_interceptor 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/lib/recipient_interceptor.rb +16 -10
- data/spec/recipient_interceptor_spec.rb +63 -11
- metadata +30 -14
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MWQ4YzI3MTIyNDFhZTNkNTM4ODJkNzQ2NmM5ZTM3NzRmMTJlZmI4MWM3NDQ5
|
10
|
-
ODQ3Y2JlN2ZlMDlhYjgwMTQwMzY5ODdkMWQ1YzkyNjdhYzU2YTdmYTliNjQz
|
11
|
-
OTg3ZWNlMjc0ODM3ZTJkYzBkZGU1NWQyNDZmOTgxNDkxNWY4NmE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MDVlNTc1ZTQ3M2IzMTA4NWE1MmUwODk4NjNjODNlZDYwZjE3N2VjMDkyMzg4
|
14
|
-
OTQ0MzljNmNkYTNlYWJkNDE5NmE5MjFlYWFjZTZhYzAwOGUzMjA0ZmVmYWUw
|
15
|
-
MzE0NWZkZjViZDhlZGQ4NTAxNWMyNTM1ZTgyM2YzYzQ1ODI4MWI=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9323d5071c9779a7a36eb152e29fe573e7537a13
|
4
|
+
data.tar.gz: 1f8674fb114b64869aab280326203f3e8f8e7bde
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d134b8d957c2ee6f65f4a6ecedff78769564a3b13104046f23424f802959f18d209fbf21ac38ac161ca7beb8cee84004a8998d3dc3a01e1229b4acf3e15ad19a
|
7
|
+
data.tar.gz: 3b9d406d84946a0d50d9eba1811d4b698f71c186d07697729650986224b6320c323abc802ee6610686b1b429249577dff28b01242c37a109c61f7dbd35f16da0
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'mail'
|
2
2
|
|
3
3
|
class RecipientInterceptor
|
4
|
-
def initialize(recipients)
|
4
|
+
def initialize(recipients, options = {})
|
5
5
|
@recipients = normalize_to_array(recipients)
|
6
|
+
@subject_prefix = options[:subject_prefix]
|
6
7
|
end
|
7
8
|
|
8
9
|
def delivering_email(message)
|
9
10
|
add_custom_headers message
|
11
|
+
add_subject_prefix message
|
10
12
|
message.to = @recipients
|
11
|
-
message.cc =
|
12
|
-
message.bcc =
|
13
|
+
message.cc = []
|
14
|
+
message.bcc = []
|
13
15
|
end
|
14
16
|
|
15
17
|
private
|
@@ -22,16 +24,20 @@ class RecipientInterceptor
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
27
|
+
def add_subject_prefix(message)
|
28
|
+
if @subject_prefix
|
29
|
+
message.subject = "#{@subject_prefix} #{message.subject}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
25
33
|
def add_custom_headers(message)
|
26
34
|
{
|
27
|
-
'X-Intercepted-To' => message.to,
|
28
|
-
'X-Intercepted-Cc' => message.cc,
|
29
|
-
'X-Intercepted-Bcc' => message.bcc
|
35
|
+
'X-Intercepted-To' => message.to || [],
|
36
|
+
'X-Intercepted-Cc' => message.cc || [],
|
37
|
+
'X-Intercepted-Bcc' => message.bcc || []
|
30
38
|
}.each do |header, addresses|
|
31
|
-
|
32
|
-
|
33
|
-
message.header = "#{message.header}\n#{header}: #{address}"
|
34
|
-
end
|
39
|
+
addresses.each do |address|
|
40
|
+
message.header = "#{message.header}#{header}: #{address}"
|
35
41
|
end
|
36
42
|
end
|
37
43
|
end
|
@@ -1,20 +1,26 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'recipient_interceptor')
|
2
2
|
|
3
3
|
describe RecipientInterceptor do
|
4
|
-
it 'overrides to/cc/bcc fields
|
5
|
-
Mail.register_interceptor RecipientInterceptor.new(
|
4
|
+
it 'overrides to/cc/bcc fields' do
|
5
|
+
Mail.register_interceptor RecipientInterceptor.new(recipient_string)
|
6
6
|
|
7
7
|
response = deliver_mail
|
8
8
|
|
9
|
-
expect(response.to).to eq [
|
9
|
+
expect(response.to).to eq [recipient_string]
|
10
10
|
expect(response.cc).to eq []
|
11
11
|
expect(response.bcc).to eq []
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'copies original to/cc/bcc fields to custom headers' do
|
15
|
+
Mail.register_interceptor RecipientInterceptor.new(recipient_string)
|
16
|
+
|
17
|
+
response = deliver_mail
|
12
18
|
|
13
|
-
expect(response
|
14
|
-
to eq
|
15
|
-
expect(response
|
19
|
+
expect(custom_header(response, 'X-Intercepted-To')).
|
20
|
+
to eq 'original.to@example.com'
|
21
|
+
expect(custom_header(response, 'X-Intercepted-Cc')).
|
16
22
|
to eq 'original.cc@example.com'
|
17
|
-
expect(response
|
23
|
+
expect(custom_header(response, 'X-Intercepted-Bcc')).
|
18
24
|
to eq 'original.bcc@example.com'
|
19
25
|
end
|
20
26
|
|
@@ -26,22 +32,68 @@ describe RecipientInterceptor do
|
|
26
32
|
expect(response.to).to eq recipient_array
|
27
33
|
end
|
28
34
|
|
35
|
+
it 'accepts a string of recipients' do
|
36
|
+
Mail.register_interceptor RecipientInterceptor.new(recipient_string)
|
37
|
+
|
38
|
+
response = deliver_mail
|
39
|
+
|
40
|
+
expect(response.to).to eq [recipient_string]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'does not prefix subject by default' do
|
44
|
+
Mail.register_interceptor RecipientInterceptor.new(recipient_string)
|
45
|
+
|
46
|
+
response = deliver_mail
|
47
|
+
|
48
|
+
expect(response.subject).to eq 'some subject'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'prefixes subject when given' do
|
52
|
+
Mail.register_interceptor RecipientInterceptor.new(
|
53
|
+
recipient_string,
|
54
|
+
subject_prefix: '[STAGING]'
|
55
|
+
)
|
56
|
+
|
57
|
+
response = deliver_mail
|
58
|
+
|
59
|
+
expect(response.subject).to eq '[STAGING] some subject'
|
60
|
+
end
|
61
|
+
|
62
|
+
def recipient_string
|
63
|
+
'staging@example.com'
|
64
|
+
end
|
65
|
+
|
66
|
+
def recipient_array
|
67
|
+
['one@example.com', 'two@example.com']
|
68
|
+
end
|
69
|
+
|
29
70
|
def deliver_mail
|
30
71
|
Mail.defaults do
|
31
72
|
delivery_method :test
|
32
73
|
end
|
33
74
|
|
34
|
-
|
75
|
+
Mail.deliver do
|
35
76
|
from 'original.from@example.com'
|
36
77
|
to 'original.to@example.com'
|
37
78
|
cc 'original.cc@example.com'
|
38
79
|
bcc 'original.bcc@example.com'
|
80
|
+
subject 'some subject'
|
39
81
|
end
|
82
|
+
end
|
40
83
|
|
41
|
-
|
84
|
+
def custom_header(response, name)
|
85
|
+
header = response.header[name]
|
86
|
+
|
87
|
+
if header.respond_to?(:map)
|
88
|
+
header.map { |h| h.value.wrapped_string }
|
89
|
+
else
|
90
|
+
header.to_s
|
91
|
+
end
|
42
92
|
end
|
43
93
|
|
44
|
-
|
45
|
-
|
94
|
+
after do
|
95
|
+
module Mail
|
96
|
+
@@delivery_interceptors = []
|
97
|
+
end
|
46
98
|
end
|
47
99
|
end
|
metadata
CHANGED
@@ -1,47 +1,62 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recipient_interceptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Croak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
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
|
+
- - '>='
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - '>='
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - '>='
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
|
-
description:
|
42
|
-
|
43
|
-
|
44
|
-
|
55
|
+
description: |2
|
56
|
+
Use RecipientInterceptor when you don't want your Ruby program to
|
57
|
+
accidentally send emails to addresses other than those on a whitelist
|
58
|
+
which you configure. For example, you could use it in your web app's
|
59
|
+
staging environment.
|
45
60
|
email: dan@thoughtbot.com
|
46
61
|
executables: []
|
47
62
|
extensions: []
|
@@ -50,7 +65,8 @@ files:
|
|
50
65
|
- lib/recipient_interceptor.rb
|
51
66
|
- spec/recipient_interceptor_spec.rb
|
52
67
|
homepage: http://github.com/croaky/recipient_interceptor
|
53
|
-
licenses:
|
68
|
+
licenses:
|
69
|
+
- MIT
|
54
70
|
metadata: {}
|
55
71
|
post_install_message:
|
56
72
|
rdoc_options: []
|
@@ -58,17 +74,17 @@ require_paths:
|
|
58
74
|
- lib
|
59
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
60
76
|
requirements:
|
61
|
-
- -
|
77
|
+
- - '>='
|
62
78
|
- !ruby/object:Gem::Version
|
63
79
|
version: '0'
|
64
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
81
|
requirements:
|
66
|
-
- -
|
82
|
+
- - '>='
|
67
83
|
- !ruby/object:Gem::Version
|
68
84
|
version: '0'
|
69
85
|
requirements: []
|
70
86
|
rubyforge_project:
|
71
|
-
rubygems_version: 2.0.
|
87
|
+
rubygems_version: 2.0.5
|
72
88
|
signing_key:
|
73
89
|
specification_version: 4
|
74
90
|
summary: Intercept recipients when delivering email with the Mail gem.
|