galakei 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +4 -1
- data/galakei.gemspec +1 -0
- data/lib/galakei/email.rb +25 -0
- data/lib/galakei/version.rb +1 -1
- data/spec/galakei/email_spec.rb +36 -0
- metadata +98 -49
data/Gemfile.lock
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
galakei (0.
|
4
|
+
galakei (0.9.0)
|
5
5
|
actionpack (>= 3.0.3)
|
6
6
|
css_parser
|
7
7
|
nokogiri
|
8
8
|
rack (>= 1.2.1)
|
9
|
+
sanitize
|
9
10
|
|
10
11
|
GEM
|
11
12
|
remote: http://rubygems.org/
|
@@ -105,6 +106,8 @@ GEM
|
|
105
106
|
railties (~> 3.0)
|
106
107
|
rspec (~> 2.5.0)
|
107
108
|
rubyzip (0.9.4)
|
109
|
+
sanitize (2.0.3)
|
110
|
+
nokogiri (< 1.6, >= 1.4.4)
|
108
111
|
selenium-webdriver (0.1.3)
|
109
112
|
childprocess (~> 0.1.5)
|
110
113
|
ffi (~> 0.6.3)
|
data/galakei.gemspec
CHANGED
data/lib/galakei/email.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'sanitize'
|
1
2
|
module Galakei::Email
|
2
3
|
|
3
4
|
GALAKEI_EMAIL_ADDRESS_PATTERNS = [
|
@@ -9,7 +10,31 @@ module Galakei::Email
|
|
9
10
|
/^.+@emnet\.ne\.jp$/,
|
10
11
|
/^.+@docomo\.ne\.jp$/ ]
|
11
12
|
|
13
|
+
SANITIZE_OPTIONS = {
|
14
|
+
:elements => %w{br a div hr},
|
15
|
+
:attributes => {'a' => ['href'] },
|
16
|
+
:protocols => {'a' => {'href' => ['http', 'https', 'mailto']}},
|
17
|
+
:whitespace_elements => []
|
18
|
+
}
|
19
|
+
|
20
|
+
TAGS_TO_PROCESS = %w{h1 h2 h3 h4 h5 h6 p}.join(',')
|
21
|
+
|
12
22
|
def self.galakei_email_address?(email)
|
13
23
|
GALAKEI_EMAIL_ADDRESS_PATTERNS.any?{|p| p =~ email }
|
14
24
|
end
|
25
|
+
|
26
|
+
def self.to_galakei_email(html_email)
|
27
|
+
doc = Nokogiri::HTML(html_email)
|
28
|
+
doc.css(TAGS_TO_PROCESS).each do |node|
|
29
|
+
node.name = "div"
|
30
|
+
node.after("<br />")
|
31
|
+
end
|
32
|
+
|
33
|
+
res = "<html><head>"
|
34
|
+
res << "<meta http-equiv=\"Content-type\" content=\"text/html;charset=#{doc.meta_encoding}\" />"
|
35
|
+
res << "</head><body>"
|
36
|
+
res << Sanitize.clean(doc.to_s, SANITIZE_OPTIONS)
|
37
|
+
res << "</body></html>"
|
38
|
+
end
|
39
|
+
|
15
40
|
end
|
data/lib/galakei/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Galakei::Email do
|
5
|
+
|
6
|
+
it "should not have h tags" do
|
7
|
+
html_email = '<h1>Email big heading</h1><h2>Second heading</h2><h6>Sixth heading</h6>'
|
8
|
+
Galakei::Email.to_galakei_email(html_email).should =~ /^((?!h[0-9]).)*$/
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not have images" do
|
12
|
+
html_email='<a href="http://dragonmobile.nuancemobiledeveloper.com/"><img src="http://www.mobilemonday.jp/wp-content/uploads/2011/01/NMDP.jpg" alt=""></a>this was an image'
|
13
|
+
Galakei::Email.to_galakei_email(html_email).should =~ /^((?!img).)*$/
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not have unsupported protocols" do
|
17
|
+
html_email='<a href="ftp://some.ftpsite.com/">Downloadz youz warez herez</a>'
|
18
|
+
Galakei::Email.to_galakei_email(html_email).should =~ /^((?!ftp).)*$/m
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should not have head elements" do
|
22
|
+
html_email='<html><head><meta http-equiv="blah" content=""><title>Document X</title><head><body></body></html>'
|
23
|
+
Galakei::Email.to_galakei_email(html_email).should =~ /^((?!head).)*$/
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have a html, head, meta and body" do
|
27
|
+
html_email='<html><head><meta http-equiv="Content-type" content="text/html;charset=UTF-8"" ><title>Document X</title><head><body>I am a body!</body></html>'
|
28
|
+
Galakei::Email.to_galakei_email(html_email).should =~ /html.*head.*meta.*body/m
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have div,href,br,hr elements" do
|
32
|
+
html_email='<div><a href="http://dragonmobile.nuancemobiledeveloper.com/"><img src="http://www.mobilemonday.jp/wp-content/uploads/2011/01/NMDP.jpg" alt=""></a></div><hr> <br><div class="register_button"><a href="http://gigs.checkin.local:3000/events/2/tickets/new?auth_token=demo">Register</a></div>'
|
33
|
+
Galakei::Email.to_galakei_email(html_email).should =~ /div(.*)href(.*)hr(.*)br/m
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
metadata
CHANGED
@@ -1,69 +1,107 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: galakei
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 59
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Paul McMahon
|
9
14
|
- Michael Reinsch
|
10
15
|
- Yuki Akamatsu
|
11
16
|
autorequire:
|
12
17
|
bindir: bin
|
13
18
|
cert_chain: []
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
|
20
|
+
date: 2011-08-29 00:00:00 Z
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
17
23
|
name: actionpack
|
18
|
-
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
26
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 1
|
31
|
+
segments:
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
- 3
|
23
35
|
version: 3.0.3
|
24
36
|
type: :runtime
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
28
39
|
name: rack
|
29
|
-
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
42
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 29
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 2
|
50
|
+
- 1
|
34
51
|
version: 1.2.1
|
35
52
|
type: :runtime
|
36
|
-
|
37
|
-
|
38
|
-
- !ruby/object:Gem::Dependency
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
39
55
|
name: css_parser
|
40
|
-
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
58
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
46
66
|
type: :runtime
|
47
|
-
|
48
|
-
|
49
|
-
- !ruby/object:Gem::Dependency
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
50
69
|
name: nokogiri
|
51
|
-
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
72
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
57
80
|
type: :runtime
|
81
|
+
version_requirements: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: sanitize
|
58
84
|
prerelease: false
|
59
|
-
|
60
|
-
|
61
|
-
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
type: :runtime
|
95
|
+
version_requirements: *id005
|
96
|
+
description: Japanese feature phones (a.k.a., keitai, galakei) have a number of restrictions over normal web browsers. This library adds support for them
|
62
97
|
email: info@mobalean.com
|
63
98
|
executables: []
|
99
|
+
|
64
100
|
extensions: []
|
101
|
+
|
65
102
|
extra_rdoc_files: []
|
66
|
-
|
103
|
+
|
104
|
+
files:
|
67
105
|
- .gitignore
|
68
106
|
- Gemfile
|
69
107
|
- Gemfile.lock
|
@@ -119,6 +157,7 @@ files:
|
|
119
157
|
- spec/app/public/stylesheets/docomo_css/simple.css
|
120
158
|
- spec/controllers/galakei/spacer_controller_spec.rb
|
121
159
|
- spec/galakei/docomo_css/stylesheet_spec.rb
|
160
|
+
- spec/galakei/email_spec.rb
|
122
161
|
- spec/galakei/emoji_table_spec.rb
|
123
162
|
- spec/galakei/filter/content_type_spec.rb
|
124
163
|
- spec/galakei/request_spec.rb
|
@@ -126,26 +165,36 @@ files:
|
|
126
165
|
- spec/spec_helper.rb
|
127
166
|
homepage: http://www.mobalean.com
|
128
167
|
licenses: []
|
168
|
+
|
129
169
|
post_install_message:
|
130
170
|
rdoc_options: []
|
131
|
-
|
171
|
+
|
172
|
+
require_paths:
|
132
173
|
- lib
|
133
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
175
|
none: false
|
135
|
-
requirements:
|
136
|
-
- -
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
|
139
|
-
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
hash: 3
|
180
|
+
segments:
|
181
|
+
- 0
|
182
|
+
version: "0"
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
184
|
none: false
|
141
|
-
requirements:
|
142
|
-
- -
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
hash: 3
|
189
|
+
segments:
|
190
|
+
- 0
|
191
|
+
version: "0"
|
145
192
|
requirements: []
|
193
|
+
|
146
194
|
rubyforge_project: galakei
|
147
195
|
rubygems_version: 1.8.6
|
148
196
|
signing_key:
|
149
197
|
specification_version: 3
|
150
198
|
summary: Japanese feature phones support
|
151
199
|
test_files: []
|
200
|
+
|