jpmobile 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 3
3
3
  :minor: 0
4
- :patch: 5
4
+ :patch: 6
5
5
  :build:
data/jpmobile.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jpmobile}
8
- s.version = "3.0.5"
8
+ s.version = "3.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yoji Shidara", "Shin-ichiro OGAWA"]
data/lib/jpmobile/mail.rb CHANGED
@@ -18,7 +18,7 @@ module Mail
18
18
 
19
19
  # change encoding
20
20
  def self.b_value_encode(str, encoding)
21
- str = Jpmobile::Util.encode(str, encoding)
21
+ str = Jpmobile::Util.encode(str, encoding.to_s)
22
22
  [Ruby19.encode_base64(str), encoding]
23
23
  end
24
24
  end
@@ -48,9 +48,10 @@ module Mail
48
48
  if @mobile = m
49
49
  @charset = m.mail_charset(@charset)
50
50
 
51
- if @body
52
- @body.charset = @charset
53
- @body.mobile = m
51
+ if self.body
52
+ self.body.content_type_with_jpmobile = self.content_type
53
+ self.body.charset = @charset
54
+ self.body.mobile = m
54
55
  end
55
56
  end
56
57
  end
@@ -60,7 +61,7 @@ module Mail
60
61
  header['subject'].mobile = @mobile if header['subject']
61
62
  header['from'].mobile = @mobile if header['from']
62
63
  header['to'].mobile = @mobile if header['to']
63
- self.charset = @mobile.mail_charset(@charset)
64
+ self.charset = @mobile.mail_charset
64
65
 
65
66
  ready_to_send!
66
67
 
@@ -116,17 +117,18 @@ module Mail
116
117
  if @mobile
117
118
  @body.charset = @charset
118
119
  @body.mobile = @mobile
120
+ @body.content_type_with_jpmobile = self.content_type
119
121
 
120
122
  if has_content_transfer_encoding? and
121
- ["base64", "quoted-printable"].include?(content_transfer_encoding) and
123
+ ["base64", "quoted-printable"].include?(self.content_transfer_encoding) and
122
124
  ["text"].include?(@mobile_main_type)
123
125
  @body.decode_transfer_encoding
124
126
  end
125
127
 
126
128
  if @body.multipart?
127
129
  @body.parts.each do |p|
128
- p.charset = @charset
129
- p.mobile = @mobile
130
+ p.charset = @mobile.mail_charset(p.charset)
131
+ p.mobile = @mobile
130
132
  end
131
133
  end
132
134
  end
@@ -272,7 +274,16 @@ module Mail
272
274
  end
273
275
  end
274
276
 
275
- if @body_part_jpmobile and @mobile
277
+ if @body_part_jpmobile and @mobile and !@charset.blank?
278
+ if ["base64", "quoted-printable"].include?(self.content_transfer_encoding) and
279
+ self.content_type.match(/text/)
280
+ @body_part_jpmobile = Jpmobile::Util.decode(@body_part_jpmobile, self.content_transfer_encoding, @charset)
281
+ self.content_transfer_encoding = @mobile.class::MAIL_CONTENT_TRANSFER_ENCODING
282
+ end
283
+ unless Jpmobile::Util.check_charset(@body_part_jpmobile, @charset)
284
+ @body_part_jpmobile = Jpmobile::Util.correct_encoding(@body_part_jpmobile)
285
+ @charset = @body_part_jpmobile.encoding.to_s
286
+ end
276
287
  @body_part_jpmobile = @mobile.decode_transfer_encoding(@body_part_jpmobile, @charset)
277
288
  end
278
289
  end
@@ -315,7 +326,7 @@ module Mail
315
326
  end
316
327
 
317
328
  class Body
318
- attr_accessor :mobile
329
+ attr_accessor :mobile, :content_type_with_jpmobile
319
330
 
320
331
  # convert encoding
321
332
  def encoded_with_jpmobile(transfer_encoding = '8bit')
@@ -323,10 +334,16 @@ module Mail
323
334
  if @mobile.to_mail_body_encoded?(@raw_source)
324
335
  @raw_source
325
336
  elsif Jpmobile::Util.ascii_8bit?(@raw_source)
326
- enc = Mail::Encodings::get_encoding(get_best_encoding(transfer_encoding))
327
- Jpmobile::Util.force_encode(enc.encode(@raw_source), nil, @charset)
337
+ _raw_source = if transfer_encoding == encoding
338
+ @raw_source
339
+ else
340
+ enc = Mail::Encodings::get_encoding(get_best_encoding(transfer_encoding))
341
+ enc.encode(@raw_source)
342
+ end
343
+ Jpmobile::Util.force_encode(_raw_source, nil, @charset)
328
344
  else
329
- if transfer_encoding == 'quoted-printable'
345
+ case transfer_encoding
346
+ when /quoted-printable/
330
347
  # [str].pack("M").gsub(/\n/, "\r\n")
331
348
  Jpmobile::Util.force_encode([@mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))].pack("M").gsub(/\n/, "\r\n"), Jpmobile::Util::BINARY, @charset)
332
349
  # @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
@@ -351,24 +368,25 @@ module Mail
351
368
  def mobile=(m)
352
369
  @mobile = m
353
370
 
371
+ if ["base64", "quoted-printable"].include?(self.encoding) and
372
+ /text/.match(self.content_type_with_jpmobile)
373
+ self.decode_transfer_encoding
374
+ end
375
+
354
376
  if self.multipart? and @mobile
355
377
  self.parts.each do |part|
356
- part.charset = @charset
378
+ part.charset = @mobile.mail_charset(part.charset)
357
379
  part.mobile = @mobile
358
- part.body.charset = @charset
380
+ part.body.charset = part.charset
359
381
  part.body.mobile = @mobile
360
382
  end
361
383
  end
362
384
  end
363
385
 
364
386
  def decode_transfer_encoding
365
- _raw_source = Encodings.get_encoding(encoding).decode(@raw_source)
366
- _extract_charset = Jpmobile::Util.extract_charset(_raw_source)
367
- unless _extract_charset.blank? or _extract_charset == @charset
368
- @charset = Jpmobile::Util.extract_charset(_raw_source)
369
- end
370
- _raw_source = Jpmobile::Util.set_encoding(_raw_source, @charset)
387
+ _raw_source = Jpmobile::Util.decode(@raw_source, self.encoding, @charset)
371
388
  @raw_source = @mobile.decode_transfer_encoding(_raw_source, @charset)
389
+ self.encoding = 'text'
372
390
  end
373
391
 
374
392
  def preamble_with_jpmobile
@@ -469,15 +487,15 @@ module Mail
469
487
 
470
488
  def mobile=(m)
471
489
  if @mobile = m
472
- self.charset = @mobile.mail_charset(@charset)
473
- self.value = @jpmobile_raw_text
490
+ self.charset = @mobile.mail_charset
491
+ self.value = @jpmobile_raw_text
474
492
  self.parse
475
493
  end
476
494
  end
477
495
 
478
496
  def encoded_with_jpmobile
479
497
  if @mobile
480
- self.charset = @mobile.mail_charset(@charset)
498
+ self.charset = @mobile.mail_charset
481
499
  end
482
500
 
483
501
  encoded_without_jpmobile
@@ -498,15 +516,15 @@ module Mail
498
516
 
499
517
  def mobile=(m)
500
518
  if @mobile = m
501
- self.charset = @mobile.mail_charset(@charset)
502
- self.value = @jpmobile_raw_text
519
+ self.charset = @mobile.mail_charset
520
+ self.value = @jpmobile_raw_text
503
521
  self.parse
504
522
  end
505
523
  end
506
524
 
507
525
  def encoded_with_jpmobile
508
526
  if @mobile
509
- self.charset = @mobile.mail_charset(@charset)
527
+ self.charset = @mobile.mail_charset
510
528
  end
511
529
 
512
530
  encoded_without_jpmobile
@@ -21,7 +21,7 @@ module Jpmobile
21
21
  # for multi to addresses
22
22
  Jpmobile::Mobile::AbstractMobile.new(nil, nil)
23
23
  end
24
- self.lookup_context.mobile = @mobile.variants
24
+ self.lookup_context.mobile = @mobile.mail_variants
25
25
 
26
26
  @mobile.decorated = headers.delete(:decorated)
27
27
 
@@ -101,11 +101,16 @@ module Jpmobile::Mobile
101
101
 
102
102
  @_variants || []
103
103
  end
104
+ def mail_variants
105
+ return @_mail_variants if @_mail_variants
106
+
107
+ @_mail_variants = variants == ['mobile'] ? [] : variants
108
+ end
104
109
 
105
110
  # メール送信用
106
111
  def to_mail_subject(str)
107
112
  Jpmobile::Util.fold_text(Jpmobile::Emoticon.unicodecr_to_utf8(str)).
108
- map{|text| "=?#{mail_charset}?B?" + [to_mail_encoding(text)].pack('m').strip + "?=" }.
113
+ map{|text| "=?#{mail_charset}?B?" + [to_mail_encoding(text)].pack('m').gsub(/\n/, '') + "?=" }.
109
114
  join("\n\s")
110
115
  end
111
116
  def to_mail_body(str)
@@ -113,7 +118,8 @@ module Jpmobile::Mobile
113
118
  end
114
119
  def mail_charset(charset = nil)
115
120
  # (charset.nil? or charset == "") ? self.class::MAIL_CHARSET : charset
116
- self.class::MAIL_CHARSET
121
+ # self.class::MAIL_CHARSET
122
+ charset.nil? || charset == '' || charset =~ /US-ASCII/i ? self.class::MAIL_CHARSET : charset
117
123
  end
118
124
  def content_transfer_encoding(headers)
119
125
  transfer_encoding = headers['Content-Transfer-Encoding']
data/lib/jpmobile/util.rb CHANGED
@@ -400,5 +400,37 @@ module Jpmobile
400
400
  end
401
401
  result
402
402
  end
403
+
404
+ def decode(str, encoding, charset)
405
+ _str = case encoding
406
+ when /quoted-printable/i
407
+ str.unpack('M').first.strip
408
+ when /base64/i
409
+ str.unpack('m').first.strip
410
+ else
411
+ str
412
+ end
413
+
414
+ _extract_charset = Jpmobile::Util.extract_charset(_str)
415
+ charset = _extract_charset unless _extract_charset.blank? or _extract_charset == charset
416
+ Jpmobile::Util.set_encoding(_str, charset)
417
+ end
418
+
419
+ def check_charset(str, charset)
420
+ if Object.const_defined?(:Encoding)
421
+ # use NKF.guess
422
+ ::Encoding.compatible?(NKF.guess(str), ::Encoding.find(charset))
423
+ else
424
+ true
425
+ end
426
+ end
427
+
428
+ def correct_encoding(str)
429
+ if str.encoding != ::Encoding::ASCII_8BIT and NKF.guess(str) != str.encoding
430
+ str.force_encoding(NKF.guess(str))
431
+ end
432
+
433
+ str
434
+ end
403
435
  end
404
436
  end
@@ -0,0 +1,42 @@
1
+ Return-Path: <au@ezweb.ne.jp>
2
+ Delivered-To: ogawa@jpmobile-info.co.jp
3
+ Subject: =?iso-2022-jp?B?RndkOiAbJEIhWhsoQk51cnNlcnlNYWlsGyRCIVtGfEZ8GyhC?=
4
+ From: au@ezweb.ne.jp
5
+ Content-Type: multipart/alternative;
6
+ boundary=Apple-Mail-453BF7C8-E087-4CEB-A163-18A4B0CBB56C
7
+ Message-Id: <5C2DBDE0-7AE2-4BD2-B932-97B59EAFED85@ezweb.ne.jp>
8
+ Date: Tue, 31 Jul 2012 10:44:23 +0900 (JST)
9
+ To: test@jpmobile-info.org
10
+ Content-Transfer-Encoding: 7bit
11
+ MIME-Version: 1.0
12
+
13
+ --Apple-Mail-453BF7C8-E087-4CEB-A163-18A4B0CBB56C
14
+ Content-Transfer-Encoding: quoted-printable
15
+ Content-Type: text/plain;
16
+ charset=iso-2022-jp
17
+
18
+
19
+
20
+ iPhone=1B$B$+$iAw?.=1B(B
21
+
22
+ Begin forwarded message:
23
+
24
+ > =1B$B$H$j$"$($:#H#T#M#L$NK\J8$G=1B(B
25
+ > =1B$B$"$l$P$$$$2DG=3D@-$r9MN8$7$F$O=1B(B
26
+ > =1B$B8+$?$,$d$O$j$Y!<$9$m$/$h$s!J>P!K$G=1B(B
27
+ > =1B$B$"$l$P$$$$$h$&$J5$$,=1B(B
28
+ > =1B$B$7$?$N$G%@%_!<$NJ8;zNs$r=1B(B
29
+ > =1B$B9M$($F8+$kD+!#=1B(B=
30
+
31
+ --Apple-Mail-453BF7C8-E087-4CEB-A163-18A4B0CBB56C
32
+ Content-Transfer-Encoding: base64
33
+ Content-Type: text/html;
34
+ charset=utf-8
35
+
36
+ 44Go44KK44GC44GI44Ga77yo77y077yt77ys44Gu5pys5paH44Gn44GC44KM
37
+ 44Gw44GE44GE5Y+v6IO95oCn44KS6ICD5oWu44GX44Gm44Gv6KaL44Gf44GM
38
+ 44KE44Gv44KK44G544O844GZ44KN44GP44KI44KT77yI56yR77yJ44Gn44GC
39
+ 44KM44Gw44GE44GE44KI44GG44Gq5rCX44GM44GX44Gf44Gu44Gn44OA44Of
40
+ 44O844Gu5paH5a2X5YiX44KS6ICD44GI44Gm6KaL44KL5pyd44CC
41
+ --Apple-Mail-453BF7C8-E087-4CEB-A163-18A4B0CBB56C--
42
+
@@ -0,0 +1,56 @@
1
+ X-Mozilla-Status: 0011
2
+ X-Mozilla-Status2: 00000000
3
+ X-Mozilla-Keys:
4
+ Return-Path: <au@ezweb.ne.jp>
5
+ Delivered-To: au@ezweb.ne.jp
6
+ References: <503ef27994050_75cf4344bfe77fe@jpmobile.jp.mail>
7
+ In-Reply-To: <503ef27994050_75cf4344bfe77fe@jpmobile.jp.mail>
8
+ Mime-Version: 1.0 (1.0)
9
+ Content-Transfer-Encoding: base64
10
+ Content-Type: text/plain;
11
+ charset=utf-8
12
+ Message-Id: <6D015993-FD10-4EE9-8B60-A4588D554649@ezweb.ne.jp>
13
+ X-Mailer: iPhone Mail (9B206)
14
+ From: "au@ezweb.ne.jp" <au@ezweb.ne.jp>
15
+ Subject: =?iso-2022-jp?B?UmU6IBskQiFaGyhCTktTQxskQiFbGyhCdGVzdA==?=
16
+ Date: Thu, 30 Aug 2012 14:49:20 +0900
17
+ To: "info@jpmobile.jp" <info@jpmobile.jp>
18
+
19
+ DQoNCmlQaG9uZeOBi+OCiemAgeS/oeKXi+KXjg0KDQpPbiAyMDEyLzA4LzMw
20
+ LCBhdCAxMzo1NiwgaW5mb0BqcG1vYmlsZS5qcCB3cm90ZToNCg0KPiDmnKzm
21
+ lofmlLnooYzjgarjgZfvvL/vvJXvvJHvvJLmloflrZfvvL/jgYLjgYLjgYLj
22
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
23
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
24
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
25
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
26
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
27
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
28
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
29
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
30
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
31
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
32
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
33
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
34
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
35
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
36
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
37
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
38
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
39
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
40
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
41
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
42
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
43
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
44
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
45
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
46
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
47
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
48
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
49
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
50
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
51
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
52
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLj
53
+ gYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLjgYLvv73vv73ilrPi
54
+ lrPilrPilrPilrPilrPilrPilrPilrPilrPilrPilrPilrPilrPilrPilrPi
55
+ lrPilrPvv70NCg==
56
+
@@ -0,0 +1,27 @@
1
+ X-Account-Key: account2
2
+ X-UIDL: 1345598846.M744553P8903V000000000000FD00I00000000C0120BDF_0.jpjp.jp,S=1186.000031434a023554
3
+ X-Mozilla-Status: 0001
4
+ X-Mozilla-Status2: 00000000
5
+ X-Mozilla-Keys:
6
+ Return-Path: <au@ezweb.ne.jp>
7
+ Delivered-To: ogawa@jpmobile.jp
8
+ Received: (qmail 8893 invoked by SAV 20120821.022 by uid 0); 22 Aug 2012 10:27:26 +0900
9
+ Received: from unknown (HELO mmsmta08.ezweb.ne.jp) (59.135.39.241)
10
+ by dc6.etius.jp (124.146.201.109) with ESMTPS (DHE-RSA-AES256-SHA encrypted); 22 Aug 2012 10:27:26 +0900
11
+ Received-SPF: pass (dc6.etius.jp: SPF record at spf-nm.ezweb.ne.jp designates 59.135.39.241 as permitted sender)
12
+ Received: from cm (pl0_4-mms [172.22.116.39])
13
+ by mmsmta08.ezweb.ne.jp (Sentrion-MTA-4.1.0/Switch-3.3.4) with SMTP id q7M1RQgt001822
14
+ for <info@jpmobile.jp>; Wed, 22 Aug 2012 10:27:26 +0900
15
+ From:au@ezweb.ne.jp
16
+ To:ogawa@jpmobile.jp
17
+ Subject:=?UTF-8?B?aVBob25lIGF1IOODoeODg+OCu+ODvOOCuA==?=
18
+ Message-ID: <212212358846052174@-212212358846052175>
19
+ Date: Tue, 22 Aug 2012 01:27:26 +0000
20
+ MIME-Version:1.0
21
+ Content-Type: text/plain; charset=utf-8
22
+ Content-Transfer-Encoding: base64
23
+
24
+ JVvlnJLlhZDlkI1dJeOBriVb5L+d6K236ICF5ZCNXSUg5qeYCgrmlr3oqK3jgavpgIHkv6HjgIIK
25
+ 6YG45oqeMeOBryVb44Ki44OJ44Os44K5MV0l44G4CumBuOaKnjLjga8lW+OCouODieODrOOCuTJd
26
+ JeOBuArov5Tkv6HjgZfjgabkuIvjgZXjgYTjgIIKCmlQaG9uZSBhdSDjg6Hjg4Pjgrvjg7zjgrg=
27
+
@@ -255,6 +255,31 @@ describe "Jpmobile::Mail" do
255
255
  end
256
256
  end
257
257
 
258
+ describe "long subject with half-characters" do
259
+ before(:each) do
260
+ @mail = Mail.new
261
+ @mail.subject = "西暦2012年09月03日は今日になるわけだが10時16分現在のこの時間ではどうかな"
262
+ @mail.body = "株式会社・・"
263
+ @mail.from = "info@jpmobile-rails.org"
264
+ end
265
+
266
+ describe "AbstractMobile" do
267
+ before(:each) do
268
+ @mobile = Jpmobile::Mobile::AbstractMobile.new(nil, nil)
269
+ @mail.mobile = @mobile
270
+ @mail.to = "むすめふさほせ <info+to@jpmobile-rails.org>"
271
+ end
272
+
273
+ context "to_s" do
274
+ it "should contain encoded subject" do
275
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?GyRCQD5OcRsoQjIwMTIbJEJHLxsoQjA5GyRCN24bKEIwMxskQkZ8JE86IxsoQg==?=")))
276
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?GyRCRnwkSyRKJGskbyQxJEAkLBsoQjEwGyRCO34bKEIxNhskQkosOD0bKEI=?=")))
277
+ ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape("=?ISO-2022-JP?B?GyRCOl8kTiQzJE47fjRWJEckTyRJJCYkKyRKGyhC?=")))
278
+ end
279
+ end
280
+ end
281
+ end
282
+
258
283
  context "with attachments" do
259
284
  before(:each) do
260
285
  @mobile = Jpmobile::Mobile::AbstractMobile.new(nil, nil)
@@ -278,6 +303,14 @@ describe "Jpmobile::Mail" do
278
303
  @mail.to_s
279
304
  }.should_not raise_error
280
305
  end
306
+
307
+ it "should encodes itself successfully with an UTF-8 filename attachment" do
308
+ @mail.attachments.inline['日本語のファイル名です.jpg'] = @photo
309
+
310
+ lambda {
311
+ @mail.to_s
312
+ }.should_not raise_error
313
+ end
281
314
  end
282
315
 
283
316
  context "encoding conversion" do
@@ -317,4 +350,40 @@ describe "Jpmobile::Mail" do
317
350
  Mail::TestMailer.deliveries.size
318
351
  end
319
352
  end
353
+
354
+ context 'sending with carrier from' do
355
+ before do
356
+ @mail = Mail.new
357
+ @mail.subject = "万葉"
358
+ @mail.to = "ちはやふる <info@jpmobile-rails.org>"
359
+ end
360
+
361
+ it 'should convert content-transfer-encoding' do
362
+ mobile = Jpmobile::Mobile::Au.new(nil, nil)
363
+ @mail.content_transfer_encoding = 'base64'
364
+ @mail.body = ['ほげ'].pack('m')
365
+ @mail.charset = 'UTF-8'
366
+
367
+ @mail.mobile = mobile
368
+ @mail.from = '<えーゆー> au@ezweb.ne.jp'
369
+
370
+ @mail.encoded.should match(/content-transfer-encoding: 7bit/i)
371
+ end
372
+
373
+ it 'should not convert content-transfer-encoding with BINARY' do
374
+ mobile = Jpmobile::Mobile::Au.new(nil, nil)
375
+ data = ['ほげ'].pack('m').strip
376
+
377
+ @mail.content_transfer_encoding = 'base64'
378
+ @mail.content_type = 'image/jpeg'
379
+ @mail.body = data
380
+ @mail.charset = 'UTF-8'
381
+
382
+ @mail.mobile = mobile
383
+ @mail.from = '<えーゆー> au@ezweb.ne.jp'
384
+
385
+ @mail.encoded.should match(/content-transfer-encoding: base64/i)
386
+ @mail.encoded.should match(data)
387
+ end
388
+ end
320
389
  end
@@ -148,6 +148,14 @@ describe "Jpmobile::Mail#receive" do
148
148
  end
149
149
  end
150
150
  end
151
+
152
+ context 'bounced mail' do
153
+ it 'should parse sub-part charset correctly' do
154
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/bounce_with_utf8_part.eml")).read)
155
+ @mail.parts.first.charset.should match(/iso-2022-jp/i)
156
+ @mail.parts.last.charset.should match(/utf-8/i)
157
+ end
158
+ end
151
159
  end
152
160
 
153
161
  describe "Docomo" do
@@ -234,6 +242,32 @@ describe "Jpmobile::Mail#receive" do
234
242
  @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/au-decomail2.eml")).read)
235
243
  }.should_not raise_error
236
244
  end
245
+
246
+ context 'From au iPhone' do
247
+ it 'charset should be UTF-8' do
248
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-message.eml")).read)
249
+ @mail.mobile.should be_a(Jpmobile::Mobile::Au)
250
+ @mail.charset.should match(/utf-8/i)
251
+ end
252
+
253
+ it 'should be encoded correctly' do
254
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-message.eml")).read)
255
+ @mail.encoded
256
+ end
257
+ end
258
+
259
+ context 'From iPad' do
260
+ it 'charset should be UTF-8' do
261
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-mail3.eml")).read)
262
+ @mail.mobile.should be_a(Jpmobile::Mobile::AbstractMobile)
263
+ @mail.charset.should match(/utf-8/i)
264
+ end
265
+
266
+ it 'should be encoded correctly' do
267
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-mail3.eml")).read)
268
+ @mail.encoded
269
+ end
270
+ end
237
271
  end
238
272
 
239
273
  describe "Softbank" do
@@ -302,6 +336,18 @@ describe "Jpmobile::Mail#receive" do
302
336
  end
303
337
  end
304
338
 
339
+ describe 'bounced mail' do
340
+ context "has jp address" do
341
+ before(:each) do
342
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/bounced-jp.eml")).read)
343
+ end
344
+
345
+ it "mobile should abstract mobile" do
346
+ @mail.mobile.should be_a Jpmobile::Mobile::AbstractMobile
347
+ end
348
+ end
349
+ end
350
+
305
351
  describe "non-Japanese mail" do
306
352
  context "us-ascii" do
307
353
  before(:each) do
@@ -132,4 +132,23 @@ describe Jpmobile::Util do
132
132
  hash[0xE6FB].should == 0x1F526
133
133
  end
134
134
  end
135
+
136
+ describe 'check_charset' do
137
+ it 'returns true if compatible' do
138
+ str = 'ABC'.force_encoding('ASCII-8BIT')
139
+ check_charset(str, 'UTF-8').should be_true
140
+ end
141
+
142
+ it 'returns false if incompatible' do
143
+ str = '再現'.encode('ISO-2022-JP')
144
+ check_charset(str, 'UTF-8').should be_false
145
+ end
146
+ end
147
+
148
+ describe 'correct_encoding' do
149
+ it 'updates encoding correctly' do
150
+ str = '再現'.force_encoding('ISO-2022-JP')
151
+ correct_encoding(str).encoding.should == Encoding::UTF_8
152
+ end
153
+ end
135
154
  end
@@ -0,0 +1,128 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
3
+ require 'mail'
4
+ require 'jpmobile/mail'
5
+
6
+ describe Jpmobile::Mobile::AbstractMobile do
7
+ subject{ Jpmobile::Mobile::AbstractMobile.new(nil, nil) }
8
+
9
+ describe '#variants' do
10
+ its(:variants){ should === ['mobile'] }
11
+ end
12
+
13
+ describe '#mail_variants' do
14
+ its(:mail_variants){ should == [] }
15
+ end
16
+ end
17
+
18
+ describe Jpmobile::Mobile::Docomo do
19
+ subject{ Jpmobile::Mobile::Docomo.new(nil, nil) }
20
+
21
+ describe '#variants' do
22
+ its(:variants){ should == ['mobile_docomo', 'mobile'] }
23
+ end
24
+
25
+ describe '#mail_variants' do
26
+ it 'have same value as #variants' do
27
+ subject.mail_variants == subject.variants
28
+ end
29
+ end
30
+ end
31
+
32
+ describe Jpmobile::Mobile::Au do
33
+ subject{ Jpmobile::Mobile::Au.new(nil, nil) }
34
+
35
+ describe '#variants' do
36
+ its(:variants){ should == ['mobile_au', 'mobile'] }
37
+ end
38
+
39
+ describe '#mail_variants' do
40
+ it 'have same value as #variants' do
41
+ subject.mail_variants == subject.variants
42
+ end
43
+ end
44
+ end
45
+
46
+ describe Jpmobile::Mobile::Softbank do
47
+ subject{ Jpmobile::Mobile::Softbank.new(nil, nil) }
48
+
49
+ describe '#variants' do
50
+ its(:variants){ should == ['mobile_softbank', 'mobile'] }
51
+ end
52
+
53
+ describe '#mail_variants' do
54
+ it 'have same value as #variants' do
55
+ subject.mail_variants == subject.variants
56
+ end
57
+ end
58
+ end
59
+
60
+ describe Jpmobile::Mobile::Android do
61
+ subject{ Jpmobile::Mobile::Android.new(nil, nil) }
62
+
63
+ describe '#variants' do
64
+ its(:variants){ should == ['smart_phone_android', 'smart_phone'] }
65
+ end
66
+
67
+ describe '#mail_variants' do
68
+ it 'have same value as #variants' do
69
+ subject.mail_variants == subject.variants
70
+ end
71
+ end
72
+ end
73
+
74
+ describe Jpmobile::Mobile::AndroidTablet do
75
+ subject{ Jpmobile::Mobile::AndroidTablet.new(nil, nil) }
76
+
77
+ describe '#variants' do
78
+ its(:variants){ should == ['tablet_android_tablet', 'tablet', 'smart_phone'] }
79
+ end
80
+
81
+ describe '#mail_variants' do
82
+ it 'have same value as #variants' do
83
+ subject.mail_variants == subject.variants
84
+ end
85
+ end
86
+ end
87
+
88
+ describe Jpmobile::Mobile::Iphone do
89
+ subject{ Jpmobile::Mobile::Iphone.new(nil, nil) }
90
+
91
+ describe '#variants' do
92
+ its(:variants) { should == ['smart_phone_iphone', 'smart_phone'] }
93
+ end
94
+
95
+ describe '#mail_variants' do
96
+ it 'have same value as #variants' do
97
+ subject.mail_variants == subject.variants
98
+ end
99
+ end
100
+ end
101
+
102
+ describe Jpmobile::Mobile::Ipad do
103
+ subject{ Jpmobile::Mobile::Ipad.new(nil, nil) }
104
+
105
+ describe '#variants' do
106
+ its(:variants){ should == ['tablet_ipad', 'tablet', 'smart_phone'] }
107
+ end
108
+
109
+ describe '#mail_variants' do
110
+ it 'have same value as #variants' do
111
+ subject.mail_variants == subject.variants
112
+ end
113
+ end
114
+ end
115
+
116
+ describe Jpmobile::Mobile::WindowsPhone do
117
+ subject{ Jpmobile::Mobile::WindowsPhone.new(nil, nil) }
118
+
119
+ describe '#variants' do
120
+ its(:variants){ should == ['smart_phone_windows_phone', 'smart_phone'] }
121
+ end
122
+
123
+ describe '#mail_variants' do
124
+ it 'have same value as #variants' do
125
+ subject.mail_variants == subject.variants
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,72 @@
1
+ Return-Path: <>
2
+ X-Original-To: info@example.jp
3
+ Delivered-To: info@example.jp
4
+ Received: by localhost (Postfix)
5
+ id 081F8161D92; Fri, 17 Aug 2012 23:05:01 +0900 (JST)
6
+ Date: Fri, 17 Aug 2012 23:05:01 +0900 (JST)
7
+ From: MAILER-DAEMON@example.jp (Mail Delivery System)
8
+ Subject: Undelivered Mail Returned to Sender
9
+ To: info@example.jp
10
+ Auto-Submitted: auto-replied
11
+ MIME-Version: 1.0
12
+ Content-Type: multipart/report; report-type=delivery-status;
13
+ boundary="EAE03161D91.1345212301/localhost"
14
+ Message-Id: <20120817140501.081F8161D92@localhost>
15
+
16
+ This is a MIME-encapsulated message.
17
+
18
+ --EAE03161D91.1345212301/localhost
19
+ Content-Description: Notification
20
+ Content-Type: text/plain; charset=us-ascii
21
+
22
+ This is the mail system at host localhost.
23
+
24
+ I'm sorry to have to inform you that your message could not
25
+ be delivered to one or more recipients. It's attached below.
26
+
27
+ For further assistance, please send mail to postmaster.
28
+
29
+ If you do so, please include this problem report. You can
30
+ delete your own text from the attached returned message.
31
+
32
+ The mail system
33
+
34
+ <unknown@docomo.ne.jp>: host mfsmax.docomo.ne.jp[203.138.181.112] said: 550
35
+ Unknown user unknown@docomo.ne.jp (in reply to end of DATA command)
36
+
37
+ --EAE03161D91.1345212301/localhost
38
+ Content-Description: Delivery report
39
+ Content-Type: message/delivery-status
40
+
41
+ Reporting-MTA: dns; localhost
42
+ X-Postfix-Queue-ID: EAE03161D91
43
+ X-Postfix-Sender: rfc822; info@example.jp
44
+ Arrival-Date: Fri, 17 Aug 2012 23:05:00 +0900 (JST)
45
+
46
+ Final-Recipient: rfc822; unknown@docomo.ne.jp
47
+ Action: failed
48
+ Status: 5.0.0
49
+ Remote-MTA: dns; mfsmax.docomo.ne.jp
50
+ Diagnostic-Code: smtp; 550 Unknown user unknown@docomo.ne.jp
51
+
52
+ --EAE03161D91.1345212301/localhost
53
+ Content-Description: Undelivered Message
54
+ Content-Type: message/rfc822
55
+
56
+ Return-Path: <info@example.jp>
57
+ Received: by localhost (Postfix, from userid 1004)
58
+ id EAE03161D91; Fri, 17 Aug 2012 23:05:00 +0900 (JST)
59
+ Date: Fri, 17 Aug 2012 23:05:00 +0900
60
+ From: info@example.jp
61
+ To: unknown@docomo.ne.jp
62
+ Message-ID: <502e4f8c8dc0a_1ed1cbf30467885@mail>
63
+ Subject: =?Shift_JIS?B?dGVzdA==?=
64
+ Mime-Version: 1.0
65
+ Content-Type: text/plain;
66
+ charset=Shift_JIS
67
+ Content-Transfer-Encoding: 7bit
68
+
69
+ test
70
+
71
+ --EAE03161D91.1345212301/localhost--
72
+
@@ -78,6 +78,7 @@ describe MobileMailer do
78
78
  raw_mail.should match(/iso-2022-jp/i)
79
79
  raw_mail.should match(Regexp.compile(Regexp.escape(ascii_8bit([utf8_to_jis("題名")].pack('m').strip))))
80
80
  raw_mail.should match(Regexp.compile(Regexp.escape(ascii_8bit(utf8_to_jis("本文")))))
81
+ raw_mail.should match(/For PC/)
81
82
  end
82
83
  end
83
84
 
@@ -663,6 +664,15 @@ describe MobileMailer, "receiving" do
663
664
  parts.first.body.should match(/テストです&#xe595;/)
664
665
  parts.last.body.raw_source.should match(/テストです&#xe595;/)
665
666
  end
667
+
668
+ context 'iPhone' do
669
+ it 'should parse correctly' do
670
+ lambda {
671
+ @mail = MobileMailer.receive(open(File.join(Rails.root, "../../../spec/unit/email-fixtures/iphone-message.eml")).read)
672
+ @mail.encoded
673
+ }.should_not raise_error
674
+ end
675
+ end
666
676
  end
667
677
 
668
678
  describe "softbank(sjis) の場合" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpmobile
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-10 00:00:00.000000000 Z
13
+ date: 2012-10-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jeweler
@@ -380,9 +380,12 @@ files:
380
380
  - spec/unit/email-fixtures/au-emoji.eml
381
381
  - spec/unit/email-fixtures/au-emoji2.eml
382
382
  - spec/unit/email-fixtures/au-emoji5.eml
383
+ - spec/unit/email-fixtures/bounce_with_utf8_part.eml
383
384
  - spec/unit/email-fixtures/docomo-emoji.eml
384
385
  - spec/unit/email-fixtures/docomo-gmail-sjis.eml
385
386
  - spec/unit/email-fixtures/docomo-jis.eml
387
+ - spec/unit/email-fixtures/iphone-mail3.eml
388
+ - spec/unit/email-fixtures/iphone-message.eml
386
389
  - spec/unit/email-fixtures/pc-mail-multi.eml
387
390
  - spec/unit/email-fixtures/pc-mail-single.eml
388
391
  - spec/unit/email-fixtures/photo.jpg
@@ -400,6 +403,7 @@ files:
400
403
  - spec/unit/spec_helper.rb
401
404
  - spec/unit/util_spec.rb
402
405
  - spec/unit/valid_ip_spec.rb
406
+ - spec/unit/variants_spec.rb
403
407
  - test/rails/.gitignore
404
408
  - test/rails/overrides/.rspec
405
409
  - test/rails/overrides/Gemfile
@@ -489,6 +493,7 @@ files:
489
493
  - test/rails/overrides/spec/fixtures/mobile_mailer/au-emoji.eml
490
494
  - test/rails/overrides/spec/fixtures/mobile_mailer/au-emoji2.eml
491
495
  - test/rails/overrides/spec/fixtures/mobile_mailer/au-emoji5.eml
496
+ - test/rails/overrides/spec/fixtures/mobile_mailer/bounced-jp.eml
492
497
  - test/rails/overrides/spec/fixtures/mobile_mailer/docomo-emoji.eml
493
498
  - test/rails/overrides/spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml
494
499
  - test/rails/overrides/spec/fixtures/mobile_mailer/docomo-jis.eml