email_blacklist 0.1.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 +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +35 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/email_blacklist.rb +39 -0
- data/spec/email_blacklist_spec.rb +81 -0
- data/spec/mailers/test_mailer.rb +10 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +12 -0
- metadata +97 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Myron Marston
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
= email_blacklist
|
2
|
+
|
3
|
+
Blacklist particular email addresses so ActionMailer doesn't deliver emails to them.
|
4
|
+
|
5
|
+
This is useful in a variety of situations:
|
6
|
+
* You can blacklist an entire domain.
|
7
|
+
* You can stop emails from being sent to users who have deactivated their accounts with your app.
|
8
|
+
* Any other reason you might want to stop emails from being sent...
|
9
|
+
|
10
|
+
== Installation
|
11
|
+
gem install email_blacklist
|
12
|
+
|
13
|
+
== Configuration
|
14
|
+
|
15
|
+
Blacklisting is as easy as:
|
16
|
+
|
17
|
+
EmailBlacklist::Config.blacklist do |email_address|
|
18
|
+
# return true if emails should not be sent to this email address.
|
19
|
+
end
|
20
|
+
|
21
|
+
The block you provide will be called with every email address used by any ActionMailer email. This includes to, cc and bcc addresses.
|
22
|
+
|
23
|
+
== Note on Patches/Pull Requests
|
24
|
+
|
25
|
+
* Fork the project.
|
26
|
+
* Make your feature addition or bug fix.
|
27
|
+
* Add tests for it. This is important so I don't break it in a
|
28
|
+
future version unintentionally.
|
29
|
+
* Commit, do not mess with rakefile, version, or history.
|
30
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
31
|
+
* Send me a pull request. Bonus points for topic branches.
|
32
|
+
|
33
|
+
== Copyright
|
34
|
+
|
35
|
+
Copyright (c) 2009 Myron Marston. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "email_blacklist"
|
8
|
+
gem.summary = %Q{Ensure no emails are ever sent to particular email addresses.}
|
9
|
+
gem.description = %Q{Blacklist particular email addresses so ActionMailer doesn't deliver emails to them.}
|
10
|
+
gem.email = "myron.marston@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/myronmarston/email_blacklist"
|
12
|
+
gem.authors = ["Myron Marston"]
|
13
|
+
gem.add_dependency 'mynyml-override'
|
14
|
+
gem.add_dependency 'actionmailer'
|
15
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "email_blacklist #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'action_mailer'
|
2
|
+
require 'override'
|
3
|
+
|
4
|
+
module EmailBlacklist
|
5
|
+
ADDRESS_TYPES = [:to, :cc, :bcc].freeze
|
6
|
+
|
7
|
+
class Config
|
8
|
+
class << self
|
9
|
+
def blacklist(&blk)
|
10
|
+
@@blacklist_block = blk
|
11
|
+
end
|
12
|
+
|
13
|
+
def blacklisted?(email_address)
|
14
|
+
return false unless @@blacklist_block
|
15
|
+
@@blacklist_block.call(email_address) ? true : false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
ActionMailer::Base.class_eval do
|
22
|
+
override :deliver!
|
23
|
+
def deliver!(mail = @mail)
|
24
|
+
if mail
|
25
|
+
all_addresses = []
|
26
|
+
|
27
|
+
EmailBlacklist::ADDRESS_TYPES.each do |address_type|
|
28
|
+
addresses = mail.send(address_type)
|
29
|
+
addresses.reject! { |a| EmailBlacklist::Config.blacklisted?(a) } if addresses
|
30
|
+
all_addresses << addresses
|
31
|
+
mail.send("#{address_type}=", addresses)
|
32
|
+
end
|
33
|
+
|
34
|
+
return if all_addresses.flatten.compact.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
super(mail)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/mailers/test_mailer')
|
3
|
+
|
4
|
+
describe EmailBlacklist::Config do
|
5
|
+
context 'when the blacklisted.org domain is blacklisted' do
|
6
|
+
before(:all) do
|
7
|
+
EmailBlacklist::Config.blacklist do |email_address|
|
8
|
+
email_address =~ /blacklisted\.org/
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return true for #blacklisted?("bob@blacklisted.org")' do
|
13
|
+
EmailBlacklist::Config.blacklisted?("bob@blacklisted.org").should == true
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should return false for #blacklisted?("bob@gmail.com")' do
|
17
|
+
EmailBlacklist::Config.blacklisted?("bob@gmail.com").should == false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when no blacklist is defined' do
|
22
|
+
before(:all) do
|
23
|
+
EmailBlacklist::Config.blacklist # ensure it's nil...
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should return false for #blacklisted?("bob@blacklisted.org")' do
|
27
|
+
EmailBlacklist::Config.blacklisted?("bob@blacklisted.org").should == false
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return false for #blacklisted?("bob@gmail.com")' do
|
31
|
+
EmailBlacklist::Config.blacklisted?("bob@gmail.com").should == false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ActionMailer do
|
37
|
+
context 'when the blacklisted.org domain is blacklisted' do
|
38
|
+
before(:all) do
|
39
|
+
EmailBlacklist::Config.blacklist do |email_address|
|
40
|
+
email_address =~ /blacklisted\.org/
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
EmailBlacklist::ADDRESS_TYPES.each do |blacklisted_address_type|
|
45
|
+
other_address_types = (EmailBlacklist::ADDRESS_TYPES - [blacklisted_address_type])
|
46
|
+
context "sending an email with #{blacklisted_address_type} set to 'bob@blacklisted.org' and #{other_address_types.join(" and ")} set to 'valid_address@gmail.com'" do
|
47
|
+
before(:all) do
|
48
|
+
options = { blacklisted_address_type => 'bob@blacklisted.org' }
|
49
|
+
other_address_types.each { |t| options[t] = 'valid_address@gmail.com' }
|
50
|
+
@email = TestMailer.deliver_email(options)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not deliver it to 'bob@blacklisted.org' for the #{blacklisted_address_type} address" do
|
54
|
+
@email.send(blacklisted_address_type).should be_nil
|
55
|
+
end
|
56
|
+
|
57
|
+
other_address_types.each do |t|
|
58
|
+
it "should deliver it to 'valid_address@gmail.com' for the #{t} address" do
|
59
|
+
@email.send(t).should == ['valid_address@gmail.com']
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "sending an email to just 'bob@blacklisted.org'" do
|
66
|
+
before(:each) do
|
67
|
+
ActionMailer::Base.deliveries.clear
|
68
|
+
TestMailer.deliver_email({:to => 'bob@blacklisted.org'})
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should not send the email at all" do
|
72
|
+
ActionMailer::Base.deliveries.should == []
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not include the friendly name in the call to #blacklisted?" do
|
78
|
+
EmailBlacklist::Config.should_receive(:blacklisted?).with('bob@blacklisted.org')
|
79
|
+
TestMailer.deliver_email({:to => 'Bob <bob@blacklisted.org>'})
|
80
|
+
end
|
81
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'email_blacklist'
|
5
|
+
require 'spec'
|
6
|
+
require 'spec/autorun'
|
7
|
+
|
8
|
+
ActionMailer::Base.delivery_method = :test
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: email_blacklist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Myron Marston
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-21 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mynyml-override
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: actionmailer
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.2.9
|
44
|
+
version:
|
45
|
+
description: Blacklist particular email addresses so ActionMailer doesn't deliver emails to them.
|
46
|
+
email: myron.marston@gmail.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- lib/email_blacklist.rb
|
62
|
+
- spec/email_blacklist_spec.rb
|
63
|
+
- spec/mailers/test_mailer.rb
|
64
|
+
- spec/spec.opts
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://github.com/myronmarston/email_blacklist
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options:
|
72
|
+
- --charset=UTF-8
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: "0"
|
86
|
+
version:
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.3.5
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Ensure no emails are ever sent to particular email addresses.
|
94
|
+
test_files:
|
95
|
+
- spec/email_blacklist_spec.rb
|
96
|
+
- spec/mailers/test_mailer.rb
|
97
|
+
- spec/spec_helper.rb
|