jpmobile 4.2.0 → 4.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3659619243b8dff1161041cd0ff72c112feebad
4
- data.tar.gz: c866458af576914e147de23255a34f007a9e87a3
3
+ metadata.gz: e92e1817ef365d523478348f5a7f3de6a1dabbdd
4
+ data.tar.gz: 9190f78e5db8ecf7250b2a30cd5433527418d51b
5
5
  SHA512:
6
- metadata.gz: da4606fadb165fdfaaee693d00e25f4ba85131cbae645d03f7a3d560f05e21d8d1d1cf64f4752b369a48e4c48b815222d80fa6fa7edfc5cda1fd554e526f3ecb
7
- data.tar.gz: 79c74f5121aa6d0948171a1847242b323efbb31deafed177d15e279c9e38a14caeb1e973962d2b17eb923cc9f638ee7cf0c72120658d19d4731953ce9df45667
6
+ metadata.gz: 87d2739e8e85d116fd397067dbc580b0c871d5a6d84fab6ad502a9208c7395ec5aef2012d4cd5b09f88a0c527e3217765505c18ecb721f2379e2f04ad696a05b
7
+ data.tar.gz: 746f7be69f65c94eed3b1037abc464f2a46304a508b605d434b14521c95f7aa2ba04a736d90a587a8bf8b3d374066cd41a38807d4fdbfa15902c24bb7e009aac
@@ -0,0 +1,28 @@
1
+ # CONTRIBUTING
2
+ ## 環境構築方法
3
+ jpmobile-ipaddressesとjpmobile-terminfoのgemをインストールしていない場合。
4
+
5
+ ```
6
+ $ git clone git@github.com:jpmobile/jpmobile.git
7
+ $ bundle install
8
+ $ cd vendor
9
+ $ git clone git@github.com:jpmobile/jpmobile-ipaddresses.git
10
+ $ git clone git@github.com:jpmobile/jpmobile-terminfo.git
11
+ ```
12
+
13
+ ## テスト
14
+ テストにはSMTP通信を行うものも含まれるため、
15
+ [koseki-mocksmtpd](https://github.com/koseki/mocksmtpd)などの、
16
+ smtpdのmockを利用する必要があります。
17
+
18
+ ### 必要なgemパッケージ
19
+ テストを実行するためには以下のgemパッケージが必要です。
20
+ * rails (include rack)
21
+ * sqlite3
22
+ * nokogiri
23
+ * rspec
24
+ * rspec-rails
25
+ * rspec-fixture
26
+ * rack-test
27
+ * mocha
28
+ * geokit
@@ -80,6 +80,11 @@
80
80
  スマートフォンからのアクセスではありません。
81
81
  <% end %>
82
82
 
83
+ <% if request.tablet? %>
84
+ タブレットからのアクセスです。
85
+ <% else %>
86
+ タブレットからのアクセスではありません。
87
+ <% end %>
83
88
 
84
89
 
85
90
  ==== 別に用意した携帯電話用コントローラへリダイレクトする例
@@ -114,7 +119,7 @@ Rack::Request#mobile.position に位置情報が格納されます。
114
119
 
115
120
  ==== {GeoKit}[http://geokit.rubyforge.org] との連携
116
121
 
117
- vandor/plugins/geokit以下にGeoKitがインストールされていると、Jpmobile::PositionにGeoKit::Mappableがincludeされる。したがって、
122
+ vendor/plugins/geokit以下にGeoKitがインストールされていると、Jpmobile::PositionにGeoKit::Mappableがincludeされる。したがって、
118
123
 
119
124
  request.mobile.position.distance_to('札幌駅')
120
125
 
@@ -288,17 +293,9 @@ trans_sid を使用する際には、例えば config/initializers/session_store
288
293
  * オプションに :decorated => true を追加すると、各キャリアのデコメに適したフォーマットで送信します。
289
294
  * ただし docomo/SoftBank でテスト出来ていないため、実験版とします。
290
295
 
291
- == テストに必要なgemパッケージ
292
- テストを実行するためには以下のgemパッケージが必要です。
293
- * rails (include rack)
294
- * sqlite3-ruby
295
- * nokogiri
296
- * rspec
297
- * rspec-rails
298
- * rspec-fixture
299
- * rack-test
300
- * mocha
301
- * geokit
296
+ == jpmobileの開発方法
297
+
298
+ jpmobileの開発に関しては {こちら}[https://github.com/jpmobile/jpmobile/blob/master/CONTRIBUTING.md]
302
299
 
303
300
  == リンク
304
301
 
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ["lib"]
18
18
 
19
- gem.add_development_dependency 'rails', '~> 4.2.0'
19
+ gem.add_development_dependency 'rails'
20
20
  gem.add_development_dependency 'rspec'
21
21
  gem.add_development_dependency 'rspec-rails'
22
22
  gem.add_development_dependency 'rspec-its'
@@ -15,5 +15,13 @@ module Jpmobile
15
15
  def mobile_filter
16
16
  ::Jpmobile::Rack.mount_middlewares
17
17
  end
18
+
19
+ def session_store(&block)
20
+ @session_store = block
21
+ end
22
+
23
+ def mount_session_store
24
+ @session_store && @session_store.call
25
+ end
18
26
  end
19
27
  end
@@ -10,8 +10,8 @@ module ActionController
10
10
  expected_view_file = lookup_context.find_template(options[:template], options[:prefixes])
11
11
 
12
12
  _candidates = lookup_context.mobile.map { |variant|
13
- target_templat = options[:template] + '_' + variant
14
- expected_view_file.virtual_path.match(target_templat)
13
+ target_template = options[:template] + '_' + variant
14
+ expected_view_file.virtual_path.match(target_template)
15
15
  }.compact
16
16
 
17
17
  if _candidates.empty?
@@ -4,17 +4,6 @@ require 'mail'
4
4
  module Mail
5
5
  # encoding patch
6
6
  Ruby19.class_eval do
7
- def self.b_value_decode(str, encoding = nil)
8
- match = str.match(/\=\?(.+)?\?[Bb]\?(.*)\?\=/m)
9
- if match
10
- charset = match[1]
11
- str = self.decode_base64(match[2])
12
- str = charset_encoder.encode(str, charset)
13
- end
14
- decoded = str.encode(Encoding::UTF_8, :invalid => :replace, :replace => "") rescue Jpmobile::Util.ascii_8bit(str)
15
- # decoded.valid_encoding? ? decoded : decoded.encode(Encoding::UTF_16LE, :invalid => :replace, :replace => "").encode(Encoding::UTF_8)
16
- end
17
-
18
7
  # change encoding
19
8
  def self.b_value_encode(str, encoding = nil)
20
9
  str = Jpmobile::Util.encode(str, encoding.to_s)
@@ -36,7 +25,7 @@ module Mail
36
25
  header['subject'].mobile = @mobile if header['subject']
37
26
  header['from'].mobile = @mobile if header['from']
38
27
  header['to'].mobile = @mobile if header['to']
39
- self.charset = @mobile.mail_charset
28
+ self.charset = @mobile.mail_charset unless multipart?
40
29
 
41
30
  ready_to_send!
42
31
 
@@ -113,7 +102,6 @@ module Mail
113
102
 
114
103
  if @body.multipart?
115
104
  @body.parts.each do |p|
116
- p.charset = @mobile.mail_charset(p.charset)
117
105
  p.mobile = @mobile
118
106
  end
119
107
  end
@@ -130,6 +118,10 @@ module Mail
130
118
  separate_parts_without_jpmobile
131
119
  end
132
120
 
121
+ def add_charset_with_jpmobile
122
+ add_charset_without_jpmobile unless multipart? && @mobile
123
+ end
124
+
133
125
  alias_method :encoded_without_jpmobile, :encoded
134
126
  alias_method :encoded, :encoded_with_jpmobile
135
127
 
@@ -142,6 +134,9 @@ module Mail
142
134
  alias_method :separate_parts_without_jpmobile, :separate_parts
143
135
  alias_method :separate_parts, :separate_parts_with_jpmobile
144
136
 
137
+ alias_method :add_charset_without_jpmobile, :add_charset
138
+ alias_method :add_charset, :add_charset_with_jpmobile
139
+
145
140
  # -- docomo
146
141
  # multipart/mixed
147
142
  # |- multipart/related
@@ -248,17 +243,9 @@ module Mail
248
243
  end
249
244
 
250
245
  # convert header(s)
251
- if self.header[:subject]
252
- subject_charset = Jpmobile::Util.extract_charset(self.header[:subject].value)
253
- self.header[:subject].charset = subject_charset unless subject_charset.blank?
254
-
255
- if @mobile
256
- subject_value = Jpmobile::Util.ascii_8bit(self.header[:subject].value.dup)
257
- subject_value = Encodings.value_decode(subject_value)
258
- subject_converting_encoding = Jpmobile::Util.detect_encoding(subject_value)
259
- v = @mobile.to_mail_internal(subject_value, subject_converting_encoding)
260
- self.header[:subject].value = Jpmobile::Util.force_encode(v, @mobile.mail_charset(subject_charset), Jpmobile::Util::UTF8)
261
- end
246
+ if header[:subject] && @mobile
247
+ header[:subject].mobile = @mobile
248
+ header[:subject].value = header[:subject].decoded
262
249
  end
263
250
 
264
251
  if @body_part_jpmobile and @mobile and !@charset.blank?
@@ -267,10 +254,6 @@ module Mail
267
254
  @body_part_jpmobile = Jpmobile::Util.decode(@body_part_jpmobile, self.content_transfer_encoding, @charset)
268
255
  self.content_transfer_encoding = @mobile.class::MAIL_CONTENT_TRANSFER_ENCODING
269
256
  end
270
- unless Jpmobile::Util.check_charset(@body_part_jpmobile, @charset)
271
- @body_part_jpmobile = Jpmobile::Util.correct_encoding(@body_part_jpmobile)
272
- @charset = @body_part_jpmobile.encoding.to_s
273
- end
274
257
  @body_part_jpmobile = @mobile.decode_transfer_encoding(@body_part_jpmobile, @charset)
275
258
  end
276
259
  end
@@ -464,8 +447,39 @@ module Mail
464
447
  end
465
448
  end
466
449
 
450
+ def decoded_with_jpmobile
451
+ if @mobile
452
+ return value unless value =~ /\=\?[^?]+\?([QB])\?[^?]*?\?\=/mi
453
+ Encodings.collapse_adjacent_encodings(value).each do |line|
454
+ line.gsub!(/\=\?[^?]+\?([QB])\?[^?]*?\?\=/mi) do |string|
455
+ case $1
456
+ when 'B','b' then decode_b_value_for_mobile(string)
457
+ when 'Q','q' then Encodings.q_value_decode(string)
458
+ else line
459
+ end
460
+ end
461
+ end.join("")
462
+ else
463
+ decoded_without_jpmobile
464
+ end
465
+ end
466
+
467
467
  alias_method :encoded_without_jpmobile, :encoded
468
468
  alias_method :encoded, :encoded_with_jpmobile
469
+
470
+ alias_method :decoded_without_jpmobile, :decoded
471
+ alias_method :decoded, :decoded_with_jpmobile
472
+
473
+ def decode_b_value_for_mobile(str)
474
+ match = str.match(/\=\?(.+)?\?[Bb]\?(.*)\?\=/m)
475
+ if match
476
+ charset = match[1]
477
+ str = Ruby19.decode_base64(match[2])
478
+ @mobile.decode_transfer_encoding(str, charset)
479
+ else
480
+ str
481
+ end
482
+ end
469
483
  end
470
484
 
471
485
  class StructuredField
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # =Android
2
+ # =iPad
3
3
 
4
4
  module Jpmobile::Mobile
5
5
  # ==iPad
@@ -36,6 +36,11 @@ module Jpmobile
36
36
  mobile and mobile.smart_phone?
37
37
  end
38
38
 
39
+ # タブレットからであれば +true+を、そうでなければ +false+ を返す
40
+ def tablet?
41
+ mobile and mobile.tablet?
42
+ end
43
+
39
44
  # 携帯電話の機種に応じて Mobile::xxx を返す。
40
45
  # 携帯電話でない場合はnilを返す。
41
46
  def mobile
@@ -11,7 +11,7 @@ module Jpmobile
11
11
 
12
12
  private
13
13
 
14
- def query(path, details, formats)
14
+ def query(path, details, formats, _)
15
15
  query = build_query(path, details)
16
16
 
17
17
  begin
@@ -1,11 +1,13 @@
1
- module ActiveRecord
2
- class SessionStore
3
- def destroy_session_with_jpmobile(env, session_id, options)
4
- destroy_session_without_jpmobile(env, session_id, options)
1
+ module ActionDispatch
2
+ module Session
3
+ class ActiveRecordStore
4
+ def destroy_session_with_jpmobile(env, session_id, options)
5
+ destroy_session_without_jpmobile(env, session_id, options)
5
6
 
6
- session_id || Jpmobile::SessionID.generate_sid
7
- end
7
+ session_id || Jpmobile::SessionID.generate_sid
8
+ end
8
9
 
9
- alias_method_chain :destroy_session, :jpmobile
10
+ alias_method_chain :destroy_session, :jpmobile
11
+ end
10
12
  end
11
13
  end
@@ -1,6 +1,6 @@
1
- module Rack
1
+ module ActionDispatch
2
2
  module Session
3
- class Memcache
3
+ class MemCacheStore
4
4
  def destroy_session_with_jpmobile(env, session_id, options)
5
5
  destroy_session_without_jpmobile(env, session_id, options)
6
6
 
@@ -29,6 +29,8 @@ module Jpmobile
29
29
  when "ActiveRecord::SessionStore"
30
30
  require 'jpmobile/session/active_record_store'
31
31
  ActionDispatch::Session::AbstractStore.send :include, ParamsOverCookie
32
+ else
33
+ Rails.application.config.jpmobile.mount_session_store
32
34
  end
33
35
  end
34
36
  end
@@ -250,7 +250,17 @@ module Jpmobile
250
250
  s.force_encoding(from) unless s.encoding == from_enc
251
251
  end
252
252
 
253
- s.encode(to)
253
+ begin
254
+ s.encode(to)
255
+ rescue ::Encoding::InvalidByteSequenceError, ::Encoding::UndefinedConversionError => e
256
+ # iPhone MailがISO-2022-JPに半角カナや①などのCP50220文字を含めてくる問題対策
257
+ if s.encoding == ::Encoding::ISO2022_JP
258
+ s.force_encoding(::Encoding::CP50220)
259
+ retry
260
+ else
261
+ raise e
262
+ end
263
+ end
254
264
  end
255
265
 
256
266
  def set_encoding(str, encoding)
@@ -346,28 +356,5 @@ module Jpmobile
346
356
  charset = _extract_charset unless _extract_charset.blank? or _extract_charset == charset
347
357
  Jpmobile::Util.set_encoding(_str, charset)
348
358
  end
349
-
350
- def check_charset(str, charset)
351
- # use NKF.guess
352
- ::Encoding.compatible?(guess_encoding(str), ::Encoding.find(charset))
353
- end
354
-
355
- def correct_encoding(str)
356
- if guess_encoding(str) != str.encoding
357
- str.force_encoding(guess_encoding(str))
358
- end
359
-
360
- str
361
- end
362
-
363
- def guess_encoding(str)
364
- encoding = NKF.guess(str)
365
- # ISO-2022-JPにおいて、JIS X201半角カナエスケープシーケンスが含まれていたらCP50220とみなす
366
- if encoding == ::Encoding::ISO2022_JP && str.dup.force_encoding(BINARY).include?("\e(I")
367
- ::Encoding::CP50220
368
- else
369
- encoding
370
- end
371
- end
372
359
  end
373
360
  end
@@ -1,3 +1,3 @@
1
1
  module Jpmobile
2
- VERSION = "4.2.0"
2
+ VERSION = "4.2.1"
3
3
  end
@@ -84,6 +84,16 @@ END
84
84
  end
85
85
  end
86
86
 
87
+ unless skip
88
+ # add gems for jpmobile spec
89
+ config_path = File.join(rails_root, 'Gemfile')
90
+ File.open(config_path, 'a+') do |file|
91
+ file.write <<-END
92
+ instance_eval File.read(File.expand_path(__FILE__) + '.jpmobile')
93
+ END
94
+ end
95
+ end
96
+
87
97
  # run tests in rails
88
98
  cd rails_root
89
99
  ruby "-S bundle install"
@@ -0,0 +1,49 @@
1
+ Return-Path: <docomo@docomo.ne.jp>
2
+ Delivered-To: info@jpm-rails.org
3
+ Date: Sun, 06 Feb 2011 17:30:48 +0900 (JST)
4
+ From: docomo@docomo.ne.jp
5
+ To: info@jpm-rails.org
6
+ Subject: =?iso-2022-jp?B?GyRCJUYlOSVIGyhC?=
7
+ Message-ID: <IMTM0i3E149a62f10PSW@docomo.ne.jp>
8
+ MIME-Version: 1.0
9
+ Content-Type: multipart/mixed; boundary="RHe5pb6n_0_"
10
+ Content-Transfer-Encoding: 7bit
11
+
12
+ --RHe5pb6n_0_
13
+ Content-Type: multipart/related; boundary="RHe5pb6n"
14
+
15
+ --RHe5pb6n
16
+ Content-Type: multipart/alternative; boundary="AzHFwESQ"
17
+
18
+ --AzHFwESQ
19
+ Content-Type: text/plain; charset="iso-2022-jp"
20
+ Content-Transfer-Encoding: 7bit
21
+
22
+
23
+
24
+ $B%F%9%H$G$9(B
25
+ --AzHFwESQ
26
+ Content-Type: text/html; charset="iso-2022-jp"
27
+ Content-Transfer-Encoding: quoted-printable
28
+
29
+ <HTML><HEAD><META http-equiv=3D"Content-Type" content=3D"text/html; charset=
30
+ =3Diso-2022-jp"></HEAD><BODY><DIV align=3D"center"><FONT color=3D"#FF4BFF">=
31
+ =1B$B%F%9%H$G$9=1B(B<IMG src=3D"cid:03@110206.172728@______F03B@docomo.ne.j=
32
+ p"></FONT></DIV></BODY></HTML>
33
+ --AzHFwESQ--
34
+
35
+ --RHe5pb6n
36
+ Content-Type: image/gif;
37
+ name="ao_hatena.gif"
38
+ Content-Transfer-Encoding: base64
39
+ Content-ID: <03@110206.172728@______F03B@docomo.ne.jp>
40
+
41
+ R0lGODlhFAAUAHAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJMgAEACwAAAAAFAAUAIIjZqoDoO0s
42
+ xf////////8AAAAAAAAAAAAIagAJCBxIsKBBgwASJjyIEIAAAQEiLmRIwOHDixADAGDocMAAjA8l
43
+ Huw4QGPCABk1FrQIcaNAiyIJslT5MiTNgQAixqyY0qVMhTh7UpSpc+LQlzuPvjSqtClFoE55towK
44
+ 06fSnEmvMo1KMSAAIfkECTIABAAsAAAAABQAFACCI2aqA6DtLMX/////////AAAAAAAAAAAACGMA
45
+ CQgcSLCgwYMIEypcSACAQ4cMGwIQICCARYgJJ1LcWDEAAIQTBwzgSPGiQY0iPToM0NFjQY0VPwrU
46
+ aJIgAIs1G7aUafPhwIk4eSq8eVHo0JwRfUZcmhHjUppGjyJlqJTpwoAAOw==
47
+ --RHe5pb6n
48
+ --RHe5pb6n_0_--
49
+
@@ -0,0 +1,16 @@
1
+ Return-Path: <softbank@i.softbank.jp>
2
+ X-Original-To: info@jpmobile-rails.org
3
+ Delivered-To: info@jpmobile-rails.org
4
+ Subject: =?iso-2022-jp?B?GyRCJUYlOSVILSEbKEI=?=
5
+ From: <softbank@i.softbank.jp>
6
+ X-Mailer: iPhone Mail (12B435)
7
+ Message-Id: <107E70FB-4920-45C4-B0DA-000000000000@i.softbank.jp>
8
+ Date: Mon, 29 Dec 2014 13:02:07 +0900
9
+ To: info@jpmobile-rails.org
10
+ Mime-Version: 1.0 (1.0)
11
+ X-SB-Service: Virus-Checked
12
+ Content-Type: text/plain; charset="iso-2022-jp"
13
+ Content-Transfer-Encoding: 7bit
14
+
15
+ $B4]?t;z$N%F%9%H$G$9-"|r(B
16
+
@@ -0,0 +1,15 @@
1
+ Delivered-To: info@jpmobile.jp
2
+ Subject: =?utf-8?B?57W15paH5a2X8J+OhQ==?=
3
+ From: "jpmobile@i.softbank.jp" <jpmobile@i.softbank.jp>
4
+ Content-Type: text/plain;
5
+ charset=utf-8
6
+ X-Mailer: iPhone Mail (12B435)
7
+ Message-Id: <6D20A3C2-DCE3-4A62-95EB-000000000000@i.softbank.jp>
8
+ Date: Wed, 17 Dec 2014 19:13:03 +0900
9
+ To: "info@jpmobile.jp" <info@jpmobile.jp>
10
+ Content-Transfer-Encoding: base64
11
+ Mime-Version: 1.0 (1.0)
12
+ X-SB-Service: Virus-Checked
13
+
14
+ 8J+OhOKdow==
15
+
@@ -83,23 +83,48 @@ describe "Jpmobile::Mail#receive" do
83
83
  end
84
84
 
85
85
  describe "Docomo" do
86
- before(:each) do
87
- @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml")).read)
88
- end
86
+ context "with sjis decomail" do
87
+ before(:each) do
88
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml")).read)
89
+ end
89
90
 
90
- it "subject should be parsed correctly" do
91
- expect(@mail.subject).to eq("テスト&#xe6ec;")
92
- end
91
+ it "subject should be parsed correctly" do
92
+ expect(@mail.subject).to eq("テスト&#xe6ec;")
93
+ end
93
94
 
94
- it "body should be parsed correctly" do
95
- expect(@mail.body.parts.size).to eq(1)
96
- @mail.body.parts.first.parts.size == 2
97
- expect(@mail.body.parts.first.parts.first.body).to match("テストです&#xe72d;")
98
- expect(@mail.body.parts.first.parts.last.body.raw_source).to match("テストです&#xe72d;")
95
+ it "body should be parsed correctly" do
96
+ expect(@mail.body.parts.size).to eq(1)
97
+ @mail.body.parts.first.parts.size == 2
98
+ expect(@mail.body.parts.first.parts.first.body).to match("テストです&#xe72d;")
99
+ expect(@mail.body.parts.first.parts.last.body.raw_source).to match("テストです&#xe72d;")
100
+ end
101
+
102
+ it "should encode correctly" do
103
+ expect(@mail.to_s).to match(Regexp.escape("g2WDWINn+ZE"))
104
+ end
105
+
106
+ it "does not cause double-conversion on reparsing" do
107
+ @reparsed = Mail.new(@mail.to_s)
108
+ expect(@reparsed.to_s).to match(Regexp.escape("g2WDWINn+ZE"))
109
+ expect(@reparsed.body.parts.first.parts.first.body).to match("テストです&#xe72d;")
110
+ end
99
111
  end
100
112
 
101
- it "should encode correctly" do
102
- expect(@mail.to_s).to match(Regexp.escape("g2WDWINn+ZE"))
113
+ context "with jis decomail" do
114
+ before(:each) do
115
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/docomo-decomail.eml")).read)
116
+ end
117
+
118
+ it "does not contain charset within multipart Content-Type" do
119
+ expect(@mail.to_s.scan(/Content-Type:\s+multipart(?:.+;\r\n)*.+[^;]\r\n/)).
120
+ to satisfy{|matches| matches.all?{|type| !type.include?('charset')}}
121
+ end
122
+
123
+ it "does not cause double-conversion on reparsing" do
124
+ @reparsed = Mail.new(@mail.to_s)
125
+ expect(@reparsed.to_s).to match(Regexp.escape("g2WDWINn"))
126
+ expect(@reparsed.parts.first.parts.first.parts.first.body.decoded).to match("テストです")
127
+ end
103
128
  end
104
129
  end
105
130
 
@@ -207,6 +232,20 @@ describe "Jpmobile::Mail#receive" do
207
232
  expect(@mail.to_s).to match(sjis_regexp(sjis("\x89\xEF\x8Bc\x82\xAA\x8AJ\x8D\xC3\xF8\xA7")))
208
233
  end
209
234
  end
235
+
236
+ context "JIS mail" do
237
+ before(:each) do
238
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/docomo-jis.eml")).read)
239
+ end
240
+
241
+ it "subject should be parsed correctly" do
242
+ expect(@mail.subject).to eq("テスト")
243
+ end
244
+
245
+ it "body should be parsed correctly" do
246
+ expect(@mail.body.to_s).to eq("テスト本文\n\n")
247
+ end
248
+ end
210
249
  end
211
250
 
212
251
  describe "Au" do
@@ -338,44 +377,58 @@ describe "Jpmobile::Mail#receive" do
338
377
  expect(@mail.to_s).to match(sjis_regexp(utf8_to_sjis("会議が開催") + sjis("\xf7\xdf")))
339
378
  end
340
379
  end
341
- end
342
380
 
343
- describe "Softbank blank-mail" do
344
- before(:each) do
345
- @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/softbank-blank.eml")).read)
346
- end
381
+ describe "blank-mail" do
382
+ before(:each) do
383
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/softbank-blank.eml")).read)
384
+ end
347
385
 
348
- it "subject should be parsed correctly" do
349
- expect(@mail.subject).to be_blank
350
- end
386
+ it "subject should be parsed correctly" do
387
+ expect(@mail.subject).to be_blank
388
+ end
351
389
 
352
- it "body should be parsed correctly" do
353
- expect(@mail.body.to_s).to be_blank
390
+ it "body should be parsed correctly" do
391
+ expect(@mail.body.to_s).to be_blank
392
+ end
354
393
  end
355
394
  end
356
395
 
357
- describe "JIS mail" do
358
- context "Docomo" do
396
+ describe "iPhone" do
397
+ context "JIS mail" do
359
398
  before(:each) do
360
- @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/docomo-jis.eml")).read)
399
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-jis.eml")).read)
400
+ end
401
+
402
+ it "body should be parsed correctly" do
403
+ expect(@mail.body.to_s).to eq("(=゚ω゚)ノ\n\n\n")
404
+ end
405
+ end
406
+
407
+ context "when the mail contains UTF-8 emojis" do
408
+ before(:each) do
409
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-unicode-emoji.eml")).read)
361
410
  end
362
411
 
363
412
  it "subject should be parsed correctly" do
364
- expect(@mail.subject).to eq("テスト")
413
+ expect(@mail.subject).to eq("絵文字\u{1F385}")
365
414
  end
366
415
 
367
416
  it "body should be parsed correctly" do
368
- expect(@mail.body.to_s).to eq("テスト本文\n\n")
417
+ expect(@mail.body.to_s).to eq("\u{1F384}\u2763")
369
418
  end
370
419
  end
371
420
 
372
- context "iPhone" do
421
+ context "when the mail contains circled-numbers" do
373
422
  before(:each) do
374
- @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-jis.eml")).read)
423
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-circled-numbers-in-jis.eml")).read)
424
+ end
425
+
426
+ it "subject should be parsed correctly" do
427
+ expect(@mail.subject).to eq("テスト①")
375
428
  end
376
429
 
377
430
  it "body should be parsed correctly" do
378
- expect(@mail.body.to_s).to eq("(=゚ω゚)ノ\n\n\n")
431
+ expect(@mail.body.to_s).to eq("丸数字のテストです②ⅱ\n\n")
379
432
  end
380
433
  end
381
434
  end
@@ -79,6 +79,16 @@ describe Jpmobile::Util do
79
79
  expect(jis_to_utf8("JIS\rSAMPLE\nTEXT\r\n")).to eq(utf8("JIS\nSAMPLE\nTEXT\n"))
80
80
  end
81
81
 
82
+ describe '#force_encode' do
83
+ it 'converts ISO-2022-JP string which contains halfwidth-kana' do
84
+ expect(force_encode("\e\x28\x49\x43\x3D\x44\e\x28\x42".force_encoding('ISO-2022-JP'), 'iso-2022-jp', 'UTF-8')).to eq 'テスト'
85
+ end
86
+
87
+ it 'does not enter infinite loop on retry' do
88
+ expect{ force_encode("\e\x28\x49\x9a\x43\x3D\x44\e\x28\x42".force_encoding('ISO-2022-JP'), 'iso-2022-jp', 'UTF-8') }.to raise_error ::Encoding::InvalidByteSequenceError
89
+ end
90
+ end
91
+
82
92
  it "fold_textでUTF-8の日本語文字列が指定文字数で折り返された配列で返ること" do
83
93
  expect(fold_text('長い日本語の題名で折り返されるかようにするには事前に分割していないとダメなことがわかりましたよ', 15)).to eq([
84
94
  '長い日本語の題名で折り返される',
@@ -132,32 +142,4 @@ describe Jpmobile::Util do
132
142
  expect(hash[0xE6FB]).to eq(0x1F526)
133
143
  end
134
144
  end
135
-
136
- describe 'check_charset' do
137
- it 'returns true if compatible' do
138
- str = 'ABC'.force_encoding('ASCII-8BIT')
139
- expect(check_charset(str, 'UTF-8')).to be_truthy
140
- end
141
-
142
- it 'returns false if incompatible' do
143
- str = '再現'.encode('ISO-2022-JP')
144
- expect(check_charset(str, 'UTF-8')).to be_falsey
145
- end
146
- end
147
-
148
- describe 'correct_encoding' do
149
- it 'updates encoding correctly' do
150
- str = '再現'.force_encoding('ISO-2022-JP')
151
- expect(correct_encoding(str).encoding).to eq(Encoding::UTF_8)
152
- end
153
- end
154
-
155
- describe 'guess_encoding' do
156
- it 'guesses encoding correclty' do
157
- expect(guess_encoding('テスト')).to eq Encoding::UTF_8
158
- expect(guess_encoding("\x83\x65\x83\x58\x83\x67")).to eq Encoding::Shift_JIS
159
- expect(guess_encoding("\e\x24\x42\x25\x46\x25\x39\x25\x48\e\x28\x42")).to eq Encoding::ISO2022_JP
160
- expect(guess_encoding("\e\x28\x49\x43\x3D\x44\e\x28\x42")).to eq Encoding::CP50220
161
- end
162
- end
163
145
  end
@@ -0,0 +1,16 @@
1
+ gem 'geokit'
2
+
3
+ gem 'jpmobile', path: './vendor/jpmobile'
4
+ gem 'jpmobile-terminfo', path: './vendor/jpmobile-terminfo'
5
+ gem 'jpmobile-ipaddresses', path: './vendor/jpmobile-ipaddresses'
6
+
7
+ gem 'activerecord-session_store'
8
+
9
+ # Bundle gems for certain environments:
10
+ group :development, :test do
11
+ gem "rspec"
12
+ gem "rspec-rails"
13
+ gem 'capybara'
14
+ gem 'capybara-webkit'
15
+ gem 'pry'
16
+ end
@@ -1,2 +1,12 @@
1
1
  Rails.application.config.jpmobile.mobile_filter
2
2
  Rails.application.config.jpmobile.form_accept_charset_conversion = true
3
+
4
+ Rails.application.config.jpmobile.session_store do
5
+ # # MemCacheStore
6
+ # require 'jpmobile/session/mem_cache_store'
7
+ # ActionDispatch::Session::MemCacheStore.send :include, Jpmobile::TransSid::ParamsOverCookie
8
+
9
+ # # ActiveRecordStore
10
+ # require 'jpmobile/session/active_record_store'
11
+ # ActionDispatch::Session::AbstractStore.send :include, Jpmobile::TransSid::ParamsOverCookie
12
+ end
@@ -37,7 +37,7 @@ describe "trans_sid functional", :type => :request do
37
37
  it "で redirect の自動書き換えが行われない" do
38
38
  res = get_with_session(@controller, "redirect", @user_agent)
39
39
 
40
- res.response.header['Location'] =~ /\/$/
40
+ expect(res.response.header['Location']).to match(/\/$/)
41
41
  end
42
42
  end
43
43
 
@@ -59,7 +59,7 @@ describe "trans_sid functional", :type => :request do
59
59
  it "で redirect の自動書き換えが行われる" do
60
60
  res = get_with_session(@controller, "redirect", @user_agent)
61
61
 
62
- res.response.header['Location'] =~ /\?_session_id=[a-zA-Z0-9]{32}$/
62
+ expect(res.response.header['Location']).to match(/\?_session_id=[a-zA-Z0-9]{32}$/)
63
63
  end
64
64
 
65
65
  # resource paths
@@ -76,7 +76,7 @@ describe "trans_sid functional", :type => :request do
76
76
  it "で @path の redirect の自動書き換えが行われる" do
77
77
  res = get_with_session(@controller, "redirect_path", @user_agent)
78
78
 
79
- res.response.header['Location'] =~ /\?_session_id=[a-zA-Z0-9]{32}$/
79
+ expect(res.response.header['Location']).to match(/\?_session_id=[a-zA-Z0-9]{32}$/)
80
80
  end
81
81
 
82
82
  # resource path with prefix
@@ -93,7 +93,7 @@ describe "trans_sid functional", :type => :request do
93
93
  it "で [:admin, @path] の redirect の自動書き換えが行われる" do
94
94
  res = get_with_session(@controller, "redirect_path_admin", @user_agent)
95
95
 
96
- res.response.header['Location'] =~ /\?_session_id=[a-zA-Z0-9]{32}$/
96
+ expect(res.response.header['Location']).to match(/\?_session_id=[a-zA-Z0-9]{32}$/)
97
97
  end
98
98
  end
99
99
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpmobile
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shin-ichiro OGAWA
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-12-22 00:00:00.000000000 Z
12
+ date: 2016-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 4.2.0
20
+ version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 4.2.0
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -160,6 +160,7 @@ extra_rdoc_files: []
160
160
  files:
161
161
  - ".gitignore"
162
162
  - ".rspec"
163
+ - CONTRIBUTING.md
163
164
  - Gemfile
164
165
  - MIT-LICENSE
165
166
  - README
@@ -248,13 +249,16 @@ files:
248
249
  - spec/unit/email-fixtures/au-emoji5.eml
249
250
  - spec/unit/email-fixtures/au-kigou.eml
250
251
  - spec/unit/email-fixtures/bounce_with_utf8_part.eml
252
+ - spec/unit/email-fixtures/docomo-decomail.eml
251
253
  - spec/unit/email-fixtures/docomo-emoji.eml
252
254
  - spec/unit/email-fixtures/docomo-gmail-sjis.eml
253
255
  - spec/unit/email-fixtures/docomo-jis.eml
256
+ - spec/unit/email-fixtures/iphone-circled-numbers-in-jis.eml
254
257
  - spec/unit/email-fixtures/iphone-cp932.eml
255
258
  - spec/unit/email-fixtures/iphone-jis.eml
256
259
  - spec/unit/email-fixtures/iphone-mail3.eml
257
260
  - spec/unit/email-fixtures/iphone-message.eml
261
+ - spec/unit/email-fixtures/iphone-unicode-emoji.eml
258
262
  - spec/unit/email-fixtures/pc-mail-attached-without-subject.eml
259
263
  - spec/unit/email-fixtures/pc-mail-multi.eml
260
264
  - spec/unit/email-fixtures/pc-mail-single.eml
@@ -277,7 +281,7 @@ files:
277
281
  - spec/unit/variants_spec.rb
278
282
  - test/rails/.gitignore
279
283
  - test/rails/overrides/.rspec
280
- - test/rails/overrides/Gemfile
284
+ - test/rails/overrides/Gemfile.jpmobile
281
285
  - test/rails/overrides/app/controllers/admin/top_controller.rb
282
286
  - test/rails/overrides/app/controllers/application_controller.rb
283
287
  - test/rails/overrides/app/controllers/docomo_guid_always_controller.rb
@@ -430,7 +434,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
430
434
  version: '0'
431
435
  requirements: []
432
436
  rubyforge_project:
433
- rubygems_version: 2.4.5
437
+ rubygems_version: 2.4.5.1
434
438
  signing_key:
435
439
  specification_version: 4
436
440
  summary: A Rails plugin for mobile devices in Japan
@@ -459,13 +463,16 @@ test_files:
459
463
  - spec/unit/email-fixtures/au-emoji5.eml
460
464
  - spec/unit/email-fixtures/au-kigou.eml
461
465
  - spec/unit/email-fixtures/bounce_with_utf8_part.eml
466
+ - spec/unit/email-fixtures/docomo-decomail.eml
462
467
  - spec/unit/email-fixtures/docomo-emoji.eml
463
468
  - spec/unit/email-fixtures/docomo-gmail-sjis.eml
464
469
  - spec/unit/email-fixtures/docomo-jis.eml
470
+ - spec/unit/email-fixtures/iphone-circled-numbers-in-jis.eml
465
471
  - spec/unit/email-fixtures/iphone-cp932.eml
466
472
  - spec/unit/email-fixtures/iphone-jis.eml
467
473
  - spec/unit/email-fixtures/iphone-mail3.eml
468
474
  - spec/unit/email-fixtures/iphone-message.eml
475
+ - spec/unit/email-fixtures/iphone-unicode-emoji.eml
469
476
  - spec/unit/email-fixtures/pc-mail-attached-without-subject.eml
470
477
  - spec/unit/email-fixtures/pc-mail-multi.eml
471
478
  - spec/unit/email-fixtures/pc-mail-single.eml
@@ -488,7 +495,7 @@ test_files:
488
495
  - spec/unit/variants_spec.rb
489
496
  - test/rails/.gitignore
490
497
  - test/rails/overrides/.rspec
491
- - test/rails/overrides/Gemfile
498
+ - test/rails/overrides/Gemfile.jpmobile
492
499
  - test/rails/overrides/app/controllers/admin/top_controller.rb
493
500
  - test/rails/overrides/app/controllers/application_controller.rb
494
501
  - test/rails/overrides/app/controllers/docomo_guid_always_controller.rb