jpmobile 1.0.12 → 2.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/Gemfile +3 -3
  2. data/README.rdoc +2 -14
  3. data/Rakefile +0 -1
  4. data/VERSION.yml +4 -4
  5. data/jpmobile.gemspec +2 -1
  6. data/lib/jpmobile.rb +1 -15
  7. data/lib/jpmobile/docomo_guid.rb +1 -1
  8. data/lib/jpmobile/emoticon.rb +3 -119
  9. data/lib/jpmobile/emoticon/z_combine.rb +1 -17
  10. data/lib/jpmobile/filter.rb +1 -6
  11. data/lib/jpmobile/helpers.rb +1 -1
  12. data/lib/jpmobile/mail.rb +27 -196
  13. data/lib/jpmobile/mailer.rb +1 -7
  14. data/lib/jpmobile/mobile/abstract_mobile.rb +36 -94
  15. data/lib/jpmobile/mobile/android.rb +0 -2
  16. data/lib/jpmobile/mobile/au.rb +0 -4
  17. data/lib/jpmobile/mobile/docomo.rb +0 -8
  18. data/lib/jpmobile/mobile/iphone.rb +15 -1
  19. data/lib/jpmobile/mobile/smart_phone.rb +0 -10
  20. data/lib/jpmobile/mobile/softbank.rb +0 -8
  21. data/lib/jpmobile/rack.rb +1 -6
  22. data/lib/jpmobile/rack/filter.rb +1 -7
  23. data/lib/jpmobile/rack/params_filter.rb +2 -2
  24. data/lib/jpmobile/rails.rb +1 -1
  25. data/lib/jpmobile/resolver.rb +2 -5
  26. data/lib/jpmobile/trans_sid.rb +1 -26
  27. data/lib/jpmobile/util.rb +11 -82
  28. data/lib/tasks/jpmobile_tasks.rake +1 -1
  29. data/spec/rack/jpmobile/emoticon_spec.rb +0 -223
  30. data/spec/rack/jpmobile/mobile_by_ua_spec.rb +1 -5
  31. data/spec/rack/jpmobile/softbank_spec.rb +1 -1
  32. data/spec/unit/emoticon_spec.rb +0 -64
  33. data/spec/unit/encoding_spec.rb +2 -2
  34. data/spec/unit/mail_spec.rb +2 -159
  35. data/spec/unit/receive_mail_spec.rb +5 -51
  36. data/spec/unit/spec_helper.rb +1 -1
  37. data/spec/unit/util_spec.rb +3 -62
  38. data/test/rails/overrides/Gemfile +1 -1
  39. data/test/rails/overrides/app/controllers/filter_controller_base.rb +0 -3
  40. data/test/rails/overrides/app/controllers/hankaku_input_filter_controller.rb +0 -3
  41. data/test/rails/overrides/app/controllers/template_path_controller.rb +0 -12
  42. data/test/rails/overrides/app/{mailers → models}/mobile_mailer.rb +1 -7
  43. data/test/rails/overrides/app/{mailers → models}/normal_mailer.rb +0 -0
  44. data/test/rails/overrides/spec/{mailers → models}/mobile_mailer_spec.rb +1 -18
  45. data/test/rails/overrides/spec/{mailers → models}/normal_mailer_spec.rb +0 -0
  46. data/test/rails/overrides/spec/requests/filter_spec.rb +0 -18
  47. data/test/rails/overrides/spec/requests/template_path_spec.rb +0 -72
  48. data/test/rails/overrides/spec/spec_helper.rb +1 -1
  49. data/test/sinatra/guestbook.rb +7 -8
  50. data/test/sinatra/test/filter_test.rb +0 -10
  51. metadata +169 -296
  52. data/lib/jpmobile/emoticon/google.rb +0 -2421
  53. data/lib/jpmobile/emoticon/unicode.rb +0 -2253
  54. data/lib/jpmobile/mobile/android_tablet.rb +0 -12
  55. data/lib/jpmobile/mobile/black_berry.rb +0 -10
  56. data/lib/jpmobile/mobile/google_emoticon.rb +0 -29
  57. data/lib/jpmobile/mobile/ipad.rb +0 -12
  58. data/lib/jpmobile/mobile/tablet.rb +0 -16
  59. data/lib/jpmobile/mobile/unicode_emoticon.rb +0 -43
  60. data/lib/jpmobile/sinatra.rb +0 -16
  61. data/spec/rack/jpmobile/black_berry_spec.rb +0 -20
  62. data/spec/unit/decorated_mail_spec.rb +0 -76
  63. data/spec/unit/email-fixtures/bounce_with_utf8_part.eml +0 -42
  64. data/spec/unit/email-fixtures/iphone-mail3.eml +0 -56
  65. data/spec/unit/email-fixtures/iphone-message.eml +0 -27
  66. data/spec/unit/email-fixtures/photo.jpg +0 -0
  67. data/spec/unit/mobile/iphone_spec.rb +0 -34
  68. data/test/rails/overrides/app/mailers/decorated_mailer.rb +0 -11
  69. data/test/rails/overrides/app/views/decorated_mailer/deco_mail.html.erb +0 -10
  70. data/test/rails/overrides/app/views/decorated_mailer/deco_mail.text.erb +0 -1
  71. data/test/rails/overrides/app/views/hankaku_input_filter/with_charset.html.erb +0 -1
  72. data/test/rails/overrides/app/views/layouts/with_charset.html.erb +0 -13
  73. data/test/rails/overrides/app/views/template_path/smart_phone_only.html.erb +0 -1
  74. data/test/rails/overrides/app/views/template_path/smart_phone_only_smart_phone.html.erb +0 -1
  75. data/test/rails/overrides/app/views/template_path/with_ipd.html.erb +0 -1
  76. data/test/rails/overrides/app/views/template_path/with_ipd_tablet_ipad.html.erb +0 -1
  77. data/test/rails/overrides/app/views/template_path/with_tblt.html.erb +0 -1
  78. data/test/rails/overrides/app/views/template_path/with_tblt_tablet.html.erb +0 -1
  79. data/test/rails/overrides/spec/fixtures/mobile_mailer/bounced-jp.eml +0 -72
  80. data/test/rails/overrides/spec/fixtures/mobile_mailer/photo.jpg +0 -0
  81. data/test/rails/overrides/spec/mailers/decorated_mailer_spec.rb +0 -44
  82. data/test/sinatra/config.ru +0 -2
  83. data/test/sinatra/views/index.erb +0 -1
  84. data/test/sinatra/views/index_mobile.erb +0 -1
  85. data/tools/e4u_conv.rb +0 -122
data/Gemfile CHANGED
@@ -2,9 +2,9 @@ source 'http://rubygems.org'
2
2
 
3
3
  group :development, :test do
4
4
  gem 'jeweler'
5
- gem 'rails', '~>3.0.17'
6
- gem 'rspec', '~>2.6.0'
7
- gem 'rspec-rails', '~>2.6.0'
5
+ gem 'rails', '3.1.0.rc5'
6
+ gem 'rspec'
7
+ gem 'rspec-rails'
8
8
  gem 'webrat'
9
9
  gem 'geokit'
10
10
  gem 'sqlite3-ruby'
data/README.rdoc CHANGED
@@ -150,19 +150,10 @@ jpmobileを読み込むとDoCoMo、Au、SoftBankの絵文字を透過的に扱
150
150
  * Rails の場合は vendor/plugins に配置し、下記の設定を追加することで有効になる。
151
151
  # Rack middleware を追加するメソッド
152
152
  Rails.application.config.jpmobile.mobile_filter
153
- or
154
- Jpmobile.config.mobile_filter
155
153
 
156
154
  * 下記の設定を追加することで、<form> タグの accept-charset が変更される。
157
155
  # <form accept-charset="Shift_JIS" ...> などに変更する
158
156
  Rails.application.config.jpmobile.form_accept_charset_conversion = true
159
- or
160
- Jpmobile.config.form_accept_charset_conversion = true
161
-
162
- * Andriod/iPhone では Google 絵文字や Unicode 6.0 絵文字が使われています。下記の設定を追加すると、互換性をもたせるために3キャリアの絵文字に変換することができます。また表示の変換も可能です。
163
- Rails.application.config.jpmobile.smart_phone_emoticon_compatibility = true
164
- or
165
- Jpmobile.config.smart_phone_emoticon_compatibility = true
166
157
 
167
158
  携帯電話上では特に問題とならない。PCブラウザでテストする際に問題となるためのオプション。
168
159
 
@@ -232,7 +223,7 @@ Androidの場合はindex_smart_phone_android.html.erb、Windows Phoneの場合
232
223
  === 位置情報の取得用リンクの生成
233
224
 
234
225
  以下のようなコードで、端末に位置情報を要求するリンクを出力する。
235
- <%= get_position_link_to("位置情報を取得する", :action=>:gps) %>
226
+ <%= get_position_link_to(:action=>:gps) %>
236
227
 
237
228
  === セッションIDの付与(Trans SID)
238
229
  ==== Cookie非対応携帯だけに付与する
@@ -280,10 +271,7 @@ trans_sid を使用する際には、例えば config/initializers/session_store
280
271
  * au は ISO-2022-JP エンコードで送信
281
272
  * ビューやレイアウトの自動振り分け
282
273
  * docomo であれば app/views/mobile_mailer/registration_mobile_docomo.html.erb など
283
- * 受信に関しては、docomo/SoftBank でテストできていないため、実験版とします。
284
- * テストして問題あれば随時報告してください。
285
- * オプションに :decorated => true を追加すると、各キャリアのデコメに適したフォーマットで送信します。
286
- * ただし docomo/SoftBank でテスト出来ていないため、実験版とします。
274
+ * 受信に関しては、docomo/SoftBank でテストできないため、実験版とします。
287
275
 
288
276
  == テストに必要なgemパッケージ
289
277
  テストを実行するためには以下のgemパッケージが必要です。
data/Rakefile CHANGED
@@ -20,7 +20,6 @@ begin
20
20
 
21
21
  gem.files.exclude 'test'
22
22
  gem.files.exclude 'spec'
23
- gem.files.exclude 'vendor'
24
23
 
25
24
  gem.add_development_dependency('jeweler', '>=1.5.1')
26
25
  gem.add_development_dependency('rspec', '>=2.3.0')
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
- ---
2
- :patch: 12
1
+ ---
2
+ :major: 2
3
3
  :minor: 0
4
- :build:
5
- :major: 1
4
+ :patch: 0
5
+ :build: pre.1
data/jpmobile.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jpmobile}
8
- s.version = "1.0.11"
8
+ s.version = "1.0.0.pre"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yoji Shidara", "Shin-ichiro OGAWA"]
@@ -332,3 +332,4 @@ Gem::Specification.new do |s|
332
332
  s.add_dependency(%q<rails>, [">= 3.0.3"])
333
333
  end
334
334
  end
335
+
data/lib/jpmobile.rb CHANGED
@@ -22,23 +22,14 @@ module Jpmobile
22
22
  autoload :Emobile, 'jpmobile/mobile/emobile'
23
23
  autoload :Willcom, 'jpmobile/mobile/willcom'
24
24
  autoload :Ddipocket, 'jpmobile/mobile/ddipocket'
25
-
26
25
  autoload :SmartPhone, 'jpmobile/mobile/smart_phone'
27
26
  autoload :Iphone, 'jpmobile/mobile/iphone'
28
27
  autoload :Android, 'jpmobile/mobile/android'
29
28
  autoload :WindowsPhone, 'jpmobile/mobile/windows_phone'
30
- autoload :BlackBerry, 'jpmobile/mobile/black_berry'
31
-
32
- autoload :Tablet, 'jpmobile/mobile/tablet'
33
- autoload :AndroidTablet, 'jpmobile/mobile/android_tablet'
34
- autoload :Ipad, 'jpmobile/mobile/ipad'
35
29
 
36
30
  autoload :Display, 'jpmobile/mobile/display'
37
31
 
38
- autoload :UnicodeEmoticon, 'jpmobile/mobile/unicode_emoticon'
39
- autoload :GoogleEmoticon, 'jpmobile/mobile/google_emoticon'
40
-
41
- DEFAULT_CARRIERS = %w(Docomo Au Softbank Vodafone Emobile Willcom Ddipocket Ipad AndroidTablet Iphone Android WindowsPhone BlackBerry)
32
+ DEFAULT_CARRIERS = %w(Docomo Au Softbank Vodafone Emobile Willcom Ddipocket Iphone Android WindowsPhone)
42
33
 
43
34
  def self.carriers
44
35
  @carriers ||= DEFAULT_CARRIERS.dup
@@ -61,11 +52,6 @@ module Jpmobile
61
52
 
62
53
  autoload :Mailer, 'jpmobile/mailer'
63
54
  autoload :Resolver, 'jpmobile/resolver'
64
-
65
- module_function
66
- def config
67
- ::Jpmobile::Configuration.instance
68
- end
69
55
  end
70
56
 
71
57
  if defined?(Rails)
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #DoCoMoの時guid=onの付与
3
3
  class ActionController::Base #:nodoc:
4
- class_inheritable_accessor :docomo_guid_mode
4
+ class_attribute :docomo_guid_mode
5
5
 
6
6
  class << self
7
7
  def docomo_guid(mode=:docomo)
@@ -26,19 +26,9 @@ module Jpmobile
26
26
  SJIS_REGEXP SOFTBANK_WEBCODE_REGEXP DOCOMO_SJIS_REGEXP AU_SJIS_REGEXP SOFTBANK_UNICODE_REGEXP
27
27
  EMOTICON_UNICODES UTF8_REGEXP
28
28
  CONVERSION_TABLE_TO_PC_EMAIL SOFTBANK_SJIS_REGEXP AU_EMAILJIS_REGEXP
29
- UNICODE_EMOTICONS UNICODE_EMOTICON_REGEXP UNICODE_EMOTICON_TO_CARRIER_EMOTICON
30
- GOOGLE_EMOTICONS GOOGLE_EMOTICON_REGEXP GOOGLE_EMOTICON_TO_CARRIER_EMOTICON
31
- CONVERSION_TABLE_TO_UNICODE_EMOTICON CONVERSION_TABLE_TO_GOOGLE_EMOTICON
32
- GETA_CODE GETA
33
29
  ).each do |const|
34
30
  autoload const, 'jpmobile/emoticon/z_combine'
35
31
  end
36
- %w( GOOGLE_TO_DOCOMO_UNICODE GOOGLE_TO_AU_UNICODE GOOGLE_TO_SOFTBANK_UNICODE ).each do |const|
37
- autoload const, 'jpmobile/emoticon/google'
38
- end
39
- %w( UNICODE_TO_DOCOMO_UNICODE UNICODE_TO_AU_UNICODE UNICODE_TO_SOFTBANK_UNICODE ).each do |const|
40
- autoload const, 'jpmobile/emoticon/unicode'
41
- end
42
32
 
43
33
  # +str+ のなかでDoCoMo絵文字をUnicode数値文字参照に置換した文字列を返す。
44
34
  def self.external_to_unicodecr_docomo(str)
@@ -90,52 +80,6 @@ module Jpmobile
90
80
  external_to_unicodecr_softbank(str)
91
81
  end
92
82
 
93
- # Unicode 6.0絵文字の変換
94
- def self.external_to_unicodecr_unicode60(str)
95
- str.gsub(UNICODE_EMOTICON_REGEXP) do |match|
96
- unicodes = match.unpack('U*')
97
- unicodes = unicodes.first if unicodes.size == 1
98
-
99
- if (emoticon = UNICODE_EMOTICON_TO_CARRIER_EMOTICON[unicodes]) == GETA_CODE
100
- GETA
101
- elsif emoticon
102
- case emoticon
103
- when GETA_CODE
104
- GETA
105
- when Integer
106
- "&#x%04x;" % emoticon
107
- when String
108
- emoticon
109
- end
110
- else
111
- # 変換できなければ〓に
112
- GETA
113
- end
114
- end
115
- end
116
-
117
- # Google絵文字の変換
118
- def self.external_to_unicodecr_google(str)
119
- str.gsub(GOOGLE_EMOTICON_REGEXP) do |match|
120
- unicodes = match.unpack('U*')
121
- unicodes = unicodes.first if unicodes.size == 1
122
-
123
- if 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
131
- end
132
- else
133
- # 変換できなければ〓に
134
- GETA
135
- end
136
- end
137
- end
138
-
139
83
  # +str+ のなかでUnicode数値文字参照で表記された絵文字を携帯側エンコーディングに置換する。
140
84
  #
141
85
  # キャリア間の変換に +conversion_table+ を使う。+conversion_table+ に+nil+を与えると、
@@ -146,7 +90,6 @@ module Jpmobile
146
90
  def self.unicodecr_to_external(str, conversion_table=nil, to_sjis=true)
147
91
  str.gsub(/&#x([0-9a-f]{4});/i) do |match|
148
92
  unicode = $1.scanf("%x").first
149
-
150
93
  if conversion_table
151
94
  converted = conversion_table[unicode] # キャリア間変換
152
95
  else
@@ -165,15 +108,9 @@ module Jpmobile
165
108
  end
166
109
  elsif webcode = SOFTBANK_UNICODE_TO_WEBCODE[converted-0x1000]
167
110
  [converted-0x1000].pack('U')
168
- elsif converted == GETA_CODE
111
+ elsif converted == GETA
169
112
  # PCで〓を表示する場合
170
- GETA
171
- elsif UNICODE_EMOTICONS.include?(converted) or GOOGLE_EMOTICONS.include?(converted)
172
- if unicode == GETA_CODE
173
- GETA
174
- else
175
- [converted].pack('U*')
176
- end
113
+ [GETA].pack("U")
177
114
  else
178
115
  # キャリア変換テーブルに指定されていたUnicodeに対応する
179
116
  # 携帯側エンコーディングが見つからない(変換テーブルの不備の可能性あり)。
@@ -216,7 +153,7 @@ module Jpmobile
216
153
  def self.unicodecr_to_au_email(in_str)
217
154
  str = Jpmobile::Util.ascii_8bit(in_str)
218
155
  regexp = Regexp.compile(Jpmobile::Util.ascii_8bit("&#x([0-9a-f]{4});"), Regexp::IGNORECASE)
219
- str = str.gsub(regexp) do |match|
156
+ str.gsub(regexp) do |match|
220
157
  unicode = $1.scanf("%x").first
221
158
  converted = CONVERSION_TABLE_TO_AU[unicode]
222
159
 
@@ -239,8 +176,6 @@ module Jpmobile
239
176
  match
240
177
  end
241
178
  end
242
- regexp = Regexp.compile(Regexp.escape(Jpmobile::Util.ascii_8bit("\x1b\x28\x42\x1b\x24\x42")), Regexp::IGNORECASE)
243
- str.gsub(regexp, '')
244
179
  end
245
180
 
246
181
  # +str+ のなかでUnicode数値文字参照で表記された絵文字をメール送信用JISコードに変換する
@@ -266,56 +201,5 @@ module Jpmobile
266
201
  end
267
202
  end
268
203
  end
269
-
270
- @@pc_emoticon_image_path = nil
271
- @@pc_emoticon_yaml = nil
272
- @@pc_emoticon_hash = nil
273
-
274
- def self.pc_emoticon_image_path
275
- @@pc_emoticon_image_path
276
- end
277
- def self.pc_emoticon_image_path=(path)
278
- @@pc_emoticon_image_path=(path)
279
- end
280
-
281
- def self.pc_emoticon_yaml=(file)
282
- @@pc_emoticon_yaml = file
283
- end
284
- def self.pc_emoticon_yaml
285
- @@pc_emoticon_yaml
286
- end
287
-
288
- def self.pc_emoticon?
289
- if @@pc_emoticon_yaml and File.exist?(@@pc_emoticon_yaml) and @@pc_emoticon_image_path
290
-
291
- unless @@pc_emoticon_hash
292
- begin
293
- yaml_hash = YAML.load_file(@@pc_emoticon_yaml)
294
- @@pc_emoticon_hash = Hash[*(yaml_hash.values.inject([]){ |r, v| r += v.to_a.flatten; r})]
295
- @@pc_emoticon_image_path.chop if @@pc_emoticon_image_path.match(/\/$/)
296
-
297
- return true
298
- rescue => ex
299
- end
300
- else
301
- return true
302
- end
303
- end
304
-
305
- return false
306
- end
307
-
308
- def self.emoticons_to_image(str)
309
- if @@pc_emoticon_hash
310
- utf8_to_unicodecr(str).gsub(/&#x([0-9a-f]{4});/i) do |match|
311
- img = @@pc_emoticon_hash[$1.upcase] || (@@pc_emoticon_hash[("%x" % ($1.scanf("%x").first - 0x1000)).upcase] rescue nil)
312
- if img
313
- "<img src=\"#{@@pc_emoticon_image_path}/#{img}.gif\" alt=\"#{img}\" />"
314
- else
315
- ""
316
- end
317
- end
318
- end
319
- end
320
204
  end
321
205
  end
@@ -4,8 +4,7 @@ end
4
4
 
5
5
  module Jpmobile
6
6
  module Emoticon
7
- GETA_CODE = 0x3013
8
- GETA = [GETA_CODE].pack('U')
7
+ GETA = 0x3013
9
8
 
10
9
  SJIS_TO_UNICODE = {}
11
10
  SJIS_TO_UNICODE.update(DOCOMO_SJIS_TO_UNICODE)
@@ -33,20 +32,5 @@ module Jpmobile
33
32
 
34
33
  SOFTBANK_SJIS_REGEXP = Regexp.union(*SOFTBANK_SJIS_TO_UNICODE.keys.map{|s| Jpmobile::Util.sjis_regexp(s)}).freeze
35
34
  AU_EMAILJIS_REGEXP = Regexp.union(*AU_EMAILJIS_TO_UNICODE.keys.map{|s| Jpmobile::Util.jis_regexp(s)})
36
-
37
- # for unicode/google emoticons
38
- UNICODE_EMOTICONS = (UNICODE_TO_DOCOMO_UNICODE.keys|UNICODE_TO_AU_UNICODE.keys|UNICODE_TO_SOFTBANK_UNICODE.keys).uniq
39
- GOOGLE_EMOTICONS = (GOOGLE_TO_DOCOMO_UNICODE.keys|GOOGLE_TO_AU_UNICODE.keys|GOOGLE_TO_SOFTBANK_UNICODE.keys).uniq
40
-
41
- UNICODE_EMOTICON_REGEXP = Regexp.union(*UNICODE_EMOTICONS.map{|x| x.kind_of?(Array) ? x.pack('UU') : [x].pack('U')}).freeze
42
- GOOGLE_EMOTICON_REGEXP = Regexp.union(*GOOGLE_EMOTICONS.map{|x| x.kind_of?(Array) ? x.pack('UU') : [x].pack('U')}).freeze
43
-
44
- UNICODE_EMOTICON_TO_CARRIER_EMOTICON = UNICODE_TO_DOCOMO_UNICODE.merge(UNICODE_TO_AU_UNICODE.merge(UNICODE_TO_SOFTBANK_UNICODE))
45
- GOOGLE_EMOTICON_TO_CARRIER_EMOTICON = GOOGLE_TO_SOFTBANK_UNICODE.merge(GOOGLE_TO_AU_UNICODE.merge(GOOGLE_TO_DOCOMO_UNICODE))
46
-
47
- CONVERSION_TABLE_TO_UNICODE_EMOTICON = Jpmobile::Util.invert_table(UNICODE_TO_DOCOMO_UNICODE).merge(
48
- Jpmobile::Util.invert_table(UNICODE_TO_AU_UNICODE).merge(Jpmobile::Util.invert_table(UNICODE_TO_SOFTBANK_UNICODE)))
49
- CONVERSION_TABLE_TO_GOOGLE_EMOTICON = Jpmobile::Util.invert_table(GOOGLE_TO_SOFTBANK_UNICODE).merge(
50
- Jpmobile::Util.invert_table(GOOGLE_TO_AU_UNICODE).merge(Jpmobile::Util.invert_table(GOOGLE_TO_DOCOMO_UNICODE)))
51
35
  end
52
36
  end
@@ -40,9 +40,6 @@ module Jpmobile
40
40
  # 内部コードから外部コードに変換
41
41
  def after(controller, options = {})
42
42
  if apply_outgoing?(controller) and controller.response.body.is_a?(String)
43
- if controller.request.mobile?
44
- options.merge!(:charset => controller.request.mobile.default_charset)
45
- end
46
43
  controller.response.body = to_external(controller.response.body, options)
47
44
  end
48
45
  end
@@ -67,9 +64,7 @@ module Jpmobile
67
64
 
68
65
  doc = convert_text_content(doc)
69
66
 
70
- html = doc.to_html.gsub("\xc2\xa0","&nbsp;")
71
- html = html.gsub(/charset=[a-z0-9\-]+/i, "charset=#{options[:charset]}") if options[:charset]
72
- html
67
+ doc.to_html
73
68
  end
74
69
  end
75
70
 
@@ -168,7 +168,7 @@ module Jpmobile
168
168
  private
169
169
  # 外部へのリンク
170
170
  def link_to_url(str, url)
171
- %{<a href="#{html_escape(url)}">#{html_escape(str)}</a>}.html_safe
171
+ link_to str, url
172
172
  end
173
173
  end
174
174
  end
data/lib/jpmobile/mail.rb CHANGED
@@ -18,7 +18,7 @@ module Mail
18
18
 
19
19
  # change encoding
20
20
  def self.b_value_encode(str, encoding)
21
- str = Jpmobile::Util.encode(str, encoding.to_s)
21
+ str = Jpmobile::Util.encode(str, encoding)
22
22
  [Ruby19.encode_base64(str), encoding]
23
23
  end
24
24
  end
@@ -48,10 +48,9 @@ module Mail
48
48
  if @mobile = m
49
49
  @charset = m.mail_charset(@charset)
50
50
 
51
- if self.body
52
- self.body.content_type_with_jpmobile = self.content_type
53
- self.body.charset = @charset
54
- self.body.mobile = m
51
+ if @body
52
+ @body.charset = @charset
53
+ @body.mobile = m
55
54
  end
56
55
  end
57
56
  end
@@ -61,23 +60,13 @@ module Mail
61
60
  header['subject'].mobile = @mobile if header['subject']
62
61
  header['from'].mobile = @mobile if header['from']
63
62
  header['to'].mobile = @mobile if header['to']
64
- self.charset = @mobile.mail_charset
63
+ self.charset = @mobile.mail_charset(@charset)
65
64
 
66
65
  ready_to_send!
67
66
 
68
67
  self.body.charset = @charset
69
68
  self.body.mobile = @mobile
70
- self.header['Content-Transfer-Encoding'] = @mobile.content_transfer_encoding(self.header)
71
- if @mobile.decorated?
72
- unless self.content_type.match(/image\//)
73
- self.header['Content-ID'] = nil
74
- end
75
-
76
- unless self.header['Content-Type'].sub_type == 'mixed'
77
- self.header['Date'] = nil
78
- self.header['Mime-Version'] = nil
79
- end
80
- end
69
+ self.header['Content-Transfer-Encoding'] = '8bit'
81
70
 
82
71
  buffer = header.encoded
83
72
  buffer << "\r\n"
@@ -116,18 +105,17 @@ module Mail
116
105
  if @mobile
117
106
  @body.charset = @charset
118
107
  @body.mobile = @mobile
119
- @body.content_type_with_jpmobile = self.content_type
120
108
 
121
109
  if has_content_transfer_encoding? and
122
- ["base64", "quoted-printable"].include?(self.content_transfer_encoding) and
110
+ ["base64", "quoted-printable"].include?(content_transfer_encoding) and
123
111
  ["text"].include?(@mobile_main_type)
124
112
  @body.decode_transfer_encoding
125
113
  end
126
114
 
127
115
  if @body.multipart?
128
116
  @body.parts.each do |p|
129
- p.charset = @mobile.mail_charset(p.charset)
130
- p.mobile = @mobile
117
+ p.charset = @charset
118
+ p.mobile = @mobile
131
119
  end
132
120
  end
133
121
  end
@@ -149,95 +137,6 @@ module Mail
149
137
  alias_method :body_lazy_without_jpmobile, :body_lazy
150
138
  alias_method :body_lazy, :body_lazy_with_jpmobile
151
139
 
152
- # -- docomo
153
- # multipart/mixed
154
- # |- multipart/related
155
- # | |- multipart/alternative
156
- # | | |- text/plain
157
- # | | |- text/html
158
- # | |- image/xxxx (インライン画像)
159
- # |- image/xxxx (添付画像)
160
-
161
- # -- au
162
- # multipart/mixed
163
- # |- multipart/alternative
164
- # | |- text/plain
165
- # | |- text/html
166
- # |- image/xxxx (インライン画像)
167
- # |- image/xxxx (添付画像)
168
-
169
- # -- normal
170
- # multipart/mixed
171
- # |- multipart/alternative
172
- # | |- text/plain
173
- # | |- text/html
174
- # | |- image/xxxx (インライン画像)
175
- # |- image/xxxx (添付画像)
176
-
177
- def rearrange!
178
- if @mobile and @mobile.decoratable?
179
- @mobile.decorated = true
180
- text_body_part = find_part_by_content_type("text/plain").first
181
- html_body_part = find_part_by_content_type("text/html").first
182
- html_body_part.transport_encoding = 'quoted-printable' if html_body_part
183
- inline_images = []
184
- attached_files = []
185
- attachments.each do |p|
186
- if p.content_type.match(/^image\//) and p.content_disposition.match(/^inline/)
187
- if p.header['Content-Type'].parameters['filename']
188
- p.header['Content-Type'].parameters['name'] = p.header['Content-Type'].parameters['filename'].to_s
189
- end
190
- inline_images << p
191
- elsif p.content_disposition
192
- attached_files << p
193
- end
194
- end
195
-
196
- alternative_part = Mail::Part.new{content_type 'multipart/alternative'}
197
- alternative_part.add_part(text_body_part) if text_body_part
198
- alternative_part.add_part(html_body_part) if html_body_part
199
-
200
- if @mobile.require_related_part?
201
- related_part = Mail::Part.new{content_type 'multipart/related'}
202
- related_part.add_part(alternative_part)
203
- inline_images.each do |inline_image|
204
- related_part.add_part(inline_image)
205
- end
206
- inline_images.clear
207
- else
208
- related_part = alternative_part
209
- end
210
-
211
- unless self.header['Content-Type'].sub_type == 'mixed'
212
- self.header['Content-Type'] = self.content_type.gsub(/#{self.header['Content-Type'].sub_type}/, 'mixed')
213
- end
214
- self.parts.clear
215
- self.body = nil
216
-
217
- self.add_part(related_part)
218
- inline_images.each do |inline_image|
219
- self.add_part(inline_image)
220
- end
221
- attached_files.each do |attached_file|
222
- self.add_part(attached_file)
223
- end
224
- end
225
- end
226
-
227
- def find_part_by_content_type(content_type)
228
- finded_parts = []
229
-
230
- self.parts.each do |part|
231
- if part.multipart?
232
- finded_parts << part.find_part_by_content_type(content_type)
233
- elsif part.content_type.match(/^#{content_type}/)
234
- finded_parts << part
235
- end
236
- end
237
-
238
- finded_parts.flatten
239
- end
240
-
241
140
  private
242
141
  def convert_encoding_jpmobile
243
142
  # decide mobile carrier
@@ -279,16 +178,7 @@ module Mail
279
178
  end
280
179
  end
281
180
 
282
- if @body_part_jpmobile and @mobile and !@charset.blank?
283
- if ["base64", "quoted-printable"].include?(self.content_transfer_encoding) and
284
- self.content_type.match(/text/)
285
- @body_part_jpmobile = Jpmobile::Util.decode(@body_part_jpmobile, self.content_transfer_encoding, @charset)
286
- self.content_transfer_encoding = @mobile.class::MAIL_CONTENT_TRANSFER_ENCODING
287
- end
288
- unless Jpmobile::Util.check_charset(@body_part_jpmobile, @charset)
289
- @body_part_jpmobile = Jpmobile::Util.correct_encoding(@body_part_jpmobile)
290
- @charset = @body_part_jpmobile.encoding.to_s
291
- end
181
+ if @body_part_jpmobile and @mobile
292
182
  @body_part_jpmobile = @mobile.decode_transfer_encoding(@body_part_jpmobile, @charset)
293
183
  end
294
184
  end
@@ -322,30 +212,15 @@ module Mail
322
212
  end
323
213
 
324
214
  class Body
325
- attr_accessor :mobile, :content_type_with_jpmobile
215
+ attr_accessor :mobile
326
216
 
327
217
  # convert encoding
328
218
  def encoded_with_jpmobile(transfer_encoding = '8bit')
329
219
  if @mobile and !multipart?
330
220
  if @mobile.to_mail_body_encoded?(@raw_source)
331
221
  @raw_source
332
- elsif Jpmobile::Util.ascii_8bit?(@raw_source)
333
- _raw_source = if transfer_encoding == encoding
334
- @raw_source
335
- else
336
- enc = Mail::Encodings::get_encoding(get_best_encoding(transfer_encoding))
337
- enc.encode(@raw_source)
338
- end
339
- Jpmobile::Util.force_encode(_raw_source, nil, @charset)
340
222
  else
341
- case transfer_encoding
342
- when /quoted-printable/
343
- # [str].pack("M").gsub(/\n/, "\r\n")
344
- Jpmobile::Util.force_encode([@mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))].pack("M").gsub(/\n/, "\r\n"), Jpmobile::Util::BINARY, @charset)
345
- # @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
346
- else
347
- @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
348
- end
223
+ @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
349
224
  end
350
225
  else
351
226
  encoded_without_jpmobile(transfer_encoding)
@@ -364,25 +239,23 @@ module Mail
364
239
  def mobile=(m)
365
240
  @mobile = m
366
241
 
367
- if ["base64", "quoted-printable"].include?(self.encoding) and
368
- /text/.match(self.content_type_with_jpmobile)
369
- self.decode_transfer_encoding
370
- end
371
-
372
242
  if self.multipart? and @mobile
373
243
  self.parts.each do |part|
374
- part.charset = @mobile.mail_charset(part.charset)
244
+ part.charset = @charset
375
245
  part.mobile = @mobile
376
- part.body.charset = part.charset
246
+ part.body.charset = @charset
377
247
  part.body.mobile = @mobile
378
248
  end
379
249
  end
380
250
  end
381
251
 
382
252
  def decode_transfer_encoding
383
- _raw_source = Jpmobile::Util.decode(@raw_source, self.encoding, @charset)
253
+ _raw_source = Encodings.get_encoding(encoding).decode(@raw_source)
254
+ unless Jpmobile::Util.extract_charset(_raw_source) == @charset
255
+ @charset = Jpmobile::Util.extract_charset(_raw_source)
256
+ end
257
+ _raw_source = Jpmobile::Util.set_encoding(_raw_source, @charset)
384
258
  @raw_source = @mobile.decode_transfer_encoding(_raw_source, @charset)
385
- self.encoding = 'text'
386
259
  end
387
260
 
388
261
  def preamble_with_jpmobile
@@ -405,7 +278,7 @@ module Mail
405
278
  if @mobile
406
279
  Jpmobile::Util.encode(crlf_boundary_without_jpmobile, @charset)
407
280
  else
408
- crlf_boundary_without_jpmobile
281
+ epilogue_without_jpmobile
409
282
  end
410
283
  end
411
284
 
@@ -413,7 +286,7 @@ module Mail
413
286
  if @mobile
414
287
  Jpmobile::Util.encode(end_boundary_without_jpmobile, @charset)
415
288
  else
416
- end_boundary_without_jpmobile
289
+ epilogue_without_jpmobile
417
290
  end
418
291
  end
419
292
 
@@ -477,15 +350,15 @@ module Mail
477
350
 
478
351
  def mobile=(m)
479
352
  if @mobile = m
480
- self.charset = @mobile.mail_charset
481
- self.value = @jpmobile_raw_text
353
+ self.charset = @mobile.mail_charset(@charset)
354
+ self.value = @jpmobile_raw_text
482
355
  self.parse
483
356
  end
484
357
  end
485
358
 
486
359
  def encoded_with_jpmobile
487
360
  if @mobile
488
- self.charset = @mobile.mail_charset
361
+ self.charset = @mobile.mail_charset(@charset)
489
362
  end
490
363
 
491
364
  encoded_without_jpmobile
@@ -506,15 +379,15 @@ module Mail
506
379
 
507
380
  def mobile=(m)
508
381
  if @mobile = m
509
- self.charset = @mobile.mail_charset
510
- self.value = @jpmobile_raw_text
382
+ self.charset = @mobile.mail_charset(@charset)
383
+ self.value = @jpmobile_raw_text
511
384
  self.parse
512
385
  end
513
386
  end
514
387
 
515
388
  def encoded_with_jpmobile
516
389
  if @mobile
517
- self.charset = @mobile.mail_charset
390
+ self.charset = @mobile.mail_charset(@charset)
518
391
  end
519
392
 
520
393
  encoded_without_jpmobile
@@ -533,48 +406,6 @@ module Mail
533
406
  alias_method :encoded, :encoded_with_jpmobile
534
407
  end
535
408
 
536
- class ContentTypeElement # :nodoc:
537
- def initialize_with_jpmobile(string)
538
- if m = string.match(/\A(.*?)(name|filename)=("|')(.+)("|')(.*?)\z/) and
539
- m[4].each_byte.detect { |b| (b == 0 || b > 127)}
540
- name = [m[4]].pack('m').strip
541
- string = "#{m[1]}#{m[2]}=#{m[3]}#{name}#{m[5]}#{m[6]}"
542
- end
543
-
544
- initialize_without_jpmobile(string)
545
- end
546
- alias_method :initialize_without_jpmobile, :initialize
547
- alias_method :initialize, :initialize_with_jpmobile
548
- end
549
-
550
- class ContentDispositionElement # :nodoc:
551
- def initialize_with_jpmobile(string)
552
- if m = string.match(/\A(.*?)(name|filename)=("|')(.+)("|')(.*?)\z/) and
553
- m[4].each_byte.detect { |b| (b == 0 || b > 127)}
554
- name = [m[4]].pack('m').strip
555
- string = "#{m[1]}#{m[2]}=#{m[3]}#{name}#{m[5]}#{m[6]}"
556
- end
557
-
558
- initialize_without_jpmobile(string)
559
- end
560
- alias_method :initialize_without_jpmobile, :initialize
561
- alias_method :initialize, :initialize_with_jpmobile
562
- end
563
-
564
- class ContentLocationElement # :nodoc:
565
- def initialize_with_jpmobile(string)
566
- if m = string.match(/\A(.*?)(name|filename)=("|')(.+)("|')(.*?)\z/) and
567
- m[4].each_byte.detect { |b| (b == 0 || b > 127)}
568
- name = [m[4]].pack('m').strip
569
- string = "#{m[1]}#{m[2]}=#{m[3]}#{name}#{m[5]}#{m[6]}"
570
- end
571
-
572
- initialize_without_jpmobile(string)
573
- end
574
- alias_method :initialize_without_jpmobile, :initialize
575
- alias_method :initialize, :initialize_with_jpmobile
576
- end
577
-
578
409
  class Sendmail
579
410
  def Sendmail.call(path, arguments, destinations, mail)
580
411
  encoded_mail = mail.encoded