jpmobile 3.0.8 → 3.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e2edbcd2cd39d6029839e6bb73f8f9f67d507e8
4
- data.tar.gz: 93da4109608ed47dfb1037e897a0d18e631f8d71
3
+ metadata.gz: 541349c0b2076a81078620a75a7c8748bf0a3f2e
4
+ data.tar.gz: 2022c410ccc6d3b2d023a944a26035c69858f6c3
5
5
  SHA512:
6
- metadata.gz: 3cb525f338b7ad6143511c026050380ced4674401fdbe1195720fcfafc2945f15f526a1afde58fa53a446914758b4b42ce1301c97bc53836d31035c9c8db638e
7
- data.tar.gz: de43af2fd1c5ac16598cfa89bc768714d0015cca706b6107e572950f71720b964c2abe7c7fadb6456147930293ed3a685fb4343d36022c6b8d2903d6871b9a54
6
+ metadata.gz: 24ac8b306c0935e458450b28d44161119d5b290eb472b51e968347ba78f34856bd087ecd9437a182d3866d9dc417a34ab5340c9358b07ad18caa151e758f1cbc
7
+ data.tar.gz: 643a14da839b80dd0ae84c2cfb14d21b41da8d86b85e6b8717d24f3df7fd64b77782bbac84c555dd35cf800717e23a9215c98cd655a98294768c7de95326dabf
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 3
3
3
  :minor: 0
4
- :patch: 8
4
+ :patch: 9
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.7"
8
+ s.version = "3.0.9"
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
@@ -47,12 +47,6 @@ module Mail
47
47
  def mobile=(m)
48
48
  if @mobile = m
49
49
  @charset = m.mail_charset(@charset)
50
-
51
- if self.body
52
- self.body.content_type_with_jpmobile = self.content_type
53
- self.body.charset = @charset
54
- self.body.mobile = m
55
- end
56
50
  end
57
51
  end
58
52
 
@@ -65,7 +59,6 @@ module Mail
65
59
 
66
60
  ready_to_send!
67
61
 
68
- self.body.charset = @charset
69
62
  self.body.mobile = @mobile
70
63
  self.header['Content-Transfer-Encoding'].value = @mobile.content_transfer_encoding(self.header)
71
64
  if @mobile.decorated?
@@ -102,6 +95,18 @@ module Mail
102
95
  self.body = body_part
103
96
  end
104
97
 
98
+ def init_with_hash_with_jpmobile(hash)
99
+ if hash[:body_raw]
100
+ @mobile = hash[:mobile]
101
+ init_with_string(hash[:body_raw])
102
+ else
103
+ init_with_hash_without_jpmobile(hash)
104
+ end
105
+ end
106
+
107
+ alias_method :init_with_hash_without_jpmobile, :init_with_hash
108
+ alias_method :init_with_hash, :init_with_hash_with_jpmobile
109
+
105
110
  def init_with_string(string)
106
111
  # convert to ASCII-8BIT for ascii incompatible encodings
107
112
  s = Jpmobile::Util.ascii_8bit(string)
@@ -115,7 +120,6 @@ module Mail
115
120
  process_body_raw_without_jpmobile
116
121
 
117
122
  if @mobile
118
- @body.charset = @charset
119
123
  @body.mobile = @mobile
120
124
  @body.content_type_with_jpmobile = self.content_type
121
125
 
@@ -139,6 +143,11 @@ module Mail
139
143
  @raw_source = value.to_crlf
140
144
  end
141
145
 
146
+ def separate_parts_with_jpmobile
147
+ @body.mobile = @mobile
148
+ separate_parts_without_jpmobile
149
+ end
150
+
142
151
  alias_method :encoded_without_jpmobile, :encoded
143
152
  alias_method :encoded, :encoded_with_jpmobile
144
153
 
@@ -148,6 +157,9 @@ module Mail
148
157
  alias_method :process_body_raw_without_jpmobile, :process_body_raw
149
158
  alias_method :process_body_raw, :process_body_raw_with_jpmobile
150
159
 
160
+ alias_method :separate_parts_without_jpmobile, :separate_parts
161
+ alias_method :separate_parts, :separate_parts_with_jpmobile
162
+
151
163
  # -- docomo
152
164
  # multipart/mixed
153
165
  # |- multipart/related
@@ -248,34 +260,23 @@ module Mail
248
260
  # override charset
249
261
  if self.header[:content_type]
250
262
  content_type_charset = Jpmobile::Util.extract_charset(self.header[:content_type].value)
263
+ @charset = content_type_charset
251
264
  unless content_type_charset.blank?
252
- @charset = content_type_charset
253
265
  self.header[:content_type].parameters[:charset] = @charset
254
266
  @mobile_main_type = self.header[:content_type].main_type
255
267
  end
256
-
257
- if !Jpmobile::Email.convertable?(self.header[:content_type].value) and content_type_charset.blank?
258
- @charset = ''
259
- end
260
268
  end
261
269
 
262
270
  # convert header(s)
263
271
  if self.header[:subject]
264
272
  subject_charset = Jpmobile::Util.extract_charset(self.header[:subject].value)
265
-
266
- # override subject encoding if @charset is blank
267
- @charset = subject_charset if !subject_charset.blank? # and @charset.blank?
268
273
  self.header[:subject].charset = subject_charset unless subject_charset.blank?
269
274
 
270
275
  if @mobile
271
276
  subject_value = Encodings.value_decode(self.header[:subject].value)
272
277
  subject_converting_encoding = Jpmobile::Util.detect_encoding(subject_value)
273
278
  v = @mobile.to_mail_internal(subject_value, subject_converting_encoding)
274
- if @charset == subject_charset and @mobile.mail_charset != @charset
275
- self.header[:subject].value = Jpmobile::Util.force_encode(v, @charset, Jpmobile::Util::UTF8)
276
- else
277
- self.header[:subject].value = Jpmobile::Util.force_encode(v, @mobile.mail_charset(@charset), Jpmobile::Util::UTF8)
278
- end
279
+ self.header[:subject].value = Jpmobile::Util.force_encode(v, @mobile.mail_charset(subject_charset), Jpmobile::Util::UTF8)
279
280
  end
280
281
  end
281
282
 
@@ -340,25 +341,18 @@ module Mail
340
341
  # convert encoding
341
342
  def encoded_with_jpmobile(transfer_encoding = '8bit')
342
343
  if @mobile and !multipart?
343
- if @mobile.to_mail_body_encoded?(@raw_source)
344
- @raw_source
345
- elsif Jpmobile::Util.ascii_8bit?(@raw_source)
344
+ case transfer_encoding
345
+ when /base64/
346
346
  _raw_source = if transfer_encoding == encoding
347
- @raw_source
347
+ @raw_source.dup
348
348
  else
349
- enc = Mail::Encodings::get_encoding(get_best_encoding(transfer_encoding))
350
- enc.encode(@raw_source)
349
+ get_best_encoding(transfer_encoding).encode(@raw_source)
351
350
  end
352
- Jpmobile::Util.force_encode(_raw_source, nil, @charset)
351
+ Jpmobile::Util.set_encoding(_raw_source, @mobile.mail_charset(@charset))
352
+ when /quoted-printable/
353
+ Jpmobile::Util.set_encoding([@mobile.to_mail_body(@raw_source)].pack("M").gsub(/\n/, "\r\n"), @mobile.mail_charset(@charset))
353
354
  else
354
- case transfer_encoding
355
- when /quoted-printable/
356
- # [str].pack("M").gsub(/\n/, "\r\n")
357
- 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)
358
- # @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
359
- else
360
- @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
361
- end
355
+ @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, nil, Jpmobile::Util::UTF8))
362
356
  end
363
357
  else
364
358
  encoded_without_jpmobile(transfer_encoding)
@@ -384,9 +378,7 @@ module Mail
384
378
 
385
379
  if self.multipart? and @mobile
386
380
  self.parts.each do |part|
387
- part.charset = @mobile.mail_charset(part.charset)
388
381
  part.mobile = @mobile
389
- part.body.charset = part.charset
390
382
  part.body.mobile = @mobile
391
383
  end
392
384
  end
@@ -400,7 +392,7 @@ module Mail
400
392
 
401
393
  def preamble_with_jpmobile
402
394
  if @mobile
403
- Jpmobile::Util.encode(@preamble, @charset)
395
+ Jpmobile::Util.encode(@preamble, @mobile.mail_charset(@charset))
404
396
  else
405
397
  preamble_without_jpmobile
406
398
  end
@@ -408,7 +400,7 @@ module Mail
408
400
 
409
401
  def epilogue_with_jpmobile
410
402
  if @mobile
411
- Jpmobile::Util.encode(@epilogue, @charset)
403
+ Jpmobile::Util.encode(@epilogue, @mobile.mail_charset(@charset))
412
404
  else
413
405
  epilogue_without_jpmobile
414
406
  end
@@ -416,7 +408,7 @@ module Mail
416
408
 
417
409
  def crlf_boundary_with_jpmobile
418
410
  if @mobile
419
- Jpmobile::Util.encode(crlf_boundary_without_jpmobile, @charset)
411
+ Jpmobile::Util.encode(crlf_boundary_without_jpmobile, @mobile.mail_charset(@charset))
420
412
  else
421
413
  crlf_boundary_without_jpmobile
422
414
  end
@@ -424,7 +416,7 @@ module Mail
424
416
 
425
417
  def end_boundary_with_jpmobile
426
418
  if @mobile
427
- Jpmobile::Util.encode(end_boundary_without_jpmobile, @charset)
419
+ Jpmobile::Util.encode(end_boundary_without_jpmobile, @mobile.mail_charset(@charset))
428
420
  else
429
421
  end_boundary_without_jpmobile
430
422
  end
@@ -453,6 +445,17 @@ module Mail
453
445
 
454
446
  alias_method :epilogue_without_jpmobile, :epilogue
455
447
  alias_method :epilogue, :epilogue_with_jpmobile
448
+
449
+ def split!(boundary)
450
+ self.boundary = boundary
451
+ parts = raw_source.split(/(?:\A|\r\n)--#{Regexp.escape(boundary)}(?=(?:--)?\s*$)/)
452
+ # Make the preamble equal to the preamble (if any)
453
+ self.preamble = parts[0].to_s.strip
454
+ # Make the epilogue equal to the epilogue (if any)
455
+ self.epilogue = parts[-1].to_s.sub('--', '').strip
456
+ parts[1...-1].to_a.each { |part| @parts << Mail::Part.new(:body_raw => part, :mobile => @mobile) }
457
+ self
458
+ end
456
459
  end
457
460
 
458
461
  class UnstructuredField
@@ -28,7 +28,6 @@ module Jpmobile
28
28
  m = super(headers, &block)
29
29
 
30
30
  m.mobile = @mobile
31
- m.charset = @mobile.mail_charset
32
31
 
33
32
  # for decorated-mail manipulation
34
33
  m.rearrange! if @mobile.decorated?
data/lib/jpmobile/util.rb CHANGED
@@ -429,18 +429,28 @@ module Jpmobile
429
429
  def check_charset(str, charset)
430
430
  if Object.const_defined?(:Encoding)
431
431
  # use NKF.guess
432
- ::Encoding.compatible?(NKF.guess(str), ::Encoding.find(charset))
432
+ ::Encoding.compatible?(guess_encoding(str), ::Encoding.find(charset))
433
433
  else
434
434
  true
435
435
  end
436
436
  end
437
437
 
438
438
  def correct_encoding(str)
439
- if str.encoding != ::Encoding::ASCII_8BIT and NKF.guess(str) != str.encoding
440
- str.force_encoding(NKF.guess(str))
439
+ if guess_encoding(str) != str.encoding
440
+ str.force_encoding(guess_encoding(str))
441
441
  end
442
442
 
443
443
  str
444
444
  end
445
+
446
+ def guess_encoding(str)
447
+ encoding = NKF.guess(str)
448
+ # ISO-2022-JPにおいて、JIS X201半角カナエスケープシーケンスが含まれていたらCP50220とみなす
449
+ if encoding == ::Encoding::ISO2022_JP && str.dup.force_encoding(BINARY).include?("\e(I")
450
+ ::Encoding::CP50220
451
+ else
452
+ encoding
453
+ end
454
+ end
445
455
  end
446
456
  end
@@ -0,0 +1,15 @@
1
+ Delivered-To: info@jpmobile.jp
2
+ From: "jis@i.softbank.jp" <jis@i.softbank.jp>
3
+ Content-Type: text/plain;
4
+ charset=iso-2022-jp
5
+ X-Mailer: iPhone Mail (12B435)
6
+ Message-Id: <F574F824-7263-44E6-8423-000000000000@i.softbank.jp>
7
+ Date: Fri, 5 Dec 2014 13:14:37 +0900
8
+ To: "info@jpmobile.jp" <info@jpmobile.jp>
9
+ Content-Transfer-Encoding: 7bit
10
+ Mime-Version: 1.0 (1.0)
11
+ X-SB-Service: Virus-Checked
12
+
13
+ (=(I_$B&X(I_(B)(II(B
14
+
15
+
@@ -0,0 +1,45 @@
1
+ X-Account-Key: account2
2
+ X-UIDL: UID44724-1271041990
3
+ X-Mozilla-Status: 0001
4
+ X-Mozilla-Status2: 10000000
5
+ X-Mozilla-Keys:
6
+ Return-Path: <info@jp.mobile>
7
+ X-Original-To: info+to@jp.mobile
8
+ Delivered-To: info+to@jp.mobile
9
+ Received: from localhost (localhost [127.0.0.1])
10
+ by mx1.jp.mobile (Postfix) with ESMTP id 916D982D3C
11
+ for <info+to@jp.mobile>; Mon, 17 Jan 2011 16:43:00 +0900 (JST)
12
+ Received: from mx1.jp.mobile ([127.0.0.1])
13
+ by localhost (mx1.jp.mobile [127.0.0.1]) (amavisd-new, port 10024)
14
+ with ESMTP id 4c+D+lqN6aOJ for <info+to@jp.mobile>;
15
+ Mon, 17 Jan 2011 16:43:00 +0900 (JST)
16
+ Received: by mx1.jp.mobile (Postfix, from userid 58)
17
+ id 68BFD82D33; Mon, 17 Jan 2011 16:43:00 +0900 (JST)
18
+ Message-ID: <4D33F300.8050702@jpmobile.jp>
19
+ Date: Mon, 17 Jan 2011 16:42:56 +0900
20
+ From: Shin-ichiro OGAWA <info@jpmobile.jp>
21
+ User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100329)
22
+ MIME-Version: 1.0
23
+ To: info+to@jp.mobile
24
+ Subject:
25
+ Content-Type: multipart/mixed;
26
+ boundary="------------010605060509040104050402"
27
+
28
+ This is a multi-part message in MIME format.
29
+ --------------010605060509040104050402
30
+ Content-Type: text/plain; charset=ISO-2022-JP
31
+ Content-Transfer-Encoding: 7bit
32
+
33
+ $BK\J8$G$9(B
34
+
35
+
36
+ --------------010605060509040104050402
37
+ Content-Transfer-Encoding: base64
38
+ Content-Type: image/gif;
39
+ name="Transparent.gif"
40
+ Content-Disposition: attachment;
41
+ filename="Transparent.gif"
42
+
43
+ R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
44
+ --------------010605060509040104050402--
45
+
@@ -67,6 +67,21 @@ describe "Jpmobile::Mail#receive" do
67
67
  end
68
68
  end
69
69
 
70
+ describe "PC mail without subject" do
71
+ before(:each) do
72
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/pc-mail-attached-without-subject.eml")).read)
73
+ end
74
+
75
+ it "body should be parsed correctly" do
76
+ @mail.body.parts.size.should == 2
77
+ @mail.body.parts.first.body.to_s.should == "本文です\n\n"
78
+ end
79
+
80
+ it "should encode correctly" do
81
+ ascii_8bit(@mail.to_s).should match(/GODlhAQABAIAAAAAAAP/)
82
+ end
83
+ end
84
+
70
85
  describe "Docomo" do
71
86
  before(:each) do
72
87
  @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml")).read)
@@ -258,7 +273,7 @@ describe "Jpmobile::Mail#receive" do
258
273
 
259
274
  it 'should be encoded correctly' do
260
275
  @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-message.eml")).read)
261
- @mail.encoded
276
+ @mail.encoded.should match(Regexp.escape("%[\e$B1`;yL>\e(B]%\e$B$N\e(B%[\e$BJ]8n<TL>\e(B]%"))
262
277
  end
263
278
  end
264
279
 
@@ -271,14 +286,14 @@ describe "Jpmobile::Mail#receive" do
271
286
 
272
287
  it 'should be encoded correctly' do
273
288
  @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-mail3.eml")).read)
274
- @mail.encoded
289
+ @mail.encoded.should match(/BK\\J82~9T\$J\$7!2#5#1#2J8;z!2/)
275
290
  end
276
291
  end
277
292
 
278
293
  it 'should not raise when parsing attached email' do
279
294
  lambda {
280
295
  @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/au-attached.eml")).read)
281
- @mail.encoded
296
+ @mail.encoded.should match('/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAPQAA')
282
297
  }.should_not raise_error
283
298
  end
284
299
  end
@@ -347,6 +362,16 @@ describe "Jpmobile::Mail#receive" do
347
362
  @mail.body.to_s.should == "テスト本文\n\n"
348
363
  end
349
364
  end
365
+
366
+ context "iPhone" do
367
+ before(:each) do
368
+ @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/iphone-jis.eml")).read)
369
+ end
370
+
371
+ it "body should be parsed correctly" do
372
+ expect(@mail.body.to_s).to eq("(=゚ω゚)ノ\n\n\n")
373
+ end
374
+ end
350
375
  end
351
376
 
352
377
  describe 'bounced mail' do
@@ -133,22 +133,33 @@ describe Jpmobile::Util do
133
133
  end
134
134
  end
135
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
136
+ if defined?(Encoding)
137
+ describe 'check_charset' do
138
+ it 'returns true if compatible' do
139
+ str = 'ABC'.force_encoding('ASCII-8BIT')
140
+ check_charset(str, 'UTF-8').should be_true
141
+ end
142
+
143
+ it 'returns false if incompatible' do
144
+ str = '再現'.encode('ISO-2022-JP')
145
+ check_charset(str, 'UTF-8').should be_false
146
+ end
140
147
  end
141
148
 
142
- it 'returns false if incompatible' do
143
- str = '再現'.encode('ISO-2022-JP')
144
- check_charset(str, 'UTF-8').should be_false
149
+ describe 'correct_encoding' do
150
+ it 'updates encoding correctly' do
151
+ str = '再現'.force_encoding('ISO-2022-JP')
152
+ correct_encoding(str).encoding.should == Encoding::UTF_8
153
+ end
145
154
  end
146
- end
147
155
 
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
156
+ describe 'guess_encoding' do
157
+ it 'guesses encoding correclty' do
158
+ expect(guess_encoding('テスト')).to eq Encoding::UTF_8
159
+ expect(guess_encoding("\x83\x65\x83\x58\x83\x67")).to eq Encoding::Shift_JIS
160
+ expect(guess_encoding("\e\x24\x42\x25\x46\x25\x39\x25\x48\e\x28\x42")).to eq Encoding::ISO2022_JP
161
+ expect(guess_encoding("\e\x28\x49\x43\x3D\x44\e\x28\x42")).to eq Encoding::CP50220
162
+ end
152
163
  end
153
164
  end
154
165
  end
@@ -474,7 +474,7 @@ describe MobileMailer, " mail address" do
474
474
  emails.first.destinations.include?(to).should be_true
475
475
  end
476
476
 
477
- it "複数のアドレスが有効になること", focus: true do
477
+ it "複数のアドレスが有効になること" do
478
478
  to_addresses = [".ruby.rails.@domomo-ezweb.ne.jp", "ruby.rails.@domomo-ezweb.ne.jp", "ruby...rails@domomo-ezweb.ne.jp"]
479
479
  to = to_addresses.join(", ")
480
480
  MobileMailer.view_selection(to, @subject, @text).deliver
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.8
4
+ version: 3.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoji Shidara
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-28 00:00:00.000000000 Z
12
+ date: 2014-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jeweler
@@ -350,8 +350,10 @@ files:
350
350
  - spec/unit/email-fixtures/docomo-emoji.eml
351
351
  - spec/unit/email-fixtures/docomo-gmail-sjis.eml
352
352
  - spec/unit/email-fixtures/docomo-jis.eml
353
+ - spec/unit/email-fixtures/iphone-jis.eml
353
354
  - spec/unit/email-fixtures/iphone-mail3.eml
354
355
  - spec/unit/email-fixtures/iphone-message.eml
356
+ - spec/unit/email-fixtures/pc-mail-attached-without-subject.eml
355
357
  - spec/unit/email-fixtures/pc-mail-multi.eml
356
358
  - spec/unit/email-fixtures/pc-mail-single.eml
357
359
  - spec/unit/email-fixtures/photo.jpg