jpmobile 0.1.6 → 1.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,19 @@
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, html)
15
+ @html = html
16
+ @text = text
17
+ mail(:to => to_mail, :subject => subject)
18
+ end
19
+ 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
@@ -0,0 +1,737 @@
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/)
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/)
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/)
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/)
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/)
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/)
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 vodafone/)
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 vodafone/)
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
+ @html = "万葉"
280
+ end
281
+
282
+ describe "PC の場合" do
283
+ before(:each) do
284
+ @to = "gate@bill.com"
285
+ end
286
+
287
+ it "漢字コードが変換されること" do
288
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
289
+
290
+ ActionMailer::Base.deliveries.size.should == 1
291
+
292
+ email.parts.size.should == 2
293
+
294
+ raw_mail = ascii_8bit(email.to_s)
295
+ raw_mail.should match(Regexp.escape(ascii_8bit(utf8_to_jis(@text))))
296
+ raw_mail.should match(Regexp.escape(ascii_8bit(utf8_to_jis(@html))))
297
+ end
298
+ end
299
+
300
+ describe "docomo の場合" do
301
+ before(:each) do
302
+ @to = "docomo@docomo.ne.jp"
303
+ end
304
+
305
+ it "漢字コードが変換されること" do
306
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
307
+
308
+ ActionMailer::Base.deliveries.size.should == 1
309
+
310
+ email.parts.size.should == 2
311
+
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)))
315
+ end
316
+
317
+ it "絵文字が変換されること" do
318
+ @text += "&#xe68b;"
319
+ @html += "&#xe676;"
320
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
321
+
322
+ ActionMailer::Base.deliveries.size.should == 1
323
+
324
+ email.parts.size.should == 2
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")))
329
+ end
330
+ end
331
+
332
+ describe "au の場合" do
333
+ before(:each) do
334
+ @to = "au@ezweb.ne.jp"
335
+ end
336
+
337
+ it "漢字コードが変換されること" do
338
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
339
+
340
+ ActionMailer::Base.deliveries.size.should == 1
341
+
342
+ email.parts.size.should == 2
343
+
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))))
347
+ end
348
+
349
+ it "絵文字が変換されること" do
350
+ @text += "&#xe68b;"
351
+ @html += "&#xe676;"
352
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
353
+
354
+ ActionMailer::Base.deliveries.size.should == 1
355
+
356
+ email.parts.size.should == 2
357
+
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"))
361
+ end
362
+ end
363
+
364
+ describe "softbank の場合" do
365
+ before(:each) do
366
+ @to = "softbank@softbank.ne.jp"
367
+ end
368
+
369
+ it "漢字コードが変換されること" do
370
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
371
+
372
+ ActionMailer::Base.deliveries.size.should == 1
373
+
374
+ email.parts.size.should == 2
375
+
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)))
379
+ end
380
+
381
+ it "絵文字が変換されること" do
382
+ @text += "&#xe68a;"
383
+ @html += "&#xe676;"
384
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
385
+
386
+ ActionMailer::Base.deliveries.size.should == 1
387
+
388
+ email.parts.size.should == 2
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")))
393
+ end
394
+ end
395
+
396
+ describe "vodafone の場合" do
397
+ before(:each) do
398
+ @to = "vodafone@d.vodafone.ne.jp"
399
+ end
400
+
401
+ it "漢字コードが変換されること" do
402
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
403
+
404
+ ActionMailer::Base.deliveries.size.should == 1
405
+
406
+ email.parts.size.should == 2
407
+
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)))
411
+ end
412
+
413
+ it "絵文字が変換されること" do
414
+ @text += "&#xe68a;"
415
+ @html += "&#xe676;"
416
+ email = MobileMailer.multi_message(@to, @subject, @text, @html).deliver
417
+
418
+ ActionMailer::Base.deliveries.size.should == 1
419
+
420
+ email.parts.size.should == 2
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")))
425
+ end
426
+ end
427
+ end
428
+ end
429
+
430
+ describe MobileMailer, " mail address" do
431
+ before(:each) do
432
+ ActionMailer::Base.deliveries = []
433
+
434
+ @subject = "日本語題名"
435
+ @text = "日本語テキスト"
436
+ end
437
+
438
+ it "ピリオドが3つ以上連続するアドレスが有効になること" do
439
+ to = "ruby...rails@domomo-ezweb.ne.jp"
440
+ MobileMailer.view_selection(to, @subject, @text).deliver
441
+
442
+ emails = ActionMailer::Base.deliveries
443
+ emails.size.should == 1
444
+ emails.first.to.include?(to).should be_true
445
+ emails.first.destinations.include?(to).should be_true
446
+ end
447
+
448
+ it "@マークの直前にピリオドあるアドレスが有効になること" do
449
+ to = "ruby.rails.@domomo-ezweb.ne.jp"
450
+ MobileMailer.view_selection(to, @subject, @text).deliver
451
+
452
+ emails = ActionMailer::Base.deliveries
453
+ emails.size.should == 1
454
+ emails.first.to.include?(to).should be_true
455
+ emails.first.destinations.include?(to).should be_true
456
+ end
457
+
458
+ it "ピリオドから始まるアドレスが有効になること" do
459
+ to = ".ruby.rails.@domomo-ezweb.ne.jp"
460
+ MobileMailer.view_selection(to, @subject, @text).deliver
461
+
462
+ emails = ActionMailer::Base.deliveries
463
+ emails.size.should == 1
464
+ emails.first.to.include?(to).should be_true
465
+ emails.first.destinations.include?(to).should be_true
466
+ end
467
+
468
+ it "複数のアドレスが有効になること" do
469
+ to = [".ruby.rails.@domomo-ezweb.ne.jp", "ruby.rails.@domomo-ezweb.ne.jp", "ruby...rails@domomo-ezweb.ne.jp"].join(", ")
470
+ MobileMailer.view_selection(to, @subject, @text).deliver
471
+
472
+ emails = ActionMailer::Base.deliveries
473
+ emails.size.should == 1
474
+ emails.first.to.should == to
475
+ emails.first.destinations.should == [to]
476
+ end
477
+ end
478
+
479
+ describe MobileMailer, "receiving" do
480
+ describe "blank mail" do
481
+ it "softbank からの空メールがで受信できること" do
482
+ email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-blank.eml").read
483
+ # expect {
484
+ email = MobileMailer.receive(email)
485
+ # }.to_not raise_error
486
+
487
+ email.subject.should be_blank
488
+ email.body.should be_blank
489
+ end
490
+ end
491
+
492
+ describe "docomo からのメールを受信するとき" do
493
+ before(:each) do
494
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/docomo-emoji.eml").read
495
+ end
496
+
497
+ it "漢字コードを適切に変換できること" do
498
+ email = MobileMailer.receive(@email)
499
+ email.subject.should match(/題名/)
500
+ email.body.should match(/本文/)
501
+ end
502
+
503
+ it "絵文字が数値参照に変わること" do
504
+ email = MobileMailer.receive(@email)
505
+
506
+ email.subject.should match(/&#xe676;/)
507
+ email.body.should match(/&#xe6e2;/)
508
+ end
509
+
510
+ describe "jis コードの場合に" do
511
+ before(:each) do
512
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/docomo-jis.eml").read
513
+ end
514
+
515
+ it "適切に変換できること" do
516
+ email = MobileMailer.receive(@email)
517
+
518
+ email.subject.should match(/テスト/)
519
+ email.body.should match(/テスト本文/)
520
+ end
521
+ end
522
+ end
523
+
524
+ describe "au からのメールを受信するとき" do
525
+ describe "jpmobile で送信したメールの場合" do
526
+ before(:each) do
527
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/au-emoji.eml").read
528
+ end
529
+
530
+ it "漢字コードを適切に変換できること" do
531
+ email = MobileMailer.receive(@email)
532
+
533
+ email.subject.should match(/題名/)
534
+ email.body.should match(/本文/)
535
+ end
536
+
537
+ it "絵文字が数値参照に変わること" do
538
+ email = MobileMailer.receive(@email)
539
+
540
+ email.subject.should match(/&#xe503;/)
541
+ email.body.should match(/&#xe522;/)
542
+ end
543
+ end
544
+
545
+ describe "実機からのメールの場合" do
546
+ before(:each) do
547
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/au-emoji2.eml").read
548
+ end
549
+
550
+ it "漢字コードを適切に変換できること" do
551
+ email = MobileMailer.receive(@email)
552
+
553
+ email.subject.should match(/題名/)
554
+ email.body.should match(/本文/)
555
+ end
556
+
557
+ it "絵文字が数値参照に変わること" do
558
+ email = MobileMailer.receive(@email)
559
+
560
+ email.subject.should match(/&#xe4f4;/)
561
+ email.body.should match(/&#xe471;/)
562
+ end
563
+ end
564
+ end
565
+
566
+ describe "softbank からのメールを受信するとき" do
567
+ describe "shift_jis のとき" do
568
+ before(:each) do
569
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-emoji.eml").read
570
+ end
571
+
572
+ it "漢字コードを適切に変換できること" do
573
+ email = MobileMailer.receive(@email)
574
+
575
+ email.subject.should match(/題名/)
576
+ email.body.should match(/本文/)
577
+ end
578
+
579
+ it "絵文字が数値参照に変わること" do
580
+ email = MobileMailer.receive(@email)
581
+
582
+ email.subject.should match(/&#xf03c;/)
583
+ email.body.should match(/&#xf21c;/)
584
+ end
585
+ end
586
+
587
+ describe "utf-8 のとき" do
588
+ before(:each) do
589
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-emoji-utf8.eml").read
590
+ end
591
+
592
+ it "漢字コードを適切に変換できること" do
593
+ email = MobileMailer.receive(@email)
594
+
595
+ email.subject.should match(/題名/)
596
+ email.body.should match(/本文/)
597
+ end
598
+
599
+ it "絵文字が数値参照に変わること" do
600
+ email = MobileMailer.receive(@email)
601
+
602
+ email.subject.should match(/&#xf03c;/)
603
+ email.body.should match(/&#xf21c;/)
604
+ end
605
+ end
606
+ end
607
+
608
+ describe "multipart メールを受信するとき" do
609
+ describe "docomo の場合" do
610
+ # NOTE: キャリアメールサーバで絵文字を変換するため検証は困難
611
+ before(:each) do
612
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml").read
613
+ end
614
+
615
+ it "正常に受信できること" do
616
+ lambda {
617
+ MobileMailer.receive(@email)
618
+ }.should_not raise_exception
619
+ end
620
+
621
+ it "絵文字が変換されること" do
622
+ email = MobileMailer.receive(@email)
623
+
624
+ email.subject.should match(/&#xe6ec;/)
625
+
626
+ email.parts.size.should == 1
627
+ email.parts.first.parts.size == 2
628
+
629
+ parts = email.parts.first.parts
630
+ parts.first.body.should match("テストです&#xe72d;")
631
+ parts.last.body.raw_source.should match("テストです&#xe72d;")
632
+ end
633
+ end
634
+
635
+ describe "au の場合" do
636
+ before(:each) do
637
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/au-decomail.eml").read
638
+ end
639
+
640
+ it "正常に受信できること" do
641
+ lambda {
642
+ MobileMailer.receive(@email)
643
+ }.should_not raise_exception
644
+ end
645
+
646
+ it "絵文字が変換されること" do
647
+ email = MobileMailer.receive(@email)
648
+
649
+ email.subject.should match(/&#xe4f4;/)
650
+
651
+ email.parts.size.should == 1
652
+ email.parts.first.parts.size == 2
653
+
654
+ parts = email.parts.first.parts
655
+ parts.first.body.should match(/テストです&#xe595;/)
656
+ parts.last.body.raw_source.should match(/テストです&#xe595;/)
657
+ end
658
+ end
659
+
660
+ describe "softbank(sjis) の場合" do
661
+ # NOTE: キャリアメールサーバで絵文字を変換するため検証は困難
662
+ before(:each) do
663
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-gmail-sjis.eml").read
664
+ end
665
+
666
+ it "正常に受信できること" do
667
+ lambda {
668
+ MobileMailer.receive(@email)
669
+ }.should_not raise_exception
670
+ end
671
+
672
+ it "絵文字が変換されること" do
673
+ email = MobileMailer.receive(@email)
674
+
675
+ email.subject.should match(/&#xf221;&#xf223;&#xf221;/)
676
+
677
+ email.parts.size.should == 2
678
+
679
+ email.parts.first.body.should match(/テストです&#xf018;/)
680
+ email.parts.last.body.raw_source.should match(/テストです&#xf231;/)
681
+ end
682
+ end
683
+
684
+ describe "softbank(utf8) の場合" do
685
+ # NOTE: キャリアメールサーバで絵文字を変換するため検証は困難
686
+ before(:each) do
687
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/softbank-gmail-utf8.eml").read
688
+ end
689
+
690
+ it "正常に受信できること" do
691
+ lambda {
692
+ MobileMailer.receive(@email)
693
+ }.should_not raise_exception
694
+ end
695
+
696
+ it "絵文字が変換されること" do
697
+ email = MobileMailer.receive(@email)
698
+
699
+ email.subject.should match(/テストです&#xf221;/)
700
+
701
+ email.parts.size.should == 2
702
+
703
+ email.parts.first.body.should match(/テストです&#xf223;/)
704
+ email.parts.last.body.raw_source.should match(/テストです&#xf223;/)
705
+ end
706
+ end
707
+
708
+ describe "添付ファイルがある場合" do
709
+ # NOTE: au のみテスト
710
+ before(:each) do
711
+ @email = open(Rails.root + "spec/fixtures/mobile_mailer/au-attached.eml").read
712
+ end
713
+
714
+ it "正常に受信できること" do
715
+ lambda {
716
+ MobileMailer.receive(@email)
717
+ }.should_not raise_exception
718
+ end
719
+
720
+ it "添付ファイルが壊れないこと" do
721
+ email = MobileMailer.receive(@email)
722
+
723
+ email.subject.should match(/&#xe481;/)
724
+
725
+ email.parts.size.should == 2
726
+
727
+ email.parts.first.body.should match(/カレンダーだ&#xe4f4;/)
728
+
729
+ email.has_attachments?.should be_true
730
+ email.attachments.size.should == 1
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
734
+ end
735
+ end
736
+ end
737
+ end