jpmobile 5.2.5 → 6.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -1
  3. data/.onkcop-config.yml +396 -0
  4. data/.rubocop.yml +71 -10
  5. data/.ruby-version +1 -1
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +157 -129
  8. data/README.md +2 -2
  9. data/jpmobile.gemspec +5 -1
  10. data/lib/jpmobile.rb +1 -0
  11. data/lib/jpmobile/configuration.rb +7 -3
  12. data/lib/jpmobile/docomo_guid.rb +2 -2
  13. data/lib/jpmobile/email.rb +2 -4
  14. data/lib/jpmobile/emoticon.rb +16 -23
  15. data/lib/jpmobile/filter.rb +9 -4
  16. data/lib/jpmobile/hook_action_view.rb +4 -10
  17. data/lib/jpmobile/hook_test_request.rb +1 -1
  18. data/lib/jpmobile/mail.rb +7 -7
  19. data/lib/jpmobile/mailer.rb +1 -1
  20. data/lib/jpmobile/mobile/abstract_mobile.rb +1 -1
  21. data/lib/jpmobile/mobile/android.rb +1 -1
  22. data/lib/jpmobile/mobile/au.rb +2 -2
  23. data/lib/jpmobile/mobile/black_berry.rb +1 -1
  24. data/lib/jpmobile/mobile/ddipocket.rb +1 -1
  25. data/lib/jpmobile/mobile/docomo.rb +6 -8
  26. data/lib/jpmobile/mobile/emobile.rb +2 -2
  27. data/lib/jpmobile/mobile/ipad.rb +1 -1
  28. data/lib/jpmobile/mobile/iphone.rb +1 -1
  29. data/lib/jpmobile/mobile/softbank.rb +2 -2
  30. data/lib/jpmobile/mobile/vodafone.rb +2 -2
  31. data/lib/jpmobile/mobile/willcom.rb +2 -2
  32. data/lib/jpmobile/mobile/windows_phone.rb +1 -1
  33. data/lib/jpmobile/rack/params_filter.rb +5 -4
  34. data/lib/jpmobile/rails.rb +9 -41
  35. data/lib/jpmobile/resolver.rb +3 -36
  36. data/lib/jpmobile/session/active_record_store.rb +1 -1
  37. data/lib/jpmobile/session/mem_cache_store.rb +1 -1
  38. data/lib/jpmobile/trans_sid.rb +1 -1
  39. data/lib/jpmobile/util.rb +4 -5
  40. data/lib/jpmobile/version.rb +1 -1
  41. data/lib/jpmobile/view_selector.rb +26 -0
  42. data/lib/tasks/jpmobile_tasks.rake +4 -4
  43. data/spec/rack/jpmobile/emoticon_spec.rb +48 -48
  44. data/spec/rack_helper.rb +1 -5
  45. data/spec/unit/email_spec.rb +1 -1
  46. data/spec/unit/receive_mail_spec.rb +10 -10
  47. data/spec/unit/util_spec.rb +4 -4
  48. data/test/rails/overrides/Gemfile.jpmobile +1 -1
  49. data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
  50. data/test/rails/overrides/app/mailboxes/application_mailbox.rb +3 -0
  51. data/test/rails/overrides/app/mailboxes/mobile_mailer_mailbox.rb +5 -0
  52. data/test/rails/overrides/app/mailers/decorated_mailer.rb +1 -1
  53. data/test/rails/overrides/db/migrate/20201111033056_create_active_storage_tables.active_storage.rb +36 -0
  54. data/test/rails/overrides/db/migrate/20201111033057_create_action_mailbox_tables.action_mailbox.rb +14 -0
  55. data/test/rails/overrides/spec/controllers/docomo_guid_spec.rb +2 -2
  56. data/test/rails/overrides/spec/controllers/hankaku_filter_controller_spec.rb +1 -1
  57. data/test/rails/overrides/spec/controllers/template_path_spec.rb +2 -0
  58. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/au-attached.eml +0 -0
  59. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/au-decomail.eml +0 -0
  60. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/au-emoji.eml +0 -0
  61. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/au-emoji2.eml +0 -0
  62. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/au-emoji5.eml +0 -0
  63. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/bounced-jp.eml +0 -0
  64. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/docomo-emoji.eml +0 -0
  65. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/docomo-gmail-sjis.eml +0 -0
  66. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/docomo-jis.eml +0 -0
  67. data/{spec/unit/email-fixtures → test/rails/overrides/spec/fixtures/files/mobile_mailer}/iphone-message.eml +0 -0
  68. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/no-from.eml +0 -0
  69. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/non-jp.eml +0 -0
  70. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/photo.jpg +0 -0
  71. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/softbank-blank.eml +0 -0
  72. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/softbank-emoji-utf8.eml +0 -0
  73. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/softbank-emoji.eml +0 -0
  74. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/softbank-gmail-sjis.eml +0 -0
  75. data/test/rails/overrides/spec/fixtures/{mobile_mailer → files/mobile_mailer}/softbank-gmail-utf8.eml +0 -0
  76. data/test/rails/overrides/spec/mailboxes/mobile_mailer_mailbox_spec.rb +265 -0
  77. data/test/rails/overrides/spec/mailers/mobile_mailer_spec.rb +0 -305
  78. data/test/rails/overrides/spec/requests/emobile_spec.rb +2 -2
  79. data/test/rails/overrides/spec/requests/trans_sid_spec.rb +9 -9
  80. metadata +82 -43
@@ -56,7 +56,7 @@ describe 'Jpmobile::Email' do
56
56
 
57
57
  describe 'japanese_mail_address_regexp' do
58
58
  before do
59
- Jpmobile::Email.japanese_mail_address_regexp = Regexp.new(/\.jp(?:[^a-zA-Z\.\-]|$)/)
59
+ Jpmobile::Email.japanese_mail_address_regexp = Regexp.new(/\.jp(?:[^a-zA-Z.\-]|$)/)
60
60
  end
61
61
 
62
62
  it '#detect_from_mail_header should return Jpmobile::Mobile::AbstractMobile when the header contains .jp address' do
@@ -7,7 +7,7 @@ describe 'Jpmobile::Mail#receive' do
7
7
 
8
8
  before(:each) do
9
9
  @to = 'info@jpmobile-rails.org'
10
- Jpmobile::Email.japanese_mail_address_regexp = Regexp.new(/\.jp[^a-zA-Z\.\-]/)
10
+ Jpmobile::Email.japanese_mail_address_regexp = Regexp.new(/\.jp[^a-zA-Z.\-]/)
11
11
  end
12
12
 
13
13
  describe 'PC mail' do
@@ -84,7 +84,7 @@ describe 'Jpmobile::Mail#receive' do
84
84
  describe 'Docomo' do
85
85
  context 'with sjis decomail' do
86
86
  before(:each) do
87
- @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml')).read)
87
+ @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/files/mobile_mailer/docomo-gmail-sjis.eml')).read)
88
88
  end
89
89
 
90
90
  it 'subject should be parsed correctly' do
@@ -129,7 +129,7 @@ describe 'Jpmobile::Mail#receive' do
129
129
 
130
130
  describe 'Au' do
131
131
  before(:each) do
132
- @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/mobile_mailer/au-decomail.eml')).read)
132
+ @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/files/mobile_mailer/au-decomail.eml')).read)
133
133
  end
134
134
 
135
135
  it 'subject should be parsed correctly' do
@@ -151,7 +151,7 @@ describe 'Jpmobile::Mail#receive' do
151
151
  describe 'Softbank' do
152
152
  context 'Shift_JIS' do
153
153
  before(:each) do
154
- @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/mobile_mailer/softbank-gmail-sjis.eml')).read)
154
+ @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/files/mobile_mailer/softbank-gmail-sjis.eml')).read)
155
155
  end
156
156
 
157
157
  it 'subject should be parsed correctly' do
@@ -170,7 +170,7 @@ describe 'Jpmobile::Mail#receive' do
170
170
 
171
171
  context 'UTF-8' do
172
172
  before(:each) do
173
- @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/mobile_mailer/softbank-gmail-utf8.eml')).read)
173
+ @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/files/mobile_mailer/softbank-gmail-utf8.eml')).read)
174
174
  end
175
175
 
176
176
  it 'subject should be parsed correctly' do
@@ -304,13 +304,13 @@ describe 'Jpmobile::Mail#receive' do
304
304
 
305
305
  context 'From au iPhone' do
306
306
  it 'charset should be UTF-8' do
307
- @mail = Mail.new(File.open(File.join(__dir__, 'email-fixtures/iphone-message.eml')).read)
307
+ @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/files/mobile_mailer/iphone-message.eml')).read)
308
308
  expect(@mail.mobile).to be_a(Jpmobile::Mobile::Au)
309
309
  expect(@mail.charset).to match(/utf-8/i)
310
310
  end
311
311
 
312
312
  it 'should be encoded correctly' do
313
- @mail = Mail.new(File.open(File.join(__dir__, 'email-fixtures/iphone-message.eml')).read)
313
+ @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/files/mobile_mailer/iphone-message.eml')).read)
314
314
  expect(@mail.encoded).to match(Regexp.escape("%[\e$B1`;yL>\e(B]%\e$B$N\e(B%[\e$BJ]8n<TL>\e(B]%"))
315
315
  end
316
316
 
@@ -435,7 +435,7 @@ describe 'Jpmobile::Mail#receive' do
435
435
  describe 'bounced mail' do
436
436
  context 'has jp address' do
437
437
  before(:each) do
438
- @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/mobile_mailer/bounced-jp.eml')).read)
438
+ @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/files/mobile_mailer/bounced-jp.eml')).read)
439
439
  end
440
440
 
441
441
  it 'mobile should abstract mobile' do
@@ -447,7 +447,7 @@ describe 'Jpmobile::Mail#receive' do
447
447
  describe 'non-Japanese mail' do
448
448
  context 'us-ascii' do
449
449
  before(:each) do
450
- @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/mobile_mailer/non-jp.eml')).read)
450
+ @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/files/mobile_mailer/non-jp.eml')).read)
451
451
  end
452
452
 
453
453
  it 'mobile should be nil' do
@@ -458,7 +458,7 @@ describe 'Jpmobile::Mail#receive' do
458
458
 
459
459
  context 'no From header' do
460
460
  before(:each) do
461
- @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/mobile_mailer/no-from.eml')).read)
461
+ @mail = Mail.new(File.open(File.join(__dir__, '../../test/rails/overrides/spec/fixtures/files/mobile_mailer/no-from.eml')).read)
462
462
  end
463
463
 
464
464
  it 'mobile should be nil' do
@@ -197,10 +197,10 @@ describe Jpmobile::Util do
197
197
  hash = invert_table(
198
198
  {
199
199
  [0x1F1E8, 0x1F1F3] => 0x3013,
200
- 0x1F1FF => 0x3013,
201
- 0x1F526 => 0xE6FB,
202
- [0x0023, 0x20E3] => 0xE6E0,
203
- 0x1F354 => 0xE673,
200
+ 0x1F1FF => 0x3013,
201
+ 0x1F526 => 0xE6FB,
202
+ [0x0023, 0x20E3] => 0xE6E0,
203
+ 0x1F354 => 0xE673,
204
204
  },
205
205
  )
206
206
  expect(hash[0x3013]).to eq([0x1F1E8, 0x1F1F3])
@@ -4,7 +4,7 @@ gem 'jpmobile', path: './vendor/jpmobile'
4
4
  gem 'jpmobile-terminfo', path: './vendor/jpmobile-terminfo'
5
5
  gem 'jpmobile-ipaddresses', path: './vendor/jpmobile-ipaddresses'
6
6
 
7
- gem 'activerecord-session_store', '~> 1.1.1'
7
+ gem 'activerecord-session_store', git: 'https://github.com/rails/activerecord-session_store.git', ref: 'f188efbc49a522123cc8acc805143824176d01c1'
8
8
 
9
9
  gem 'pry'
10
10
  gem 'pry-byebug'
@@ -5,7 +5,7 @@ class MobileSpecController < ApplicationController
5
5
  end
6
6
 
7
7
  def file_render
8
- render file: File.join(Rails.public_path, '422')
8
+ render file: File.join(Rails.public_path, '422.html')
9
9
  end
10
10
 
11
11
  def no_mobile
@@ -0,0 +1,3 @@
1
+ class ApplicationMailbox < ActionMailbox::Base
2
+ routing(/.*/ => :mobile_mailer)
3
+ end
@@ -0,0 +1,5 @@
1
+ class MobileMailerMailbox < ApplicationMailbox
2
+ def process
3
+ mail
4
+ end
5
+ end
@@ -3,7 +3,7 @@ class DecoratedMailer < Jpmobile::Mailer::Base
3
3
  default to: 'info@jp.mobile'
4
4
 
5
5
  def deco_mail(to_mail)
6
- attachments.inline['photo.jpg'] = File.open(File.join(Rails.root, 'spec/fixtures/mobile_mailer/photo.jpg')).read
6
+ attachments.inline['photo.jpg'] = File.open(File.join(Rails.root, 'spec/fixtures/files/mobile_mailer/photo.jpg')).read
7
7
 
8
8
  mail(to: to_mail, subject: '題名', decorated: true)
9
9
  end
@@ -0,0 +1,36 @@
1
+ # This migration comes from active_storage (originally 20170806125915)
2
+ class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
3
+ def change
4
+ create_table :active_storage_blobs do |t|
5
+ t.string :key, null: false
6
+ t.string :filename, null: false
7
+ t.string :content_type
8
+ t.text :metadata
9
+ t.string :service_name, null: false
10
+ t.bigint :byte_size, null: false
11
+ t.string :checksum, null: false
12
+ t.datetime :created_at, null: false
13
+
14
+ t.index [:key], unique: true
15
+ end
16
+
17
+ create_table :active_storage_attachments do |t|
18
+ t.string :name, null: false
19
+ t.references :record, null: false, polymorphic: true, index: false
20
+ t.references :blob, null: false
21
+
22
+ t.datetime :created_at, null: false
23
+
24
+ t.index [:record_type, :record_id, :name, :blob_id], name: 'index_active_storage_attachments_uniqueness', unique: true
25
+ t.foreign_key :active_storage_blobs, column: :blob_id
26
+ end
27
+
28
+ create_table :active_storage_variant_records do |t|
29
+ t.belongs_to :blob, null: false, index: false
30
+ t.string :variation_digest, null: false
31
+
32
+ t.index %i[blob_id variation_digest], name: 'index_active_storage_variant_records_uniqueness', unique: true
33
+ t.foreign_key :active_storage_blobs, column: :blob_id
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ # This migration comes from action_mailbox (originally 20180917164000)
2
+ class CreateActionMailboxTables < ActiveRecord::Migration[6.0]
3
+ def change
4
+ create_table :action_mailbox_inbound_emails do |t|
5
+ t.integer :status, default: 0, null: false
6
+ t.string :message_id, null: false
7
+ t.string :message_checksum, null: false
8
+
9
+ t.timestamps
10
+
11
+ t.index [:message_id, :message_checksum], name: 'index_action_mailbox_inbound_emails_uniqueness', unique: true
12
+ end
13
+ end
14
+ end
@@ -6,7 +6,7 @@ shared_examples_for 'docomo_guid が起動しないとき' do
6
6
  it 'で link_to の自動書き換えが行われない' do
7
7
  get :link
8
8
 
9
- expect(response.body).to match(%r{href=\".+/link\"})
9
+ expect(response.body).to match(%r{href=".+/link"})
10
10
  end
11
11
  end
12
12
 
@@ -14,7 +14,7 @@ shared_examples_for 'docomo_guid が起動するとき' do
14
14
  it 'で link_to の自動書き換えが行われる' do
15
15
  get :link
16
16
 
17
- expect(response.body).to match(%r{href=\".+/link\?guid=ON\"})
17
+ expect(response.body).to match(%r{href=".+/link\?guid=ON"})
18
18
  end
19
19
  end
20
20
 
@@ -1,6 +1,6 @@
1
1
  require 'rails_helper'
2
2
 
3
- describe Jpmobile::HankakuFilterController, type: :controller do
3
+ describe HankakuFilterController, type: :controller do
4
4
  describe '#index' do
5
5
  let(:params) { { prefecture_ids: ['1', '2'] } }
6
6
 
@@ -1,6 +1,8 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  describe TemplatePathController, type: :controller do
4
+ render_views
5
+
4
6
  before do
5
7
  request.user_agent = user_agent
6
8
  end
@@ -0,0 +1,265 @@
1
+ require 'rails_helper'
2
+ require 'action_mailbox/test_helper'
3
+
4
+ describe MobileMailerMailbox, type: :mailbox do
5
+ include ActionMailbox::TestHelper
6
+
7
+ describe 'blank mail' do
8
+ it 'softbank からの空メールがで受信できること' do
9
+ expect {
10
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/softbank-blank.eml')
11
+
12
+ expect(inbound_email.mail.subject).to be_blank
13
+ expect(inbound_email.mail.body).to be_blank
14
+ }.to_not raise_error
15
+ end
16
+ end
17
+
18
+ describe 'docomo からのメールを受信するとき' do
19
+ it '漢字コードを適切に変換できること' do
20
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/docomo-emoji.eml')
21
+
22
+ expect(inbound_email.mail.subject).to match(/題名/)
23
+ expect(inbound_email.mail.body).to match(/本文/)
24
+ end
25
+
26
+ it '絵文字が数値参照に変わること' do
27
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/docomo-emoji.eml')
28
+
29
+ expect(inbound_email.mail.subject).to match(/&#xe676;/)
30
+ expect(inbound_email.mail.body).to match(/&#xe6e2;/)
31
+ end
32
+
33
+ describe 'jis コードの場合に' do
34
+ it '適切に変換できること' do
35
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/docomo-jis.eml')
36
+
37
+ expect(inbound_email.mail.subject).to match(/テスト/)
38
+ expect(inbound_email.mail.body).to match(/テスト本文/)
39
+ end
40
+ end
41
+ end
42
+
43
+ describe 'au からのメールを受信するとき' do
44
+ describe 'jpmobile で送信したメールの場合' do
45
+ it '漢字コードを適切に変換できること' do
46
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/au-emoji.eml')
47
+
48
+ expect(inbound_email.mail.subject).to match(/題名/)
49
+ expect(inbound_email.mail.body).to match(/本文/)
50
+ end
51
+
52
+ it '絵文字が数値参照に変わること' do
53
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/au-emoji.eml')
54
+
55
+ expect(inbound_email.mail.subject).to match(/&#xe503;/)
56
+ expect(inbound_email.mail.body).to match(/&#xe522;/)
57
+ end
58
+ end
59
+
60
+ describe '実機からのメールの場合' do
61
+ it '漢字コードを適切に変換できること' do
62
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/au-emoji2.eml')
63
+
64
+ expect(inbound_email.mail.subject).to match(/題名/)
65
+ expect(inbound_email.mail.body).to match(/本文/)
66
+ end
67
+
68
+ it '絵文字が数値参照に変わること' do
69
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/au-emoji2.eml')
70
+
71
+ expect(inbound_email.mail.subject).to match(/&#xe4f4;/)
72
+ expect(inbound_email.mail.body).to match(/&#xe471;/)
73
+ end
74
+ end
75
+ end
76
+
77
+ describe 'softbank からのメールを受信するとき' do
78
+ describe 'shift_jis のとき' do
79
+ it '漢字コードを適切に変換できること' do
80
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/softbank-emoji.eml')
81
+
82
+ expect(inbound_email.mail.subject).to match(/題名/)
83
+ expect(inbound_email.mail.body).to match(/本文/)
84
+ end
85
+
86
+ it '絵文字が数値参照に変わること' do
87
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/softbank-emoji.eml')
88
+
89
+ expect(inbound_email.mail.subject).to match(/&#xf03c;/)
90
+ expect(inbound_email.mail.body).to match(/&#xf21c;/)
91
+ end
92
+ end
93
+
94
+ describe 'utf-8 のとき' do
95
+ it '漢字コードを適切に変換できること' do
96
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/softbank-emoji.eml')
97
+
98
+ expect(inbound_email.mail.subject).to match(/題名/)
99
+ expect(inbound_email.mail.body).to match(/本文/)
100
+ end
101
+
102
+ it '絵文字が数値参照に変わること' do
103
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/softbank-emoji-utf8.eml')
104
+
105
+ expect(inbound_email.mail.subject).to match(/&#xf03c;/)
106
+ expect(inbound_email.mail.body).to match(/&#xf21c;/)
107
+ end
108
+ end
109
+ end
110
+
111
+ describe 'multipart メールを受信するとき' do
112
+ describe 'docomo の場合' do
113
+ # NOTE: キャリアメールサーバで絵文字を変換するため検証は困難
114
+ it '正常に受信できること' do
115
+ expect {
116
+ receive_inbound_email_from_fixture('mobile_mailer/docomo-gmail-sjis.eml')
117
+ }.not_to raise_exception
118
+ end
119
+
120
+ it '絵文字が変換されること' do
121
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/docomo-gmail-sjis.eml')
122
+
123
+ expect(inbound_email.mail.subject).to match(/&#xe6ec;/)
124
+
125
+ expect(inbound_email.mail.parts.size).to eq(1)
126
+ expect(inbound_email.mail.parts.first.parts.size).to eq(2)
127
+
128
+ parts = inbound_email.mail.parts.first.parts
129
+ expect(parts.first.body).to match('テストです&#xe72d;')
130
+ expect(parts.last.body.raw_source).to match('テストです&#xe72d;')
131
+ end
132
+ end
133
+
134
+ describe 'au の場合' do
135
+ it '正常に受信できること' do
136
+ expect {
137
+ receive_inbound_email_from_fixture('mobile_mailer/au-decomail.eml')
138
+ }.not_to raise_exception
139
+ end
140
+
141
+ it '絵文字が変換されること' do
142
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/au-decomail.eml')
143
+
144
+ expect(inbound_email.mail.subject).to match(/&#xe4f4;/)
145
+
146
+ expect(inbound_email.mail.parts.size).to eq(1)
147
+ expect(inbound_email.mail.parts.first.parts.size).to eq(2)
148
+
149
+ parts = inbound_email.mail.parts.first.parts
150
+ expect(parts.first.body).to match(/テストです&#xe595;/)
151
+ expect(parts.last.body.raw_source).to match(/テストです&#xe595;/)
152
+ end
153
+
154
+ context 'iPhone' do
155
+ it 'should parse correctly' do
156
+ expect {
157
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/iphone-message.eml')
158
+ inbound_email.mail.encoded
159
+ }.not_to raise_error
160
+ end
161
+ end
162
+ end
163
+
164
+ describe 'softbank(sjis) の場合' do
165
+ # NOTE: キャリアメールサーバで絵文字を変換するため検証は困難
166
+ it '正常に受信できること' do
167
+ expect {
168
+ receive_inbound_email_from_fixture('mobile_mailer/softbank-gmail-sjis.eml')
169
+ }.not_to raise_exception
170
+ end
171
+
172
+ it '絵文字が変換されること' do
173
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/softbank-gmail-sjis.eml')
174
+
175
+ expect(inbound_email.mail.subject).to match(/&#xf221;&#xf223;&#xf221;/)
176
+
177
+ expect(inbound_email.mail.parts.size).to eq(2)
178
+
179
+ expect(inbound_email.mail.parts.first.body).to match(/テストです&#xf018;/)
180
+ expect(inbound_email.mail.parts.last.body.raw_source).to match(/テストです&#xf231;/)
181
+ end
182
+ end
183
+
184
+ describe 'softbank(utf8) の場合' do
185
+ # NOTE: キャリアメールサーバで絵文字を変換するため検証は困難
186
+ it '正常に受信できること' do
187
+ expect {
188
+ receive_inbound_email_from_fixture('mobile_mailer/softbank-gmail-utf8.eml')
189
+ }.not_to raise_exception
190
+ end
191
+
192
+ it '絵文字が変換されること' do
193
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/softbank-gmail-utf8.eml')
194
+
195
+ expect(inbound_email.mail.subject).to match(/テストです&#xf221;/)
196
+
197
+ expect(inbound_email.mail.parts.size).to eq(2)
198
+
199
+ expect(inbound_email.mail.parts.first.body).to match(/テストです&#xf223;/)
200
+ expect(inbound_email.mail.parts.last.body.raw_source).to match(/テストです&#xf223;/)
201
+ end
202
+ end
203
+
204
+ describe '添付ファイルがある場合' do
205
+ # NOTE: au のみテスト
206
+ it '正常に受信できること' do
207
+ expect {
208
+ receive_inbound_email_from_fixture('mobile_mailer/au-attached.eml')
209
+ }.not_to raise_exception
210
+ end
211
+
212
+ it '添付ファイルが壊れないこと' do
213
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/au-attached.eml')
214
+
215
+ expect(inbound_email.mail.subject).to match(/&#xe481;/)
216
+
217
+ expect(inbound_email.mail.parts.size).to eq(2)
218
+
219
+ expect(inbound_email.mail.parts.first.body).to match(/カレンダーだ&#xe4f4;/)
220
+
221
+ expect(inbound_email.mail.has_attachments?).to be_truthy
222
+ expect(inbound_email.mail.attachments.size).to eq(1)
223
+ expect(inbound_email.mail.attachments['20098calendar01.jpg'].content_type).to match('image/jpeg')
224
+ expect(inbound_email.mail.attachments['20098calendar01.jpg'].body.to_s.size).to eq(86412)
225
+ expect(inbound_email.mail.attachments['20098calendar01.jpg'].body.to_s[6..9]).to eq('JFIF')
226
+ end
227
+ end
228
+ end
229
+
230
+ describe 'PCからメールを受信するとき' do
231
+ describe '日本語ではない場合' do
232
+ before(:each) do
233
+ @email = file_fixture('mobile_mailer/non-jp.eml').read
234
+ end
235
+
236
+ it '正常に受信できること' do
237
+ expect {
238
+ receive_inbound_email_from_fixture('mobile_mailer/non-jp.eml')
239
+ }.not_to raise_exception
240
+ end
241
+
242
+ it 'mobile が nil であること' do
243
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/non-jp.eml')
244
+ expect(inbound_email.mail.mobile).to be_nil
245
+ end
246
+ end
247
+
248
+ describe 'From がない場合' do
249
+ before(:each) do
250
+ @email = file_fixture('mobile_mailer/no-from.eml').read
251
+ end
252
+
253
+ it '正常に受信できること' do
254
+ expect {
255
+ receive_inbound_email_from_fixture('mobile_mailer/no-from.eml')
256
+ }.not_to raise_exception
257
+ end
258
+
259
+ it 'mobile が nil であること' do
260
+ inbound_email = receive_inbound_email_from_fixture('mobile_mailer/no-from.eml')
261
+ expect(inbound_email.mail.mobile).to be_nil
262
+ end
263
+ end
264
+ end
265
+ end