jpmobile 3.0.9 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +19 -0
- data/Gemfile +3 -11
- data/MIT-LICENSE +1 -1
- data/README.rdoc +7 -8
- data/Rakefile +1 -43
- data/VERSION.yml +1 -1
- data/jpmobile.gemspec +22 -38
- data/lib/jpmobile.rb +3 -1
- data/lib/jpmobile/configuration.rb +19 -0
- data/lib/jpmobile/emoticon/z_combine.rb +0 -4
- data/lib/jpmobile/hook_action_controller.rb +27 -0
- data/lib/jpmobile/mail.rb +56 -77
- data/lib/jpmobile/mailer.rb +1 -0
- data/lib/jpmobile/rack.rb +0 -16
- data/lib/jpmobile/resolver.rb +1 -1
- data/lib/jpmobile/util.rb +35 -128
- data/lib/jpmobile/version.rb +3 -0
- data/lib/tasks/jpmobile_tasks.rake +2 -2
- data/spec/unit/receive_mail_spec.rb +3 -28
- data/spec/unit/util_spec.rb +12 -23
- data/test/rails/overrides/Gemfile +46 -5
- data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +3 -0
- data/test/rails/overrides/app/models/user.rb +0 -1
- data/test/rails/overrides/app/views/layouts/application.html.erb +12 -0
- data/test/rails/overrides/app/views/layouts/application_mobile.html.erb +1 -1
- data/test/rails/overrides/app/views/mobile_mailer/default_to_mail.text.erb +1 -0
- data/test/rails/overrides/app/views/mobile_spec/_partial_view_sample.html.erb +1 -0
- data/test/rails/overrides/app/views/mobile_spec/no_mobile.html.erb +3 -0
- data/test/rails/overrides/config/routes.rb +2 -2
- data/test/rails/overrides/spec/controllers/mobile_spec_controller_spec.rb +36 -2
- data/test/rails/overrides/spec/mailers/mobile_mailer_spec.rb +4 -5
- metadata +194 -142
- data/spec/unit/email-fixtures/iphone-jis.eml +0 -15
- data/spec/unit/email-fixtures/pc-mail-attached-without-subject.eml +0 -45
data/lib/jpmobile/mailer.rb
CHANGED
data/lib/jpmobile/rack.rb
CHANGED
@@ -11,22 +11,6 @@ module Jpmobile
|
|
11
11
|
::Rails.application.middleware.insert_before('ActionDispatch::ParamsParser', Jpmobile::Rack::Filter)
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
15
|
-
class Configuration
|
16
|
-
include Singleton
|
17
|
-
|
18
|
-
attr_accessor :form_accept_charset_conversion
|
19
|
-
attr_accessor :smart_phone_emoticon_compatibility
|
20
|
-
|
21
|
-
def initialize
|
22
|
-
@form_accept_charset_conversion = false
|
23
|
-
@smart_phone_emoticon_compatibility = false
|
24
|
-
end
|
25
|
-
|
26
|
-
def mobile_filter
|
27
|
-
::Jpmobile::Rack.mount_middlewares
|
28
|
-
end
|
29
|
-
end
|
30
14
|
end
|
31
15
|
|
32
16
|
module Rack
|
data/lib/jpmobile/resolver.rb
CHANGED
@@ -49,7 +49,7 @@ module Jpmobile
|
|
49
49
|
|
50
50
|
if format
|
51
51
|
variant = template.match(/.+#{path}(.+)\.#{format.to_sym.to_s}.*$/) ? $1 : ''
|
52
|
-
virtual_path = variant.blank? ?
|
52
|
+
virtual_path = variant.blank? ? path.virtual : path.to_str + variant
|
53
53
|
else
|
54
54
|
virtual_path = path.virtual
|
55
55
|
end
|
data/lib/jpmobile/util.rb
CHANGED
@@ -160,19 +160,11 @@ module Jpmobile
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def regexp_utf8_to_sjis(utf8_str)
|
163
|
-
|
164
|
-
Regexp.compile(Regexp.escape(utf8_to_sjis(utf8_str)))
|
165
|
-
else
|
166
|
-
Regexp.compile(Regexp.escape(utf8_to_sjis(utf8_str),"s"),nil,'s')
|
167
|
-
end
|
163
|
+
Regexp.compile(Regexp.escape(utf8_to_sjis(utf8_str)))
|
168
164
|
end
|
169
165
|
|
170
166
|
def regexp_to_sjis(sjis_str)
|
171
|
-
|
172
|
-
Regexp.compile(Regexp.escape(sjis(sjis_str)))
|
173
|
-
else
|
174
|
-
Regexp.compile(Regexp.escape(sjis_str,"s"),nil,'s')
|
175
|
-
end
|
167
|
+
Regexp.compile(Regexp.escape(sjis(sjis_str)))
|
176
168
|
end
|
177
169
|
|
178
170
|
def hash_to_utf8(hash)
|
@@ -183,24 +175,19 @@ module Jpmobile
|
|
183
175
|
end
|
184
176
|
|
185
177
|
def sjis_regexp(sjis)
|
186
|
-
sjis_str = sjis.kind_of?(Numeric)
|
178
|
+
sjis_str = if sjis.kind_of?(Numeric)
|
179
|
+
[sjis].pack('n')
|
180
|
+
else
|
181
|
+
sjis
|
182
|
+
end
|
187
183
|
|
188
|
-
|
189
|
-
Regexp.compile(Regexp.escape(sjis_str.force_encoding(SJIS)))
|
190
|
-
else
|
191
|
-
Regexp.compile(Regexp.escape(sjis_str,"s"),nil,'s')
|
192
|
-
end
|
184
|
+
Regexp.compile(Regexp.escape(sjis_str.force_encoding(SJIS)))
|
193
185
|
end
|
194
186
|
|
195
187
|
def jis_regexp(jis)
|
196
188
|
jis_str = jis.kind_of?(Numeric) ? [jis].pack('n') : jis
|
197
189
|
|
198
|
-
|
199
|
-
# Regexp.compile(Regexp.escape(jis_str.force_encoding("stateless-ISO-2022-JP-KDDI"))) # for au only
|
200
|
-
Regexp.compile(Regexp.escape(jis_str.force_encoding(BINARY))) # for au only
|
201
|
-
else
|
202
|
-
Regexp.compile(Regexp.escape(jis_str,"j"),nil,'j')
|
203
|
-
end
|
190
|
+
Regexp.compile(Regexp.escape(jis_str.force_encoding(BINARY)))
|
204
191
|
end
|
205
192
|
|
206
193
|
def jis_string_regexp
|
@@ -217,20 +204,7 @@ module Jpmobile
|
|
217
204
|
elsif utf8?(str) and charset.match(/utf-8/i)
|
218
205
|
str
|
219
206
|
else
|
220
|
-
|
221
|
-
str.encode(charset)
|
222
|
-
else
|
223
|
-
case charset
|
224
|
-
when /iso-2022-jp/i
|
225
|
-
NKF.nkf("-j", str)
|
226
|
-
when /shift_jis/i
|
227
|
-
NKF.nkf("-s", str)
|
228
|
-
when /utf-8/i
|
229
|
-
NKF.nkf("-w", str)
|
230
|
-
else
|
231
|
-
str
|
232
|
-
end
|
233
|
-
end
|
207
|
+
str.encode(charset)
|
234
208
|
end
|
235
209
|
end
|
236
210
|
|
@@ -266,50 +240,22 @@ module Jpmobile
|
|
266
240
|
s = str.dup
|
267
241
|
return str if detect_encoding(str) == to
|
268
242
|
|
269
|
-
if
|
270
|
-
to = SJIS if to =~ /shift_jis/i
|
271
|
-
|
272
|
-
to_enc = ::Encoding.find(to)
|
273
|
-
return str if s.encoding == to_enc
|
243
|
+
to = SJIS if to =~ /shift_jis/i
|
274
244
|
|
275
|
-
|
276
|
-
|
277
|
-
s.force_encoding(from) unless s.encoding == from_enc
|
278
|
-
end
|
245
|
+
to_enc = ::Encoding.find(to)
|
246
|
+
return str if s.encoding == to_enc
|
279
247
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
opt << case from
|
284
|
-
when /iso-2022-jp/i
|
285
|
-
"-Jx"
|
286
|
-
when /shift_jis/i
|
287
|
-
"-Sx"
|
288
|
-
when /utf-8/i
|
289
|
-
"-Wx"
|
290
|
-
else
|
291
|
-
""
|
292
|
-
end
|
293
|
-
opt << case to
|
294
|
-
when /iso-2022-jp/i
|
295
|
-
"-j"
|
296
|
-
when /shift_jis/i, /windows_31j/i
|
297
|
-
"-s"
|
298
|
-
when /utf-8/i
|
299
|
-
"-w"
|
300
|
-
else
|
301
|
-
""
|
302
|
-
end
|
303
|
-
NKF.nkf(opt.join(" "), str)
|
248
|
+
if from
|
249
|
+
from_enc = ::Encoding.find(from)
|
250
|
+
s.force_encoding(from) unless s.encoding == from_enc
|
304
251
|
end
|
252
|
+
|
253
|
+
s.encode(to)
|
305
254
|
end
|
306
255
|
|
307
256
|
def set_encoding(str, encoding)
|
308
|
-
if encoding
|
309
|
-
|
310
|
-
|
311
|
-
str.force_encoding(encoding)
|
312
|
-
end
|
257
|
+
encoding = SJIS if encoding =~ /shift_jis/i
|
258
|
+
str.force_encoding(encoding)
|
313
259
|
|
314
260
|
str
|
315
261
|
end
|
@@ -328,32 +274,17 @@ module Jpmobile
|
|
328
274
|
end
|
329
275
|
|
330
276
|
def detect_encoding(str)
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
BINARY
|
341
|
-
else
|
342
|
-
BINARY
|
343
|
-
end
|
277
|
+
case str.encoding
|
278
|
+
when ::Encoding::ISO2022_JP
|
279
|
+
JIS
|
280
|
+
when ::Encoding::Shift_JIS, ::Encoding::Windows_31J, ::Encoding::CP932
|
281
|
+
SJIS
|
282
|
+
when ::Encoding::UTF_8
|
283
|
+
UTF8
|
284
|
+
when ::Encoding::ASCII_8BIT
|
285
|
+
BINARY
|
344
286
|
else
|
345
|
-
|
346
|
-
when NKF::SJIS
|
347
|
-
SJIS
|
348
|
-
when NKF::JIS
|
349
|
-
JIS
|
350
|
-
when NKF::UTF8
|
351
|
-
UTF8
|
352
|
-
when NKF::BINARY
|
353
|
-
BINARY
|
354
|
-
else
|
355
|
-
BINARY
|
356
|
-
end
|
287
|
+
BINARY
|
357
288
|
end
|
358
289
|
end
|
359
290
|
|
@@ -384,17 +315,7 @@ module Jpmobile
|
|
384
315
|
def split_text(str, size = 15)
|
385
316
|
return nil if str.nil? or str == ''
|
386
317
|
|
387
|
-
|
388
|
-
[str[0..(size-1)], str[size..-1]]
|
389
|
-
else
|
390
|
-
str = str.split(//u)
|
391
|
-
text = str[0..(size-1)]
|
392
|
-
text = text.join if text
|
393
|
-
remain = str[size..-1]
|
394
|
-
remain = remain.join if remain
|
395
|
-
[text, remain]
|
396
|
-
end
|
397
|
-
|
318
|
+
[str[0..(size-1)], str[size..-1]]
|
398
319
|
end
|
399
320
|
|
400
321
|
def invert_table(hash)
|
@@ -427,30 +348,16 @@ module Jpmobile
|
|
427
348
|
end
|
428
349
|
|
429
350
|
def check_charset(str, charset)
|
430
|
-
|
431
|
-
|
432
|
-
::Encoding.compatible?(guess_encoding(str), ::Encoding.find(charset))
|
433
|
-
else
|
434
|
-
true
|
435
|
-
end
|
351
|
+
# use NKF.guess
|
352
|
+
::Encoding.compatible?(NKF.guess(str), ::Encoding.find(charset))
|
436
353
|
end
|
437
354
|
|
438
355
|
def correct_encoding(str)
|
439
|
-
if
|
440
|
-
str.force_encoding(
|
356
|
+
if str.encoding != ::Encoding::ASCII_8BIT and NKF.guess(str) != str.encoding
|
357
|
+
str.force_encoding(NKF.guess(str))
|
441
358
|
end
|
442
359
|
|
443
360
|
str
|
444
361
|
end
|
445
|
-
|
446
|
-
def guess_encoding(str)
|
447
|
-
encoding = NKF.guess(str)
|
448
|
-
# ISO-2022-JPにおいて、JIS X201半角カナエスケープシーケンスが含まれていたらCP50220とみなす
|
449
|
-
if encoding == ::Encoding::ISO2022_JP && str.dup.force_encoding(BINARY).include?("\e(I")
|
450
|
-
::Encoding::CP50220
|
451
|
-
else
|
452
|
-
encoding
|
453
|
-
end
|
454
|
-
end
|
455
362
|
end
|
456
363
|
end
|
@@ -42,7 +42,7 @@ namespace :test do
|
|
42
42
|
FileUtils.rm_rf("Gemfile.lock")
|
43
43
|
FileUtils.rm_rf(rails_root)
|
44
44
|
FileUtils.mkdir_p(rails_root)
|
45
|
-
`
|
45
|
+
`rails new #{rails_root} --skip-bundle`
|
46
46
|
end
|
47
47
|
|
48
48
|
# setup jpmobile
|
@@ -93,7 +93,7 @@ END
|
|
93
93
|
# run tests in rails
|
94
94
|
cd rails_root
|
95
95
|
ruby "-S bundle install"
|
96
|
-
ruby "-S rake db:migrate
|
96
|
+
ruby "-S rake db:migrate" unless skip
|
97
97
|
ruby "-S rake spec"
|
98
98
|
# ruby "-S rspec -b --color spec/requests/filter_spec.rb -e 'jpmobile integration spec HankakuInputFilterController SoftBank 910T からのアクセス it should behave like hankaku_filter :input => true のとき はtextareaの中では半角に変換されないこと'"
|
99
99
|
end
|
@@ -67,21 +67,6 @@ describe "Jpmobile::Mail#receive" do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
describe "PC mail without subject" do
|
71
|
-
before(:each) do
|
72
|
-
@mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/pc-mail-attached-without-subject.eml")).read)
|
73
|
-
end
|
74
|
-
|
75
|
-
it "body should be parsed correctly" do
|
76
|
-
@mail.body.parts.size.should == 2
|
77
|
-
@mail.body.parts.first.body.to_s.should == "本文です\n\n"
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should encode correctly" do
|
81
|
-
ascii_8bit(@mail.to_s).should match(/GODlhAQABAIAAAAAAAP/)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
70
|
describe "Docomo" do
|
86
71
|
before(:each) do
|
87
72
|
@mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml")).read)
|
@@ -273,7 +258,7 @@ describe "Jpmobile::Mail#receive" do
|
|
273
258
|
|
274
259
|
it 'should be encoded correctly' do
|
275
260
|
@mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-message.eml")).read)
|
276
|
-
@mail.encoded
|
261
|
+
@mail.encoded
|
277
262
|
end
|
278
263
|
end
|
279
264
|
|
@@ -286,14 +271,14 @@ describe "Jpmobile::Mail#receive" do
|
|
286
271
|
|
287
272
|
it 'should be encoded correctly' do
|
288
273
|
@mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-mail3.eml")).read)
|
289
|
-
@mail.encoded
|
274
|
+
@mail.encoded
|
290
275
|
end
|
291
276
|
end
|
292
277
|
|
293
278
|
it 'should not raise when parsing attached email' do
|
294
279
|
lambda {
|
295
280
|
@mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/au-attached.eml")).read)
|
296
|
-
@mail.encoded
|
281
|
+
@mail.encoded
|
297
282
|
}.should_not raise_error
|
298
283
|
end
|
299
284
|
end
|
@@ -362,16 +347,6 @@ describe "Jpmobile::Mail#receive" do
|
|
362
347
|
@mail.body.to_s.should == "テスト本文\n\n"
|
363
348
|
end
|
364
349
|
end
|
365
|
-
|
366
|
-
context "iPhone" do
|
367
|
-
before(:each) do
|
368
|
-
@mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-jis.eml")).read)
|
369
|
-
end
|
370
|
-
|
371
|
-
it "body should be parsed correctly" do
|
372
|
-
expect(@mail.body.to_s).to eq("(=゚ω゚)ノ\n\n\n")
|
373
|
-
end
|
374
|
-
end
|
375
350
|
end
|
376
351
|
|
377
352
|
describe 'bounced mail' do
|
data/spec/unit/util_spec.rb
CHANGED
@@ -133,33 +133,22 @@ describe Jpmobile::Util do
|
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
check_charset(str, 'UTF-8').should be_true
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'returns false if incompatible' do
|
144
|
-
str = '再現'.encode('ISO-2022-JP')
|
145
|
-
check_charset(str, 'UTF-8').should be_false
|
146
|
-
end
|
136
|
+
describe 'check_charset' do
|
137
|
+
it 'returns true if compatible' do
|
138
|
+
str = 'ABC'.force_encoding('ASCII-8BIT')
|
139
|
+
check_charset(str, 'UTF-8').should be_true
|
147
140
|
end
|
148
141
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
correct_encoding(str).encoding.should == Encoding::UTF_8
|
153
|
-
end
|
142
|
+
it 'returns false if incompatible' do
|
143
|
+
str = '再現'.encode('ISO-2022-JP')
|
144
|
+
check_charset(str, 'UTF-8').should be_false
|
154
145
|
end
|
146
|
+
end
|
155
147
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
expect(guess_encoding("\e\x24\x42\x25\x46\x25\x39\x25\x48\e\x28\x42")).to eq Encoding::ISO2022_JP
|
161
|
-
expect(guess_encoding("\e\x28\x49\x43\x3D\x44\e\x28\x42")).to eq Encoding::CP50220
|
162
|
-
end
|
148
|
+
describe 'correct_encoding' do
|
149
|
+
it 'updates encoding correctly' do
|
150
|
+
str = '再現'.force_encoding('ISO-2022-JP')
|
151
|
+
correct_encoding(str).encoding.should == Encoding::UTF_8
|
163
152
|
end
|
164
153
|
end
|
165
154
|
end
|
@@ -1,21 +1,62 @@
|
|
1
|
-
source '
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rails',
|
3
|
+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
4
|
+
gem 'rails', '4.0.0'
|
4
5
|
|
5
|
-
|
6
|
+
# Use sqlite3 as the database for Active Record
|
7
|
+
gem 'sqlite3'
|
6
8
|
|
7
|
-
|
8
|
-
gem '
|
9
|
+
# Use SCSS for stylesheets
|
10
|
+
gem 'sass-rails', '~> 4.0.0'
|
11
|
+
|
12
|
+
# Use Uglifier as compressor for JavaScript assets
|
13
|
+
gem 'uglifier', '>= 1.3.0'
|
14
|
+
|
15
|
+
# Use CoffeeScript for .js.coffee assets and views
|
16
|
+
gem 'coffee-rails', '~> 4.0.0'
|
17
|
+
|
18
|
+
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
19
|
+
# gem 'therubyracer', platforms: :ruby
|
9
20
|
|
21
|
+
# Use jquery as the JavaScript library
|
10
22
|
gem 'jquery-rails'
|
11
23
|
|
24
|
+
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
|
25
|
+
gem 'turbolinks'
|
26
|
+
|
27
|
+
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
28
|
+
gem 'jbuilder', '~> 1.2'
|
29
|
+
|
30
|
+
group :doc do
|
31
|
+
# bundle exec rake doc:rails generates the API under doc/api.
|
32
|
+
gem 'sdoc', require: false
|
33
|
+
end
|
34
|
+
|
35
|
+
# Use ActiveModel has_secure_password
|
36
|
+
# gem 'bcrypt-ruby', '~> 3.0.0'
|
37
|
+
|
38
|
+
# Use unicorn as the app server
|
39
|
+
# gem 'unicorn'
|
40
|
+
|
41
|
+
# Use Capistrano for deployment
|
42
|
+
# gem 'capistrano', group: :development
|
43
|
+
|
44
|
+
# Use debugger
|
45
|
+
# gem 'debugger', group: [:development, :test]
|
46
|
+
|
47
|
+
gem 'geokit'
|
48
|
+
gem 'hpricot'
|
49
|
+
|
12
50
|
gem 'jpmobile', :path => '../../../'
|
13
51
|
gem 'jpmobile-terminfo', :path => '../../../vendor/jpmobile-terminfo'
|
14
52
|
gem 'jpmobile-ipaddresses', :path => '../../../vendor/jpmobile-ipaddresses'
|
15
53
|
|
54
|
+
gem 'activerecord-session_store', github: 'rails/activerecord-session_store'
|
55
|
+
|
16
56
|
# Bundle gems for certain environments:
|
17
57
|
group :development, :test do
|
18
58
|
gem "rspec", ">= 2.8.0"
|
19
59
|
gem "rspec-rails", ">= 2.8.0"
|
20
60
|
gem 'webrat'
|
61
|
+
gem 'pry'
|
21
62
|
end
|