jpmobile 0.1.6 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/README +0 -0
  2. data/README.rdoc +58 -29
  3. data/Rakefile +1 -1
  4. data/VERSION.yml +4 -4
  5. data/lib/jpmobile.rb +3 -0
  6. data/lib/jpmobile/email.rb +17 -2
  7. data/lib/jpmobile/emoticon.rb +87 -23
  8. data/lib/jpmobile/emoticon/au.rb +644 -0
  9. data/lib/jpmobile/emoticon/softbank.rb +488 -0
  10. data/lib/jpmobile/emoticon/z_combine.rb +16 -13
  11. data/lib/jpmobile/hook_action_controller.rb +1 -13
  12. data/lib/jpmobile/hook_action_view.rb +3 -62
  13. data/lib/jpmobile/mail.rb +316 -0
  14. data/lib/jpmobile/mailer.rb +31 -0
  15. data/lib/jpmobile/mobile/abstract_mobile.rb +66 -0
  16. data/lib/jpmobile/mobile/au.rb +25 -2
  17. data/lib/jpmobile/mobile/docomo.rb +23 -1
  18. data/lib/jpmobile/mobile/emobile.rb +1 -1
  19. data/lib/jpmobile/mobile/softbank.rb +33 -1
  20. data/lib/jpmobile/mobile/vodafone.rb +1 -1
  21. data/lib/jpmobile/mobile/willcom.rb +1 -1
  22. data/lib/jpmobile/path_set.rb +40 -0
  23. data/lib/jpmobile/rails.rb +24 -0
  24. data/lib/jpmobile/resolver.rb +38 -0
  25. data/lib/jpmobile/util.rb +223 -14
  26. data/lib/tasks/jpmobile_tasks.rake +41 -48
  27. data/spec/rack/jpmobile/emoticon_spec.rb +3 -8
  28. data/spec/rack/jpmobile/filter_spec.rb +1 -1
  29. data/spec/rack/jpmobile/params_filter_spec.rb +4 -4
  30. data/spec/rack_helper.rb +5 -9
  31. data/spec/unit/detect_by_email_spec.rb +29 -0
  32. data/spec/unit/emoticon_spec.rb +90 -0
  33. data/spec/unit/encoding_spec.rb +102 -0
  34. data/spec/unit/mail_spec.rb +117 -0
  35. data/spec/unit/receive_mail_spec.rb +289 -0
  36. data/spec/unit/spec_helper.rb +8 -0
  37. data/spec/unit/util_spec.rb +5 -0
  38. data/test/rails/overrides/app/controllers/application_controller.rb +3 -2
  39. data/test/rails/overrides/app/controllers/template_path_controller.rb +8 -0
  40. data/test/rails/overrides/app/models/mobile_mailer.rb +19 -0
  41. data/test/rails/overrides/app/models/normal_mailer.rb +9 -0
  42. data/test/rails/overrides/spec/models/mobile_mailer_spec.rb +737 -0
  43. data/test/rails/overrides/spec/models/normal_mailer_spec.rb +34 -0
  44. data/test/rails/overrides/spec/requests/template_path_spec.rb +13 -7
  45. data/test/rails/overrides/spec/spec_helper.rb +6 -0
  46. data/test/rails/rails_root/app/controllers/application_controller.rb +3 -2
  47. data/test/rails/rails_root/app/controllers/template_path_controller.rb +8 -0
  48. data/test/rails/rails_root/app/models/mobile_mailer.rb +2 -1
  49. data/test/rails/rails_root/app/models/normal_mailer.rb +9 -0
  50. data/test/rails/rails_root/config/initializers/secret_token.rb +1 -1
  51. data/test/rails/rails_root/spec/models/mobile_mailer_spec.rb +73 -80
  52. data/test/rails/rails_root/spec/models/normal_mailer_spec.rb +34 -0
  53. data/test/rails/rails_root/spec/requests/template_path_spec.rb +13 -7
  54. data/test/rails/rails_root/spec/spec_helper.rb +1 -1
  55. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile.rb +2 -1
  56. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +7 -5
  57. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_controller.rb +1 -13
  58. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_view.rb +3 -62
  59. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mail.rb +162 -111
  60. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mailer.rb +31 -0
  61. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/abstract_mobile.rb +34 -3
  62. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +2 -5
  63. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/docomo.rb +4 -5
  64. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +7 -8
  65. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/path_set.rb +40 -0
  66. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rack/params_filter.rb +1 -1
  67. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/rails.rb +24 -0
  68. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/resolver.rb +38 -0
  69. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/util.rb +33 -23
  70. metadata +43 -14
  71. data/test/legacy/emoticon_test.rb +0 -63
  72. data/test/legacy/helper.rb +0 -8
  73. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_mailer.rb +0 -22
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe NormalMailer do
5
+ include Jpmobile::Util
6
+
7
+ before(:each) do
8
+ ActionMailer::Base.deliveries = []
9
+
10
+ @to = ["outer@jp.mobile", "outer1@jp.mobile"]
11
+ @subject = "日本語題名"
12
+ @text = "日本語テキスト"
13
+ end
14
+
15
+ context "PC宛メール" do
16
+ it "正常に送信できること" do
17
+ email = NormalMailer.msg(@to, "題名", "本文").deliver
18
+
19
+ ActionMailer::Base.deliveries.size.should == 1
20
+ (email.to - @to).should be_empty
21
+ end
22
+
23
+ it "UTF-8のままであること" do
24
+ email = NormalMailer.msg(@to, @subject, @text).deliver
25
+
26
+ ActionMailer::Base.deliveries.size.should == 1
27
+
28
+ raw_mail = ascii_8bit(email.to_s)
29
+ raw_mail.should match(/UTF-8/i)
30
+ raw_mail.should match(Regexp.escape("=E6=97=A5=E6=9C=AC=E8=AA=9E=E9=A1=8C=E5=90=8D"))
31
+ raw_mail.should match(Regexp.escape([@text].pack("m").strip))
32
+ end
33
+ end
34
+ end
@@ -13,7 +13,7 @@ describe TemplatePathController, "DoCoMo SH902i からのアクセス" do
13
13
  it 'テンプレートの探索順が正しいこと' do
14
14
  get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
15
15
 
16
- controller.view_paths.mobile_template_candidates.should == [ 'mobile_docomo', 'mobile' ]
16
+ controller.lookup_context.mobile.should == [ 'mobile_docomo', 'mobile' ]
17
17
  end
18
18
  end
19
19
 
@@ -24,7 +24,7 @@ describe TemplatePathController, "au CA32 からのアクセス" do
24
24
  it 'テンプレートの探索順が正しいこと' do
25
25
  get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
26
26
 
27
- controller.view_paths.mobile_template_candidates.should == [ 'mobile_au', 'mobile' ]
27
+ controller.lookup_context.mobile.should == [ 'mobile_au', 'mobile' ]
28
28
  end
29
29
  end
30
30
 
@@ -35,7 +35,7 @@ describe TemplatePathController, "Vodafone V903T からのアクセス" do
35
35
  it 'テンプレートの探索順が正しいこと' do
36
36
  get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
37
37
 
38
- controller.view_paths.mobile_template_candidates.should == [ 'mobile_vodafone', 'mobile_softbank', 'mobile' ]
38
+ controller.lookup_context.mobile.should == [ 'mobile_vodafone', 'mobile_softbank', 'mobile' ]
39
39
  end
40
40
  end
41
41
 
@@ -46,7 +46,7 @@ describe TemplatePathController, "SoftBank 910T からのアクセス" do
46
46
  it 'テンプレートの探索順が正しいこと' do
47
47
  get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
48
48
 
49
- controller.view_paths.mobile_template_candidates.should == [ 'mobile_softbank', 'mobile' ]
49
+ controller.lookup_context.mobile.should == [ 'mobile_softbank', 'mobile' ]
50
50
  end
51
51
  end
52
52
 
@@ -57,7 +57,7 @@ describe TemplatePathController, "iPhone からのアクセス" do
57
57
  it 'テンプレートの探索順が正しいこと' do
58
58
  get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
59
59
 
60
- controller.view_paths.mobile_template_candidates.should == [ 'smart_phone_iphone', 'smart_phone' ]
60
+ controller.lookup_context.mobile.should == [ 'smart_phone_iphone', 'smart_phone' ]
61
61
  end
62
62
  end
63
63
 
@@ -68,7 +68,7 @@ describe TemplatePathController, "Android からのアクセス" do
68
68
  it 'テンプレートの探索順が正しいこと' do
69
69
  get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
70
70
 
71
- controller.view_paths.mobile_template_candidates.should == [ 'smart_phone_android', 'smart_phone' ]
71
+ controller.lookup_context.mobile.should == [ 'smart_phone_android', 'smart_phone' ]
72
72
  end
73
73
  end
74
74
 
@@ -79,7 +79,7 @@ describe TemplatePathController, "Windows Phone からのアクセス" do
79
79
  it 'テンプレートの探索順が正しいこと' do
80
80
  get "/template_path/index", {}, { "HTTP_USER_AGENT" => @user_agent}
81
81
 
82
- controller.view_paths.mobile_template_candidates.should == [ 'smart_phone_windows_phone', 'smart_phone' ]
82
+ controller.lookup_context.mobile.should == [ 'smart_phone_windows_phone', 'smart_phone' ]
83
83
  end
84
84
  end
85
85
 
@@ -111,6 +111,12 @@ describe TemplatePathController, "integrated_views" do
111
111
 
112
112
  response.should have_tag("h1", :content => "show_mobile_docomo.html.erb")
113
113
  end
114
+
115
+ it 'disable_mobile_view! のときには index.html.erb が使用されること' do
116
+ get "/template_path/index", {:pc => true}, { "HTTP_USER_AGENT" => @user_agent}
117
+
118
+ response.should have_tag("h1", :content => "index.html.erb")
119
+ end
114
120
  end
115
121
 
116
122
  context "SoftBankからのアクセスの場合" do
@@ -27,6 +27,12 @@ RSpec.configure do |config|
27
27
  config.include Webrat::HaveTagMatcher
28
28
  config.include Jpmobile::Util
29
29
  config.before(:each) { Webrat.configuration.mode = :rails }
30
+
31
+ config.filter_run :focus => true
32
+ config.run_all_when_everything_filtered = true
33
+ config.color_enabled = true
34
+ config.filter_run_excluding :broken => true
35
+ # config.full_backtrace = true
30
36
  end
31
37
 
32
38
  require 'pp'
@@ -1,5 +1,6 @@
1
- require 'rubygems'
2
- require 'action_controller'
1
+ # require 'rubygems'
2
+ # require 'action_controller'
3
3
 
4
4
  class ApplicationController < ActionController::Base
5
+ include Jpmobile::ViewSelector
5
6
  end
@@ -1,9 +1,17 @@
1
1
  class TemplatePathController < ApplicationController
2
2
  def index
3
3
  @q = params[:q]
4
+
5
+ if params[:pc]
6
+ disable_mobile_view!
7
+ end
4
8
  end
5
9
 
6
10
  def show
7
11
  end
12
+
13
+ def optioned_index
14
+ render :action => "index"
15
+ end
8
16
  end
9
17
 
@@ -11,7 +11,8 @@ class MobileMailer < Jpmobile::Mailer::Base
11
11
  email
12
12
  end
13
13
 
14
- def multi_message(to_mail, subject_text, text)
14
+ def multi_message(to_mail, subject_text, text, html)
15
+ @html = html
15
16
  @text = text
16
17
  mail(:to => to_mail, :subject => subject)
17
18
  end
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+ class NormalMailer < ActionMailer::Base
3
+ default :from => "info@jp.mobile"
4
+
5
+ def msg(to_mail, subject_text, text)
6
+ @text = text
7
+ mail(:to => to_mail, :subject => subject_text)
8
+ end
9
+ end
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- RailsRoot::Application.config.secret_token = 'd8432b7143e2cf7e88965fc1f4c6e5cb51218a48d2235876c7fe47351d599793242abd6636307611e7a1a1dde90d5466139bcce0e44342450902fc7a3c676168'
7
+ RailsRoot::Application.config.secret_token = '23417af8bf908eea220f39faa992f7a25a753df87b6f0f4bfd9fec3ccf0dad629004cc608a9aaed4532f58231f16dfa9875cd21fbb4c58bde26bdc4aa9103979'
@@ -85,7 +85,7 @@ describe MobileMailer do
85
85
 
86
86
  raw_mail = email.to_s
87
87
  raw_mail.should match(/shift_jis/i)
88
- # raw_mail.should match(/For docomo/) # TODO: revise Resolver in view selector
88
+ # raw_mail.should match(/For docomo/)
89
89
  raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvA=="))
90
90
  raw_mail.should match(Regexp.compile(utf8_to_sjis(@text)))
91
91
  end
@@ -99,7 +99,7 @@ describe MobileMailer do
99
99
  ActionMailer::Base.deliveries.size.should == 1
100
100
 
101
101
  raw_mail = email.to_s
102
- # raw_mail.should match(/For docomo/) # TODO: revise Resolver in view selector
102
+ raw_mail.should match(/For docomo/)
103
103
  raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvPjX"))
104
104
  raw_mail.should match(regexp_to_sjis("\xf8\xec"))
105
105
  end
@@ -113,7 +113,7 @@ describe MobileMailer do
113
113
  ActionMailer::Base.deliveries.size.should == 1
114
114
 
115
115
  raw_mail = email.to_s
116
- # raw_mail.should match(/For docomo/) # TODO: revise Resolver in view selector
116
+ raw_mail.should match(/For docomo/)
117
117
  raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvLnesNE="))
118
118
  raw_mail.should match(Regexp.compile(Regexp.escape(utf8_to_sjis(half_kana_text))))
119
119
  end
@@ -154,7 +154,7 @@ describe MobileMailer do
154
154
  ActionMailer::Base.deliveries.size.should == 1
155
155
 
156
156
  raw_mail = ascii_8bit(email.to_s)
157
- # raw_mail.should match(/For au/) # TODO: revise Resolver in view selector
157
+ raw_mail.should match(/For au/)
158
158
  raw_mail.should match(Regexp.escape("GyRCRnxLXDhsQmpMPhsoQhskQnZeGyhC"))
159
159
  raw_mail.should match(Regexp.compile(ascii_8bit("\x76\x21")))
160
160
  end
@@ -182,7 +182,7 @@ describe MobileMailer do
182
182
 
183
183
  raw_mail = email.to_s
184
184
  raw_mail.should match(/shift_jis/i)
185
- # raw_mail.should match(/For softbank/) # TODO: revise Resolver in view selector
185
+ raw_mail.should match(/For softbank/)
186
186
  raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvA=="))
187
187
  raw_mail.should match(Regexp.compile(utf8_to_sjis(@text)))
188
188
  end
@@ -196,7 +196,7 @@ describe MobileMailer do
196
196
  ActionMailer::Base.deliveries.size.should == 1
197
197
 
198
198
  raw_mail = email.to_s
199
- # raw_mail.should match(/For softbank/) # TODO: revise Resolver in view selector
199
+ raw_mail.should match(/For softbank/)
200
200
  raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvPl8"))
201
201
  raw_mail.should match(regexp_to_sjis("\xf7\x6a"))
202
202
  end
@@ -224,7 +224,7 @@ describe MobileMailer do
224
224
 
225
225
  raw_mail = email.to_s
226
226
  raw_mail.should match(/shift_jis/i)
227
- # raw_mail.should match(/For softbank/) # TODO: revise Resolver in view selector
227
+ raw_mail.should match(/For vodafone/)
228
228
  raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvA=="))
229
229
  raw_mail.should match(Regexp.compile(utf8_to_sjis(@text)))
230
230
  end
@@ -238,7 +238,7 @@ describe MobileMailer do
238
238
  ActionMailer::Base.deliveries.size.should == 1
239
239
 
240
240
  raw_mail = email.to_s
241
- # raw_mail.should match(/For softbank/) # TODO: revise Resolver in view selector
241
+ raw_mail.should match(/For vodafone/)
242
242
  raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvPl8"))
243
243
  raw_mail.should match(regexp_to_sjis("\xf7\x6a"))
244
244
  end
@@ -276,6 +276,7 @@ describe MobileMailer do
276
276
 
277
277
  @subject = "題名"
278
278
  @text = "本文"
279
+ @html = "万葉"
279
280
  end
280
281
 
281
282
  describe "PC の場合" do
@@ -283,8 +284,8 @@ describe MobileMailer do
283
284
  @to = "gate@bill.com"
284
285
  end
285
286
 
286
- it "漢字コードが変換されること", :focus => true do
287
- email = MobileMailer.multi_message(@to, @subject, @text).deliver
287
+ it "漢字コードが変換されること" do
288
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
288
289
 
289
290
  ActionMailer::Base.deliveries.size.should == 1
290
291
 
@@ -292,7 +293,7 @@ describe MobileMailer do
292
293
 
293
294
  raw_mail = ascii_8bit(email.to_s)
294
295
  raw_mail.should match(Regexp.escape(ascii_8bit(utf8_to_jis(@text))))
295
- raw_mail.should match(Regexp.escape(ascii_8bit(utf8_to_jis("万葉"))))
296
+ raw_mail.should match(Regexp.escape(ascii_8bit(utf8_to_jis(@html))))
296
297
  end
297
298
  end
298
299
 
@@ -302,31 +303,29 @@ describe MobileMailer do
302
303
  end
303
304
 
304
305
  it "漢字コードが変換されること" do
305
- MobileMailer.multi_message(@to, @subject, @text).deliver
306
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
306
307
 
307
- emails = ActionMailer::Base.deliveries
308
- emails.size.should == 1
309
- email = emails.first
308
+ ActionMailer::Base.deliveries.size.should == 1
310
309
 
311
310
  email.parts.size.should == 2
312
311
 
313
- email.parts.first.body.unpack("m").first.should match(Regexp.compile(Regexp.escape(NKF.nkf("-sWx", @html), 's'), nil, 's'))
314
-
315
- email.parts.last.charset.should match(/^shift_jis$/i)
316
- email.parts.last.body.should match(/#{Regexp.escape(NKF.nkf("-sWx", @plain))}/)
312
+ raw_mail = email.to_s
313
+ raw_mail.should match(sjis_regexp(utf8_to_sjis(@text)))
314
+ raw_mail.should match(sjis_regexp(utf8_to_sjis(@html)))
317
315
  end
318
316
 
319
317
  it "絵文字が変換されること" do
320
318
  @text += "&#xe68b;"
321
- MobileMailer.multi_message(@to, @subject, @text).deliver
319
+ @html += "&#xe676;"
320
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
322
321
 
323
- emails = ActionMailer::Base.deliveries
324
- emails.size.should == 1
325
- email = emails.first
322
+ ActionMailer::Base.deliveries.size.should == 1
326
323
 
327
324
  email.parts.size.should == 2
328
- email.parts.first.body.unpack("m").first.should match(Regexp.compile(Regexp.escape([0xf8ec].pack('n'), 's'), nil, 's'))
329
- email.parts.last.body.should match(Regexp.compile(Regexp.escape([0xf8d7].pack('n'), 's'), nil, 's'))
325
+
326
+ raw_mail = email.to_s
327
+ raw_mail.should match(sjis_regexp(sjis("\xf8\xec")))
328
+ raw_mail.should match(sjis_regexp(sjis("\xf8\xd7")))
330
329
  end
331
330
  end
332
331
 
@@ -336,32 +335,29 @@ describe MobileMailer do
336
335
  end
337
336
 
338
337
  it "漢字コードが変換されること" do
339
- MobileMailer.multi_message(@to, @subject, @text).deliver
338
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
340
339
 
341
- emails = ActionMailer::Base.deliveries
342
- emails.size.should == 1
343
- email = emails.first
340
+ ActionMailer::Base.deliveries.size.should == 1
344
341
 
345
342
  email.parts.size.should == 2
346
343
 
347
- NKF.nkf("-mQ", email.parts.first.body).should match(/#{Regexp.escape(NKF.nkf("-jWx", @html))}/)
348
-
349
- email.parts.last.charset.should match(/^iso-2022-jp$/i)
350
- email.parts.last.body.should match(/#{Regexp.escape(NKF.nkf("-jWx", @plain))}/)
344
+ raw_mail = ascii_8bit(email.to_s)
345
+ raw_mail.should match(Regexp.escape(ascii_8bit(utf8_to_jis(@text))))
346
+ raw_mail.should match(Regexp.escape(ascii_8bit(utf8_to_jis(@html))))
351
347
  end
352
348
 
353
349
  it "絵文字が変換されること" do
354
- @text += "&#xe676;"
355
- MobileMailer.multi_message(@to, @subject, @text).deliver
350
+ @text += "&#xe68b;"
351
+ @html += "&#xe676;"
352
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
356
353
 
357
- emails = ActionMailer::Base.deliveries
358
- emails.size.should == 1
359
- email = emails.first
354
+ ActionMailer::Base.deliveries.size.should == 1
360
355
 
361
356
  email.parts.size.should == 2
362
357
 
363
- NKF.nkf("-mQ", email.parts.first.body).should match(/#{Regexp.escape([0x7621].pack('n'))}/)
364
- email.parts.last.body.should match(/#{Regexp.escape([0x765e].pack('n'))}/)
358
+ raw_mail = ascii_8bit(email.to_s)
359
+ raw_mail.should match(jis_regexp("\x76\x21"))
360
+ raw_mail.should match(jis_regexp("\x76\x5e"))
365
361
  end
366
362
  end
367
363
 
@@ -371,31 +367,29 @@ describe MobileMailer do
371
367
  end
372
368
 
373
369
  it "漢字コードが変換されること" do
374
- MobileMailer.multi_message(@to, @subject, @text).deliver
370
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
375
371
 
376
- emails = ActionMailer::Base.deliveries
377
- emails.size.should == 1
378
- email = emails.first
372
+ ActionMailer::Base.deliveries.size.should == 1
379
373
 
380
374
  email.parts.size.should == 2
381
375
 
382
- email.parts.first.body.unpack("m").first.should match(Regexp.compile(Regexp.escape(NKF.nkf("-sWx", @html), 's'), nil, 's'))
383
-
384
- email.parts.last.charset.should match(/^shift_jis$/i)
385
- email.parts.last.body.should match(/#{Regexp.escape(NKF.nkf("-sWx", @plain))}/)
376
+ raw_mail = email.to_s
377
+ raw_mail.should match(sjis_regexp(utf8_to_sjis(@text)))
378
+ raw_mail.should match(sjis_regexp(utf8_to_sjis(@html)))
386
379
  end
387
380
 
388
381
  it "絵文字が変換されること" do
389
382
  @text += "&#xe68a;"
390
- MobileMailer.multi_message(@to, @subject, @text).deliver
383
+ @html += "&#xe676;"
384
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
391
385
 
392
- emails = ActionMailer::Base.deliveries
393
- emails.size.should == 1
394
- email = emails.first
386
+ ActionMailer::Base.deliveries.size.should == 1
395
387
 
396
388
  email.parts.size.should == 2
397
- email.parts.first.body.unpack("m").first.should match(Regexp.compile(Regexp.escape([0xf76a].pack('n'), 's'), nil, 's'))
398
- email.parts.last.body.should match(Regexp.compile(Regexp.escape([0xf97c].pack('n'), 's'), nil, 's'))
389
+
390
+ raw_mail = email.to_s
391
+ raw_mail.should match(sjis_regexp(sjis("\xf7\x6a")))
392
+ raw_mail.should match(sjis_regexp(sjis("\xf9\x7c")))
399
393
  end
400
394
  end
401
395
 
@@ -405,31 +399,29 @@ describe MobileMailer do
405
399
  end
406
400
 
407
401
  it "漢字コードが変換されること" do
408
- MobileMailer.multi_message(@to, @subject, @text).deliver
402
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
409
403
 
410
- emails = ActionMailer::Base.deliveries
411
- emails.size.should == 1
412
- email = emails.first
404
+ ActionMailer::Base.deliveries.size.should == 1
413
405
 
414
406
  email.parts.size.should == 2
415
407
 
416
- NKF.nkf("-mQ", email.parts.first.body).should match(/#{Regexp.escape(NKF.nkf("-jWx", @html))}/)
417
-
418
- email.parts.last.charset.should match(/^iso-2022-jp$/i)
419
- email.parts.last.body.should match(/#{Regexp.escape(NKF.nkf("-jWx", @plain))}/)
408
+ raw_mail = email.to_s
409
+ raw_mail.should match(sjis_regexp(utf8_to_sjis(@text)))
410
+ raw_mail.should match(sjis_regexp(utf8_to_sjis(@html)))
420
411
  end
421
412
 
422
413
  it "絵文字が変換されること" do
423
414
  @text += "&#xe68a;"
424
- MobileMailer.multi_message(@to, @subject, @text).deliver
415
+ @html += "&#xe676;"
416
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
425
417
 
426
- emails = ActionMailer::Base.deliveries
427
- emails.size.should == 1
428
- email = emails.first
418
+ ActionMailer::Base.deliveries.size.should == 1
429
419
 
430
420
  email.parts.size.should == 2
431
- NKF.nkf("-mQwJ", email.parts.first.body).should match(/〓/)
432
- NKF.nkf("-wJ", email.parts.last.body).should match(/〓/)
421
+
422
+ raw_mail = email.to_s
423
+ raw_mail.should match(sjis_regexp(sjis("\xf7\x6a")))
424
+ raw_mail.should match(sjis_regexp(sjis("\xf9\x7c")))
433
425
  end
434
426
  end
435
427
  end
@@ -604,7 +596,7 @@ describe MobileMailer, "receiving" do
604
596
  email.body.should match(/本文/)
605
597
  end
606
598
 
607
- it "絵文字が数値参照に変わること", :broken => true do
599
+ it "絵文字が数値参照に変わること" do
608
600
  email = MobileMailer.receive(@email)
609
601
 
610
602
  email.subject.should match(/&#xf03c;/)
@@ -613,9 +605,9 @@ describe MobileMailer, "receiving" do
613
605
  end
614
606
  end
615
607
 
616
- describe "multipart メールを受信するとき", :broken => true do
608
+ describe "multipart メールを受信するとき" do
617
609
  describe "docomo の場合" do
618
- # NOTE: 要検証
610
+ # NOTE: キャリアメールサーバで絵文字を変換するため検証は困難
619
611
  before(:each) do
620
612
  @email = open(Rails.root + "spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml").read
621
613
  end
@@ -635,8 +627,8 @@ describe MobileMailer, "receiving" do
635
627
  email.parts.first.parts.size == 2
636
628
 
637
629
  parts = email.parts.first.parts
638
- parts.first.body.should match(/テストです&#xe72d;/)
639
- parts.last.body.should match(/テストです&#xe72d;/)
630
+ parts.first.body.should match("テストです&#xe72d;")
631
+ parts.last.body.raw_source.should match("テストです&#xe72d;")
640
632
  end
641
633
  end
642
634
 
@@ -661,12 +653,12 @@ describe MobileMailer, "receiving" do
661
653
 
662
654
  parts = email.parts.first.parts
663
655
  parts.first.body.should match(/テストです&#xe595;/)
664
- parts.last.body.should match(/テストです&#xe595;/)
656
+ parts.last.body.raw_source.should match(/テストです&#xe595;/)
665
657
  end
666
658
  end
667
659
 
668
660
  describe "softbank(sjis) の場合" do
669
- # NOTE: 要検証
661
+ # NOTE: キャリアメールサーバで絵文字を変換するため検証は困難
670
662
  before(:each) do
671
663
  @email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-gmail-sjis.eml").read
672
664
  end
@@ -685,12 +677,12 @@ describe MobileMailer, "receiving" do
685
677
  email.parts.size.should == 2
686
678
 
687
679
  email.parts.first.body.should match(/テストです&#xf018;/)
688
- email.parts.last.body.should match(/テストです&#xf231;/)
680
+ email.parts.last.body.raw_source.should match(/テストです&#xf231;/)
689
681
  end
690
682
  end
691
683
 
692
684
  describe "softbank(utf8) の場合" do
693
- # NOTE: 要検証
685
+ # NOTE: キャリアメールサーバで絵文字を変換するため検証は困難
694
686
  before(:each) do
695
687
  @email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-gmail-utf8.eml").read
696
688
  end
@@ -709,7 +701,7 @@ describe MobileMailer, "receiving" do
709
701
  email.parts.size.should == 2
710
702
 
711
703
  email.parts.first.body.should match(/テストです&#xf223;/)
712
- email.parts.last.body.should match(/テストです&#xf223;/)
704
+ email.parts.last.body.raw_source.should match(/テストです&#xf223;/)
713
705
  end
714
706
  end
715
707
 
@@ -736,8 +728,9 @@ describe MobileMailer, "receiving" do
736
728
 
737
729
  email.has_attachments?.should be_true
738
730
  email.attachments.size.should == 1
739
- email.attachments.first.content_type.should == "image/jpeg"
740
- email.attachments.first.read[6..9].should == "JFIF"
731
+ email.attachments['20098calendar01.jpg'].content_type.should match("image/jpeg")
732
+ email.attachments['20098calendar01.jpg'].body.to_s[2..6] == "JFIF"
733
+ email.attachments['20098calendar01.jpg'].body.to_s.size == 86412
741
734
  end
742
735
  end
743
736
  end