eyepaste-mail 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README.md +74 -0
- data/Rakefile +1 -0
- data/eyepaste-mail.gemspec +24 -0
- data/lib/eyepaste-mail.rb +7 -0
- data/lib/eyepaste-mail/interceptor.rb +34 -0
- data/lib/eyepaste-mail/version.rb +5 -0
- data/spec/interceptor_spec.rb +109 -0
- data/spec/spec_helper.rb +7 -0
- metadata +82 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# eyepaste-mail
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
eyepaste-mail is a ruby gem that implements a "mail interceptor" as specified by the popular [Mail](https://github.com/mikel/mail) gem.
|
6
|
+
|
7
|
+
After registering the eyepaste-mail interceptor with the Mail gem, any emails sent with Mail are inspected before delivery and the "to" addresses are munged in the following way:
|
8
|
+
|
9
|
+
`inbox@example.com -> inbox_example.com@eyepaste.com`
|
10
|
+
|
11
|
+
After delivery, the above email would be available at:
|
12
|
+
|
13
|
+
`http://www.eyepaste.com/inbox/inbox_example.com@eyepaste.com`
|
14
|
+
|
15
|
+
And as RSS at:
|
16
|
+
|
17
|
+
`http://www.eyepaste.com/inbox/inbox_example.com@eyepaste.com.rss`
|
18
|
+
|
19
|
+
|
20
|
+
## Whitelisting
|
21
|
+
|
22
|
+
By default, the eyepaste-mail interceptor munges all addresses. To allow some addresses to pass through unaltered, you can define a whitelist in the following ways:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# pass a regexp
|
26
|
+
Eyepaste::Mail::Interceptor.set_white_list /.+?@example.com/
|
27
|
+
|
28
|
+
# pass an array of regexps
|
29
|
+
Eyepaste::Mail::Interceptor.set_white_list [/.+?@example.com/, /^testing_.+?@example.com/]
|
30
|
+
|
31
|
+
# pass a block, it will be called every time a message is examined and munged
|
32
|
+
Eyepaste::Mail::Interceptor.set_white_list do
|
33
|
+
# must return a regexp object or array of regexp objects
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## Registering The Interceptor
|
38
|
+
|
39
|
+
To register the interceptor with the Mail gem, call:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# optionally define a white_list:
|
43
|
+
Eyepaste::Mail::Interceptor.set_white_list /.+?@example.com/
|
44
|
+
|
45
|
+
# register with Mail
|
46
|
+
Mail.register_interceptor(Eyepaste::Mail::Interceptor)
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
## Rails 3.2
|
51
|
+
|
52
|
+
Make sure eyepaste-mail is required by your Gemfile and you have then run `bundle install`
|
53
|
+
|
54
|
+
To only munge emails in a particular environment, you can place the following in an environment file. For development, place in `config/environments/development.rb`:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# optionally define a white_list:
|
58
|
+
Eyepaste::Mail::Interceptor.set_white_list /.+?@example.com/
|
59
|
+
|
60
|
+
# register with ActionMailer::Base (which wraps the call to Mail.register_interceptor)
|
61
|
+
ActionMailer::Base.register_interceptor(Eyepaste::Mail::Interceptor)
|
62
|
+
```
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
eyepaste-email is licensed under the MIT license:
|
67
|
+
|
68
|
+
Copyright (c) 2012. Jon Moniaci.
|
69
|
+
|
70
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
71
|
+
|
72
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
73
|
+
|
74
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "eyepaste-mail/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "eyepaste-mail"
|
7
|
+
s.version = Eyepaste::Mail::VERSION
|
8
|
+
s.authors = ["Jon Moniaci"]
|
9
|
+
s.email = ["jonmoniaci [at] gmail.com"]
|
10
|
+
s.homepage = "https://github.com/corporealfunk/eyepaste-mail"
|
11
|
+
s.summary = %q{Works with Mail gem to munge email 'To:' addresses into @eyepaste.com addresses}
|
12
|
+
s.description = %q{Implements an email interceptor which, when registered with the Mail gem, munges all "To:" email address to @eyepaste.com addresses. Especially helpful in dev or staging environments when you don't want emails delivered to actual addresses, but you may want to verify actual delivery.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "eyepaste-mail"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "mail"
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Eyepaste
|
2
|
+
module Mail
|
3
|
+
class Interceptor
|
4
|
+
@@white_list = nil
|
5
|
+
|
6
|
+
def self.set_white_list(white_list=nil, &block)
|
7
|
+
@@white_list = block || white_list
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get_white_list
|
11
|
+
return [] if @@white_list.nil?
|
12
|
+
|
13
|
+
white_list = @@white_list.kind_of?(Proc) ? @@white_list.call : @@white_list
|
14
|
+
|
15
|
+
white_list.respond_to?(:each) ? white_list : [white_list]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.delivering_email(message)
|
19
|
+
message.to = message[:to].addrs.map do |addr|
|
20
|
+
email = addr.address
|
21
|
+
on_white_list = get_white_list.any? { |regexp| regexp.match(email)}
|
22
|
+
if !on_white_list
|
23
|
+
munged_email = "#{email.gsub(/@/, '_')}@eyepaste.com"
|
24
|
+
formatted_address = addr.format.gsub(email, munged_email)
|
25
|
+
else
|
26
|
+
formatted_address = addr.format
|
27
|
+
end
|
28
|
+
|
29
|
+
formatted_address
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mail'
|
3
|
+
|
4
|
+
describe Eyepaste::Mail::Interceptor do
|
5
|
+
after(:each) do
|
6
|
+
# clear the white list after each test
|
7
|
+
Eyepaste::Mail::Interceptor.set_white_list(nil)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".set_white_list" do
|
11
|
+
context "when regexp passed" do
|
12
|
+
it "sets the white_list to an array with the regexp as only element" do
|
13
|
+
Eyepaste::Mail::Interceptor.set_white_list(/.+?@testdomain\.com/)
|
14
|
+
Eyepaste::Mail::Interceptor.get_white_list.should == [/.+?@testdomain\.com/]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when array of regexps passed" do
|
19
|
+
it "sets the white_list to the array" do
|
20
|
+
Eyepaste::Mail::Interceptor.set_white_list([/.+?@testdomain\.com/])
|
21
|
+
Eyepaste::Mail::Interceptor.get_white_list.should == [/.+?@testdomain\.com/]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when block passed" do
|
26
|
+
context "when block returns a regexp" do
|
27
|
+
it "return value of proc is wrapped in an array" do
|
28
|
+
Eyepaste::Mail::Interceptor.set_white_list do
|
29
|
+
/white list proc/
|
30
|
+
end
|
31
|
+
Eyepaste::Mail::Interceptor.get_white_list.should == [/white list proc/]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when block returns an array" do
|
36
|
+
it "return value of proc is an array" do
|
37
|
+
Eyepaste::Mail::Interceptor.set_white_list do
|
38
|
+
[/white list proc/]
|
39
|
+
end
|
40
|
+
Eyepaste::Mail::Interceptor.get_white_list.should == [/white list proc/]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe ".delivering_mail" do
|
47
|
+
context "when single to address" do
|
48
|
+
before(:each) do
|
49
|
+
@message = Mail.new do
|
50
|
+
to 'Hallow World <hallowworld@example.com>'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when address matches white_list" do
|
55
|
+
before(:each) do
|
56
|
+
Eyepaste::Mail::Interceptor.set_white_list(/.+?@example\.com/)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "does not alter the to address" do
|
60
|
+
expect {
|
61
|
+
Eyepaste::Mail::Interceptor.delivering_email(@message)
|
62
|
+
}.to_not change(@message[:to], :to_s)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "retains the formatted To: header" do
|
66
|
+
Eyepaste::Mail::Interceptor.delivering_email(@message)
|
67
|
+
@message[:to].to_s.should == 'Hallow World <hallowworld@example.com>'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when address does not match white_list" do
|
72
|
+
it "alters the to address" do
|
73
|
+
expect {
|
74
|
+
Eyepaste::Mail::Interceptor.delivering_email(@message)
|
75
|
+
}.to change(@message[:to], :to_s)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "munges the to address to an eyepaste email" do
|
79
|
+
Eyepaste::Mail::Interceptor.delivering_email(@message)
|
80
|
+
@message[:to].addresses.first.should == 'hallowworld_example.com@eyepaste.com'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "retains the formatted To: header" do
|
84
|
+
Eyepaste::Mail::Interceptor.delivering_email(@message)
|
85
|
+
@message[:to].to_s.should == 'Hallow World <hallowworld_example.com@eyepaste.com>'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when multiple to addresses" do
|
91
|
+
before(:each) do
|
92
|
+
Eyepaste::Mail::Interceptor.set_white_list(/.+?@example\.com/)
|
93
|
+
@message = Mail.new do
|
94
|
+
to 'Hallow World <hallowworld@example.com>, flatearth@domain.com'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it "alters the to addresses that don't match the white list" do
|
99
|
+
Eyepaste::Mail::Interceptor.delivering_email(@message)
|
100
|
+
@message[:to].addresses.should == ['hallowworld@example.com', 'flatearth_domain.com@eyepaste.com']
|
101
|
+
end
|
102
|
+
|
103
|
+
it "retains the formatted To: header" do
|
104
|
+
Eyepaste::Mail::Interceptor.delivering_email(@message)
|
105
|
+
@message[:to].to_s.should == 'Hallow World <hallowworld@example.com>, flatearth_domain.com@eyepaste.com'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eyepaste-mail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Moniaci
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70100348192140 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70100348192140
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mail
|
27
|
+
requirement: &70100348191720 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70100348191720
|
36
|
+
description: Implements an email interceptor which, when registered with the Mail
|
37
|
+
gem, munges all "To:" email address to @eyepaste.com addresses. Especially helpful
|
38
|
+
in dev or staging environments when you don't want emails delivered to actual addresses,
|
39
|
+
but you may want to verify actual delivery.
|
40
|
+
email:
|
41
|
+
- jonmoniaci [at] gmail.com
|
42
|
+
executables: []
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- eyepaste-mail.gemspec
|
51
|
+
- lib/eyepaste-mail.rb
|
52
|
+
- lib/eyepaste-mail/interceptor.rb
|
53
|
+
- lib/eyepaste-mail/version.rb
|
54
|
+
- spec/interceptor_spec.rb
|
55
|
+
- spec/spec_helper.rb
|
56
|
+
homepage: https://github.com/corporealfunk/eyepaste-mail
|
57
|
+
licenses: []
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project: eyepaste-mail
|
76
|
+
rubygems_version: 1.8.10
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Works with Mail gem to munge email 'To:' addresses into @eyepaste.com addresses
|
80
|
+
test_files:
|
81
|
+
- spec/interceptor_spec.rb
|
82
|
+
- spec/spec_helper.rb
|