mail-redirector 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mail-redirector.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'rake', '0.8.7'
data/README.markdown ADDED
@@ -0,0 +1,44 @@
1
+ Mail Redirector
2
+ ===============
3
+
4
+ Installation
5
+ ------------
6
+
7
+ ### In Your Gemfile
8
+
9
+ > gem 'mail-redirector
10
+
11
+ ### In config/initializers/mail-redirector.rb
12
+
13
+ > MailRedirector.setup_interceptor 'test@example.com'
14
+
15
+ That's it!
16
+
17
+
18
+ What it's doing
19
+ ---------------
20
+
21
+ In all environments other than PRODUCTION or TEST, mail sent through
22
+ ActionMailer will be redirected to test@example.com. No mail will be
23
+ sent to its original destination. Instead, the X-Originally-To mail
24
+ header will be set, allowing you to determine who the mail would have
25
+ gone to had it not been redirected.
26
+
27
+ Mail in the TEST environment is specifically NOT redirected on the
28
+ assumption that it is more convenient to configure action mailer
29
+ to test delivery mode and still allow the tests to have access to
30
+ the original to field for testing purposes.
31
+
32
+
33
+ I want more control!
34
+ --------------------
35
+
36
+ If you want to change what addresses mail is redirected to in each
37
+ environment, then INSTEAD of calling setup_interceptor, place
38
+ a line of code like this:
39
+
40
+ > ActionMailer::Base.register_interceptor(MailRedirector.new("test@example.com"))
41
+
42
+ In each environment file, or wherever makes sense for you.
43
+
44
+ Happy redirecting!
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+ task default: :spec
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.verbose = false
8
+ t.rspec_opts = "--color"
9
+ end
10
+
@@ -0,0 +1,15 @@
1
+ class MailRedirector < Struct.new(:destination)
2
+ def delivering_email(m)
3
+ m['X-Originally-To'] = m.to.to_s
4
+ m.to = destination
5
+ end
6
+
7
+ def self.setup_interceptor(email_to_redirect_to)
8
+ unless Rails.env.production? || Rails.env.test?
9
+ ActionMailer::Base.register_interceptor(
10
+ MailRedirector.new(email_to_redirect_to)
11
+ )
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,2 @@
1
+ require_relative '../mail-redirector'
2
+ MailRedirector::VERSION = "0.0.1"
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "mail-redirector/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "mail-redirector"
7
+ s.version = MailRedirector::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["David Vollbracht"]
10
+ s.email = ["david@finario.com"]
11
+ s.homepage = "http://github.com/flipstone/mail-redirector"
12
+ s.summary = %q{Simple Rails 3 mail interceptor to redirect action mailer messages to a test address.}
13
+ s.description = <<-end_desc
14
+ Protect yourself for ever accidentally sendmail emails from an environment other than production. MailRedirector
15
+ lets you specify an email address to redirect all mail send by ActionMailer to. It also sets the X-Originally-To
16
+ header to the original recipients, ensuring you can inspect to message and verify it would have gone to the correct
17
+ recipients.
18
+ end_desc
19
+
20
+ s.add_dependency 'actionmailer', '>= 3.0.0'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe MailRedirector do
4
+ describe "delivering_email" do
5
+ it "sets the to" do
6
+ m = Mail.new to: "bar@example.com"
7
+
8
+ MailRedirector.new('test@example.com').delivering_email m
9
+ m.to.should == ['test@example.com']
10
+ end
11
+
12
+ it "sets a header with the original to" do
13
+ m = Mail.new to: "bar@example.com"
14
+ MailRedirector.new.delivering_email m
15
+ m['X-Originally-To'].to_s.should =~ /bar@example\.com/
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler'
2
+ require 'action_mailer'
3
+ require 'mail'
4
+ require_relative '../lib/mail-redirector'
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mail-redirector
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - David Vollbracht
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-09-02 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: actionmailer
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
32
+ version: 3.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: |
36
+ Protect yourself for ever accidentally sendmail emails from an environment other than production. MailRedirector
37
+ lets you specify an email address to redirect all mail send by ActionMailer to. It also sets the X-Originally-To
38
+ header to the original recipients, ensuring you can inspect to message and verify it would have gone to the correct
39
+ recipients.
40
+
41
+ email:
42
+ - david@finario.com
43
+ executables: []
44
+
45
+ extensions: []
46
+
47
+ extra_rdoc_files: []
48
+
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - README.markdown
53
+ - Rakefile
54
+ - lib/mail-redirector.rb
55
+ - lib/mail-redirector/version.rb
56
+ - mail-redirector.gemspec
57
+ - spec/mail_redirector_spec.rb
58
+ - spec/spec_helper.rb
59
+ has_rdoc: true
60
+ homepage: http://github.com/flipstone/mail-redirector
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Simple Rails 3 mail interceptor to redirect action mailer messages to a test address.
91
+ test_files:
92
+ - spec/mail_redirector_spec.rb
93
+ - spec/spec_helper.rb