mail_safe 0.1.0 → 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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/README.rdoc +20 -11
- data/Rakefile +62 -0
- data/VERSION.yml +3 -2
- data/lib/mail_safe/config.rb +18 -2
- data/mail_safe.gemspec +69 -0
- data/test/config_test.rb +147 -44
- metadata +15 -9
data/.document
ADDED
data/README.rdoc
CHANGED
@@ -10,36 +10,45 @@ with a note stating where the email was originally intended to go.
|
|
10
10
|
|
11
11
|
== Download
|
12
12
|
|
13
|
-
Github: http://github.com/myronmarston/mail_safe
|
13
|
+
Github: http://github.com/myronmarston/mail_safe
|
14
14
|
|
15
15
|
Gem:
|
16
|
-
gem install
|
16
|
+
gem install mail_safe --source http://gemcutter.org
|
17
17
|
|
18
|
-
==
|
18
|
+
== Installation
|
19
19
|
|
20
20
|
Load the gem in your non-production environments using Rails' 2.1+ gem support. For example, I'm loading this in
|
21
21
|
config/environments/development.rb and config/environments/staging.rb:
|
22
22
|
|
23
|
-
config.gem '
|
23
|
+
config.gem 'mail_safe', :source => 'http://gemcutter.org'
|
24
24
|
|
25
|
-
Be sure not to load this in your production
|
26
|
-
recipients.
|
25
|
+
IMPORTANT: Be sure not to load this in your production environment, otherwise, your emails won't be sent to the proper
|
26
|
+
recipients. In your test environment, you probably won't want this, either--rails ensures that no emails are ever sent in the
|
27
|
+
test environment, and tests that check outbound email recipients may fail.
|
27
28
|
|
28
|
-
|
29
|
+
== Configuration
|
30
|
+
|
31
|
+
In many cases, no configuration is necessary. If you have git installed, and you've registered your email address
|
32
|
+
with it (check with "git config user.email" in your shell), mail safe will use this. All emails will be sent to this address.
|
33
|
+
|
34
|
+
Otherwise, you can configure mail safe's behavior. Create a file at config/initializers/mail_safe.rb, similar to the following:
|
29
35
|
|
30
36
|
if defined?(MailSafe::Config)
|
31
37
|
MailSafe::Config.internal_address_definition = /.*@my-domain\.com/i
|
32
38
|
MailSafe::Config.replacement_address = 'me@my-domain.com'
|
33
39
|
end
|
34
40
|
|
35
|
-
The internal address definition determines which addresses will be ignored (i.e. sent normally) and which will be replaced. Email
|
36
|
-
addresses will be sent normally; all other email addresses will be replaced by the replacement address.
|
41
|
+
The internal address definition determines which addresses will be ignored (i.e. sent normally) and which will be replaced. Email
|
42
|
+
being sent to internal addresses will be sent normally; all other email addresses will be replaced by the replacement address.
|
37
43
|
|
38
44
|
These settings can also take procs if you need something more flexible:
|
39
45
|
|
40
46
|
if defined?(MailSafe::Config)
|
41
|
-
|
42
|
-
|
47
|
+
MailSafe::Config.internal_address_definition = lambda { |address|
|
48
|
+
address =~ /.*@domain1\.com/i ||
|
49
|
+
address =~ /.*@domain2\.com/i ||
|
50
|
+
address == 'full-address@domain.com'
|
51
|
+
}
|
43
52
|
|
44
53
|
# Useful if your mail server allows + dynamic email addresses like gmail.
|
45
54
|
MailSafe::Config.replacement_address = lambda { |address| "my-address+#{address.gsub(/[\w\-.]/, '_')}@gmail.com" }
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "mail_safe"
|
8
|
+
gem.summary = %Q{Keep your ActionMailer emails from escaping into the wild during development.}
|
9
|
+
gem.email = "myron.marston@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/myronmarston/mail_safe"
|
11
|
+
gem.authors = ["Myron Marston"]
|
12
|
+
|
13
|
+
gem.add_dependency 'activesupport'
|
14
|
+
gem.add_dependency 'actionmailer'
|
15
|
+
|
16
|
+
gem.add_development_dependency 'Shoulda'
|
17
|
+
gem.add_development_dependency 'mocha'
|
18
|
+
|
19
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
|
+
end
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
test.libs << 'lib' << 'test'
|
28
|
+
test.pattern = 'test/**/*_test.rb'
|
29
|
+
test.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
require 'rcov/rcovtask'
|
34
|
+
Rcov::RcovTask.new do |test|
|
35
|
+
test.libs << 'test'
|
36
|
+
test.pattern = 'test/**/*_test.rb'
|
37
|
+
test.verbose = true
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
task :rcov do
|
41
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
if File.exist?('VERSION.yml')
|
51
|
+
config = YAML.load(File.read('VERSION.yml'))
|
52
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
53
|
+
else
|
54
|
+
version = ""
|
55
|
+
end
|
56
|
+
|
57
|
+
rdoc.rdoc_dir = 'rdoc'
|
58
|
+
rdoc.title = "mail_safe #{version}"
|
59
|
+
rdoc.rdoc_files.include('README*')
|
60
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
61
|
+
end
|
62
|
+
|
data/VERSION.yml
CHANGED
data/lib/mail_safe/config.rb
CHANGED
@@ -8,7 +8,9 @@ module MailSafe
|
|
8
8
|
case internal_address_definition
|
9
9
|
when Regexp then address =~ internal_address_definition
|
10
10
|
when Proc then internal_address_definition.call(address)
|
11
|
-
else
|
11
|
+
else
|
12
|
+
return address.downcase == developer_email_address.downcase if developer_email_address
|
13
|
+
raise InvalidConfigSettingError.new("internal_address_definition must be a Regexp or Proc, but was: #{internal_address_definition.class.to_s}")
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
@@ -18,8 +20,22 @@ module MailSafe
|
|
18
20
|
case replacement_address
|
19
21
|
when String then replacement_address
|
20
22
|
when Proc then replacement_address.call(original_address)
|
21
|
-
else
|
23
|
+
else
|
24
|
+
return developer_email_address if developer_email_address
|
25
|
+
raise InvalidConfigSettingError.new("replacement_address must be a String or Proc, but was: #{replacement_address.class.to_s}")
|
22
26
|
end
|
23
27
|
end
|
28
|
+
|
29
|
+
def self.developer_email_address
|
30
|
+
unless defined?(@@developer_email_address)
|
31
|
+
@@developer_email_address = begin
|
32
|
+
`git config user.email`.chomp
|
33
|
+
rescue
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
@@developer_email_address
|
39
|
+
end
|
24
40
|
end
|
25
41
|
end
|
data/mail_safe.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mail_safe}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Myron Marston"]
|
12
|
+
s.date = %q{2009-11-06}
|
13
|
+
s.email = %q{myron.marston@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION.yml",
|
25
|
+
"lib/mail_safe.rb",
|
26
|
+
"lib/mail_safe/action_mailer.rb",
|
27
|
+
"lib/mail_safe/address_replacer.rb",
|
28
|
+
"lib/mail_safe/config.rb",
|
29
|
+
"mail_safe.gemspec",
|
30
|
+
"test/config_test.rb",
|
31
|
+
"test/mailer_test.rb",
|
32
|
+
"test/mailers/test_mailer.rb",
|
33
|
+
"test/test_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/myronmarston/mail_safe}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{Keep your ActionMailer emails from escaping into the wild during development.}
|
40
|
+
s.test_files = [
|
41
|
+
"test/config_test.rb",
|
42
|
+
"test/mailer_test.rb",
|
43
|
+
"test/mailers/test_mailer.rb",
|
44
|
+
"test/test_helper.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
53
|
+
s.add_runtime_dependency(%q<actionmailer>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<Shoulda>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
58
|
+
s.add_dependency(%q<actionmailer>, [">= 0"])
|
59
|
+
s.add_dependency(%q<Shoulda>, [">= 0"])
|
60
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
64
|
+
s.add_dependency(%q<actionmailer>, [">= 0"])
|
65
|
+
s.add_dependency(%q<Shoulda>, [">= 0"])
|
66
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
data/test/config_test.rb
CHANGED
@@ -1,74 +1,177 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ConfigTest < Test::Unit::TestCase
|
4
|
-
context '
|
5
|
-
|
6
|
-
|
4
|
+
context '#developer_email_address' do
|
5
|
+
teardown do
|
6
|
+
# clear class variable caching...
|
7
|
+
MailSafe::Config.class_eval do
|
8
|
+
remove_class_variable(:@@developer_email_address)
|
9
|
+
end
|
7
10
|
end
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
context 'when git is installed' do
|
13
|
+
setup do
|
14
|
+
backtick_call_count = 0
|
15
|
+
# mock out the ` method. I can't find a simpler way to do this with mocha.
|
16
|
+
Kernel.class_eval do
|
17
|
+
define_method '`'.to_sym do |cmd|
|
18
|
+
backtick_call_count += 1
|
19
|
+
return "too many calls" if backtick_call_count > 1
|
20
|
+
if cmd == 'git config user.email'
|
21
|
+
"developer@domain.com\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
12
26
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
27
|
+
should "guess the developer's email address using git" do
|
28
|
+
assert_equal 'developer@domain.com', MailSafe::Config.developer_email_address
|
29
|
+
end
|
17
30
|
|
18
|
-
|
19
|
-
|
20
|
-
|
31
|
+
should "cache the developer's email address so multiple system calls aren't made" do
|
32
|
+
assert_equal MailSafe::Config.developer_email_address, MailSafe::Config.developer_email_address
|
33
|
+
end
|
21
34
|
end
|
22
35
|
|
23
|
-
|
24
|
-
|
25
|
-
|
36
|
+
context 'when git is not installed' do
|
37
|
+
setup do
|
38
|
+
backtick_call_count = 0
|
39
|
+
# mock out the ` method. I can't find a simpler way to do this with mocha.
|
40
|
+
Kernel.class_eval do
|
41
|
+
define_method '`'.to_sym do |cmd|
|
42
|
+
backtick_call_count += 1
|
43
|
+
return "too many calls" if backtick_call_count > 1
|
44
|
+
if cmd == 'git config user.email'
|
45
|
+
raise RuntimeError.new("Git is not installed")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
should "return nil" do
|
52
|
+
assert_nil MailSafe::Config.developer_email_address
|
53
|
+
end
|
26
54
|
|
27
|
-
|
28
|
-
|
55
|
+
should "cache the developer's email address so multiple system calls aren't made" do
|
56
|
+
assert_equal MailSafe::Config.developer_email_address, MailSafe::Config.developer_email_address
|
57
|
+
end
|
29
58
|
end
|
30
59
|
end
|
31
60
|
|
32
|
-
context '
|
33
|
-
|
34
|
-
|
35
|
-
|
61
|
+
context '#is_internal_address?' do
|
62
|
+
context 'when internal_address_definition is not set' do
|
63
|
+
setup do
|
64
|
+
MailSafe::Config.internal_address_definition = nil
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'and #developer_email_address has a value' do
|
68
|
+
setup do
|
69
|
+
@developer_address = 'developer@domain.com'
|
70
|
+
MailSafe::Config.expects(:developer_email_address).at_least_once.returns(@developer_address)
|
71
|
+
end
|
72
|
+
|
73
|
+
should 'return true when passed the developer email address' do
|
74
|
+
assert MailSafe::Config.is_internal_address?(@developer_address)
|
75
|
+
end
|
76
|
+
|
77
|
+
should 'return true when passed the developer email address with different casing' do
|
78
|
+
assert MailSafe::Config.is_internal_address?(@developer_address.upcase)
|
79
|
+
end
|
36
80
|
|
37
|
-
|
38
|
-
|
39
|
-
|
81
|
+
should 'return false when passed another email address' do
|
82
|
+
assert !MailSafe::Config.is_internal_address?('another-address@domain.com')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'and #developer_email_address has no value' do
|
87
|
+
setup do
|
88
|
+
MailSafe::Config.expects(:developer_email_address).returns(nil)
|
89
|
+
end
|
90
|
+
|
91
|
+
should 'raise an error' do
|
92
|
+
assert_raise MailSafe::InvalidConfigSettingError do
|
93
|
+
MailSafe::Config.is_internal_address?('abc@foo.com')
|
94
|
+
end
|
95
|
+
end
|
40
96
|
end
|
41
97
|
end
|
42
|
-
end
|
43
98
|
|
44
|
-
|
45
|
-
|
46
|
-
|
99
|
+
context 'when internal_address_definition is set to a regexp' do
|
100
|
+
setup do
|
101
|
+
MailSafe::Config.internal_address_definition = /.*@example\.com/
|
102
|
+
end
|
103
|
+
|
104
|
+
should 'return true if the address matches the regexp' do
|
105
|
+
assert MailSafe::Config.is_internal_address?('someone@example.com')
|
106
|
+
end
|
107
|
+
|
108
|
+
should 'return false if the address does not match the regexp' do
|
109
|
+
assert !MailSafe::Config.is_internal_address?('someone@another-domain.com')
|
110
|
+
end
|
47
111
|
end
|
48
112
|
|
49
|
-
|
50
|
-
|
113
|
+
context 'When internal_address_definition is set to a lambda, #is_internal_address?' do
|
114
|
+
setup do
|
115
|
+
MailSafe::Config.internal_address_definition = lambda { |address| address.size < 15 }
|
116
|
+
end
|
117
|
+
|
118
|
+
should 'return true if the lambda returns true for the given address' do
|
119
|
+
assert MailSafe::Config.is_internal_address?('abc@foo.com')
|
120
|
+
end
|
121
|
+
|
122
|
+
should 'return false if the lambda returns false for the given address' do
|
123
|
+
assert !MailSafe::Config.is_internal_address?('a-long-address@example.com')
|
124
|
+
end
|
51
125
|
end
|
52
126
|
end
|
53
127
|
|
54
|
-
context '
|
55
|
-
|
56
|
-
|
57
|
-
|
128
|
+
context '#get_replacement_address' do
|
129
|
+
context 'when replacement_address is set to a string' do
|
130
|
+
setup do
|
131
|
+
MailSafe::Config.replacement_address = 'me@mydomain.com'
|
132
|
+
end
|
58
133
|
|
59
|
-
|
60
|
-
|
134
|
+
should 'return the configured replacement address' do
|
135
|
+
assert_equal 'me@mydomain.com', MailSafe::Config.get_replacement_address('you@example.com')
|
136
|
+
end
|
61
137
|
end
|
62
|
-
end
|
63
138
|
|
64
|
-
|
65
|
-
|
66
|
-
|
139
|
+
context 'when replacement_address is set to a proc' do
|
140
|
+
setup do
|
141
|
+
MailSafe::Config.replacement_address = lambda { |address| "me+#{address.split('@').first}@mydomain.com" }
|
142
|
+
end
|
143
|
+
|
144
|
+
should 'return the configured replacement address' do
|
145
|
+
assert_equal 'me+you@mydomain.com', MailSafe::Config.get_replacement_address('you@example.com')
|
146
|
+
end
|
67
147
|
end
|
68
148
|
|
69
|
-
|
70
|
-
|
71
|
-
MailSafe::Config.
|
149
|
+
context 'when replacement_address is not set' do
|
150
|
+
setup do
|
151
|
+
MailSafe::Config.replacement_address = nil
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'and #developer_email_address has a value' do
|
155
|
+
setup do
|
156
|
+
@developer_address = 'developer@domain.com'
|
157
|
+
MailSafe::Config.expects(:developer_email_address).at_least_once.returns(@developer_address)
|
158
|
+
end
|
159
|
+
|
160
|
+
should 'return the developer address' do
|
161
|
+
assert_equal @developer_address, MailSafe::Config.get_replacement_address('you@example.com')
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'and #developer_email_address has no value' do
|
166
|
+
setup do
|
167
|
+
MailSafe::Config.expects(:developer_email_address).returns(nil)
|
168
|
+
end
|
169
|
+
|
170
|
+
should 'raise an error' do
|
171
|
+
assert_raise MailSafe::InvalidConfigSettingError do
|
172
|
+
MailSafe::Config.get_replacement_address('you@example.com')
|
173
|
+
end
|
174
|
+
end
|
72
175
|
end
|
73
176
|
end
|
74
177
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail_safe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Myron Marston
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-06 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -59,27 +59,30 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
|
61
61
|
extra_rdoc_files:
|
62
|
-
- README.rdoc
|
63
62
|
- LICENSE
|
63
|
+
- README.rdoc
|
64
64
|
files:
|
65
|
+
- .document
|
66
|
+
- .gitignore
|
67
|
+
- LICENSE
|
65
68
|
- README.rdoc
|
69
|
+
- Rakefile
|
66
70
|
- VERSION.yml
|
71
|
+
- lib/mail_safe.rb
|
67
72
|
- lib/mail_safe/action_mailer.rb
|
68
73
|
- lib/mail_safe/address_replacer.rb
|
69
74
|
- lib/mail_safe/config.rb
|
70
|
-
-
|
75
|
+
- mail_safe.gemspec
|
71
76
|
- test/config_test.rb
|
72
77
|
- test/mailer_test.rb
|
73
78
|
- test/mailers/test_mailer.rb
|
74
79
|
- test/test_helper.rb
|
75
|
-
- LICENSE
|
76
80
|
has_rdoc: true
|
77
81
|
homepage: http://github.com/myronmarston/mail_safe
|
78
82
|
licenses: []
|
79
83
|
|
80
84
|
post_install_message:
|
81
85
|
rdoc_options:
|
82
|
-
- --inline-source
|
83
86
|
- --charset=UTF-8
|
84
87
|
require_paths:
|
85
88
|
- lib
|
@@ -100,7 +103,10 @@ requirements: []
|
|
100
103
|
rubyforge_project:
|
101
104
|
rubygems_version: 1.3.5
|
102
105
|
signing_key:
|
103
|
-
specification_version:
|
106
|
+
specification_version: 3
|
104
107
|
summary: Keep your ActionMailer emails from escaping into the wild during development.
|
105
|
-
test_files:
|
106
|
-
|
108
|
+
test_files:
|
109
|
+
- test/config_test.rb
|
110
|
+
- test/mailer_test.rb
|
111
|
+
- test/mailers/test_mailer.rb
|
112
|
+
- test/test_helper.rb
|