ahoy_email 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +3 -3
- data/ahoy_email.gemspec +1 -1
- data/lib/ahoy_email.rb +6 -5
- data/lib/ahoy_email/engine.rb +11 -4
- data/lib/ahoy_email/mailer.rb +1 -1
- data/lib/ahoy_email/processor.rb +5 -1
- data/lib/ahoy_email/version.rb +1 -1
- data/test/mailer_test.rb +62 -0
- data/test/test_helper.rb +0 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bd419ac1420c0d404b6137e3804545193969ecd8aab0444c919e9f7b5e5fae4
|
4
|
+
data.tar.gz: 3cce5d71d203a287992fc6560910f596f3cf74b0ef24861df8f5ed27ad9bd3b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b163a83c5a2f78e7a2576940f1d7d0bb25bb38fec0203571adf387ffa2e380c5ed164fff92ba12c00f81a30d7b43b39e41d7a68a1d94b86f2dfc27c48139eb16
|
7
|
+
data.tar.gz: 816a961760e8fedf55efa9b5b59f38decdf0fdd12531dc5a52f83c09178bddf820e93eb375c47100e10bd4e9f2aba7b4c2efabde952ebfc589cf20d2d0418537
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -99,13 +99,13 @@ Use `track open: false` to skip this.
|
|
99
99
|
A redirect is added to links to track clicks in HTML emails.
|
100
100
|
|
101
101
|
```
|
102
|
-
|
102
|
+
https://chartkick.com
|
103
103
|
```
|
104
104
|
|
105
105
|
becomes
|
106
106
|
|
107
107
|
```
|
108
|
-
|
108
|
+
https://yoursite.com/ahoy/messages/rAnDoMtOkEn/click?url=https%3A%2F%2Fchartkick.com&signature=...
|
109
109
|
```
|
110
110
|
|
111
111
|
A signature is added to prevent [open redirects](https://www.owasp.org/index.php/Open_redirect).
|
@@ -251,7 +251,7 @@ track unsubscribe_links: true
|
|
251
251
|
Use a different model
|
252
252
|
|
253
253
|
```ruby
|
254
|
-
AhoyEmail.message_model = UserMessage
|
254
|
+
AhoyEmail.message_model = -> { UserMessage }
|
255
255
|
```
|
256
256
|
|
257
257
|
## Upgrading
|
data/ahoy_email.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.required_ruby_version = ">= 2.
|
20
|
+
spec.required_ruby_version = ">= 2.2.0"
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "railties"
|
23
23
|
spec.add_runtime_dependency "actionmailer"
|
data/lib/ahoy_email.rb
CHANGED
@@ -17,14 +17,15 @@ module AhoyEmail
|
|
17
17
|
open: true,
|
18
18
|
click: true,
|
19
19
|
utm_params: true,
|
20
|
-
utm_source:
|
20
|
+
utm_source: ->(message, mailer) { mailer.mailer_name },
|
21
21
|
utm_medium: "email",
|
22
22
|
utm_term: nil,
|
23
23
|
utm_content: nil,
|
24
|
-
utm_campaign:
|
25
|
-
user:
|
26
|
-
mailer:
|
27
|
-
url_options: {}
|
24
|
+
utm_campaign: ->(message, mailer) { mailer.action_name },
|
25
|
+
user: ->(message, mailer) { (message.to.size == 1 ? User.where(email: message.to.first).first : nil) rescue nil },
|
26
|
+
mailer: ->(message, mailer) { "#{mailer.class.name}##{mailer.action_name}" },
|
27
|
+
url_options: {},
|
28
|
+
heuristic_parse: false
|
28
29
|
}
|
29
30
|
|
30
31
|
self.subscribers = []
|
data/lib/ahoy_email/engine.rb
CHANGED
@@ -3,10 +3,17 @@ require "rails/engine"
|
|
3
3
|
module AhoyEmail
|
4
4
|
class Engine < ::Rails::Engine
|
5
5
|
initializer "ahoy_email" do |app|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
AhoyEmail.secret_token ||= begin
|
7
|
+
creds =
|
8
|
+
if app.respond_to?(:credentials) && app.credentials.secret_key_base
|
9
|
+
app.credentials
|
10
|
+
elsif app.respond_to?(:secrets)
|
11
|
+
app.secrets
|
12
|
+
else
|
13
|
+
app.config
|
14
|
+
end
|
15
|
+
|
16
|
+
creds.respond_to?(:secret_key_base) ? creds.secret_key_base : creds.secret_token
|
10
17
|
end
|
11
18
|
|
12
19
|
AhoyEmail.belongs_to = {optional: true} if Rails::VERSION::MAJOR >= 5
|
data/lib/ahoy_email/mailer.rb
CHANGED
data/lib/ahoy_email/processor.rb
CHANGED
@@ -157,7 +157,11 @@ module AhoyEmail
|
|
157
157
|
# Return uri if valid, nil otherwise
|
158
158
|
def parse_uri(href)
|
159
159
|
# to_s prevent to return nil from this method
|
160
|
-
|
160
|
+
if options[:heuristic_parse]
|
161
|
+
Addressable::URI.heuristic_parse(href.to_s) rescue nil
|
162
|
+
else
|
163
|
+
Addressable::URI.parse(href.to_s) rescue nil
|
164
|
+
end
|
161
165
|
end
|
162
166
|
|
163
167
|
def url_for(opt)
|
data/lib/ahoy_email/version.rb
CHANGED
data/test/mailer_test.rb
CHANGED
@@ -25,6 +25,31 @@ class UserMailer < ActionMailer::Base
|
|
25
25
|
html_message('<a href="http://example.org?baz[]=1&baz[]=2">Hi<a>')
|
26
26
|
end
|
27
27
|
|
28
|
+
def heuristic_parse
|
29
|
+
track heuristic_parse: true
|
30
|
+
html_message('<a href="example.org">Hi<a>')
|
31
|
+
end
|
32
|
+
|
33
|
+
def mailto
|
34
|
+
track heuristic_parse: true
|
35
|
+
html_message('<a href="mailto:someone@yoursite.com">Email Us</a>')
|
36
|
+
end
|
37
|
+
|
38
|
+
def app_link
|
39
|
+
track heuristic_parse: true
|
40
|
+
html_message('<a href="fb://profile/33138223345">Email Us</a>')
|
41
|
+
end
|
42
|
+
|
43
|
+
def welcome4_heuristic
|
44
|
+
track heuristic_parse: true
|
45
|
+
html_message('<a href="http://example.org">Hi<a>')
|
46
|
+
end
|
47
|
+
|
48
|
+
def welcome5_heuristic
|
49
|
+
track heuristic_parse: true
|
50
|
+
html_message('<a href="http://example.org?baz[]=1&baz[]=2">Hi<a>')
|
51
|
+
end
|
52
|
+
|
28
53
|
private
|
29
54
|
|
30
55
|
def prevent_delivery_to_guests
|
@@ -74,6 +99,43 @@ class MailerTest < Minitest::Test
|
|
74
99
|
assert_match "baz%5B%5D=1&baz%5B%5D=2", body
|
75
100
|
end
|
76
101
|
|
102
|
+
def test_heuristic_parse
|
103
|
+
# Should convert the URI fragment into a URI
|
104
|
+
message = UserMailer.heuristic_parse
|
105
|
+
body = message.body.to_s
|
106
|
+
assert_match "http://example.org", body
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_mailto
|
110
|
+
# heuristic parse should ignore the mailto link
|
111
|
+
message = UserMailer.mailto
|
112
|
+
body = message.body.to_s
|
113
|
+
assert_match "<a href=\"mailto:someone@yoursite.com\">", body
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_app_link
|
117
|
+
# heuristic parse should ignore the app link
|
118
|
+
message = UserMailer.app_link
|
119
|
+
body = message.body.to_s
|
120
|
+
assert_match "<a href=\"fb://profile/33138223345\">", body
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_utm_params_heuristic_parse
|
124
|
+
# heuristic parse should not have unexpected side effects
|
125
|
+
message = UserMailer.welcome4_heuristic
|
126
|
+
body = message.body.to_s
|
127
|
+
assert_match "utm_campaign=welcome4", body
|
128
|
+
assert_match "utm_medium=email", body
|
129
|
+
assert_match "utm_source=user_mailer", body
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_array_params_heuristic_parse
|
133
|
+
# heuristic parse should not have unexpected side effects
|
134
|
+
message = UserMailer.welcome5_heuristic
|
135
|
+
body = message.body.to_s
|
136
|
+
assert_match "baz%5B%5D=1&baz%5B%5D=2", body
|
137
|
+
end
|
138
|
+
|
77
139
|
private
|
78
140
|
|
79
141
|
def assert_message(method)
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahoy_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -224,7 +224,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
224
|
requirements:
|
225
225
|
- - ">="
|
226
226
|
- !ruby/object:Gem::Version
|
227
|
-
version: 2.
|
227
|
+
version: 2.2.0
|
228
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
229
|
requirements:
|
230
230
|
- - ">="
|