jpmobile 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. data/VERSION.yml +1 -1
  2. data/lib/jpmobile/rack/params_filter.rb +1 -1
  3. data/test/rails/rails_root/app/models/mobile_mailer.rb +18 -0
  4. data/test/rails/rails_root/config/initializers/secret_token.rb +1 -1
  5. data/test/rails/rails_root/spec/models/mobile_mailer_spec.rb +744 -0
  6. data/test/rails/rails_root/spec/spec_helper.rb +6 -0
  7. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile.rb +2 -0
  8. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/email.rb +17 -2
  9. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon.rb +85 -23
  10. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/au.rb +644 -0
  11. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/softbank.rb +488 -0
  12. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/emoticon/z_combine.rb +16 -13
  13. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/hook_action_mailer.rb +22 -0
  14. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mail.rb +265 -0
  15. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/abstract_mobile.rb +35 -0
  16. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/au.rb +28 -2
  17. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/docomo.rb +24 -1
  18. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/emobile.rb +1 -1
  19. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/softbank.rb +34 -1
  20. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/vodafone.rb +1 -1
  21. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/mobile/willcom.rb +1 -1
  22. data/test/rails/rails_root/vendor/plugins/jpmobile/lib/jpmobile/util.rb +214 -13
  23. metadata +11 -3
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 5
4
+ :patch: 6
5
5
  :build:
@@ -37,7 +37,7 @@ module Jpmobile
37
37
  k, v = param_pair.split("=")
38
38
  k = to_internal(k) if k
39
39
  v = to_internal(v) if v
40
- new_array << "#{k}=#{v}" if k and v
40
+ new_array << "#{k}=#{v}" if k
41
41
  end
42
42
 
43
43
  new_array.join("&")
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ class MobileMailer < Jpmobile::Mailer::Base
3
+ default :from => "info@jp.mobile"
4
+
5
+ def view_selection(to_mail, subject_text, text)
6
+ @text = text
7
+ mail(:to => to_mail, :subject => subject_text)
8
+ end
9
+
10
+ def receive(email)
11
+ email
12
+ end
13
+
14
+ def multi_message(to_mail, subject_text, text)
15
+ @text = text
16
+ mail(:to => to_mail, :subject => subject)
17
+ end
18
+ 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 = '48ba9ac780d58f5ec08701d73d252900c9e2d89cbcc0107da56f8aa2add56a3a5849505e5408e58fa9228118f85ff9ca214ce19f4c2fe2b2a696abcc44e3ec65'
7
+ RailsRoot::Application.config.secret_token = 'd8432b7143e2cf7e88965fc1f4c6e5cb51218a48d2235876c7fe47351d599793242abd6636307611e7a1a1dde90d5466139bcce0e44342450902fc7a3c676168'
@@ -0,0 +1,744 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe MobileMailer 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
+ @sjis_regexp = %r!=\?shift_jis\?B\?(.+)\?=!
14
+ @jis_regexp = %r!=\?iso-2022-jp\?B\?(.+)\?=!
15
+ end
16
+
17
+ shared_examples_for "PC宛メール" do
18
+ it "正常に送信できること" do
19
+ email = MobileMailer.view_selection(@to, "題名", "本文").deliver
20
+
21
+ ActionMailer::Base.deliveries.size.should == 1
22
+ email.to.include?(@to).should be_true
23
+ end
24
+
25
+ it "ISO-2022-JPに変換されること" do
26
+ email = MobileMailer.view_selection(@to, "題名", "本文").deliver
27
+
28
+ ActionMailer::Base.deliveries.size.should == 1
29
+
30
+ raw_mail = ascii_8bit(email.to_s)
31
+ raw_mail.should match(/iso-2022-jp/i)
32
+ raw_mail.should match(Regexp.compile(Regexp.escape(ascii_8bit([utf8_to_jis("題名")].pack('m').strip))))
33
+ raw_mail.should match(Regexp.compile(Regexp.escape(ascii_8bit(utf8_to_jis("本文")))))
34
+ end
35
+
36
+ it "絵文字がゲタ(〓)に変換されること" do
37
+ email = MobileMailer.view_selection(@to, "題名&#xe676;", "本文&#xe68b;".html_safe).deliver
38
+
39
+ ActionMailer::Base.deliveries.size.should == 1
40
+
41
+ raw_mail = ascii_8bit(email.to_s)
42
+ raw_mail.should match(Regexp.escape("GyRCQmpMPiIuGyhC"))
43
+ raw_mail.should match(Regexp.compile(Regexp.escape(ascii_8bit(utf8_to_jis("本文〓")))))
44
+ end
45
+
46
+ it "quoted-printableではないときに勝手に変換されないこと" do
47
+ email = MobileMailer.view_selection(@to, "題名",
48
+ "本文です\nhttp://test.rails/foo/bar/index?d=430d0d1cea109cdb384ec5554b890e3940f293c7&e=ZVG%0FE%16%5E%07%04%21P%5CZ%06%00%0D%1D%40L").deliver
49
+
50
+ ActionMailer::Base.deliveries.size.should == 1
51
+
52
+ raw_mail = ascii_8bit(email.to_s)
53
+ raw_mail.should match(/ZVG%0FE%16%5E%07%04%21P%5CZ%06%00%0D%1D%40L/)
54
+ end
55
+ end
56
+
57
+ describe "PC宛に送るとき" do
58
+ before(:each) do
59
+ @to = "bill.gate@microsoft.com"
60
+ end
61
+
62
+ it_behaves_like "PC宛メール"
63
+
64
+ it "複数に配信するときもISO-2022-JPに変換されること" do
65
+ email = MobileMailer.view_selection(@to, "題名", "本文").deliver
66
+
67
+ ActionMailer::Base.deliveries.size.should == 1
68
+
69
+ raw_mail = ascii_8bit(email.to_s)
70
+ raw_mail.should match(/iso-2022-jp/i)
71
+ raw_mail.should match(Regexp.compile(Regexp.escape(ascii_8bit([utf8_to_jis("題名")].pack('m').strip))))
72
+ raw_mail.should match(Regexp.compile(Regexp.escape(ascii_8bit(utf8_to_jis("本文")))))
73
+ end
74
+ end
75
+
76
+ describe "docomo にメールを送るとき" do
77
+ before(:each) do
78
+ @to = "docomo@docomo.ne.jp"
79
+ end
80
+
81
+ it "subject/body が Shift-JIS になること" do
82
+ email = MobileMailer.view_selection(@to, @subject, @text).deliver
83
+
84
+ ActionMailer::Base.deliveries.size.should == 1
85
+
86
+ raw_mail = email.to_s
87
+ raw_mail.should match(/shift_jis/i)
88
+ # raw_mail.should match(/For docomo/) # TODO: revise Resolver in view selector
89
+ raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvA=="))
90
+ raw_mail.should match(Regexp.compile(utf8_to_sjis(@text)))
91
+ end
92
+
93
+ it "数値参照の絵文字が変換されること" do
94
+ emoji_subject = @subject + "&#xe676;"
95
+ emoji_text = @text + "&#xe68b;"
96
+
97
+ email = MobileMailer.view_selection(@to, emoji_subject, emoji_text.html_safe).deliver
98
+
99
+ ActionMailer::Base.deliveries.size.should == 1
100
+
101
+ raw_mail = email.to_s
102
+ # raw_mail.should match(/For docomo/) # TODO: revise Resolver in view selector
103
+ raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvPjX"))
104
+ raw_mail.should match(regexp_to_sjis("\xf8\xec"))
105
+ end
106
+
107
+ it "半角カナがそのまま送信されること" do
108
+ half_kana_subject = @subject + "ゲーム"
109
+ half_kana_text = @text + "ブック"
110
+
111
+ email = MobileMailer.view_selection(@to, half_kana_subject, half_kana_text).deliver
112
+
113
+ ActionMailer::Base.deliveries.size.should == 1
114
+
115
+ raw_mail = email.to_s
116
+ # raw_mail.should match(/For docomo/) # TODO: revise Resolver in view selector
117
+ raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvLnesNE="))
118
+ raw_mail.should match(Regexp.compile(Regexp.escape(utf8_to_sjis(half_kana_text))))
119
+ end
120
+
121
+ it "quoted-printable ではないときに勝手に変換されないこと" do
122
+ email = MobileMailer.view_selection(@to, "題名",
123
+ "本文です\nhttp://test.rails/foo/bar/index?d=430d0d1cea109cdb384ec5554b890e3940f293c7&e=ZVG%0FE%16%5E%07%04%21P%5CZ%06%00%0D%1D%40L").deliver
124
+
125
+ ActionMailer::Base.deliveries.size.should == 1
126
+
127
+ raw_mail = email.to_s
128
+ raw_mail.should match(/ZVG%0FE%16%5E%07%04%21P%5CZ%06%00%0D%1D%40L/)
129
+ end
130
+ end
131
+
132
+ describe "au にメールを送るとき" do
133
+ before(:each) do
134
+ @to = "au@ezweb.ne.jp"
135
+ end
136
+
137
+ it "subject/body がISO-2022-JPになること" do
138
+ email = MobileMailer.view_selection(@to, @subject, @text).deliver
139
+
140
+ ActionMailer::Base.deliveries.size.should == 1
141
+
142
+ raw_mail = ascii_8bit(email.to_s)
143
+ raw_mail.should match(/iso-2022-jp/i)
144
+ raw_mail.should match(Regexp.compile(Regexp.escape(ascii_8bit([utf8_to_jis(@subject)].pack('m').strip))))
145
+ raw_mail.should match(Regexp.compile(Regexp.escape(ascii_8bit(utf8_to_jis(@text)))))
146
+ end
147
+
148
+ it "数値参照が絵文字に変換されること" do
149
+ emoji_subject = @subject + "&#xe676;"
150
+ emoji_text = @text + "&#xe68b;"
151
+
152
+ email = MobileMailer.view_selection(@to, emoji_subject, emoji_text.html_safe).deliver
153
+
154
+ ActionMailer::Base.deliveries.size.should == 1
155
+
156
+ raw_mail = ascii_8bit(email.to_s)
157
+ # raw_mail.should match(/For au/) # TODO: revise Resolver in view selector
158
+ raw_mail.should match(Regexp.escape("GyRCRnxLXDhsQmpMPhsoQhskQnZeGyhC"))
159
+ raw_mail.should match(Regexp.compile(ascii_8bit("\x76\x21")))
160
+ end
161
+
162
+ it "quoted-printable ではないときに勝手に変換されないこと" do
163
+ email = MobileMailer.view_selection(@to, "題名",
164
+ "本文です\nhttp://test.rails/foo/bar/index?d=430d0d1cea109cdb384ec5554b890e3940f293c7&e=ZVG%0FE%16%5E%07%04%21P%5CZ%06%00%0D%1D%40L").deliver
165
+
166
+ ActionMailer::Base.deliveries.size.should == 1
167
+
168
+ raw_mail = ascii_8bit(email.to_s)
169
+ raw_mail.should match(/ZVG%0FE%16%5E%07%04%21P%5CZ%06%00%0D%1D%40L/)
170
+ end
171
+ end
172
+
173
+ describe "softbank にメールを送るとき" do
174
+ before(:each) do
175
+ @to = "softbank@softbank.ne.jp"
176
+ end
177
+
178
+ it "subject/body が Shift_JIS になること" do
179
+ email = MobileMailer.view_selection(@to, @subject, @text).deliver
180
+
181
+ ActionMailer::Base.deliveries.size.should == 1
182
+
183
+ raw_mail = email.to_s
184
+ raw_mail.should match(/shift_jis/i)
185
+ # raw_mail.should match(/For softbank/) # TODO: revise Resolver in view selector
186
+ raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvA=="))
187
+ raw_mail.should match(Regexp.compile(utf8_to_sjis(@text)))
188
+ end
189
+
190
+ it "数値参照が絵文字に変換されること" do
191
+ emoji_subject = @subject + "&#xe676;"
192
+ emoji_text = @text + "&#xe68a;"
193
+
194
+ email = MobileMailer.view_selection(@to, emoji_subject, emoji_text.html_safe).deliver
195
+
196
+ ActionMailer::Base.deliveries.size.should == 1
197
+
198
+ raw_mail = email.to_s
199
+ # raw_mail.should match(/For softbank/) # TODO: revise Resolver in view selector
200
+ raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvPl8"))
201
+ raw_mail.should match(regexp_to_sjis("\xf7\x6a"))
202
+ end
203
+
204
+ it "quoted-printable ではないときに勝手に変換されないこと" do
205
+ email = MobileMailer.view_selection(@to, "題名",
206
+ "本文です\nhttp://test.rails/foo/bar/index?d=430d0d1cea109cdb384ec5554b890e3940f293c7&e=ZVG%0FE%16%5E%07%04%21P%5CZ%06%00%0D%1D%40L").deliver
207
+
208
+ ActionMailer::Base.deliveries.size.should == 1
209
+
210
+ raw_mail = email.to_s
211
+ raw_mail.should match(/ZVG%0FE%16%5E%07%04%21P%5CZ%06%00%0D%1D%40L/)
212
+ end
213
+ end
214
+
215
+ describe "vodafone にメールを送るとき" do
216
+ before(:each) do
217
+ @to = "vodafone@d.vodafone.ne.jp"
218
+ end
219
+
220
+ it "subject/body が Shift_JIS になること" do
221
+ email = MobileMailer.view_selection(@to, @subject, @text).deliver
222
+
223
+ ActionMailer::Base.deliveries.size.should == 1
224
+
225
+ raw_mail = email.to_s
226
+ raw_mail.should match(/shift_jis/i)
227
+ # raw_mail.should match(/For softbank/) # TODO: revise Resolver in view selector
228
+ raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvA=="))
229
+ raw_mail.should match(Regexp.compile(utf8_to_sjis(@text)))
230
+ end
231
+
232
+ it "数値参照が絵文字に変換されること" do
233
+ emoji_subject = @subject + "&#xe676;"
234
+ emoji_text = @text + "&#xe68a;"
235
+
236
+ email = MobileMailer.view_selection(@to, emoji_subject, emoji_text.html_safe).deliver
237
+
238
+ ActionMailer::Base.deliveries.size.should == 1
239
+
240
+ raw_mail = email.to_s
241
+ # raw_mail.should match(/For softbank/) # TODO: revise Resolver in view selector
242
+ raw_mail.should match(Regexp.escape("k/qWe4zqkeiWvPl8"))
243
+ raw_mail.should match(regexp_to_sjis("\xf7\x6a"))
244
+ end
245
+
246
+ it "quoted-printable ではないときに勝手に変換されないこと" do
247
+ email = MobileMailer.view_selection(@to, "題名",
248
+ "本文です\nhttp://test.rails/foo/bar/index?d=430d0d1cea109cdb384ec5554b890e3940f293c7&e=ZVG%0FE%16%5E%07%04%21P%5CZ%06%00%0D%1D%40L").deliver
249
+
250
+ ActionMailer::Base.deliveries.size.should == 1
251
+
252
+ raw_mail = email.to_s
253
+ raw_mail.should match(/ZVG%0FE%16%5E%07%04%21P%5CZ%06%00%0D%1D%40L/)
254
+ end
255
+ end
256
+
257
+ describe "willcom にメールを送るとき" do
258
+ before(:each) do
259
+ @to = "willcom@wm.pdx.ne.jp"
260
+ end
261
+
262
+ it_behaves_like "PC宛メール"
263
+ end
264
+
265
+ describe "emobile にメールを送るとき" do
266
+ before(:each) do
267
+ @to = "emobile@emnet.ne.jp"
268
+ end
269
+
270
+ it_behaves_like "PC宛メール"
271
+ end
272
+
273
+ describe "multipart メールを送信するとき" do
274
+ before(:each) do
275
+ ActionMailer::Base.deliveries = []
276
+
277
+ @subject = "題名"
278
+ @text = "本文"
279
+ end
280
+
281
+ describe "PC の場合" do
282
+ before(:each) do
283
+ @to = "gate@bill.com"
284
+ end
285
+
286
+ it "漢字コードが変換されること", :focus => true do
287
+ email = MobileMailer.multi_message(@to, @subject, @text).deliver
288
+
289
+ ActionMailer::Base.deliveries.size.should == 1
290
+
291
+ email.parts.size.should == 2
292
+
293
+ raw_mail = ascii_8bit(email.to_s)
294
+ 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
+ end
297
+ end
298
+
299
+ describe "docomo の場合" do
300
+ before(:each) do
301
+ @to = "docomo@docomo.ne.jp"
302
+ end
303
+
304
+ it "漢字コードが変換されること" do
305
+ MobileMailer.multi_message(@to, @subject, @text).deliver
306
+
307
+ emails = ActionMailer::Base.deliveries
308
+ emails.size.should == 1
309
+ email = emails.first
310
+
311
+ email.parts.size.should == 2
312
+
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))}/)
317
+ end
318
+
319
+ it "絵文字が変換されること" do
320
+ @text += "&#xe68b;"
321
+ MobileMailer.multi_message(@to, @subject, @text).deliver
322
+
323
+ emails = ActionMailer::Base.deliveries
324
+ emails.size.should == 1
325
+ email = emails.first
326
+
327
+ 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'))
330
+ end
331
+ end
332
+
333
+ describe "au の場合" do
334
+ before(:each) do
335
+ @to = "au@ezweb.ne.jp"
336
+ end
337
+
338
+ it "漢字コードが変換されること" do
339
+ MobileMailer.multi_message(@to, @subject, @text).deliver
340
+
341
+ emails = ActionMailer::Base.deliveries
342
+ emails.size.should == 1
343
+ email = emails.first
344
+
345
+ email.parts.size.should == 2
346
+
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))}/)
351
+ end
352
+
353
+ it "絵文字が変換されること" do
354
+ @text += "&#xe676;"
355
+ MobileMailer.multi_message(@to, @subject, @text).deliver
356
+
357
+ emails = ActionMailer::Base.deliveries
358
+ emails.size.should == 1
359
+ email = emails.first
360
+
361
+ email.parts.size.should == 2
362
+
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'))}/)
365
+ end
366
+ end
367
+
368
+ describe "softbank の場合" do
369
+ before(:each) do
370
+ @to = "softbank@softbank.ne.jp"
371
+ end
372
+
373
+ it "漢字コードが変換されること" do
374
+ MobileMailer.multi_message(@to, @subject, @text).deliver
375
+
376
+ emails = ActionMailer::Base.deliveries
377
+ emails.size.should == 1
378
+ email = emails.first
379
+
380
+ email.parts.size.should == 2
381
+
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))}/)
386
+ end
387
+
388
+ it "絵文字が変換されること" do
389
+ @text += "&#xe68a;"
390
+ MobileMailer.multi_message(@to, @subject, @text).deliver
391
+
392
+ emails = ActionMailer::Base.deliveries
393
+ emails.size.should == 1
394
+ email = emails.first
395
+
396
+ 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'))
399
+ end
400
+ end
401
+
402
+ describe "vodafone の場合" do
403
+ before(:each) do
404
+ @to = "vodafone@d.vodafone.ne.jp"
405
+ end
406
+
407
+ it "漢字コードが変換されること" do
408
+ MobileMailer.multi_message(@to, @subject, @text).deliver
409
+
410
+ emails = ActionMailer::Base.deliveries
411
+ emails.size.should == 1
412
+ email = emails.first
413
+
414
+ email.parts.size.should == 2
415
+
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))}/)
420
+ end
421
+
422
+ it "絵文字が変換されること" do
423
+ @text += "&#xe68a;"
424
+ MobileMailer.multi_message(@to, @subject, @text).deliver
425
+
426
+ emails = ActionMailer::Base.deliveries
427
+ emails.size.should == 1
428
+ email = emails.first
429
+
430
+ 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(/〓/)
433
+ end
434
+ end
435
+ end
436
+ end
437
+
438
+ describe MobileMailer, " mail address" do
439
+ before(:each) do
440
+ ActionMailer::Base.deliveries = []
441
+
442
+ @subject = "日本語題名"
443
+ @text = "日本語テキスト"
444
+ end
445
+
446
+ it "ピリオドが3つ以上連続するアドレスが有効になること" do
447
+ to = "ruby...rails@domomo-ezweb.ne.jp"
448
+ MobileMailer.view_selection(to, @subject, @text).deliver
449
+
450
+ emails = ActionMailer::Base.deliveries
451
+ emails.size.should == 1
452
+ emails.first.to.include?(to).should be_true
453
+ emails.first.destinations.include?(to).should be_true
454
+ end
455
+
456
+ it "@マークの直前にピリオドあるアドレスが有効になること" do
457
+ to = "ruby.rails.@domomo-ezweb.ne.jp"
458
+ MobileMailer.view_selection(to, @subject, @text).deliver
459
+
460
+ emails = ActionMailer::Base.deliveries
461
+ emails.size.should == 1
462
+ emails.first.to.include?(to).should be_true
463
+ emails.first.destinations.include?(to).should be_true
464
+ end
465
+
466
+ it "ピリオドから始まるアドレスが有効になること" do
467
+ to = ".ruby.rails.@domomo-ezweb.ne.jp"
468
+ MobileMailer.view_selection(to, @subject, @text).deliver
469
+
470
+ emails = ActionMailer::Base.deliveries
471
+ emails.size.should == 1
472
+ emails.first.to.include?(to).should be_true
473
+ emails.first.destinations.include?(to).should be_true
474
+ end
475
+
476
+ it "複数のアドレスが有効になること" do
477
+ to = [".ruby.rails.@domomo-ezweb.ne.jp", "ruby.rails.@domomo-ezweb.ne.jp", "ruby...rails@domomo-ezweb.ne.jp"].join(", ")
478
+ MobileMailer.view_selection(to, @subject, @text).deliver
479
+
480
+ emails = ActionMailer::Base.deliveries
481
+ emails.size.should == 1
482
+ emails.first.to.should == to
483
+ emails.first.destinations.should == [to]
484
+ end
485
+ end
486
+
487
+ describe MobileMailer, "receiving" do
488
+ describe "blank mail" do
489
+ it "softbank からの空メールがで受信できること" do
490
+ email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-blank.eml").read
491
+ # expect {
492
+ email = MobileMailer.receive(email)
493
+ # }.to_not raise_error
494
+
495
+ email.subject.should be_blank
496
+ email.body.should be_blank
497
+ end
498
+ end
499
+
500
+ describe "docomo からのメールを受信するとき" do
501
+ before(:each) do
502
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/docomo-emoji.eml").read
503
+ end
504
+
505
+ it "漢字コードを適切に変換できること" do
506
+ email = MobileMailer.receive(@email)
507
+ email.subject.should match(/題名/)
508
+ email.body.should match(/本文/)
509
+ end
510
+
511
+ it "絵文字が数値参照に変わること" do
512
+ email = MobileMailer.receive(@email)
513
+
514
+ email.subject.should match(/&#xe676;/)
515
+ email.body.should match(/&#xe6e2;/)
516
+ end
517
+
518
+ describe "jis コードの場合に" do
519
+ before(:each) do
520
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/docomo-jis.eml").read
521
+ end
522
+
523
+ it "適切に変換できること" do
524
+ email = MobileMailer.receive(@email)
525
+
526
+ email.subject.should match(/テスト/)
527
+ email.body.should match(/テスト本文/)
528
+ end
529
+ end
530
+ end
531
+
532
+ describe "au からのメールを受信するとき" do
533
+ describe "jpmobile で送信したメールの場合" do
534
+ before(:each) do
535
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/au-emoji.eml").read
536
+ end
537
+
538
+ it "漢字コードを適切に変換できること" do
539
+ email = MobileMailer.receive(@email)
540
+
541
+ email.subject.should match(/題名/)
542
+ email.body.should match(/本文/)
543
+ end
544
+
545
+ it "絵文字が数値参照に変わること" do
546
+ email = MobileMailer.receive(@email)
547
+
548
+ email.subject.should match(/&#xe503;/)
549
+ email.body.should match(/&#xe522;/)
550
+ end
551
+ end
552
+
553
+ describe "実機からのメールの場合" do
554
+ before(:each) do
555
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/au-emoji2.eml").read
556
+ end
557
+
558
+ it "漢字コードを適切に変換できること" do
559
+ email = MobileMailer.receive(@email)
560
+
561
+ email.subject.should match(/題名/)
562
+ email.body.should match(/本文/)
563
+ end
564
+
565
+ it "絵文字が数値参照に変わること" do
566
+ email = MobileMailer.receive(@email)
567
+
568
+ email.subject.should match(/&#xe4f4;/)
569
+ email.body.should match(/&#xe471;/)
570
+ end
571
+ end
572
+ end
573
+
574
+ describe "softbank からのメールを受信するとき" do
575
+ describe "shift_jis のとき" do
576
+ before(:each) do
577
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-emoji.eml").read
578
+ end
579
+
580
+ it "漢字コードを適切に変換できること" do
581
+ email = MobileMailer.receive(@email)
582
+
583
+ email.subject.should match(/題名/)
584
+ email.body.should match(/本文/)
585
+ end
586
+
587
+ it "絵文字が数値参照に変わること" do
588
+ email = MobileMailer.receive(@email)
589
+
590
+ email.subject.should match(/&#xf03c;/)
591
+ email.body.should match(/&#xf21c;/)
592
+ end
593
+ end
594
+
595
+ describe "utf-8 のとき" do
596
+ before(:each) do
597
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-emoji-utf8.eml").read
598
+ end
599
+
600
+ it "漢字コードを適切に変換できること" do
601
+ email = MobileMailer.receive(@email)
602
+
603
+ email.subject.should match(/題名/)
604
+ email.body.should match(/本文/)
605
+ end
606
+
607
+ it "絵文字が数値参照に変わること", :broken => true do
608
+ email = MobileMailer.receive(@email)
609
+
610
+ email.subject.should match(/&#xf03c;/)
611
+ email.body.should match(/&#xf21c;/)
612
+ end
613
+ end
614
+ end
615
+
616
+ describe "multipart メールを受信するとき", :broken => true do
617
+ describe "docomo の場合" do
618
+ # NOTE: 要検証
619
+ before(:each) do
620
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml").read
621
+ end
622
+
623
+ it "正常に受信できること" do
624
+ lambda {
625
+ MobileMailer.receive(@email)
626
+ }.should_not raise_exception
627
+ end
628
+
629
+ it "絵文字が変換されること" do
630
+ email = MobileMailer.receive(@email)
631
+
632
+ email.subject.should match(/&#xe6ec;/)
633
+
634
+ email.parts.size.should == 1
635
+ email.parts.first.parts.size == 2
636
+
637
+ parts = email.parts.first.parts
638
+ parts.first.body.should match(/テストです&#xe72d;/)
639
+ parts.last.body.should match(/テストです&#xe72d;/)
640
+ end
641
+ end
642
+
643
+ describe "au の場合" do
644
+ before(:each) do
645
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/au-decomail.eml").read
646
+ end
647
+
648
+ it "正常に受信できること" do
649
+ lambda {
650
+ MobileMailer.receive(@email)
651
+ }.should_not raise_exception
652
+ end
653
+
654
+ it "絵文字が変換されること" do
655
+ email = MobileMailer.receive(@email)
656
+
657
+ email.subject.should match(/&#xe4f4;/)
658
+
659
+ email.parts.size.should == 1
660
+ email.parts.first.parts.size == 2
661
+
662
+ parts = email.parts.first.parts
663
+ parts.first.body.should match(/テストです&#xe595;/)
664
+ parts.last.body.should match(/テストです&#xe595;/)
665
+ end
666
+ end
667
+
668
+ describe "softbank(sjis) の場合" do
669
+ # NOTE: 要検証
670
+ before(:each) do
671
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-gmail-sjis.eml").read
672
+ end
673
+
674
+ it "正常に受信できること" do
675
+ lambda {
676
+ MobileMailer.receive(@email)
677
+ }.should_not raise_exception
678
+ end
679
+
680
+ it "絵文字が変換されること" do
681
+ email = MobileMailer.receive(@email)
682
+
683
+ email.subject.should match(/&#xf221;&#xf223;&#xf221;/)
684
+
685
+ email.parts.size.should == 2
686
+
687
+ email.parts.first.body.should match(/テストです&#xf018;/)
688
+ email.parts.last.body.should match(/テストです&#xf231;/)
689
+ end
690
+ end
691
+
692
+ describe "softbank(utf8) の場合" do
693
+ # NOTE: 要検証
694
+ before(:each) do
695
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-gmail-utf8.eml").read
696
+ end
697
+
698
+ it "正常に受信できること" do
699
+ lambda {
700
+ MobileMailer.receive(@email)
701
+ }.should_not raise_exception
702
+ end
703
+
704
+ it "絵文字が変換されること" do
705
+ email = MobileMailer.receive(@email)
706
+
707
+ email.subject.should match(/テストです&#xf221;/)
708
+
709
+ email.parts.size.should == 2
710
+
711
+ email.parts.first.body.should match(/テストです&#xf223;/)
712
+ email.parts.last.body.should match(/テストです&#xf223;/)
713
+ end
714
+ end
715
+
716
+ describe "添付ファイルがある場合" do
717
+ # NOTE: au のみテスト
718
+ before(:each) do
719
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/au-attached.eml").read
720
+ end
721
+
722
+ it "正常に受信できること" do
723
+ lambda {
724
+ MobileMailer.receive(@email)
725
+ }.should_not raise_exception
726
+ end
727
+
728
+ it "添付ファイルが壊れないこと" do
729
+ email = MobileMailer.receive(@email)
730
+
731
+ email.subject.should match(/&#xe481;/)
732
+
733
+ email.parts.size.should == 2
734
+
735
+ email.parts.first.body.should match(/カレンダーだ&#xe4f4;/)
736
+
737
+ email.has_attachments?.should be_true
738
+ email.attachments.size.should == 1
739
+ email.attachments.first.content_type.should == "image/jpeg"
740
+ email.attachments.first.read[6..9].should == "JFIF"
741
+ end
742
+ end
743
+ end
744
+ end