mail_gate 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -0
- data/lib/mail_gate/filter.rb +20 -0
- data/lib/mail_gate/version.rb +1 -1
- data/test/test_helper.rb +2 -1
- data/test/unit/mail_gate/filter_test.rb +21 -0
- metadata +6 -6
data/README.md
CHANGED
@@ -59,6 +59,28 @@ CNN::Application.configure do
|
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
62
|
+
When the email is sent, any emails that end up being extracted because they don't match the whitelist will be appended to the email's body so you know the intended recipients. So if you had a whitelist only for CNN.com, and you sent an email out to nytimes.com, it'd look something like:
|
63
|
+
|
64
|
+
```
|
65
|
+
Thanks for reading our interesting article!
|
66
|
+
|
67
|
+
Extracted Recipients: user@nytimes.com
|
68
|
+
```
|
69
|
+
|
70
|
+
If you dislike that behavior, you can easily turn it off by setting `append_emails` to `false` in the settings.
|
71
|
+
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# config/environments/staging.rb
|
75
|
+
CNN::Application.configure do
|
76
|
+
config.action_mailer.delivery_method = :mail_gate
|
77
|
+
config.action_mailer.mail_gate_settings = {
|
78
|
+
:whitelist => /cnn.com/,
|
79
|
+
:append_emails => false
|
80
|
+
}
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
62
84
|
By default the emails send will have the same subject that they normally would. If you'd like to customize the subject to inform the reader where it was sent from you can do that with the `:subject_prefix` option:
|
63
85
|
|
64
86
|
```ruby
|
data/lib/mail_gate/filter.rb
CHANGED
@@ -39,10 +39,21 @@ module MailGate
|
|
39
39
|
#
|
40
40
|
# Returns instance of Mail::Message.
|
41
41
|
def deliver!(mail)
|
42
|
+
unless settings[:append_emails] == false
|
43
|
+
original_emails = email_list(mail)
|
44
|
+
end
|
45
|
+
|
42
46
|
%w{ to cc bcc }.each do |field|
|
43
47
|
mail.send(:"#{field}=", filter_emails(mail.send(field)))
|
44
48
|
end
|
45
49
|
|
50
|
+
unless settings[:append_emails] == false
|
51
|
+
new_emails = original_emails - email_list(mail)
|
52
|
+
if !new_emails.empty?
|
53
|
+
mail.body = "#{mail.body}\n\nExtracted Recipients: #{new_emails.join(', ')}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
46
57
|
if settings[:subject_prefix]
|
47
58
|
mail.subject = settings[:subject_prefix] + mail.subject
|
48
59
|
end
|
@@ -82,5 +93,14 @@ module MailGate
|
|
82
93
|
|
83
94
|
email_list.length > 1 ? email_list : email_list.shift
|
84
95
|
end
|
96
|
+
|
97
|
+
# Private: Get all unique emails across all headers that the email may contain.
|
98
|
+
#
|
99
|
+
# mail - Mail object
|
100
|
+
#
|
101
|
+
# Return Array of email addresses.
|
102
|
+
def email_list(mail)
|
103
|
+
[mail.to, mail.bcc, mail.cc].flatten.uniq.compact
|
104
|
+
end
|
85
105
|
end
|
86
106
|
end
|
data/lib/mail_gate/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -29,7 +29,8 @@ class Test::Unit::TestCase
|
|
29
29
|
def with_whitelist(options={})
|
30
30
|
filter = MailGate::Filter.new \
|
31
31
|
:whitelist => options.delete(:whitelist),
|
32
|
-
:subject_prefix => options.delete(:subject_prefix)
|
32
|
+
:subject_prefix => options.delete(:subject_prefix),
|
33
|
+
:append_emails => options.delete(:append_emails)
|
33
34
|
|
34
35
|
mail = Mail.new options.merge(:from => 'test@mail_gate.com')
|
35
36
|
|
@@ -75,4 +75,25 @@ class TestFilter < Test::Unit::TestCase
|
|
75
75
|
|
76
76
|
assert_equal '[staging] Welcome to the site!', mail.subject
|
77
77
|
end
|
78
|
+
|
79
|
+
def test_append_emails_is_included
|
80
|
+
mail = with_whitelist \
|
81
|
+
:to => %w{ garrett@site.com matt@site.com luke@skywalker.com luke@copy.com },
|
82
|
+
:bcc => 'garrett@example.com',
|
83
|
+
:body => 'Test',
|
84
|
+
:whitelist => /site.com|copy.com/
|
85
|
+
|
86
|
+
assert_match /luke@skywalker.com\, garrett@example.com$/, mail.body.to_s
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_appended_emails_not_included
|
90
|
+
mail = with_whitelist \
|
91
|
+
:to => %w{ garrett@site.com matt@site.com luke@skywalker.com luke@copy.com },
|
92
|
+
:bcc => 'garrett@example.com',
|
93
|
+
:body => 'Test',
|
94
|
+
:whitelist => /site.com|copy.com/,
|
95
|
+
:append_emails => false
|
96
|
+
|
97
|
+
assert_no_match /Extracted Recipients/, mail.body.to_s
|
98
|
+
end
|
78
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail_gate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mail
|
16
|
-
requirement: &
|
16
|
+
requirement: &70139081871840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 2.4.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70139081871840
|
25
25
|
description: MailGate is an additional delivery method for the Mail gem that lets
|
26
26
|
you restrict the delivery of mail to only whitelisted emails.
|
27
27
|
email:
|
@@ -57,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
57
|
version: '0'
|
58
58
|
segments:
|
59
59
|
- 0
|
60
|
-
hash:
|
60
|
+
hash: 2893690760553553373
|
61
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
segments:
|
68
68
|
- 0
|
69
|
-
hash:
|
69
|
+
hash: 2893690760553553373
|
70
70
|
requirements: []
|
71
71
|
rubyforge_project:
|
72
72
|
rubygems_version: 1.8.17
|