test_mail_interceptor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +18 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +31 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/test_mail_interceptor.rb +60 -0
- data/test/helper.rb +18 -0
- data/test/test_test_mail_interceptor.rb +7 -0
- metadata +112 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.5.2)
|
6
|
+
bundler (~> 1.0.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rake (0.9.2)
|
10
|
+
shoulda (2.11.3)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.0.0)
|
17
|
+
jeweler (~> 1.5.2)
|
18
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Galaxy Cats IT Consulting GmbH
|
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,31 @@
|
|
1
|
+
= test_mail_interceptor
|
2
|
+
|
3
|
+
With this library you can catch all outgoing e-mails and redirect them to a specific address. This is very useful for testing purpose, for example on your staging/testing server.
|
4
|
+
|
5
|
+
== How to configure
|
6
|
+
|
7
|
+
In your Gemfile include
|
8
|
+
|
9
|
+
gem 'test_mail_interceptor'
|
10
|
+
|
11
|
+
then add these two lines to your config (for example environments/staging.rb)
|
12
|
+
|
13
|
+
config.mail_interceptor.intercept_mail = true
|
14
|
+
config.mail_interceptor.test_recipient = "catch-all-staging@example.com"
|
15
|
+
|
16
|
+
|
17
|
+
== Contributing to test_mail_interceptor
|
18
|
+
|
19
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
20
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
21
|
+
* Fork the project
|
22
|
+
* Start a feature/bugfix branch
|
23
|
+
* Commit and push until you are happy with your contribution
|
24
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
25
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
26
|
+
|
27
|
+
== Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2011 Galaxy Cats IT Consulting GmbH. See LICENSE.txt for
|
30
|
+
further details.
|
31
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "test_mail_interceptor"
|
16
|
+
gem.homepage = "http://github.com/thyphoon/test_mail_interceptor"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{redirect all outgoing emails to one address}
|
19
|
+
gem.description = %Q{With this library you can catch all outgoing e-mails and redirect them to a specific address. This is very useful for testing purpose, for example on your staging/testing server.}
|
20
|
+
gem.email = "andi@galaxycats.com"
|
21
|
+
gem.authors = ["Andi Bade"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :default => :test
|
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 = "test_mail_interceptor #{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,60 @@
|
|
1
|
+
class TestMailInterceptor
|
2
|
+
|
3
|
+
def self.delivering_email(mail)
|
4
|
+
if Rails.application.config.mail_interceptor.intercept_mail
|
5
|
+
interceptor = new(mail)
|
6
|
+
interceptor.handle_multipart_mail
|
7
|
+
interceptor.change_original_recipients_to_test_recipients
|
8
|
+
interceptor.clean_cc_and_bcc_recipients
|
9
|
+
|
10
|
+
return interceptor.mail
|
11
|
+
end
|
12
|
+
|
13
|
+
return mail
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :mail
|
17
|
+
|
18
|
+
def initialize(mail)
|
19
|
+
@mail = mail
|
20
|
+
end
|
21
|
+
|
22
|
+
def handle_multipart_mail
|
23
|
+
if mail.multipart?
|
24
|
+
mail.parts.each do |part|
|
25
|
+
if part.content_type =~ /^text\/html/
|
26
|
+
part.body = generate_test_mail_header_html + part.body.raw_source
|
27
|
+
else
|
28
|
+
part.body = generate_test_mail_header + part.body.raw_source
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
mail.body = generate_test_mail_header + mail.body.raw_source
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def change_original_recipients_to_test_recipients
|
37
|
+
mail.to = Rails.application.config.mail_interceptor.test_recipient
|
38
|
+
end
|
39
|
+
|
40
|
+
def clean_cc_and_bcc_recipients
|
41
|
+
mail.cc = nil
|
42
|
+
mail.bcc = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def generate_test_mail_header
|
48
|
+
%Q{------------------------------- Test-Mail (#{Rails.env}) -------------------------------
|
49
|
+
Original-Recipient: #{mail.to.join(", ")}
|
50
|
+
CC: #{mail.cc ? mail.cc.join(", ") : "no CC"}
|
51
|
+
BCC: #{mail.bcc ? mail.bcc.join(", ") : "no BCC"}
|
52
|
+
----------------------------------------------------------------------------------
|
53
|
+
}.gsub(/^\s+/, '')
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_test_mail_header_html
|
57
|
+
generate_test_mail_header.gsub(/\n/, "<br>")
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'test_mail_interceptor'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test_mail_interceptor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Andi Bade
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-06-09 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
type: :development
|
22
|
+
name: shoulda
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
requirement: *id001
|
31
|
+
prerelease: false
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
type: :development
|
34
|
+
name: bundler
|
35
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 1
|
41
|
+
- 0
|
42
|
+
- 0
|
43
|
+
version: 1.0.0
|
44
|
+
requirement: *id002
|
45
|
+
prerelease: false
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
type: :development
|
48
|
+
name: jeweler
|
49
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 1
|
55
|
+
- 5
|
56
|
+
- 2
|
57
|
+
version: 1.5.2
|
58
|
+
requirement: *id003
|
59
|
+
prerelease: false
|
60
|
+
description: With this library you can catch all outgoing e-mails and redirect them to a specific address. This is very useful for testing purpose, for example on your staging/testing server.
|
61
|
+
email: andi@galaxycats.com
|
62
|
+
executables: []
|
63
|
+
|
64
|
+
extensions: []
|
65
|
+
|
66
|
+
extra_rdoc_files:
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.rdoc
|
69
|
+
files:
|
70
|
+
- .document
|
71
|
+
- Gemfile
|
72
|
+
- Gemfile.lock
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.rdoc
|
75
|
+
- Rakefile
|
76
|
+
- VERSION
|
77
|
+
- lib/test_mail_interceptor.rb
|
78
|
+
- test/helper.rb
|
79
|
+
- test/test_test_mail_interceptor.rb
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: http://github.com/thyphoon/test_mail_interceptor
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
requirements: []
|
104
|
+
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.3.6
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: redirect all outgoing emails to one address
|
110
|
+
test_files:
|
111
|
+
- test/helper.rb
|
112
|
+
- test/test_test_mail_interceptor.rb
|