actionview-encoded_mail_to 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +20 -4
- data/Gemfile +4 -0
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/actionview-encoded_mail_to.gemspec +3 -1
- data/lib/action_view/encoded_mail_to/mail_to_with_encoding.rb +104 -106
- data/lib/action_view/encoded_mail_to/version.rb +1 -1
- data/test/test_actionview-encoded_mail_to.rb +2 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8b0721d292877e6dda9b740676c558b44e5d5d3
|
4
|
+
data.tar.gz: 0fd2f8f2bdaff2157629e1adca5aa7d288da79ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bab2ea1803620e87b920b5aa6422d61b9a4a98ede91cebf438702107e806381da015a74d9ffa8068d589b16656c02013098a775d2981ce556f008300ebe0404b
|
7
|
+
data.tar.gz: c173894318bf4f37b9ea55e0407ed0b61f58b97b0e5f7941b37986befe22b63ae918ff1866d8ba1f22b9bcdb24e649a1c624d82e34ccaf70769bca14fd826663
|
data/.travis.yml
CHANGED
@@ -1,7 +1,23 @@
|
|
1
1
|
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache:
|
4
|
+
- bundler
|
2
5
|
rvm:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
- 2.0.0
|
7
|
+
- 2.1.10
|
8
|
+
- 2.2.5
|
9
|
+
- 2.3.1
|
10
|
+
before_install: gem update bundler
|
7
11
|
script: bundle exec rake test
|
12
|
+
env:
|
13
|
+
matrix:
|
14
|
+
- RAILS_VERSION="~> 4.0.0"
|
15
|
+
- RAILS_VERSION="~> 4.1.0"
|
16
|
+
- RAILS_VERSION="~> 4.2.0"
|
17
|
+
- RAILS_VERSION="~> 5.0.0"
|
18
|
+
matrix:
|
19
|
+
exclude:
|
20
|
+
- rvm: 2.0.0
|
21
|
+
env: RAILS_VERSION="~> 5.0.0"
|
22
|
+
- rvm: 2.1.10
|
23
|
+
env: RAILS_VERSION="~> 5.0.0"
|
data/Gemfile
CHANGED
@@ -1,3 +1,7 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gemspec
|
4
|
+
|
5
|
+
gem 'railties', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
|
6
|
+
gem 'mime-types', '~> 2' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0')
|
7
|
+
gem 'rack', '~> 1' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2')
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
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
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/
|
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/actionview/lib/action_view/helpers/url_helper.rb)).
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
data/Rakefile
CHANGED
@@ -12,7 +12,9 @@ Gem::Specification.new do |s|
|
|
12
12
|
|
13
13
|
s.add_dependency 'rails'
|
14
14
|
s.add_development_dependency 'minitest'
|
15
|
-
|
15
|
+
|
16
|
+
s.required_ruby_version = '>= 2.0.0'
|
17
|
+
|
16
18
|
s.files = `git ls-files`.split("\n")
|
17
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
20
|
s.require_paths = ["lib"]
|
@@ -1,120 +1,118 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
|
-
module EncodedMailTo
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
html_options
|
52
|
-
|
53
|
-
|
54
|
-
else
|
55
|
-
_mail_to_with_encoding email_address, name, html_options, &block
|
56
|
-
end
|
2
|
+
module ActionView
|
3
|
+
module EncodedMailTo
|
4
|
+
module MailToWithEncoding
|
5
|
+
# Creates a mailto link tag to the specified +email_address+, which is
|
6
|
+
# also used as the name of the link unless +name+ is specified. Additional
|
7
|
+
# HTML attributes for the link can be passed in +html_options+.
|
8
|
+
#
|
9
|
+
# +mail_to+ has several methods for hindering email harvesters and customizing
|
10
|
+
# the email itself by passing special keys to +html_options+.
|
11
|
+
#
|
12
|
+
# ==== Options
|
13
|
+
# * <tt>:encode</tt> - This key will accept the strings "javascript" or "hex".
|
14
|
+
# Passing "javascript" will dynamically create and encode the mailto link then
|
15
|
+
# eval it into the DOM of the page. This method will not show the link on
|
16
|
+
# the page if the user has JavaScript disabled. Passing "hex" will hex
|
17
|
+
# encode the +email_address+ before outputting the mailto link.
|
18
|
+
# * <tt>:replace_at</tt> - When the link +name+ isn't provided, the
|
19
|
+
# +email_address+ is used for the link label. You can use this option to
|
20
|
+
# obfuscate the +email_address+ by substituting the @ sign with the string
|
21
|
+
# given as the value.
|
22
|
+
# * <tt>:replace_dot</tt> - When the link +name+ isn't provided, the
|
23
|
+
# +email_address+ is used for the link label. You can use this option to
|
24
|
+
# obfuscate the +email_address+ by substituting the . in the email with the
|
25
|
+
# string given as the value.
|
26
|
+
# * <tt>:subject</tt> - Preset the subject line of the email.
|
27
|
+
# * <tt>:body</tt> - Preset the body of the email.
|
28
|
+
# * <tt>:cc</tt> - Carbon Copy additional recipients on the email.
|
29
|
+
# * <tt>:bcc</tt> - Blind Carbon Copy additional recipients on the email.
|
30
|
+
#
|
31
|
+
# ==== Examples
|
32
|
+
# mail_to "me@domain.com"
|
33
|
+
# # => <a href="mailto:me@domain.com">me@domain.com</a>
|
34
|
+
#
|
35
|
+
# mail_to "me@domain.com", "My email", encode: "javascript"
|
36
|
+
# # => <script>eval(decodeURIComponent('%64%6f%63...%27%29%3b'))</script>
|
37
|
+
#
|
38
|
+
# mail_to "me@domain.com", "My email", encode: "hex"
|
39
|
+
# # => <a href="mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d">My email</a>
|
40
|
+
#
|
41
|
+
# mail_to "me@domain.com", nil, replace_at: "_at_", replace_dot: "_dot_", class: "email"
|
42
|
+
# # => <a href="mailto:me@domain.com" class="email">me_at_domain_dot_com</a>
|
43
|
+
#
|
44
|
+
# mail_to "me@domain.com", "My email", cc: "ccaddress@domain.com",
|
45
|
+
# subject: "This is an example email"
|
46
|
+
# # => <a href="mailto:me@domain.com?cc=ccaddress@domain.com&subject=This%20is%20an%20example%20email">My email</a>
|
47
|
+
def mail_to(email_address, name = nil, html_options = {}, &block)
|
48
|
+
html_options, name = name || {}, nil if block_given? && html_options.blank?
|
49
|
+
html_options.stringify_keys!
|
50
|
+
if %w[encode replace_at replace_dot].none?{ |option| html_options.has_key? option }
|
51
|
+
super email_address, name, html_options, &block
|
52
|
+
else
|
53
|
+
_mail_to_with_encoding email_address, name, html_options, &block
|
57
54
|
end
|
58
|
-
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def _mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
|
63
|
-
email_address = ERB::Util.html_escape(email_address)
|
55
|
+
end
|
64
56
|
|
65
|
-
|
57
|
+
private
|
66
58
|
|
67
|
-
|
68
|
-
|
69
|
-
ERB::Util.html_escape "#{item}=#{Rack::Utils.escape_path(option)}"
|
70
|
-
}.compact
|
71
|
-
extras = extras.empty? ? '' : '?' + extras.join('&')
|
59
|
+
def _mail_to_with_encoding(email_address, name = nil, html_options = {}, &block)
|
60
|
+
email_address = ERB::Util.html_escape(email_address)
|
72
61
|
|
73
|
-
|
74
|
-
email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.key?("replace_at")
|
75
|
-
email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.key?("replace_dot")
|
62
|
+
encode = html_options.delete("encode").to_s
|
76
63
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
set_attributes += "a.setAttribute('#{name}', '#{value}');"
|
83
|
-
end
|
84
|
-
script_id = rand(36**8).to_s(36)
|
85
|
-
if block_given?
|
86
|
-
block_content = capture(&block).gsub('\'', %q(\\\')).gsub(/\n/, ' ')
|
87
|
-
link_content = "a.innerHTML='#{block_content}';"
|
88
|
-
else
|
89
|
-
link_content = "a.appendChild(document.createTextNode('#{name || email_address_obfuscated.html_safe}'));"
|
90
|
-
end
|
91
|
-
create_link = "var script = document.getElementById('mail_to-#{script_id}');" +
|
92
|
-
"var a = document.createElement('a');" +
|
93
|
-
"#{set_attributes}" +
|
94
|
-
link_content +
|
95
|
-
"script.parentNode.insertBefore(a,script);"
|
96
|
-
create_link.each_byte do |c|
|
97
|
-
string << sprintf("%%%x", c)
|
98
|
-
end
|
99
|
-
"<script id=\"mail_to-#{script_id}\">eval(decodeURIComponent('#{string}'))</script>".html_safe
|
100
|
-
when "hex"
|
101
|
-
email_address_encoded = email_address_obfuscated.unpack('C*').map {|c|
|
102
|
-
sprintf("&#%d;", c)
|
103
|
-
}.join
|
64
|
+
extras = %w{ cc bcc body subject }.map { |item|
|
65
|
+
option = html_options.delete(item) || next
|
66
|
+
ERB::Util.html_escape "#{item}=#{Rack::Utils.escape_path(option)}"
|
67
|
+
}.compact
|
68
|
+
extras = extras.empty? ? '' : '?' + extras.join('&')
|
104
69
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
char = c.chr
|
109
|
-
char =~ /\w/ ? sprintf("%%%x", c) : char
|
110
|
-
}.join
|
70
|
+
email_address_obfuscated = email_address.to_str
|
71
|
+
email_address_obfuscated.gsub!(/@/, html_options.delete("replace_at")) if html_options.key?("replace_at")
|
72
|
+
email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.key?("replace_dot")
|
111
73
|
|
112
|
-
|
74
|
+
case encode
|
75
|
+
when "javascript"
|
76
|
+
string = ''
|
77
|
+
set_attributes = ''
|
78
|
+
html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe).each_pair do |name,value|
|
79
|
+
set_attributes += "a.setAttribute('#{name}', '#{value}');"
|
80
|
+
end
|
81
|
+
script_id = rand(36**8).to_s(36)
|
82
|
+
if block_given?
|
83
|
+
block_content = capture(&block).gsub('\'', %q(\\\')).gsub(/\n/, ' ')
|
84
|
+
link_content = "a.innerHTML='#{block_content}';"
|
113
85
|
else
|
114
|
-
|
86
|
+
link_content = "a.appendChild(document.createTextNode('#{name || email_address_obfuscated.html_safe}'));"
|
115
87
|
end
|
88
|
+
create_link = "var script = document.getElementById('mail_to-#{script_id}');" +
|
89
|
+
"var a = document.createElement('a');" +
|
90
|
+
"#{set_attributes}" +
|
91
|
+
link_content +
|
92
|
+
"script.parentNode.insertBefore(a,script);"
|
93
|
+
create_link.each_byte do |c|
|
94
|
+
string << sprintf("%%%x", c)
|
95
|
+
end
|
96
|
+
"<script id=\"mail_to-#{script_id}\">eval(decodeURIComponent('#{string}'))</script>".html_safe
|
97
|
+
when "hex"
|
98
|
+
email_address_encoded = email_address_obfuscated.unpack('C*').map {|c|
|
99
|
+
sprintf("&#%d;", c)
|
100
|
+
}.join
|
101
|
+
|
102
|
+
string = 'mailto:'.unpack('C*').map { |c|
|
103
|
+
sprintf("&#%d;", c)
|
104
|
+
}.join + email_address.unpack('C*').map { |c|
|
105
|
+
char = c.chr
|
106
|
+
char =~ /\w/ ? sprintf("%%%x", c) : char
|
107
|
+
}.join
|
108
|
+
|
109
|
+
content_tag "a", name || email_address_encoded.html_safe, html_options.merge("href" => "#{string}#{extras}".html_safe), &block
|
110
|
+
else
|
111
|
+
content_tag "a", name || email_address_obfuscated.html_safe, html_options.merge("href" => "mailto:#{email_address}#{extras}".html_safe), &block
|
116
112
|
end
|
117
|
-
|
113
|
+
end
|
118
114
|
end
|
119
115
|
end
|
120
116
|
end
|
117
|
+
|
118
|
+
ActionView::Helpers::UrlHelper.send :prepend, ActionView::EncodedMailTo::MailToWithEncoding
|
@@ -9,17 +9,11 @@ require 'action_view/helpers/url_helper'
|
|
9
9
|
require 'action_view/encoded_mail_to/mail_to_with_encoding'
|
10
10
|
require 'action_view/buffers'
|
11
11
|
|
12
|
-
class TestActionViewEncodedMailTo < MiniTest::
|
12
|
+
class TestActionViewEncodedMailTo < MiniTest::Unit::TestCase
|
13
13
|
include ActionView::Helpers::UrlHelper
|
14
14
|
|
15
15
|
attr_accessor :output_buffer
|
16
16
|
|
17
|
-
def test_initialization
|
18
|
-
[:mail_to, :mail_to_with_encoding, :mail_to_without_encoding].each do |method|
|
19
|
-
assert_includes ActionView::Helpers::UrlHelper.instance_methods, method
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
17
|
def test_mail_to
|
24
18
|
assert_equal %{<a href="mailto:nick@example.com">nick@example.com</a>}, mail_to("nick@example.com")
|
25
19
|
assert_equal %{<a href="mailto:nick@example.com">Nick Reed</a>}, mail_to("nick@example.com", "Nick Reed")
|
@@ -35,7 +29,7 @@ class TestActionViewEncodedMailTo < MiniTest::Test
|
|
35
29
|
|
36
30
|
def test_mail_to_without_encoding
|
37
31
|
assert_equal mail_to("nick@example.com", "Nick Reed"),
|
38
|
-
|
32
|
+
"<a href=\"mailto:nick@example.com\">Nick Reed</a>"
|
39
33
|
end
|
40
34
|
|
41
35
|
def test_mail_to_with_javascript
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionview-encoded_mail_to
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Reed
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -67,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
67
|
requirements:
|
68
68
|
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
70
|
+
version: 2.0.0
|
71
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|