actionview-encoded_mail_to 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Users/reednj/code/rails/actionview-encoded_mail_to/Gemfile +3 -0
- data/Users/reednj/code/rails/actionview-encoded_mail_to/Gemfile.lock +94 -0
- data/Users/reednj/code/rails/actionview-encoded_mail_to/LICENSE.txt +22 -0
- data/Users/reednj/code/rails/actionview-encoded_mail_to/README.md +61 -0
- data/Users/reednj/code/rails/actionview-encoded_mail_to/Rakefile +7 -0
- data/Users/reednj/code/rails/actionview-encoded_mail_to/actionview-encoded_mail_to.gemspec +19 -0
- data/Users/reednj/code/rails/actionview-encoded_mail_to/lib/action_view/encoded_mail_to/mail_to_with_encoding.rb +113 -0
- data/Users/reednj/code/rails/actionview-encoded_mail_to/lib/action_view/encoded_mail_to/version.rb +5 -0
- data/Users/reednj/code/rails/actionview-encoded_mail_to/lib/actionview-encoded_mail_to.rb +14 -0
- data/Users/reednj/code/rails/actionview-encoded_mail_to/pkg/actionview-encoded_mail_to-1.0.0.gem +0 -0
- data/Users/reednj/code/rails/actionview-encoded_mail_to/test/test_actionview-encoded_mail_to.rb +109 -0
- metadata +84 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
actionview-encoded_mail_to (1.0.0)
|
5
|
+
rails
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionmailer (3.2.9)
|
11
|
+
actionpack (= 3.2.9)
|
12
|
+
mail (~> 2.4.4)
|
13
|
+
actionpack (3.2.9)
|
14
|
+
activemodel (= 3.2.9)
|
15
|
+
activesupport (= 3.2.9)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.4)
|
19
|
+
rack (~> 1.4.0)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.2.1)
|
23
|
+
activemodel (3.2.9)
|
24
|
+
activesupport (= 3.2.9)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activerecord (3.2.9)
|
27
|
+
activemodel (= 3.2.9)
|
28
|
+
activesupport (= 3.2.9)
|
29
|
+
arel (~> 3.0.2)
|
30
|
+
tzinfo (~> 0.3.29)
|
31
|
+
activeresource (3.2.9)
|
32
|
+
activemodel (= 3.2.9)
|
33
|
+
activesupport (= 3.2.9)
|
34
|
+
activesupport (3.2.9)
|
35
|
+
i18n (~> 0.6)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
arel (3.0.2)
|
38
|
+
builder (3.0.4)
|
39
|
+
erubis (2.7.0)
|
40
|
+
hike (1.2.1)
|
41
|
+
i18n (0.6.1)
|
42
|
+
journey (1.0.4)
|
43
|
+
json (1.7.5)
|
44
|
+
mail (2.4.4)
|
45
|
+
i18n (>= 0.4.0)
|
46
|
+
mime-types (~> 1.16)
|
47
|
+
treetop (~> 1.4.8)
|
48
|
+
mime-types (1.19)
|
49
|
+
minitest (4.3.3)
|
50
|
+
multi_json (1.5.0)
|
51
|
+
polyglot (0.3.3)
|
52
|
+
rack (1.4.1)
|
53
|
+
rack-cache (1.2)
|
54
|
+
rack (>= 0.4)
|
55
|
+
rack-ssl (1.3.2)
|
56
|
+
rack
|
57
|
+
rack-test (0.6.2)
|
58
|
+
rack (>= 1.0)
|
59
|
+
rails (3.2.9)
|
60
|
+
actionmailer (= 3.2.9)
|
61
|
+
actionpack (= 3.2.9)
|
62
|
+
activerecord (= 3.2.9)
|
63
|
+
activeresource (= 3.2.9)
|
64
|
+
activesupport (= 3.2.9)
|
65
|
+
bundler (~> 1.0)
|
66
|
+
railties (= 3.2.9)
|
67
|
+
railties (3.2.9)
|
68
|
+
actionpack (= 3.2.9)
|
69
|
+
activesupport (= 3.2.9)
|
70
|
+
rack-ssl (~> 1.3.2)
|
71
|
+
rake (>= 0.8.7)
|
72
|
+
rdoc (~> 3.4)
|
73
|
+
thor (>= 0.14.6, < 2.0)
|
74
|
+
rake (10.0.2)
|
75
|
+
rdoc (3.12)
|
76
|
+
json (~> 1.4)
|
77
|
+
sprockets (2.2.2)
|
78
|
+
hike (~> 1.2)
|
79
|
+
multi_json (~> 1.0)
|
80
|
+
rack (~> 1.0)
|
81
|
+
tilt (~> 1.1, != 1.3.0)
|
82
|
+
thor (0.16.0)
|
83
|
+
tilt (1.3.3)
|
84
|
+
treetop (1.4.12)
|
85
|
+
polyglot
|
86
|
+
polyglot (>= 0.3.1)
|
87
|
+
tzinfo (0.3.35)
|
88
|
+
|
89
|
+
PLATFORMS
|
90
|
+
ruby
|
91
|
+
|
92
|
+
DEPENDENCIES
|
93
|
+
actionview-encoded_mail_to!
|
94
|
+
minitest
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Nick Reed
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# actionview-encoded_mail_to
|
2
|
+
[![Build Status](https://secure.travis-ci.org/reednj77/actionview-encoded_mail_to.png)](http://travis-ci.org/reednj77/actionview-encoded_mail_to)
|
3
|
+
|
4
|
+
Deprecated support for email address obfuscation within the **mail_to** helper method. Restores the options `:encode`, `:replace_at`, and `:replace_dot`, which were removed from Rails in version 4.0.
|
5
|
+
|
6
|
+
Any call to **mail_to** that _doesn't_ include any of these options will be passed through to the core **mail_to** helper (in [ActionView::Helpers::UrlHelper](https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/url_helper.rb)).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'actionview-encoded_mail_to'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install actionview-encoded_mail_to
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Use the `mail_to` helper method just as you did prior to Rails 4.0.
|
25
|
+
|
26
|
+
#### Restored Options
|
27
|
+
|
28
|
+
* `:encode` - This key will accept the strings "javascript" or "hex".
|
29
|
+
Passing "javascript" will dynamically create and encode the mailto link then
|
30
|
+
eval it into the DOM of the page. This method will not show the link on
|
31
|
+
the page if the user has JavaScript disabled. Passing "hex" will hex
|
32
|
+
encode the email_address before outputting the mailto link.
|
33
|
+
* `:replace_at` - When the link name isn't provided, the
|
34
|
+
email_address is used for the link label. You can use this option to
|
35
|
+
obfuscate the email_address by substituting the @ sign with the string
|
36
|
+
given as the value.
|
37
|
+
* `:replace_dot` - When the link name isn't provided, the
|
38
|
+
email_address is used for the link label. You can use this option to
|
39
|
+
obfuscate the email_address by substituting the `.` in the email with the
|
40
|
+
string given as the value.
|
41
|
+
|
42
|
+
#### Examples
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
mail_to "me@domain.com", "My email", encode: "javascript"
|
46
|
+
# => <script>eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
|
47
|
+
|
48
|
+
mail_to "me@domain.com", "My email", encode: "hex"
|
49
|
+
# => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
|
50
|
+
|
51
|
+
mail_to "me@domain.com", nil, replace_at: "_at_", replace_dot: "_dot_", class: "email"
|
52
|
+
# => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
|
53
|
+
```
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create new Pull Request
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/action_view/encoded_mail_to/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'actionview-encoded_mail_to'
|
6
|
+
s.version = ActionView::EncodedMailTo::VERSION
|
7
|
+
s.authors = 'Nick Reed'
|
8
|
+
s.email = 'reednj77@gmail.com'
|
9
|
+
s.description = %q{Rails mail_to helper with encoding (removed from core in Rails 4.0)}
|
10
|
+
s.summary = %q{Deprecated support for email address obfuscation within the mail_to helper method.}
|
11
|
+
s.homepage = 'https://github.com/reednj77/actionview-encoded_mail_to'
|
12
|
+
|
13
|
+
s.add_dependency 'rails'
|
14
|
+
s.add_development_dependency 'minitest'
|
15
|
+
|
16
|
+
s.files = Dir["#{File.dirname(__FILE__)}/**/*"]
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module EncodedMailTo
|
4
|
+
module ::ActionView
|
5
|
+
module Helpers
|
6
|
+
module UrlHelper
|
7
|
+
# Creates a mailto link tag to the specified +email_address+, which is
|
8
|
+
# also used as the name of the link unless +name+ is specified. Additional
|
9
|
+
# HTML attributes for the link can be passed in +html_options+.
|
10
|
+
#
|
11
|
+
# +mail_to+ has several methods for hindering email harvesters and customizing
|
12
|
+
# the email itself by passing special keys to +html_options+.
|
13
|
+
#
|
14
|
+
# ==== Options
|
15
|
+
# * <tt>:encode</tt> - This key will accept the strings "javascript" or "hex".
|
16
|
+
# Passing "javascript" will dynamically create and encode the mailto link then
|
17
|
+
# eval it into the DOM of the page. This method will not show the link on
|
18
|
+
# the page if the user has JavaScript disabled. Passing "hex" will hex
|
19
|
+
# encode the +email_address+ before outputting the mailto link.
|
20
|
+
# * <tt>:replace_at</tt> - When the link +name+ isn't provided, the
|
21
|
+
# +email_address+ is used for the link label. You can use this option to
|
22
|
+
# obfuscate the +email_address+ by substituting the @ sign with the string
|
23
|
+
# given as the value.
|
24
|
+
# * <tt>:replace_dot</tt> - When the link +name+ isn't provided, the
|
25
|
+
# +email_address+ is used for the link label. You can use this option to
|
26
|
+
# obfuscate the +email_address+ by substituting the . in the email with the
|
27
|
+
# string given as the value.
|
28
|
+
# * <tt>:subject</tt> - Preset the subject line of the email.
|
29
|
+
# * <tt>:body</tt> - Preset the body of the email.
|
30
|
+
# * <tt>:cc</tt> - Carbon Copy additional recipients on the email.
|
31
|
+
# * <tt>:bcc</tt> - Blind Carbon Copy additional recipients on the email.
|
32
|
+
#
|
33
|
+
# ==== Examples
|
34
|
+
# mail_to "me@domain.com"
|
35
|
+
# # => <a href="mailto:me@domain.com">me@domain.com</a>
|
36
|
+
#
|
37
|
+
# mail_to "me@domain.com", "My email", encode: "javascript"
|
38
|
+
# # => <script>eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
|
39
|
+
#
|
40
|
+
# mail_to "me@domain.com", "My email", encode: "hex"
|
41
|
+
# # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
|
42
|
+
#
|
43
|
+
# mail_to "me@domain.com", nil, replace_at: "_at_", replace_dot: "_dot_", class: "email"
|
44
|
+
# # => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
|
45
|
+
#
|
46
|
+
# mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
|
47
|
+
# subject: "This is an example email"
|
48
|
+
# # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
|
49
|
+
def mail_to_with_encoding(email_address, name = nil, html_options = {})
|
50
|
+
html_options.stringify_keys!
|
51
|
+
if %w[encode replace_at replace_dot].none?{ |option| html_options.has_key? option }
|
52
|
+
mail_to_without_encoding email_address, name, html_options
|
53
|
+
else
|
54
|
+
_mail_to_with_encoding email_address, name, html_options
|
55
|
+
end
|
56
|
+
end
|
57
|
+
alias_method_chain :mail_to, :encoding
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def _mail_to_with_encoding(email_address, name = nil, html_options = {})
|
62
|
+
email_address = ERB::Util.html_escape(email_address)
|
63
|
+
|
64
|
+
encode = html_options.delete("encode").to_s
|
65
|
+
|
66
|
+
extras = %w{ cc bcc body subject }.map { |item|
|
67
|
+
option = html_options.delete(item) || next
|
68
|
+
"#{item}=#{Rack::Utils.escape_path(option)}"
|
69
|
+
}.compact
|
70
|
+
extras = extras.empty? ? '' : '?' + ERB::Util.html_escape(extras.join('&'))
|
71
|
+
|
72
|
+
email_address_obfuscated = email_address.to_str
|
73
|
+
email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.key?("replace_at")
|
74
|
+
email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.key?("replace_dot")
|
75
|
+
|
76
|
+
case encode
|
77
|
+
when "javascript"
|
78
|
+
string = ''
|
79
|
+
set_attributes = ''
|
80
|
+
html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe).each_pair do |name,value|
|
81
|
+
set_attributes += "a.setAttribute('#{name}', '#{value}');"
|
82
|
+
end
|
83
|
+
create_link = "var script = document.getElementsByTagName('script');" +
|
84
|
+
"script = script[script.length - 1];" +
|
85
|
+
"var a = document.createElement('a');" +
|
86
|
+
"#{set_attributes}" +
|
87
|
+
"a.appendChild(document.createTextNode('#{name || email_address_obfuscated.html_safe}'));" +
|
88
|
+
"script.parentNode.insertBefore(a,script);"
|
89
|
+
create_link.each_byte do |c|
|
90
|
+
string << sprintf("%%%x", c)
|
91
|
+
end
|
92
|
+
"<script>eval(decodeURIComponent('#{string}'))</script>".html_safe
|
93
|
+
when "hex"
|
94
|
+
email_address_encoded = email_address_obfuscated.unpack('C*').map {|c|
|
95
|
+
sprintf("&#%d;", c)
|
96
|
+
}.join
|
97
|
+
|
98
|
+
string = 'mailto:'.unpack('C*').map { |c|
|
99
|
+
sprintf("&#%d;", c)
|
100
|
+
}.join + email_address.unpack('C*').map { |c|
|
101
|
+
char = c.chr
|
102
|
+
char =~ /\w/ ? sprintf("%%%x", c) : char
|
103
|
+
}.join
|
104
|
+
|
105
|
+
content_tag "a", name || email_address_encoded.html_safe, html_options.merge("href" => "#{string}#{extras}".html_safe)
|
106
|
+
else
|
107
|
+
content_tag "a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "action_view/encoded_mail_to/version"
|
2
|
+
|
3
|
+
module ActionView
|
4
|
+
module EncodedMailTo
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
initializer 'actionview-encoded_mail_to' do |app|
|
7
|
+
ActiveSupport.on_load(:action_view) do
|
8
|
+
require 'action_view/encoded_mail_to/mail_to_with_encoding'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
data/Users/reednj/code/rails/actionview-encoded_mail_to/pkg/actionview-encoded_mail_to-1.0.0.gem
ADDED
Binary file
|
data/Users/reednj/code/rails/actionview-encoded_mail_to/test/test_actionview-encoded_mail_to.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'rails'
|
5
|
+
require 'action_pack'
|
6
|
+
require 'action_view/helpers/capture_helper'
|
7
|
+
require 'action_view/helpers/url_helper'
|
8
|
+
require 'action_view/encoded_mail_to/mail_to_with_encoding'
|
9
|
+
|
10
|
+
class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
|
11
|
+
include ActionView::Helpers::UrlHelper
|
12
|
+
|
13
|
+
def test_initialization
|
14
|
+
[:mail_to, :mail_to_with_encoding, :mail_to_without_encoding].each do |method|
|
15
|
+
assert_includes ActionView::Helpers::UrlHelper.instance_methods, method
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_mail_to
|
20
|
+
assert_equal %{<a href="mailto:nick@example.com">nick@example.com</a>}, mail_to("nick@example.com")
|
21
|
+
assert_equal %{<a href="mailto:nick@example.com">Nick Reed</a>}, mail_to("nick@example.com", "Nick Reed")
|
22
|
+
assert_equal %{<a class="admin" href="mailto:nick@example.com">Nick Reed</a>},
|
23
|
+
mail_to("nick@example.com", "Nick Reed", "class" => "admin")
|
24
|
+
assert_equal mail_to("nick@example.com", "Nick Reed", "class" => "admin"),
|
25
|
+
mail_to("nick@example.com", "Nick Reed", class: "admin")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_mail_to_without_encoding
|
29
|
+
assert_equal mail_to("nick@example.com", "Nick Reed"),
|
30
|
+
mail_to_without_encoding("nick@example.com", "Nick Reed")
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_mail_to_with_javascript
|
34
|
+
assert_equal(
|
35
|
+
"<script>eval(decodeURIComponent('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%73%42%79%54%61%67%4e%61%6d%65%28%27%73%63%72%69%70%74%27%29%3b%73%63%72%69%70%74%20%3d%20%73%63%72%69%70%74%5b%73%63%72%69%70%74%2e%6c%65%6e%67%74%68%20%2d%20%31%5d%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%27%29%3b%61%2e%61%70%70%65%6e%64%43%68%69%6c%64%28%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%54%65%78%74%4e%6f%64%65%28%27%4d%79%20%65%6d%61%69%6c%27%29%29%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'))</script>",
|
36
|
+
mail_to("me@domain.com", "My email", encode: "javascript")
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_mail_to_with_javascript_unicode
|
41
|
+
assert_equal(
|
42
|
+
"<script>eval(decodeURIComponent('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%73%42%79%54%61%67%4e%61%6d%65%28%27%73%63%72%69%70%74%27%29%3b%73%63%72%69%70%74%20%3d%20%73%63%72%69%70%74%5b%73%63%72%69%70%74%2e%6c%65%6e%67%74%68%20%2d%20%31%5d%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%75%6e%69%63%6f%64%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%27%29%3b%61%2e%61%70%70%65%6e%64%43%68%69%6c%64%28%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%54%65%78%74%4e%6f%64%65%28%27%c3%ba%6e%69%63%6f%64%65%27%29%29%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'))</script>",
|
43
|
+
mail_to("unicode@example.com", "únicode", encode: "javascript")
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_mail_with_options
|
48
|
+
assert_equal(
|
49
|
+
%{<a href="mailto:me@example.com?cc=ccaddress%40example.com&bcc=bccaddress%40example.com&body=This%20is%20the%20body%20of%20the%20message.&subject=This%20is%20an%20example%20email">My email</a>},
|
50
|
+
mail_to("me@example.com", "My email", cc: "ccaddress@example.com", bcc: "bccaddress@example.com", subject: "This is an example email", body: "This is the body of the message.")
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_mail_to_with_img
|
55
|
+
assert_equal %{<a href="mailto:feedback@example.com"><img src="/feedback.png" /></a>},
|
56
|
+
mail_to('feedback@example.com', '<img src="/feedback.png" />'.html_safe)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_mail_to_with_hex
|
60
|
+
assert_equal(
|
61
|
+
%{<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>},
|
62
|
+
mail_to("me@domain.com", "My email", encode: "hex")
|
63
|
+
)
|
64
|
+
|
65
|
+
assert_equal(
|
66
|
+
%{<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">me@domain.com</a>},
|
67
|
+
mail_to("me@domain.com", nil, encode: "hex")
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_mail_to_with_replace_options
|
72
|
+
assert_equal(
|
73
|
+
%{<a href="mailto:me@domain.com">me(at)domain(dot)com</a>},
|
74
|
+
mail_to("me@domain.com", nil, replace_at: "(at)", replace_dot: "(dot)")
|
75
|
+
)
|
76
|
+
|
77
|
+
assert_equal(
|
78
|
+
%{<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">me(at)domain.com</a>},
|
79
|
+
mail_to("me@domain.com", nil, encode: "hex", replace_at: "(at)")
|
80
|
+
)
|
81
|
+
|
82
|
+
assert_equal(
|
83
|
+
%{<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>},
|
84
|
+
mail_to("me@domain.com", "My email", encode: "hex", replace_at: "(at)")
|
85
|
+
)
|
86
|
+
|
87
|
+
assert_equal(
|
88
|
+
%{<a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">me(at)domain(dot)com</a>},
|
89
|
+
mail_to("me@domain.com", nil, encode: "hex", replace_at: "(at)", replace_dot: "(dot)")
|
90
|
+
)
|
91
|
+
|
92
|
+
assert_equal(
|
93
|
+
%{<script>eval(decodeURIComponent('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%73%42%79%54%61%67%4e%61%6d%65%28%27%73%63%72%69%70%74%27%29%3b%73%63%72%69%70%74%20%3d%20%73%63%72%69%70%74%5b%73%63%72%69%70%74%2e%6c%65%6e%67%74%68%20%2d%20%31%5d%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%27%29%3b%61%2e%61%70%70%65%6e%64%43%68%69%6c%64%28%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%54%65%78%74%4e%6f%64%65%28%27%4d%79%20%65%6d%61%69%6c%27%29%29%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'))</script>},
|
94
|
+
mail_to("me@domain.com", "My email", encode: "javascript", replace_at: "(at)", replace_dot: "(dot)")
|
95
|
+
)
|
96
|
+
|
97
|
+
assert_equal(
|
98
|
+
%{<script>eval(decodeURIComponent('%76%61%72%20%73%63%72%69%70%74%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%67%65%74%45%6c%65%6d%65%6e%74%73%42%79%54%61%67%4e%61%6d%65%28%27%73%63%72%69%70%74%27%29%3b%73%63%72%69%70%74%20%3d%20%73%63%72%69%70%74%5b%73%63%72%69%70%74%2e%6c%65%6e%67%74%68%20%2d%20%31%5d%3b%76%61%72%20%61%20%3d%20%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%61%27%29%3b%61%2e%73%65%74%41%74%74%72%69%62%75%74%65%28%27%68%72%65%66%27%2c%20%27%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%27%29%3b%61%2e%61%70%70%65%6e%64%43%68%69%6c%64%28%64%6f%63%75%6d%65%6e%74%2e%63%72%65%61%74%65%54%65%78%74%4e%6f%64%65%28%27%6d%65%28%61%74%29%64%6f%6d%61%69%6e%28%64%6f%74%29%63%6f%6d%27%29%29%3b%73%63%72%69%70%74%2e%70%61%72%65%6e%74%4e%6f%64%65%2e%69%6e%73%65%72%74%42%65%66%6f%72%65%28%61%2c%73%63%72%69%70%74%29%3b'))</script>},
|
99
|
+
mail_to("me@domain.com", nil, encode: "javascript", replace_at: "(at)", replace_dot: "(dot)")
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_mail_to_returns_html_safe_string
|
104
|
+
assert mail_to("me@domain.com").html_safe?
|
105
|
+
assert mail_to("me@domain.com", "My email", encode: "javascript").html_safe?
|
106
|
+
assert mail_to("me@domain.com", "My email", encode: "hex").html_safe?
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actionview-encoded_mail_to
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nick Reed
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &70108798011700 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70108798011700
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: minitest
|
27
|
+
requirement: &70108798009140 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70108798009140
|
36
|
+
description: Rails mail_to helper with encoding (removed from core in Rails 4.0)
|
37
|
+
email: reednj77@gmail.com
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/actionview-encoded_mail_to.gemspec
|
43
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/Gemfile
|
44
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/Gemfile.lock
|
45
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/lib/action_view/encoded_mail_to/mail_to_with_encoding.rb
|
46
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/lib/action_view/encoded_mail_to/version.rb
|
47
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/lib/actionview-encoded_mail_to.rb
|
48
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/LICENSE.txt
|
49
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/pkg/actionview-encoded_mail_to-1.0.0.gem
|
50
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/Rakefile
|
51
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/README.md
|
52
|
+
- /Users/reednj/code/rails/actionview-encoded_mail_to/test/test_actionview-encoded_mail_to.rb
|
53
|
+
homepage: https://github.com/reednj77/actionview-encoded_mail_to
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
hash: -1136833040237664497
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
hash: -1136833040237664497
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.10
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Deprecated support for email address obfuscation within the mail_to helper
|
83
|
+
method.
|
84
|
+
test_files: []
|