mail_interceptor 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -19
- data/lib/mail_interceptor.rb +3 -1
- data/lib/mail_interceptor/version.rb +1 -1
- data/mail_interceptor.gemspec +2 -2
- data/test/mail_interceptor_test.rb +9 -7
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 519692ac3fb68840234a78cc4868c0305c129bf0
|
4
|
+
data.tar.gz: 28be53d6876eae2aa09301022ee1162a1c036a88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 898f3f4f3240815ab68ae7e28d126f4280516fca853acf00107fd112a8ca6aded5eeaf09a06e4811f61895fba3b7b0b47aff2e8cc38063bdf3f742bd2e86b672
|
7
|
+
data.tar.gz: 24afd80b88edccd7fc1becca837c5248bdd2cf919794f5d51ce897ffe274416ccb4fd49c84ad7e94d15603ba60c5fd69e0609749fdbdedcacce52a3c6c61a942
|
data/README.md
CHANGED
@@ -1,62 +1,92 @@
|
|
1
1
|
# MailInterceptor
|
2
2
|
|
3
|
-
|
3
|
+
[![Circle CI](https://circleci.com/gh/bigbinary/mail_interceptor.svg?style=svg)](https://circleci.com/gh/bigbinary/mail_interceptor)
|
4
|
+
|
5
|
+
This gem intercepts and forwards email to a forwarding address in
|
6
|
+
non-production environment. However it also provides ability to not
|
7
|
+
intercept certain emails so that testing of emails is easier in
|
8
|
+
development/staging environment.
|
9
|
+
|
10
|
+
If `subject_prefix` is supplied then that is added to every single email
|
11
|
+
in both production and non-production environment.
|
4
12
|
|
5
13
|
## Installation
|
6
14
|
|
7
15
|
Add this line to your application's Gemfile:
|
8
16
|
|
9
|
-
```
|
17
|
+
```ruby
|
10
18
|
gem 'mail_interceptor'
|
11
19
|
```
|
12
20
|
|
13
21
|
## Usage
|
14
22
|
|
15
|
-
```
|
23
|
+
```ruby
|
16
24
|
# config/initializer/mail_interceptor.rb
|
17
25
|
|
18
|
-
|
19
|
-
|
20
|
-
|
26
|
+
options = { forward_emails_to: 'intercepted_emails@domain.com',
|
27
|
+
deliver_emails_to: ["@wheel.com"],
|
28
|
+
subject_prefix: 'WHEEL' }
|
29
|
+
|
30
|
+
interceptor = MailInterceptor::Interceptor.new(options)
|
21
31
|
ActionMailer::Base.register_interceptor(interceptor)
|
22
32
|
```
|
23
33
|
|
24
|
-
|
34
|
+
### deliver_emails_to
|
25
35
|
|
26
36
|
Passing __deliver_emails_to__ is optional. If no "deliver_emails_to"
|
27
|
-
is passed then all emails will be forwarded
|
37
|
+
is passed then all emails will be intercepted and forwarded in
|
38
|
+
non-production environment.
|
28
39
|
|
29
40
|
Let's say that you want to actually deliver all emails having the pattern
|
30
|
-
"@BigBinary.com"
|
31
|
-
like `john@BigBinary.com` will not be intercepted and John will actually
|
32
|
-
get an email in non-production environment.
|
41
|
+
"@BigBinary.com". Here is how it can be accomplished.
|
33
42
|
|
43
|
+
```ruby
|
44
|
+
MailInterceptor::Interceptor.new({ forward_emails_to: 'intercepted_emails@domain.com',
|
45
|
+
deliver_emails_to: ["@bigbinary.com"] })
|
34
46
|
```
|
35
|
-
|
47
|
+
|
48
|
+
If you want the emails to be delivered only if the email address is
|
49
|
+
`qa@bigbinary.com` then that can be done too.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
MailInterceptor::Interceptor.new({ forward_emails_to: 'intercepted_emails@domain.com',
|
53
|
+
deliver_emails_to: ["qa@bigbinary.com"] })
|
36
54
|
```
|
37
55
|
|
56
|
+
Now only `qa@bigbinary.com` will get its emails delivered and all other emails
|
57
|
+
will be intercepted and forwarded.
|
58
|
+
|
38
59
|
The regular expression is matched without case sensitive. So you can mix lowercase
|
39
60
|
and uppercase and it won't matter.
|
40
61
|
|
41
|
-
|
62
|
+
### subject_prefix
|
42
63
|
|
43
64
|
__subject_prefix__ is optional. If it is supplied then it is added to
|
44
|
-
the front of the subject
|
65
|
+
the front of the subject. In non-production environment the environment
|
66
|
+
name is also added.
|
45
67
|
|
46
68
|
```
|
47
69
|
[WHEEL] Forgot password
|
48
70
|
[WHEEL STAGING] Forgot password
|
49
71
|
```
|
50
72
|
|
51
|
-
|
73
|
+
### forward_emails_to
|
52
74
|
|
53
75
|
This is a required field.
|
54
76
|
|
55
|
-
It
|
56
|
-
in which case emails are forwarded to each of those emails in the array.
|
77
|
+
It takes a single email as string.
|
57
78
|
|
79
|
+
```ruby
|
80
|
+
MailInterceptor::Interceptor.new({ forward_emails_to: 'intercepted_emails@bigbinary.com' })
|
81
|
+
```
|
58
82
|
|
59
|
-
|
83
|
+
It can also take an array of emails in which case emails are forwarded to each of those emails in the array.
|
60
84
|
|
85
|
+
```ruby
|
86
|
+
MailInterceptor::Interceptor.new({ forward_emails_to: ['intercepted_emails@bigbinary.com',
|
87
|
+
'qa@bigbinary.com' })
|
88
|
+
```
|
89
|
+
|
90
|
+
#### Brought to you by
|
61
91
|
|
62
|
-
![BigBinary](http://bigbinary.com/assets/common/logo.png)
|
92
|
+
[![BigBinary logo](http://bigbinary.com/assets/common/logo.png)](http://BigBinary.com)
|
data/lib/mail_interceptor.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/object/blank'
|
2
|
+
require 'active_support/core_ext/array'
|
1
3
|
require "mail_interceptor/version"
|
2
4
|
|
3
5
|
module MailInterceptor
|
@@ -9,11 +11,11 @@ module MailInterceptor
|
|
9
11
|
@subject_prefix = options[:subject_prefix] || ''
|
10
12
|
@forward_emails_to = options.fetch :forward_emails_to
|
11
13
|
|
14
|
+
add_env_info_to_subject_prefix
|
12
15
|
sanitize_forward_emails_to
|
13
16
|
end
|
14
17
|
|
15
18
|
def delivering_email message
|
16
|
-
add_env_info_to_subject_prefix
|
17
19
|
add_subject_prefix message
|
18
20
|
message.to = normalize_recipients(message.to).flatten.uniq
|
19
21
|
end
|
data/mail_interceptor.gemspec
CHANGED
@@ -17,9 +17,9 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
+
spec.add_runtime_dependency "activesupport"
|
20
21
|
spec.add_development_dependency "bundler"
|
21
|
-
spec.add_development_dependency "rake"
|
22
22
|
spec.add_development_dependency "minitest"
|
23
|
-
spec.add_development_dependency "activesupport"
|
24
23
|
spec.add_development_dependency "mocha"
|
24
|
+
spec.add_development_dependency "rake"
|
25
25
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
3
|
require 'minitest/autorun'
|
4
|
-
require 'active_support/all'
|
5
4
|
require 'ostruct'
|
6
5
|
require 'mocha/mini_test'
|
7
6
|
require_relative './../lib/mail_interceptor'
|
@@ -10,6 +9,7 @@ class MailInterceptorTest < Minitest::Test
|
|
10
9
|
|
11
10
|
def setup
|
12
11
|
@message = OpenStruct.new
|
12
|
+
stub_env_methods('test')
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_normalized_deliver_emails_to
|
@@ -37,7 +37,6 @@ class MailInterceptorTest < Minitest::Test
|
|
37
37
|
interceptor = ::MailInterceptor::Interceptor.new forward_emails_to: 'test@example.com',
|
38
38
|
subject_prefix: nil
|
39
39
|
@message.subject = 'Forgot password'
|
40
|
-
stub_env_methods(interceptor, 'test')
|
41
40
|
|
42
41
|
interceptor.delivering_email @message
|
43
42
|
assert_equal "Forgot password", @message.subject
|
@@ -47,17 +46,20 @@ class MailInterceptorTest < Minitest::Test
|
|
47
46
|
interceptor = ::MailInterceptor::Interceptor.new forward_emails_to: 'test@example.com',
|
48
47
|
subject_prefix: 'wheel'
|
49
48
|
@message.subject = 'Forgot password'
|
50
|
-
stub_env_methods(interceptor, 'test')
|
51
49
|
|
52
50
|
interceptor.delivering_email @message
|
53
51
|
assert_equal "[wheel TEST] Forgot password", @message.subject
|
52
|
+
|
53
|
+
@message.subject = 'Another Forgot password'
|
54
|
+
interceptor.delivering_email @message
|
55
|
+
assert_equal "[wheel TEST] Another Forgot password", @message.subject
|
54
56
|
end
|
55
57
|
|
56
58
|
def test_subject_prefix_in_production
|
59
|
+
stub_env_methods('production')
|
57
60
|
interceptor = ::MailInterceptor::Interceptor.new forward_emails_to: 'test@example.com',
|
58
61
|
subject_prefix: 'wheel'
|
59
62
|
@message.subject = 'Forgot password'
|
60
|
-
stub_env_methods(interceptor, 'production')
|
61
63
|
|
62
64
|
interceptor.delivering_email @message
|
63
65
|
assert_equal "[wheel] Forgot password", @message.subject
|
@@ -90,8 +92,8 @@ class MailInterceptorTest < Minitest::Test
|
|
90
92
|
|
91
93
|
private
|
92
94
|
|
93
|
-
def stub_env_methods(
|
94
|
-
|
95
|
-
|
95
|
+
def stub_env_methods(env)
|
96
|
+
::MailInterceptor::Interceptor.any_instance.stubs(:env).returns(env)
|
97
|
+
::MailInterceptor::Interceptor.any_instance.stubs(:production?).returns(env == 'production')
|
96
98
|
end
|
97
99
|
end
|
metadata
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail_interceptor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neeraj Singh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: mocha
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|