jpmobile 5.0.0 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -3
- data/.rubocop.yml +123 -0
- data/CONTRIBUTING.md +16 -14
- data/Gemfile +6 -0
- data/Gemfile.lock +198 -0
- data/README.md +409 -0
- data/Rakefile +9 -9
- data/circle.yml +14 -0
- data/jpmobile.gemspec +9 -10
- data/lib/jpmobile.rb +6 -5
- data/lib/jpmobile/datum_conv.rb +35 -35
- data/lib/jpmobile/docomo_guid.rb +7 -8
- data/lib/jpmobile/email.rb +12 -12
- data/lib/jpmobile/emoticon.rb +85 -76
- data/lib/jpmobile/emoticon/au.rb +1284 -1284
- data/lib/jpmobile/emoticon/conversion_table.rb +3905 -3906
- data/lib/jpmobile/emoticon/docomo.rb +252 -252
- data/lib/jpmobile/emoticon/google.rb +9 -9
- data/lib/jpmobile/emoticon/softbank.rb +471 -471
- data/lib/jpmobile/emoticon/unicode.rb +9 -9
- data/lib/jpmobile/emoticon/z_combine.rb +20 -23
- data/lib/jpmobile/encoding.rb +1 -1
- data/lib/jpmobile/fallback_view_selector.rb +2 -3
- data/lib/jpmobile/filter.rb +44 -47
- data/lib/jpmobile/helpers.rb +38 -38
- data/lib/jpmobile/hook_action_view.rb +7 -7
- data/lib/jpmobile/hook_test_request.rb +0 -1
- data/lib/jpmobile/lookup_context.rb +1 -2
- data/lib/jpmobile/mail.rb +156 -134
- data/lib/jpmobile/mailer.rb +4 -4
- data/lib/jpmobile/mobile/abstract_mobile.rb +62 -36
- data/lib/jpmobile/mobile/android.rb +0 -1
- data/lib/jpmobile/mobile/android_tablet.rb +0 -1
- data/lib/jpmobile/mobile/au.rb +40 -28
- data/lib/jpmobile/mobile/black_berry.rb +0 -1
- data/lib/jpmobile/mobile/ddipocket.rb +1 -2
- data/lib/jpmobile/mobile/docomo.rb +47 -36
- data/lib/jpmobile/mobile/emobile.rb +1 -2
- data/lib/jpmobile/mobile/google_emoticon.rb +1 -1
- data/lib/jpmobile/mobile/ipad.rb +0 -1
- data/lib/jpmobile/mobile/iphone.rb +0 -1
- data/lib/jpmobile/mobile/smart_phone.rb +0 -1
- data/lib/jpmobile/mobile/softbank.rb +24 -20
- data/lib/jpmobile/mobile/tablet.rb +0 -1
- data/lib/jpmobile/mobile/unicode_emoticon.rb +15 -15
- data/lib/jpmobile/mobile/vodafone.rb +0 -1
- data/lib/jpmobile/mobile/willcom.rb +7 -7
- data/lib/jpmobile/mobile/windows_phone.rb +0 -1
- data/lib/jpmobile/path_set.rb +1 -1
- data/lib/jpmobile/position.rb +30 -14
- data/lib/jpmobile/rack/filter.rb +4 -4
- data/lib/jpmobile/rack/mobile_carrier.rb +0 -1
- data/lib/jpmobile/rack/params_filter.rb +7 -6
- data/lib/jpmobile/rails.rb +3 -4
- data/lib/jpmobile/request_with_mobile.rb +9 -6
- data/lib/jpmobile/resolver.rb +23 -17
- data/lib/jpmobile/session/active_record_store.rb +7 -9
- data/lib/jpmobile/session/mem_cache_store.rb +7 -9
- data/lib/jpmobile/sinatra.rb +1 -1
- data/lib/jpmobile/trans_sid.rb +15 -20
- data/lib/jpmobile/util.rb +61 -77
- data/lib/jpmobile/version.rb +1 -1
- data/lib/tasks/jpmobile_tasks.rake +35 -28
- data/spec/rack/jpmobile/android_spec.rb +5 -5
- data/spec/rack/jpmobile/au_spec.rb +74 -59
- data/spec/rack/jpmobile/black_berry_spec.rb +5 -5
- data/spec/rack/jpmobile/docomo_spec.rb +77 -64
- data/spec/rack/jpmobile/emoticon_spec.rb +137 -121
- data/spec/rack/jpmobile/filter_spec.rb +149 -128
- data/spec/rack/jpmobile/iphone_spec.rb +9 -8
- data/spec/rack/jpmobile/mobile_by_ua_spec.rb +22 -21
- data/spec/rack/jpmobile/params_filter_spec.rb +104 -96
- data/spec/rack/jpmobile/softbank_spec.rb +49 -42
- data/spec/rack/jpmobile/willcom_spec.rb +22 -18
- data/spec/rack/jpmobile/windows_phone.rb +5 -5
- data/spec/rack_helper.rb +9 -8
- data/spec/spec_helper.rb +5 -6
- data/spec/unit/decorated_mail_spec.rb +8 -9
- data/spec/unit/email_spec.rb +44 -44
- data/spec/unit/emoticon_spec.rb +57 -58
- data/spec/unit/encoding_spec.rb +35 -36
- data/spec/unit/is_carrier_spec.rb +49 -49
- data/spec/unit/mail_spec.rb +153 -143
- data/spec/unit/mobile/iphone_spec.rb +6 -7
- data/spec/unit/receive_mail_spec.rb +172 -173
- data/spec/unit/spec_helper.rb +6 -6
- data/spec/unit/util_spec.rb +125 -46
- data/spec/unit/valid_ip_spec.rb +35 -35
- data/spec/unit/variants_spec.rb +18 -19
- data/test/rails/overrides/Gemfile +54 -0
- data/test/rails/overrides/Gemfile.jpmobile +1 -2
- data/test/rails/overrides/app/controllers/admin/top_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/docomo_guid_base_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/filter_controller_base.rb +14 -6
- data/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
- data/test/rails/overrides/app/controllers/template_path_controller.rb +1 -2
- data/test/rails/overrides/app/controllers/trans_sid_base_controller.rb +18 -10
- data/test/rails/overrides/app/controllers/trans_sid_metal_controller.rb +0 -1
- data/test/rails/overrides/app/mailers/decorated_mailer.rb +3 -4
- data/test/rails/overrides/app/mailers/mobile_mailer.rb +5 -6
- data/test/rails/overrides/app/mailers/normal_mailer.rb +2 -3
- data/test/rails/overrides/autotest/discover.rb +2 -2
- data/test/rails/overrides/config/initializers/jpmobile_generator.rb +2 -2
- data/test/rails/overrides/config/routes.rb +95 -2
- data/test/rails/overrides/db/migrate/001_add_sessions_table.rb +2 -2
- data/test/rails/overrides/db/migrate/20100824062306_create_users.rb +1 -1
- data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +24 -25
- data/test/rails/overrides/spec/controllers/helpers_spec.rb +88 -88
- data/test/rails/overrides/spec/controllers/mobile_spec_controller_spec.rb +9 -9
- data/test/rails/overrides/spec/controllers/template_path_spec.rb +19 -19
- data/test/rails/overrides/spec/features/admin/top_spec.rb +7 -7
- data/test/rails/overrides/spec/features/filter_spec.rb +101 -102
- data/test/rails/overrides/spec/helpers/helpers_spec.rb +4 -4
- data/test/rails/overrides/spec/mailers/decorated_mailer_spec.rb +12 -12
- data/test/rails/overrides/spec/mailers/mobile_mailer_spec.rb +209 -194
- data/test/rails/overrides/spec/mailers/normal_mailer_spec.rb +10 -10
- data/test/rails/overrides/spec/rails_helper.rb +1 -1
- data/test/rails/overrides/spec/requests/docomo_spec.rb +13 -13
- data/test/rails/overrides/spec/requests/emobile_spec.rb +19 -19
- data/test/rails/overrides/spec/requests/pc_spec.rb +6 -6
- data/test/rails/overrides/spec/requests/softbank_emulator_spec.rb +6 -6
- data/test/rails/overrides/spec/requests/template_path_spec.rb +60 -60
- data/test/rails/overrides/spec/requests/trans_sid_spec.rb +89 -89
- data/test/sinatra/test/filter_test.rb +10 -11
- data/tools/e4u_conv.rb +0 -1
- metadata +18 -14
- data/README +0 -0
- data/README.rdoc +0 -308
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'pathname'
|
@@ -8,28 +8,28 @@ include FileUtils
|
|
8
8
|
desc 'Default: run unit tests.'
|
9
9
|
task :default => :test
|
10
10
|
|
11
|
-
desc
|
11
|
+
desc 'Update misc tables'
|
12
12
|
task :update do
|
13
|
-
Dir.glob(
|
13
|
+
Dir.glob('tools/update_*.rb').each do |path|
|
14
14
|
ruby path
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
namespace :test do
|
19
|
-
desc
|
19
|
+
desc 'Preparation of external modules'
|
20
20
|
task :prepare do
|
21
21
|
external_repos = [
|
22
|
-
|
23
|
-
|
22
|
+
'jpmobile-ipaddresses',
|
23
|
+
'jpmobile-terminfo',
|
24
24
|
]
|
25
|
-
github_prefix =
|
26
|
-
vendor_path = Pathname.new(Dir.pwd).join(
|
25
|
+
github_prefix = 'git://github.com/jpmobile'
|
26
|
+
vendor_path = Pathname.new(Dir.pwd).join('vendor')
|
27
27
|
FileUtils.mkdir_p(vendor_path)
|
28
28
|
|
29
29
|
FileUtils.cd(vendor_path) do
|
30
30
|
external_repos.each do |repos|
|
31
31
|
unless File.directory?("#{repos}/.git")
|
32
|
-
Git.clone("#{github_prefix}/#{repos}.git", repos, {:path => vendor_path})
|
32
|
+
Git.clone("#{github_prefix}/#{repos}.git", repos, { :path => vendor_path })
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/circle.yml
ADDED
data/jpmobile.gemspec
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'jpmobile/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
6
|
+
gem.name = 'jpmobile'
|
8
7
|
gem.version = Jpmobile::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.description =
|
12
|
-
gem.summary =
|
8
|
+
gem.authors = ['Shin-ichiro OGAWA', 'Yoji Shidara']
|
9
|
+
gem.email = ['rust.stnard@gmail.com']
|
10
|
+
gem.description = 'A Rails plugin for mobile devices in Japan'
|
11
|
+
gem.summary = 'Rails plugin for mobile devices in Japan'
|
13
12
|
gem.homepage = 'http://jpmobile-rails.org'
|
14
13
|
|
15
|
-
gem.files = `git ls-files`.split(
|
14
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
16
15
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
-
gem.require_paths = [
|
16
|
+
gem.require_paths = ['lib']
|
18
17
|
|
19
18
|
gem.add_development_dependency 'rails', '~> 5.0.0'
|
20
|
-
gem.add_development_dependency 'rspec'
|
21
|
-
gem.add_development_dependency 'rspec-rails'
|
19
|
+
gem.add_development_dependency 'rspec'
|
20
|
+
gem.add_development_dependency 'rspec-rails'
|
22
21
|
gem.add_development_dependency 'rspec-its'
|
23
22
|
gem.add_development_dependency 'capybara-webkit'
|
24
23
|
gem.add_development_dependency 'geokit'
|
data/lib/jpmobile.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require "jpmobile/version"
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__)) unless $LOAD_PATH.include?(File.dirname(__FILE__)) ||
|
2
|
+
$LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
require 'jpmobile/version'
|
5
4
|
require 'singleton'
|
6
5
|
require 'rack/utils'
|
7
6
|
|
@@ -41,7 +40,7 @@ module Jpmobile
|
|
41
40
|
autoload :UnicodeEmoticon, 'jpmobile/mobile/unicode_emoticon'
|
42
41
|
autoload :GoogleEmoticon, 'jpmobile/mobile/google_emoticon'
|
43
42
|
|
44
|
-
DEFAULT_CARRIERS = %w
|
43
|
+
DEFAULT_CARRIERS = %w[Docomo Au Softbank Vodafone Emobile Willcom Ddipocket Ipad AndroidTablet Iphone Android WindowsPhone BlackBerry].freeze
|
45
44
|
|
46
45
|
def self.carriers
|
47
46
|
@carriers ||= DEFAULT_CARRIERS.dup
|
@@ -65,10 +64,12 @@ module Jpmobile
|
|
65
64
|
|
66
65
|
autoload :FallbackViewSelector, 'jpmobile/fallback_view_selector'
|
67
66
|
|
67
|
+
autoload :ParamsOverCookie, 'jpmobile/trans_sid'
|
68
68
|
autoload :TransSidRedirecting, 'jpmobile/trans_sid'
|
69
69
|
autoload :TransSid, 'jpmobile/trans_sid'
|
70
70
|
|
71
71
|
module_function
|
72
|
+
|
72
73
|
def config
|
73
74
|
::Jpmobile::Configuration.instance
|
74
75
|
end
|
data/lib/jpmobile/datum_conv.rb
CHANGED
@@ -5,68 +5,68 @@
|
|
5
5
|
# 日本測量協会, 2002.
|
6
6
|
|
7
7
|
module DatumConv
|
8
|
-
GRS80 = [
|
9
|
-
Bessel = [
|
10
|
-
Tokyo97toITRF94 = [-146.414, 507.337, 680.507]
|
11
|
-
ITRF94toTokyo97 = [
|
12
|
-
Deg2Rad = Math::PI/180
|
8
|
+
GRS80 = [6_378_137, 298.257222101].freeze
|
9
|
+
Bessel = [6_377_397.155, 299.152813].freeze
|
10
|
+
Tokyo97toITRF94 = [-146.414, 507.337, 680.507].freeze
|
11
|
+
ITRF94toTokyo97 = [146.414, -507.337, -680.507].freeze
|
12
|
+
Deg2Rad = Math::PI / 180
|
13
13
|
|
14
14
|
# 緯度(度),経度(度),高度(m)を三次元直交座標(m)に変換する。
|
15
|
-
def self.blh2xyz(b_deg,l_deg,he,datum)
|
15
|
+
def self.blh2xyz(b_deg, l_deg, he, datum)
|
16
16
|
a = datum[0].to_f
|
17
|
-
f = 1.0/datum[1]
|
17
|
+
f = 1.0 / datum[1]
|
18
18
|
b = b_deg * Deg2Rad
|
19
19
|
l = l_deg * Deg2Rad
|
20
20
|
|
21
21
|
e2 = f * (2 - f)
|
22
|
-
n = a / Math.sqrt(1 - e2 * Math.sin(b)**2
|
22
|
+
n = a / Math.sqrt(1 - e2 * Math.sin(b)**2)
|
23
23
|
|
24
|
-
x = (n+he)*Math.cos(b)*Math.cos(l)
|
25
|
-
y = (n+he)*Math.cos(b)*Math.sin(l)
|
26
|
-
z = (n*(1-e2)+he)*Math.sin(b)
|
27
|
-
return x,y,z
|
24
|
+
x = (n + he) * Math.cos(b) * Math.cos(l)
|
25
|
+
y = (n + he) * Math.cos(b) * Math.sin(l)
|
26
|
+
z = (n * (1 - e2) + he) * Math.sin(b)
|
27
|
+
return x, y, z
|
28
28
|
end
|
29
29
|
|
30
30
|
# 三次元直交座標(m)を緯度(度),経度(度),高度(m)に変換する。
|
31
|
-
def self.xyz2blh(x,y,z,datum)
|
31
|
+
def self.xyz2blh(x, y, z, datum)
|
32
32
|
a = datum[0].to_f
|
33
|
-
f = 1.0/datum[1]
|
33
|
+
f = 1.0 / datum[1]
|
34
34
|
e2 = f * (2 - f)
|
35
|
-
l = Math.atan2(y,x)
|
35
|
+
l = Math.atan2(y, x)
|
36
36
|
|
37
|
-
p = Math.sqrt(x**2+y**2)
|
38
|
-
r = Math.sqrt(p**2+z**2)
|
39
|
-
u = Math.atan2(z*((1-f)+e2*a/r),p)
|
40
|
-
b = Math.atan2(z*(1-f)+e2*a*Math.sin(u)**3,(1-f)*(p-e2*a*Math.cos(u)**3))
|
37
|
+
p = Math.sqrt(x**2 + y**2)
|
38
|
+
r = Math.sqrt(p**2 + z**2)
|
39
|
+
u = Math.atan2(z * ((1 - f) + e2 * a / r), p)
|
40
|
+
b = Math.atan2(z * (1 - f) + e2 * a * Math.sin(u)**3, (1 - f) * (p - e2 * a * Math.cos(u)**3))
|
41
41
|
|
42
|
-
he = p*Math.cos(b) + z*Math.sin(b) - a*Math.sqrt(1-e2*Math.sin(b)**2)
|
42
|
+
he = p * Math.cos(b) + z * Math.sin(b) - a * Math.sqrt(1 - e2 * Math.sin(b)**2)
|
43
43
|
|
44
44
|
b_deg = b / Deg2Rad
|
45
45
|
l_deg = l / Deg2Rad
|
46
|
-
return b_deg,l_deg,he
|
46
|
+
return b_deg, l_deg, he
|
47
47
|
end
|
48
48
|
|
49
49
|
# 三次元直交座標でシフトする。
|
50
|
-
def self.xyz2xyz(x,y,z,d)
|
51
|
-
return x+d[0],y+d[1],z+d[2]
|
50
|
+
def self.xyz2xyz(x, y, z, d)
|
51
|
+
return x + d[0], y + d[1], z + d[2]
|
52
52
|
end
|
53
53
|
|
54
54
|
# 日本測地系から世界測地系に変換する。
|
55
|
-
def self.tky2jgd(b,l,he=0)
|
56
|
-
x,y,z = blh2xyz(b,l,he,Bessel)
|
57
|
-
x,y,z = xyz2xyz(x,y,z,Tokyo97toITRF94)
|
58
|
-
b,l,he = xyz2blh(x,y,z,GRS80)
|
59
|
-
return b,l,he
|
55
|
+
def self.tky2jgd(b, l, he = 0)
|
56
|
+
x, y, z = blh2xyz(b, l, he, Bessel)
|
57
|
+
x, y, z = xyz2xyz(x, y, z, Tokyo97toITRF94)
|
58
|
+
b, l, he = xyz2blh(x, y, z, GRS80)
|
59
|
+
return b, l, he
|
60
60
|
end
|
61
61
|
|
62
62
|
# 世界測地系から日本測地系に変換する。
|
63
|
-
def self.jgd2tky(b,l,he=0)
|
64
|
-
x,y,z = blh2xyz(b,l,he,GRS80)
|
65
|
-
x,y,z = xyz2xyz(x,y,z,ITRF94toTokyo97)
|
66
|
-
b,l,he = xyz2blh(x,y,z,Bessel)
|
67
|
-
return b,l,he
|
63
|
+
def self.jgd2tky(b, l, he = 0)
|
64
|
+
x, y, z = blh2xyz(b, l, he, GRS80)
|
65
|
+
x, y, z = xyz2xyz(x, y, z, ITRF94toTokyo97)
|
66
|
+
b, l, he = xyz2blh(x, y, z, Bessel)
|
67
|
+
return b, l, he
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
#DatumConv.tky2jgd(b,l)
|
72
|
-
#DatumConv.jgd2tky(b,l)
|
71
|
+
# DatumConv.tky2jgd(b,l)
|
72
|
+
# DatumConv.jgd2tky(b,l)
|
data/lib/jpmobile/docomo_guid.rb
CHANGED
@@ -1,27 +1,26 @@
|
|
1
|
-
#
|
2
|
-
#DoCoMoの時guid=onの付与
|
1
|
+
# DoCoMoの時guid=onの付与
|
3
2
|
class ActionController::Base #:nodoc:
|
4
3
|
class_attribute :docomo_guid_mode
|
5
4
|
|
6
5
|
class << self
|
7
|
-
def docomo_guid(mode
|
6
|
+
def docomo_guid(mode = :docomo)
|
8
7
|
include Jpmobile::DocomoGuid
|
9
8
|
self.docomo_guid_mode = mode
|
10
9
|
end
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
13
|
module Jpmobile::DocomoGuid #:nodoc:
|
16
14
|
protected
|
15
|
+
|
17
16
|
def default_url_options
|
18
17
|
result = super || {}
|
19
18
|
return result unless request # for test process
|
20
19
|
return result unless apply_add_guid?
|
21
|
-
|
20
|
+
result.merge({ guid: 'ON' })
|
22
21
|
end
|
23
22
|
|
24
|
-
#guid=ONを付与すべきか否かを返す
|
23
|
+
# guid=ONを付与すべきか否かを返す
|
25
24
|
def apply_add_guid?
|
26
25
|
return true if docomo_guid_mode == :always
|
27
26
|
return false if docomo_guid_mode == :none
|
@@ -34,10 +33,10 @@ module Jpmobile::DocomoGuid #:nodoc:
|
|
34
33
|
return false unless request.mobile.valid_ip?
|
35
34
|
end
|
36
35
|
|
37
|
-
|
36
|
+
true
|
38
37
|
end
|
39
38
|
|
40
39
|
def not_apply_guid_user_agent?
|
41
|
-
request.user_agent.match(
|
40
|
+
request.user_agent.match(%r{(?:Googlebot|Y!J-SRD/1\.0|Y!J-MBS/1\.0)})
|
42
41
|
end
|
43
42
|
end
|
data/lib/jpmobile/email.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
# =メールアドレスモジュール
|
3
2
|
#
|
4
3
|
module Jpmobile
|
5
4
|
# email関連の処理
|
6
5
|
class Email
|
7
6
|
class << self
|
8
|
-
@@japanese_mail_address_regexp = nil
|
9
|
-
@@converting_content_type = ['text/plain', 'text/html']
|
10
|
-
|
11
7
|
# メールアドレスよりキャリア情報を取得する
|
12
8
|
# _param1_:: email メールアドレス
|
13
9
|
# return :: Jpmobile::Mobileで定義されている携帯キャリアクラス
|
@@ -24,8 +20,8 @@ module Jpmobile
|
|
24
20
|
Mobile.carriers.each do |const|
|
25
21
|
c = Mobile.const_get(const)
|
26
22
|
if c::MAIL_ADDRESS_REGEXP &&
|
27
|
-
|
28
|
-
|
23
|
+
header.match(/(\S+@[A-Za-z0-9\-\.\_]+)/) &&
|
24
|
+
Regexp.last_match(1).match(/^#{c::MAIL_ADDRESS_REGEXP}$/)
|
29
25
|
return c
|
30
26
|
end
|
31
27
|
end
|
@@ -37,17 +33,21 @@ module Jpmobile
|
|
37
33
|
nil
|
38
34
|
end
|
39
35
|
|
40
|
-
|
41
|
-
@@japanese_mail_address_regexp = regexp
|
42
|
-
end
|
36
|
+
attr_writer :japanese_mail_address_regexp
|
43
37
|
|
44
38
|
def japanese_mail?(header)
|
45
|
-
|
39
|
+
@japanese_mail_address_regexp and header.match(@japanese_mail_address_regexp)
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_writer :converting_content_type
|
43
|
+
|
44
|
+
def converting_content_type
|
45
|
+
@converting_content_type ||= ['text/plain', 'text/html']
|
46
46
|
end
|
47
47
|
|
48
48
|
def convertable?(content_type)
|
49
|
-
if
|
50
|
-
|
49
|
+
if converting_content_type.respond_to?(:each)
|
50
|
+
converting_content_type.each do |c|
|
51
51
|
return true if content_type.match(c)
|
52
52
|
end
|
53
53
|
end
|
data/lib/jpmobile/emoticon.rb
CHANGED
@@ -1,27 +1,25 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
1
|
require 'scanf'
|
4
2
|
require 'nkf'
|
5
3
|
|
6
4
|
module Jpmobile
|
7
5
|
# 絵文字関連処理
|
8
6
|
module Emoticon
|
9
|
-
%w
|
7
|
+
%w[DOCOMO_SJIS_TO_UNICODE DOCOMO_UNICODE_TO_SJIS].each do |const|
|
10
8
|
autoload const, 'jpmobile/emoticon/docomo'
|
11
9
|
end
|
12
|
-
%w
|
10
|
+
%w[AU_SJIS_TO_UNICODE AU_UNICODE_TO_EMAILJIS AU_SJIS_TO_EMAIL_JIS AU_EMAILJIS_TO_UNICODE].each do |const|
|
13
11
|
autoload const, 'jpmobile/emoticon/au'
|
14
12
|
end
|
15
|
-
%w
|
13
|
+
%w[
|
16
14
|
SOFTBANK_UNICODE_TO_WEBCODE SOFTBANK_WEBCODE_TO_UNICODE
|
17
15
|
SOFTBANK_UNICODE_TO_SJIS SOFTBANK_SJIS_TO_UNICODE
|
18
|
-
|
16
|
+
].each do |const|
|
19
17
|
autoload const, 'jpmobile/emoticon/softbank'
|
20
18
|
end
|
21
|
-
%w
|
19
|
+
%w[CONVERSION_TABLE_TO_DOCOMO CONVERSION_TABLE_TO_AU CONVERSION_TABLE_TO_SOFTBANK].each do |const|
|
22
20
|
autoload const, 'jpmobile/emoticon/conversion_table'
|
23
21
|
end
|
24
|
-
%w
|
22
|
+
%w[
|
25
23
|
SJIS_TO_UNICODE UNICODE_TO_SJIS
|
26
24
|
SJIS_REGEXP SOFTBANK_WEBCODE_REGEXP DOCOMO_SJIS_REGEXP AU_SJIS_REGEXP SOFTBANK_UNICODE_REGEXP
|
27
25
|
EMOTICON_UNICODES UTF8_REGEXP
|
@@ -30,13 +28,13 @@ module Jpmobile
|
|
30
28
|
GOOGLE_EMOTICONS GOOGLE_EMOTICON_REGEXP GOOGLE_EMOTICON_TO_CARRIER_EMOTICON
|
31
29
|
CONVERSION_TABLE_TO_UNICODE_EMOTICON CONVERSION_TABLE_TO_GOOGLE_EMOTICON
|
32
30
|
GETA_CODE GETA
|
33
|
-
|
31
|
+
].each do |const|
|
34
32
|
autoload const, 'jpmobile/emoticon/z_combine'
|
35
33
|
end
|
36
|
-
%w
|
34
|
+
%w[GOOGLE_TO_DOCOMO_UNICODE GOOGLE_TO_AU_UNICODE GOOGLE_TO_SOFTBANK_UNICODE].each do |const|
|
37
35
|
autoload const, 'jpmobile/emoticon/google'
|
38
36
|
end
|
39
|
-
%w
|
37
|
+
%w[UNICODE_TO_DOCOMO_UNICODE UNICODE_TO_AU_UNICODE UNICODE_TO_SOFTBANK_UNICODE].each do |const|
|
40
38
|
autoload const, 'jpmobile/emoticon/unicode'
|
41
39
|
end
|
42
40
|
|
@@ -45,7 +43,7 @@ module Jpmobile
|
|
45
43
|
str.gsub(DOCOMO_SJIS_REGEXP) do |match|
|
46
44
|
sjis = match.unpack('n').first
|
47
45
|
unicode = DOCOMO_SJIS_TO_UNICODE[sjis]
|
48
|
-
unicode ? (
|
46
|
+
unicode ? ('&#x%04x;' % unicode) : match
|
49
47
|
end
|
50
48
|
end
|
51
49
|
|
@@ -54,7 +52,7 @@ module Jpmobile
|
|
54
52
|
str.gsub(AU_SJIS_REGEXP) do |match|
|
55
53
|
sjis = match.unpack('n').first
|
56
54
|
unicode = AU_SJIS_TO_UNICODE[sjis]
|
57
|
-
unicode ? (
|
55
|
+
unicode ? ('&#x%04x;' % unicode) : match
|
58
56
|
end
|
59
57
|
end
|
60
58
|
|
@@ -65,7 +63,7 @@ module Jpmobile
|
|
65
63
|
jis_string.gsub(/[\x21-\x7e]{2}/) do |match|
|
66
64
|
jis = match.unpack('n').first
|
67
65
|
unicode = AU_EMAILJIS_TO_UNICODE[jis]
|
68
|
-
unicode ? Jpmobile::Util.ascii_8bit("\x1b\x28\x42&#x%04x;\x1b\x24\x42"%unicode) : match
|
66
|
+
unicode ? Jpmobile::Util.ascii_8bit("\x1b\x28\x42&#x%04x;\x1b\x24\x42" % unicode) : match
|
69
67
|
end
|
70
68
|
end
|
71
69
|
end
|
@@ -75,17 +73,19 @@ module Jpmobile
|
|
75
73
|
# SoftBank Unicode
|
76
74
|
str.gsub(SOFTBANK_UNICODE_REGEXP) do |match|
|
77
75
|
unicode = match.unpack('U').first
|
78
|
-
|
76
|
+
'&#x%04x;' % (unicode + 0x1000)
|
79
77
|
end
|
80
78
|
end
|
79
|
+
|
81
80
|
def self.external_to_unicodecr_softbank_sjis(str)
|
82
81
|
# SoftBank Shift_JIS
|
83
82
|
str.gsub(SOFTBANK_SJIS_REGEXP) do |match|
|
84
83
|
sjis = match.unpack('n').first
|
85
84
|
unicode = SOFTBANK_SJIS_TO_UNICODE[sjis]
|
86
|
-
|
85
|
+
'&#x%04x;' % (unicode + 0x1000)
|
87
86
|
end
|
88
87
|
end
|
88
|
+
|
89
89
|
def self.external_to_unicodecr_vodafone(str)
|
90
90
|
external_to_unicodecr_softbank(str)
|
91
91
|
end
|
@@ -103,7 +103,7 @@ module Jpmobile
|
|
103
103
|
when GETA_CODE
|
104
104
|
GETA
|
105
105
|
when Integer
|
106
|
-
|
106
|
+
'&#x%04x;' % emoticon
|
107
107
|
when String
|
108
108
|
emoticon
|
109
109
|
end
|
@@ -120,15 +120,14 @@ module Jpmobile
|
|
120
120
|
unicodes = match.unpack('U*')
|
121
121
|
unicodes = unicodes.first if unicodes.size == 1
|
122
122
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
123
|
+
emoticon = GOOGLE_EMOTICON_TO_CARRIER_EMOTICON[unicodes]
|
124
|
+
case emoticon
|
125
|
+
when GETA_CODE
|
126
|
+
GETA
|
127
|
+
when Integer
|
128
|
+
'&#x%04x;' % emoticon
|
129
|
+
when String
|
130
|
+
emoticon
|
132
131
|
else
|
133
132
|
# 変換できなければ〓に
|
134
133
|
GETA
|
@@ -143,32 +142,33 @@ module Jpmobile
|
|
143
142
|
#
|
144
143
|
# 携帯側エンコーディングがShift_JIS場合は +to_sjis+ に +true+ を指定する。
|
145
144
|
# +true+ を指定すると変換テーブルに文字列が指定されている場合にShift_JISで出力される。
|
146
|
-
def self.unicodecr_to_external(str, conversion_table=nil, to_sjis=true)
|
145
|
+
def self.unicodecr_to_external(str, conversion_table = nil, to_sjis = true)
|
147
146
|
str.gsub(/&#x([0-9a-f]{4});/i) do |match|
|
148
|
-
unicode =
|
147
|
+
unicode = Regexp.last_match(1).scanf('%x').first
|
149
148
|
|
150
|
-
if conversion_table
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
149
|
+
converted = if conversion_table
|
150
|
+
conversion_table[unicode] # キャリア間変換
|
151
|
+
else
|
152
|
+
unicode # 変換しない
|
153
|
+
end
|
155
154
|
|
156
155
|
# 携帯側エンコーディングに変換する
|
157
156
|
case converted
|
158
157
|
when Integer
|
159
158
|
# 変換先がUnicodeで指定されている。つまり対応する絵文字がある。
|
160
|
-
|
159
|
+
sjis = UNICODE_TO_SJIS[converted]
|
160
|
+
if sjis
|
161
161
|
if to_sjis
|
162
162
|
Jpmobile::Util.sjis([sjis].pack('n'))
|
163
163
|
else
|
164
|
-
[converted].pack(
|
164
|
+
[converted].pack('U')
|
165
165
|
end
|
166
|
-
elsif SOFTBANK_UNICODE_TO_WEBCODE[converted-0x1000]
|
167
|
-
[converted-0x1000].pack('U')
|
166
|
+
elsif SOFTBANK_UNICODE_TO_WEBCODE[converted - 0x1000]
|
167
|
+
[converted - 0x1000].pack('U')
|
168
168
|
elsif converted == GETA_CODE
|
169
169
|
# PCで〓を表示する場合
|
170
170
|
GETA
|
171
|
-
elsif UNICODE_EMOTICONS.include?(converted)
|
171
|
+
elsif UNICODE_EMOTICONS.include?(converted) || GOOGLE_EMOTICONS.include?(converted)
|
172
172
|
if unicode == GETA_CODE
|
173
173
|
GETA
|
174
174
|
else
|
@@ -181,7 +181,7 @@ module Jpmobile
|
|
181
181
|
end
|
182
182
|
when String
|
183
183
|
# 変換先が数値参照だと、再変換する
|
184
|
-
if converted
|
184
|
+
if converted =~ /&#x([0-9a-f]{4});/i
|
185
185
|
self.unicodecr_to_external(converted, conversion_table, to_sjis)
|
186
186
|
else
|
187
187
|
# 変換先が文字列で指定されている。
|
@@ -193,21 +193,23 @@ module Jpmobile
|
|
193
193
|
end
|
194
194
|
end
|
195
195
|
end
|
196
|
+
|
196
197
|
# +str+ のなかでUnicode数値文字参照で表記された絵文字をUTF-8に置換する。
|
197
198
|
def self.unicodecr_to_utf8(str)
|
198
199
|
str.gsub(/&#x([0-9a-f]{4});/i) do |match|
|
199
|
-
unicode =
|
200
|
-
if UNICODE_TO_SJIS[unicode] || SOFTBANK_UNICODE_TO_WEBCODE[unicode-0x1000]
|
200
|
+
unicode = Regexp.last_match(1).scanf('%x').first
|
201
|
+
if UNICODE_TO_SJIS[unicode] || SOFTBANK_UNICODE_TO_WEBCODE[unicode - 0x1000]
|
201
202
|
[unicode].pack('U')
|
202
203
|
else
|
203
204
|
match
|
204
205
|
end
|
205
206
|
end
|
206
207
|
end
|
208
|
+
|
207
209
|
# +str+ のなかでUTF-8で表記された絵文字をUnicode数値文字参照に置換する。
|
208
210
|
def self.utf8_to_unicodecr(str)
|
209
211
|
str.gsub(UTF8_REGEXP) do |match|
|
210
|
-
|
212
|
+
'&#x%04x;' % match.unpack('U').first
|
211
213
|
end
|
212
214
|
end
|
213
215
|
|
@@ -215,17 +217,19 @@ module Jpmobile
|
|
215
217
|
# au 専用
|
216
218
|
def self.unicodecr_to_au_email(in_str)
|
217
219
|
str = Jpmobile::Util.ascii_8bit(in_str)
|
218
|
-
regexp = Regexp.compile(Jpmobile::Util.ascii_8bit(
|
220
|
+
regexp = Regexp.compile(Jpmobile::Util.ascii_8bit('&#x([0-9a-f]{4});'), Regexp::IGNORECASE)
|
219
221
|
str = str.gsub(regexp) do |match|
|
220
|
-
unicode =
|
222
|
+
unicode = Regexp.last_match(1).scanf('%x').first
|
221
223
|
converted = CONVERSION_TABLE_TO_AU[unicode]
|
222
224
|
|
223
225
|
# メール用エンコーディングに変換する
|
224
226
|
case converted
|
225
227
|
when Integer
|
226
|
-
|
227
|
-
|
228
|
-
|
228
|
+
sjis = UNICODE_TO_SJIS[converted]
|
229
|
+
if sjis
|
230
|
+
email_jis = SJIS_TO_EMAIL_JIS[sjis]
|
231
|
+
if email_jis
|
232
|
+
Jpmobile::Util.ascii_8bit("\x1b\x24\x42#{[email_jis].pack("n")}\x1b\x28\x42")
|
229
233
|
else
|
230
234
|
Jpmobile::Util.ascii_8bit([sjis].pack('n'))
|
231
235
|
end
|
@@ -247,13 +251,14 @@ module Jpmobile
|
|
247
251
|
# softbank 専用
|
248
252
|
def self.unicodecr_to_softbank_email(str)
|
249
253
|
str.gsub(/&#x([0-9a-f]{4});/i) do |match|
|
250
|
-
unicode =
|
254
|
+
unicode = Regexp.last_match(1).scanf('%x').first
|
251
255
|
converted = CONVERSION_TABLE_TO_SOFTBANK[unicode]
|
252
256
|
|
253
257
|
# メール用エンコーディングに変換する
|
254
258
|
case converted
|
255
259
|
when Integer
|
256
|
-
|
260
|
+
sjis = SOFTBANK_UNICODE_TO_SJIS[converted - 0x1000]
|
261
|
+
if sjis
|
257
262
|
Jpmobile::Util.sjis([sjis].pack('n'))
|
258
263
|
else
|
259
264
|
match
|
@@ -267,53 +272,57 @@ module Jpmobile
|
|
267
272
|
end
|
268
273
|
end
|
269
274
|
|
270
|
-
@@pc_emoticon_image_path = nil
|
271
|
-
@@pc_emoticon_yaml = nil
|
272
|
-
@@pc_emoticon_hash = nil
|
273
|
-
|
274
275
|
def self.pc_emoticon_image_path
|
275
|
-
|
276
|
+
@pc_emoticon_image_path
|
276
277
|
end
|
278
|
+
|
277
279
|
def self.pc_emoticon_image_path=(path)
|
278
|
-
|
280
|
+
@pc_emoticon_image_path = path
|
279
281
|
end
|
280
282
|
|
281
283
|
def self.pc_emoticon_yaml=(file)
|
282
|
-
|
284
|
+
@pc_emoticon_yaml = file
|
283
285
|
end
|
286
|
+
|
284
287
|
def self.pc_emoticon_yaml
|
285
|
-
|
288
|
+
@pc_emoticon_yaml
|
286
289
|
end
|
287
290
|
|
288
291
|
def self.pc_emoticon?
|
289
|
-
if
|
292
|
+
if @pc_emoticon_yaml && File.exist?(@pc_emoticon_yaml) && @pc_emoticon_image_path
|
293
|
+
return true if @pc_emoticon_hash
|
290
294
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
@@pc_emoticon_image_path.chop if @@pc_emoticon_image_path.match(/\/$/)
|
295
|
+
begin
|
296
|
+
yaml_hash = YAML.load_file(@pc_emoticon_yaml)
|
297
|
+
@pc_emoticon_hash = Hash[*(yaml_hash.values.inject([]) { |r, v| r += v.to_a.flatten; r })]
|
298
|
+
@pc_emoticon_image_path.chop if @pc_emoticon_image_path =~ %r{/$}
|
296
299
|
|
297
|
-
return true
|
298
|
-
rescue
|
299
|
-
end
|
300
|
-
else
|
301
300
|
return true
|
301
|
+
rescue
|
302
302
|
end
|
303
303
|
end
|
304
304
|
|
305
|
-
|
305
|
+
false
|
306
306
|
end
|
307
307
|
|
308
308
|
def self.emoticons_to_image(str)
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
309
|
+
return str unless @pc_emoticon_hash
|
310
|
+
|
311
|
+
utf8_to_unicodecr(str).gsub(/&#x([0-9a-f]{4});/i) do
|
312
|
+
img = @pc_emoticon_hash[Regexp.last_match(1).upcase]
|
313
|
+
unless img
|
314
|
+
img =
|
315
|
+
begin
|
316
|
+
@pc_emoticon_hash[('%x' % (Regexp.last_match(1).scanf('%x').first - 0x1000)).upcase]
|
317
|
+
rescue
|
318
|
+
nil
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
if img
|
323
|
+
"<img src=\"#{@pc_emoticon_image_path}/#{img}.gif\" alt=\"#{img}\" />"
|
324
|
+
else
|
325
|
+
''
|
317
326
|
end
|
318
327
|
end
|
319
328
|
end
|