futurechimp-sanitize_email 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +154 -0
- data/Rakefile +78 -0
- data/VERSION.yml +5 -0
- data/init.rb +1 -0
- data/lib/sanitize_email.rb +6 -0
- data/lib/sanitize_email/custom_environments.rb +21 -0
- data/lib/sanitize_email/sanitize_email.rb +109 -0
- data/sanitize_email.gemspec +55 -0
- data/test/sample_mailer.rb +24 -0
- data/test/sanitize_email_test.rb +76 -0
- data/test/test_helper.rb +16 -0
- metadata +83 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Peter H. Boling of 9thBit LLC
|
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,154 @@
|
|
1
|
+
= sanitize_email
|
2
|
+
|
3
|
+
This gem allows you to globally override your mail delivery settings. It's particularly helpful when you want to omit the delivery of email (e.g. in development/test environments) or alter the to/cc/bcc (e.g. in staging or demo environments) of all email generated from your application.
|
4
|
+
|
5
|
+
It is a "configure it and forget it" type gem that requires very little setup. It includes some very innocuous monkey patching of ActionMailer::Base to work its magic.
|
6
|
+
|
7
|
+
It currently solves three common problems in ruby web applications that use ActionMailer:
|
8
|
+
|
9
|
+
=== Working Locally with Production Data
|
10
|
+
|
11
|
+
Peter described this common problem in his original plugin implementation as such:
|
12
|
+
|
13
|
+
* I have a production site with live data.
|
14
|
+
* I dump the live data and securely transfer it to another machine (rync -e ssh), and import it using a few rake tasks here: http://github.com/pboling/sir-du-bob
|
15
|
+
* On this separate machine (staging, or development) I run tests, and test various features which often send out email (registration/signup, order placement, etc.)
|
16
|
+
* I usually want the emails to get sent from these non-production environments so I can verify what they look like when sent, but I don't ever want to risk them getting sent to addresses that are not mine.
|
17
|
+
|
18
|
+
=== Re-routing Email on a Staging or QA Server
|
19
|
+
|
20
|
+
Another very important use case for me is to transparently re-route email generated from a staging or QA server to an appropriate person. For example, it's common for us to set up a staging server for a client to use to view our progress and test out new features. It's important for any email that is generated from our web application be delivered to the client's inbox so that they can review the content and ensure that it's acceptable. Similarly, we set up QA instances for our own QA team and we use {rails-caddy}[http://github.com/jtrupiano/rails-caddy] to allow each QA person to configure it specifically for them.
|
21
|
+
|
22
|
+
=== Testing Email from a Hot Production Server
|
23
|
+
|
24
|
+
If you install this gem on a production server (which I don't always do), you can load up script/console and override the to/cc/bcc on all emails for the duration of your console session. This allows you to poke and prod a live production instance, and route all email to your own inbox for inspection. The best part is that this can all be accomplished without changing a single line of your application code.
|
25
|
+
|
26
|
+
== Install as a RubyGem
|
27
|
+
|
28
|
+
Gem Using Git building from source:
|
29
|
+
|
30
|
+
mkdir -p ~/src
|
31
|
+
cd ~/src
|
32
|
+
git clone git://github.com/pboling/sanitize_email.git
|
33
|
+
cd sanitize_email
|
34
|
+
gem build sanitize_email.gemspec
|
35
|
+
sudo gem install sanitize_email-0.3.6.gem # (Or whatever version gets built)
|
36
|
+
|
37
|
+
Gemcutter is the hot new gem host, and you can use it like this:
|
38
|
+
|
39
|
+
[sudo] gem install gemcutter
|
40
|
+
[sudo] gem tumble # makes gemcutter gem source first in line
|
41
|
+
[sudo] gem install sanitize_email
|
42
|
+
|
43
|
+
Then in your environment.rb (if you are just going to use it from the console, you can require it as needed there, and skip the config.gem):
|
44
|
+
|
45
|
+
config.gem 'sanitize_email'
|
46
|
+
|
47
|
+
Then cd to your rails app to optionally freeze the gem into your app (if you roll this way):
|
48
|
+
|
49
|
+
rake gems:freeze GEM=sanitize_email
|
50
|
+
|
51
|
+
== Install as a Plugin
|
52
|
+
|
53
|
+
Plugin using Git:
|
54
|
+
|
55
|
+
# Installation as plugin works too! (let me know if you find any bugs, as I don't ever run it this way.)
|
56
|
+
./script/plugin install git://github.com/pboling/sanitize_email.git
|
57
|
+
|
58
|
+
== Install as a Git Submodule (plugin)
|
59
|
+
|
60
|
+
git submodule add git://github.com/pboling/sanitize_email.git vendor/plugins/sanitize_email
|
61
|
+
|
62
|
+
== Setup
|
63
|
+
|
64
|
+
It only requires a few lines of configuration:
|
65
|
+
|
66
|
+
* Rails 1.x: Add to bottom of environment.rb
|
67
|
+
|
68
|
+
* Rails 2.x: Use an initializer, stick it in any initializer file, or create a new one for sanitize_email
|
69
|
+
|
70
|
+
Add this bit and customize for your app:
|
71
|
+
|
72
|
+
# Settings for sanitize_email gem. These can be overridden in individual config/%env%/environment.rb files.
|
73
|
+
|
74
|
+
require 'sanitize_email'
|
75
|
+
ActionMailer::Base.sanitized_recipients = "jtrupiano@gmail.com"
|
76
|
+
ActionMailer::Base.sanitized_bcc = nil
|
77
|
+
ActionMailer::Base.sanitized_cc = nil
|
78
|
+
|
79
|
+
# optionally, you can configure sanitize_email to to include the "real" email address as the 'user name' of the
|
80
|
+
# "sanitized" email (e.g. "real@address.com <sanitized@email.com>")
|
81
|
+
ActionMailer::Base.use_actual_email_as_sanitized_user_name = true # defaults to false
|
82
|
+
|
83
|
+
# These are the environments whose outgoing email BCC, CC and recipients fields will be overridden!
|
84
|
+
# All environments not listed will be treated as normal.
|
85
|
+
ActionMailer::Base.local_environments = %w( development test staging )
|
86
|
+
|
87
|
+
Keep in mind, this is ruby (and possibly rails), so you can add conditionals or utilize different environment.rb files to customize these settings on a per-environment basis.
|
88
|
+
|
89
|
+
But wait there's more:
|
90
|
+
|
91
|
+
Let's say you have a method in your model that you can call to test the signup email.
|
92
|
+
You want to be able to test sending it to any user at any time... but you don't want
|
93
|
+
the user to ACTUALLY get the email, even in production. A dilemma, yes? Not anymore!
|
94
|
+
|
95
|
+
All your mailers get a force_sanitize class method which takes precedence over the environment override.
|
96
|
+
|
97
|
+
When force_sanitize is nil it will not be used by sanitize_email to determine if it should override the recipients, bcc, and cc.
|
98
|
+
|
99
|
+
|
100
|
+
== Example
|
101
|
+
|
102
|
+
So here's how you can use force_sanitize to override the override.
|
103
|
+
|
104
|
+
Even if you set:
|
105
|
+
|
106
|
+
ActionMailer::Base.local_environments = %w( development )
|
107
|
+
|
108
|
+
and are in the development environment, you can override the override anywhere in your code.
|
109
|
+
|
110
|
+
class User < ActiveRecord::Base
|
111
|
+
def test_signup_email_me_only
|
112
|
+
UserMailer.force_sanitize = true
|
113
|
+
UserMailer.deliver_signup_notification(self)
|
114
|
+
UserMailer.force_sanitize = nil
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_signup_email_user_only
|
118
|
+
UserMailer.force_sanitize = false
|
119
|
+
UserMailer.deliver_signup_notification(self)
|
120
|
+
UserMailer.force_sanitize = nil
|
121
|
+
end
|
122
|
+
|
123
|
+
# this third method would conditionally use the overridden recipients based on current Rails environment
|
124
|
+
def test_signup_email_environment
|
125
|
+
UserMailer.deliver_signup_notification(self)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
Load the console with ruby script/console and regardless of what environment you are in:
|
130
|
+
|
131
|
+
> User.find(4).test_signup_email_me_only
|
132
|
+
|
133
|
+
and the email will have it's recipients, bcc, and cc overridden to be whatever you set the sanitized values to be.
|
134
|
+
Then if you want to send it to the actual user, instead of yourself
|
135
|
+
|
136
|
+
> User.find(4).test_signup_email_user_only
|
137
|
+
|
138
|
+
== Authors
|
139
|
+
|
140
|
+
Peter Boling is the author of the gem/plugin. John Trupiano did the initial conversion from plugin to gem as well as improving the code.
|
141
|
+
|
142
|
+
== Contributors
|
143
|
+
|
144
|
+
George Anderson's work / improvements has been merged in.
|
145
|
+
|
146
|
+
== References
|
147
|
+
* {Source Code}[http://github.com/pboling/sanitize_email]
|
148
|
+
* {Gem Release Announcement}[http://blog.smartlogicsolutions.com/2009/04/25/reintroducing-sanitize_email-work-with-production-email-without-fear/]
|
149
|
+
* {Peter's Original Writeup}[http://galtzo.blogspot.com/2008/11/sanitize-email-never-worry-about.html]
|
150
|
+
* {Using sanitize_email to Preview HTML Emails Locally}[http://blog.smartlogicsolutions.com/2009/04/30/using-sanitize-email-to-preview-html-emails-locally/]
|
151
|
+
|
152
|
+
Copyright (c) 2008-9 {Peter H. Boling}[http://www.peterboling.com/about.html] of {9thBit LLC}[http://www.peterboling.com/]
|
153
|
+
Copyright (c) 2009 {John Trupiano}[http://smartlogicsolutions.com/wiki/John_Trupiano] of {SmartLogic Solutions, LLC}[http://www.smartlogicsolutions.com]
|
154
|
+
Released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gemspec|
|
8
|
+
gemspec.name = "futurechimp-sanitize_email"
|
9
|
+
gemspec.summary = "Tool to aid in development, testing, qa, and production troubleshooting of email issues without worrying that emails will get sent to actual live addresses."
|
10
|
+
gemspec.description = %q{Test an application's email abilities without ever sending a message to actual live addresses}
|
11
|
+
gemspec.email = ['peter.boling@gmail.com', 'jtrupiano@gmail.com', 'george@benevolentcode.com', 'dave.hrycyszyn@headlondon.com']
|
12
|
+
gemspec.homepage = "http://github.com/pboling/sanitize_email"
|
13
|
+
gemspec.authors = ["Peter Boling", "John Trupiano", "George Anderson", "Dave Hrycyszyn"]
|
14
|
+
gemspec.add_dependency 'actionmailer'
|
15
|
+
gemspec.files = ["lib/sanitize_email/custom_environments.rb",
|
16
|
+
"lib/sanitize_email/sanitize_email.rb",
|
17
|
+
"lib/sanitize_email.rb",
|
18
|
+
"init.rb",
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"Rakefile",
|
21
|
+
"README.rdoc",
|
22
|
+
"sanitize_email.gemspec",
|
23
|
+
"VERSION.yml",
|
24
|
+
"test/sample_mailer.rb",
|
25
|
+
"test/sanitize_email_test.rb"]
|
26
|
+
end
|
27
|
+
Jeweler::GemcutterTasks.new
|
28
|
+
rescue LoadError
|
29
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Default: run unit tests.'
|
33
|
+
task :default => :test
|
34
|
+
|
35
|
+
desc 'Test the sanitize_email plugin.'
|
36
|
+
Rake::TestTask.new(:test) do |t|
|
37
|
+
t.libs << 'lib'
|
38
|
+
t.pattern = 'test/**/*_test.rb'
|
39
|
+
t.verbose = true
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Generate documentation for the sanitize_email plugin.'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
config = YAML.load(File.read('VERSION.yml'))
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "sanitize_email #{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
51
|
+
|
52
|
+
# Rubyforge documentation task
|
53
|
+
begin
|
54
|
+
require 'rake/contrib/sshpublisher'
|
55
|
+
namespace :rubyforge do
|
56
|
+
|
57
|
+
desc "Release gem and RDoc documentation to RubyForge"
|
58
|
+
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
59
|
+
|
60
|
+
namespace :release do
|
61
|
+
desc "Publish RDoc to RubyForge."
|
62
|
+
task :docs => [:rdoc] do
|
63
|
+
config = YAML.load(
|
64
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
65
|
+
)
|
66
|
+
|
67
|
+
host = "#{config['username']}@rubyforge.org"
|
68
|
+
remote_dir = "/var/www/gforge-projects/johntrupiano/sanitize_email/"
|
69
|
+
local_dir = 'rdoc'
|
70
|
+
|
71
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
rescue LoadError
|
76
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
77
|
+
end
|
78
|
+
|
data/VERSION.yml
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'sanitize_email'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#Copyright (c) 2008-9 Peter H. Boling of 9thBit LLC
|
2
|
+
#Released under the MIT license
|
3
|
+
|
4
|
+
module NinthBit
|
5
|
+
module CustomEnvironments
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(ClassMethods)
|
9
|
+
|
10
|
+
base.cattr_accessor :local_environments
|
11
|
+
base.local_environments = %w( development test )
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def consider_local?
|
16
|
+
local_environments.include?(defined?(Rails) ? Rails.env : RAILS_ENV)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#Copyright (c) 2008-9 Peter H. Boling of 9thBit LLC
|
2
|
+
#Released under the MIT license
|
3
|
+
|
4
|
+
module NinthBit
|
5
|
+
module SanitizeEmail
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
|
9
|
+
# Adds the following class attributes to the classes that include NinthBit::SanitizeEmail
|
10
|
+
base.cattr_accessor :force_sanitize
|
11
|
+
base.force_sanitize = nil
|
12
|
+
|
13
|
+
# Specify the BCC addresses for the messages that go out in 'local' environments
|
14
|
+
base.cattr_accessor :sanitized_bcc
|
15
|
+
base.sanitized_bcc = nil
|
16
|
+
|
17
|
+
# Specify the CC addresses for the messages that go out in 'local' environments
|
18
|
+
base.cattr_accessor :sanitized_cc
|
19
|
+
base.sanitized_cc = nil
|
20
|
+
|
21
|
+
# The recipient addresses for the messages, either as a string (for a single
|
22
|
+
# address) or an array (for multiple addresses) that go out in 'local' environments
|
23
|
+
base.cattr_accessor :sanitized_recipients
|
24
|
+
base.sanitized_recipients = nil
|
25
|
+
|
26
|
+
# Use the 'real' email address as the username for the sanitized email address
|
27
|
+
# e.g. "real@example.com <sanitized@example.com>"
|
28
|
+
base.cattr_accessor :use_actual_email_as_sanitized_user_name
|
29
|
+
base.use_actual_email_as_sanitized_user_name = false
|
30
|
+
|
31
|
+
# Prepend the 'real' email address onto the Subject line of the message
|
32
|
+
# e.g. "real@example.com rest of subject"
|
33
|
+
base.cattr_accessor :use_actual_email_prepended_to_subject
|
34
|
+
base.use_actual_email_prepended_to_subject = false
|
35
|
+
|
36
|
+
base.class_eval do
|
37
|
+
# We need to alias these methods so that our new methods get used instead
|
38
|
+
alias :real_bcc :bcc
|
39
|
+
alias :real_cc :cc
|
40
|
+
alias :real_recipients :recipients
|
41
|
+
alias :real_subject :subject
|
42
|
+
|
43
|
+
def localish?
|
44
|
+
# consider_local is a method in sanitize_email/lib/custom_environments.rb
|
45
|
+
# it is included in ActionMailer in sanitize_email/init.rb
|
46
|
+
!self.class.force_sanitize.nil? ? self.class.force_sanitize : self.class.consider_local?
|
47
|
+
end
|
48
|
+
|
49
|
+
def subject(*lines)
|
50
|
+
real_subject(*lines)
|
51
|
+
localish? ? override_subject : real_subject
|
52
|
+
end
|
53
|
+
|
54
|
+
def recipients(*addresses)
|
55
|
+
real_recipients(*addresses)
|
56
|
+
if localish?
|
57
|
+
puts "sanitize_email error: sanitized_recipients is not set" if self.class.sanitized_recipients.nil?
|
58
|
+
override_email(:recipients)
|
59
|
+
else
|
60
|
+
real_recipients
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def cc(*addresses)
|
65
|
+
real_cc(*addresses)
|
66
|
+
localish? ? override_email(:cc) : real_cc
|
67
|
+
end
|
68
|
+
|
69
|
+
def bcc(*addresses)
|
70
|
+
real_bcc(*addresses)
|
71
|
+
localish? ? override_email(:bcc) : real_bcc
|
72
|
+
end
|
73
|
+
|
74
|
+
#######
|
75
|
+
private
|
76
|
+
#######
|
77
|
+
|
78
|
+
def override_subject
|
79
|
+
real_recipients.nil? ? real_subject : "Sanitized: [#{RAILS_ENV.upcase}](#{real_recipients}) #{real_subject}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def override_email(type)
|
83
|
+
real_addresses, sanitized_addresses =
|
84
|
+
case type
|
85
|
+
when :recipients
|
86
|
+
[real_recipients, self.class.sanitized_recipients]
|
87
|
+
when :cc
|
88
|
+
[real_cc, self.class.sanitized_cc]
|
89
|
+
when :bcc
|
90
|
+
[real_bcc, self.class.sanitized_bcc]
|
91
|
+
else raise "sanitize_email error: unknown email override"
|
92
|
+
end
|
93
|
+
|
94
|
+
# If there were no original recipients, then we DO NOT override the nil with the sanitized recipients
|
95
|
+
return nil if real_addresses.nil?
|
96
|
+
return sanitized_addresses if sanitized_addresses.nil? || !self.class.use_actual_email_as_sanitized_user_name
|
97
|
+
|
98
|
+
out = real_addresses.inject([]) do |result, real_recipient|
|
99
|
+
result << sanitized_addresses.map{|sanitized| "#{real_recipient} <#{sanitized}>"}
|
100
|
+
result
|
101
|
+
end.flatten
|
102
|
+
return out
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end # end Module SanitizeEmail
|
108
|
+
end # end Module NinthBit
|
109
|
+
|
@@ -0,0 +1,55 @@
|
|
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{sanitize_email}
|
8
|
+
s.version = "0.3.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Peter Boling", "John Trupiano", "George Anderson"]
|
12
|
+
s.date = %q{2009-11-10}
|
13
|
+
s.description = %q{Test an application's email abilities without ever sending a message to actual live addresses}
|
14
|
+
s.email = ["peter.boling@gmail.com", "jtrupiano@gmail.com", "george@benevolentcode.com"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION.yml",
|
23
|
+
"init.rb",
|
24
|
+
"lib/sanitize_email.rb",
|
25
|
+
"lib/sanitize_email/custom_environments.rb",
|
26
|
+
"lib/sanitize_email/sanitize_email.rb",
|
27
|
+
"sanitize_email.gemspec",
|
28
|
+
"test/sample_mailer.rb",
|
29
|
+
"test/sanitize_email_test.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/pboling/sanitize_email}
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
33
|
+
s.require_paths = ["lib"]
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
35
|
+
s.summary = %q{Tool to aid in development, testing, qa, and production troubleshooting of email issues without worrying that emails will get sent to actual live addresses.}
|
36
|
+
s.test_files = [
|
37
|
+
"test/sample_mailer.rb",
|
38
|
+
"test/sanitize_email_test.rb",
|
39
|
+
"test/test_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<actionmailer>, [">= 0"])
|
48
|
+
else
|
49
|
+
s.add_dependency(%q<actionmailer>, [">= 0"])
|
50
|
+
end
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<actionmailer>, [">= 0"])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class SampleMailer < ActionMailer::Base
|
2
|
+
|
3
|
+
def gmail_override
|
4
|
+
@recipients = "to_real@email.com"
|
5
|
+
@cc = "cc_real@email.com"
|
6
|
+
@bcc = "bcc_real@email.com"
|
7
|
+
|
8
|
+
@subject = "Hello there"
|
9
|
+
|
10
|
+
part :content_type => "text/html", :body => "Hello there"
|
11
|
+
end
|
12
|
+
|
13
|
+
def gmail_override_multiple_recipient
|
14
|
+
@recipients = ["to_0_real@email.com", "to_1_real@email.com"]
|
15
|
+
@cc = "cc_real@email.com"
|
16
|
+
@bcc = "bcc_real@email.com"
|
17
|
+
|
18
|
+
@subject = "Hello there, multiple"
|
19
|
+
|
20
|
+
part :content_type => "text/html", :body => "Hello there, multiple."
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
class SanitizeEmailTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
ENV['RAILS_ENV'] = 'test'
|
6
|
+
end
|
7
|
+
|
8
|
+
def prepare_sanitizations(to = nil, cc = nil, bcc = nil, use_actual_email_as_sanitized_user_name = false)
|
9
|
+
ActionMailer::Base.sanitized_recipients = to
|
10
|
+
ActionMailer::Base.sanitized_cc = cc
|
11
|
+
ActionMailer::Base.sanitized_bcc = bcc
|
12
|
+
ActionMailer::Base.local_environments = %w( test )
|
13
|
+
ActionMailer::Base.use_actual_email_as_sanitized_user_name = use_actual_email_as_sanitized_user_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_send_can_override_recips_cc_bcc_all_independently
|
17
|
+
prepare_sanitizations("to_sanitized@email.com", "cc_sanitized@email.com")
|
18
|
+
|
19
|
+
tmail = SampleMailer.create_gmail_override
|
20
|
+
assert_equal ["to_sanitized@email.com"], tmail.to
|
21
|
+
assert_equal ["cc_sanitized@email.com"], tmail.cc
|
22
|
+
assert_equal nil, tmail.bcc
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_to_with_override
|
26
|
+
prepare_sanitizations("to_sanitized@email.com", nil, nil, :override_username)
|
27
|
+
tmail = SampleMailer.create_gmail_override
|
28
|
+
assert_equal "to_real@email.com", tmail.to_addrs[0].name
|
29
|
+
assert_equal "to_sanitized@email.com", tmail.to_addrs[0].address
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_tcc_with_override
|
33
|
+
prepare_sanitizations("to_sanitized@email.com", "cc_sanitized@email.com", nil, :override_username)
|
34
|
+
tmail = SampleMailer.create_gmail_override
|
35
|
+
assert_equal "cc_real@email.com", tmail.cc_addrs[0].name
|
36
|
+
assert_equal "cc_sanitized@email.com", tmail.cc_addrs[0].address
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_bcc_with_override
|
40
|
+
prepare_sanitizations("to_sanitized@email.com", nil, "bcc_sanitized@email.com", :override_username)
|
41
|
+
tmail = SampleMailer.create_gmail_override
|
42
|
+
assert_equal "bcc_real@email.com", tmail.bcc_addrs[0].name
|
43
|
+
assert_equal "bcc_sanitized@email.com", tmail.bcc_addrs[0].address
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_override_with_multiple_santiized_emails
|
47
|
+
prepare_sanitizations(["to_0_sanitized@email.com", "to_1_sanitized@email.com"], nil, nil, :override_username)
|
48
|
+
tmail = SampleMailer.create_gmail_override
|
49
|
+
tmail.to_addrs.each_with_index do |mail, idx|
|
50
|
+
assert_equal "to_real@email.com", mail.name
|
51
|
+
assert_equal "to_#{idx}_sanitized@email.com", mail.address
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_overriding_multiple_real_addresses
|
56
|
+
prepare_sanitizations("to_sanitized@email.com", nil, nil, :override_username)
|
57
|
+
tmail = SampleMailer.create_gmail_override_multiple_recipient
|
58
|
+
tmail.to_addrs.each_with_index do |mail, idx|
|
59
|
+
assert_equal "to_#{idx}_real@email.com", mail.name
|
60
|
+
assert_equal "to_sanitized@email.com", mail.address
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_overriding_multiple_real_addresses_with_multiple_sanitized_emails
|
65
|
+
prepare_sanitizations(["to_0_sanitized@email.com", "to_1_sanitized@email.com"], nil, nil, :override_username)
|
66
|
+
tmail = SampleMailer.create_gmail_override_multiple_recipient
|
67
|
+
|
68
|
+
assert tmail.to_addrs.map(&:name).include?("to_0_real@email.com")
|
69
|
+
assert tmail.to_addrs.map(&:name).include?("to_1_real@email.com")
|
70
|
+
|
71
|
+
assert tmail.to_addrs.map(&:address).include?("to_0_sanitized@email.com")
|
72
|
+
assert tmail.to_addrs.map(&:address).include?("to_1_sanitized@email.com")
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
RAILS_ROOT = '.' unless defined?(RAILS_ROOT)
|
6
|
+
RAILS_ENV = 'test'
|
7
|
+
|
8
|
+
require File.join(File.dirname(__FILE__), "..", "init")
|
9
|
+
|
10
|
+
# configure ActionMailer
|
11
|
+
ActionMailer::Base.template_root = File.join(File.dirname(__FILE__), "test")
|
12
|
+
ActionMailer::Base.sanitized_recipients = "test@example.com"
|
13
|
+
ActionMailer::Base.sanitized_bcc = nil
|
14
|
+
ActionMailer::Base.sanitized_cc = nil
|
15
|
+
|
16
|
+
require 'test/sample_mailer'
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: futurechimp-sanitize_email
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Boling
|
8
|
+
- John Trupiano
|
9
|
+
- George Anderson
|
10
|
+
- Dave Hrycyszyn
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2009-11-23 00:00:00 +00:00
|
16
|
+
default_executable:
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: actionmailer
|
20
|
+
type: :runtime
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: "0"
|
27
|
+
version:
|
28
|
+
description: Test an application's email abilities without ever sending a message to actual live addresses
|
29
|
+
email:
|
30
|
+
- peter.boling@gmail.com
|
31
|
+
- jtrupiano@gmail.com
|
32
|
+
- george@benevolentcode.com
|
33
|
+
- dave.hrycyszyn@headlondon.com
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- README.rdoc
|
40
|
+
files:
|
41
|
+
- MIT-LICENSE
|
42
|
+
- README.rdoc
|
43
|
+
- Rakefile
|
44
|
+
- VERSION.yml
|
45
|
+
- init.rb
|
46
|
+
- lib/sanitize_email.rb
|
47
|
+
- lib/sanitize_email/custom_environments.rb
|
48
|
+
- lib/sanitize_email/sanitize_email.rb
|
49
|
+
- sanitize_email.gemspec
|
50
|
+
- test/sample_mailer.rb
|
51
|
+
- test/sanitize_email_test.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/pboling/sanitize_email
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --charset=UTF-8
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.3.5
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Tool to aid in development, testing, qa, and production troubleshooting of email issues without worrying that emails will get sent to actual live addresses.
|
80
|
+
test_files:
|
81
|
+
- test/test_helper.rb
|
82
|
+
- test/sanitize_email_test.rb
|
83
|
+
- test/sample_mailer.rb
|