jpmobile 4.1.0.rc1 → 4.1.0

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: 2b0f241ba03225004123b6f08d987f2311f75d2f
4
- data.tar.gz: 8fcff8ad38f8f22b37fe56af7352273abe3ee07a
3
+ metadata.gz: 3d1af2f3d8ba046eb0483cab4e30cf3ece9b7666
4
+ data.tar.gz: d23803bc647766e423a64756a20652e1c0291414
5
5
  SHA512:
6
- metadata.gz: 61351a0a29f21d528b49697814707a8da681029bf86e55681ab0453013e809709136c320653d21ba85567539aaa6d9a8c6c95f14427427c5b117dcf2ddc0890f
7
- data.tar.gz: b93a1d05668f5d752a713139aa41d8a7c860a491fc3e633c37c1cd0051667b84014f49eea2c796ecd6d6a326fd995b26f21cc23dfa0f8a132c3b1b0a0f18f4f8
6
+ metadata.gz: 44996d540aa84b9ec1a1265c6f3c447cc44391cf4b527bfacb449b9db4cdd909dadf6c29299920c02fb63b0f0e397564d4b7538dd46fb026cae6ea388cda9691
7
+ data.tar.gz: aa84dcbdb131aca10fe68d19838e5068fe08d53573f55ea748c12f8e06beb546e397f5c0e9af7065aeec948239db795018866f14a53ae76144aad632deafcb6e
data/lib/jpmobile/mail.rb CHANGED
@@ -29,12 +29,6 @@ module Mail
29
29
  def mobile=(m)
30
30
  if @mobile = m
31
31
  @charset = m.mail_charset(@charset)
32
-
33
- if self.body
34
- self.body.content_type_with_jpmobile = self.content_type
35
- self.body.charset = @charset
36
- self.body.mobile = m
37
- end
38
32
  end
39
33
  end
40
34
 
@@ -47,7 +41,6 @@ module Mail
47
41
 
48
42
  ready_to_send!
49
43
 
50
- self.body.charset = @charset
51
44
  self.body.mobile = @mobile
52
45
  self.header['Content-Transfer-Encoding'].value = @mobile.content_transfer_encoding(self.header)
53
46
  if @mobile.decorated?
@@ -84,6 +77,18 @@ module Mail
84
77
  self.body = body_part
85
78
  end
86
79
 
80
+ def init_with_hash_with_jpmobile(hash)
81
+ if hash[:body_raw]
82
+ @mobile = hash[:mobile]
83
+ init_with_string(hash[:body_raw])
84
+ else
85
+ init_with_hash_without_jpmobile(hash)
86
+ end
87
+ end
88
+
89
+ alias_method :init_with_hash_without_jpmobile, :init_with_hash
90
+ alias_method :init_with_hash, :init_with_hash_with_jpmobile
91
+
87
92
  def init_with_string(string)
88
93
  # convert to ASCII-8BIT for ascii incompatible encodings
89
94
  s = Jpmobile::Util.ascii_8bit(string)
@@ -97,7 +102,6 @@ module Mail
97
102
  process_body_raw_without_jpmobile
98
103
 
99
104
  if @mobile
100
- @body.charset = @charset
101
105
  @body.mobile = @mobile
102
106
  @body.content_type_with_jpmobile = self.content_type
103
107
 
@@ -121,6 +125,11 @@ module Mail
121
125
  @raw_source = value.to_crlf
122
126
  end
123
127
 
128
+ def separate_parts_with_jpmobile
129
+ @body.mobile = @mobile
130
+ separate_parts_without_jpmobile
131
+ end
132
+
124
133
  alias_method :encoded_without_jpmobile, :encoded
125
134
  alias_method :encoded, :encoded_with_jpmobile
126
135
 
@@ -130,6 +139,9 @@ module Mail
130
139
  alias_method :process_body_raw_without_jpmobile, :process_body_raw
131
140
  alias_method :process_body_raw, :process_body_raw_with_jpmobile
132
141
 
142
+ alias_method :separate_parts_without_jpmobile, :separate_parts
143
+ alias_method :separate_parts, :separate_parts_with_jpmobile
144
+
133
145
  # -- docomo
134
146
  # multipart/mixed
135
147
  # |- multipart/related
@@ -230,34 +242,23 @@ module Mail
230
242
  # override charset
231
243
  if self.header[:content_type]
232
244
  content_type_charset = Jpmobile::Util.extract_charset(self.header[:content_type].value)
245
+ @charset = content_type_charset
233
246
  unless content_type_charset.blank?
234
- @charset = content_type_charset
235
247
  self.header[:content_type].parameters[:charset] = @charset
236
248
  @mobile_main_type = self.header[:content_type].main_type
237
249
  end
238
-
239
- if !Jpmobile::Email.convertable?(self.header[:content_type].value) and content_type_charset.blank?
240
- @charset = ''
241
- end
242
250
  end
243
251
 
244
252
  # convert header(s)
245
253
  if self.header[:subject]
246
254
  subject_charset = Jpmobile::Util.extract_charset(self.header[:subject].value)
247
-
248
- # override subject encoding if @charset is blank
249
- @charset = subject_charset if !subject_charset.blank? # and @charset.blank?
250
255
  self.header[:subject].charset = subject_charset unless subject_charset.blank?
251
256
 
252
257
  if @mobile
253
258
  subject_value = Encodings.value_decode(self.header[:subject].value)
254
259
  subject_converting_encoding = Jpmobile::Util.detect_encoding(subject_value)
255
260
  v = @mobile.to_mail_internal(subject_value, subject_converting_encoding)
256
- if @charset == subject_charset and @mobile.mail_charset != @charset
257
- self.header[:subject].value = Jpmobile::Util.force_encode(v, @charset, Jpmobile::Util::UTF8)
258
- else
259
- self.header[:subject].value = Jpmobile::Util.force_encode(v, @mobile.mail_charset(@charset), Jpmobile::Util::UTF8)
260
- end
261
+ self.header[:subject].value = Jpmobile::Util.force_encode(v, @mobile.mail_charset(subject_charset), Jpmobile::Util::UTF8)
261
262
  end
262
263
  end
263
264
 
@@ -322,25 +323,18 @@ module Mail
322
323
  # convert encoding
323
324
  def encoded_with_jpmobile(transfer_encoding = '8bit')
324
325
  if @mobile and !multipart?
325
- if @mobile.to_mail_body_encoded?(@raw_source)
326
- @raw_source
327
- elsif Jpmobile::Util.ascii_8bit?(@raw_source)
326
+ case transfer_encoding
327
+ when /base64/
328
328
  _raw_source = if transfer_encoding == encoding
329
- @raw_source
329
+ @raw_source.dup
330
330
  else
331
- enc = Mail::Encodings::get_encoding(get_best_encoding(transfer_encoding))
332
- enc.encode(@raw_source)
331
+ get_best_encoding(transfer_encoding).encode(@raw_source)
333
332
  end
334
- Jpmobile::Util.force_encode(_raw_source, nil, @charset)
333
+ Jpmobile::Util.set_encoding(_raw_source, @mobile.mail_charset(@charset))
334
+ when /quoted-printable/
335
+ Jpmobile::Util.set_encoding([@mobile.to_mail_body(@raw_source)].pack("M").gsub(/\n/, "\r\n"), @mobile.mail_charset(@charset))
335
336
  else
336
- case transfer_encoding
337
- when /quoted-printable/
338
- # [str].pack("M").gsub(/\n/, "\r\n")
339
- 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)
340
- # @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
341
- else
342
- @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, @charset, Jpmobile::Util::UTF8))
343
- end
337
+ @mobile.to_mail_body(Jpmobile::Util.force_encode(@raw_source, nil, Jpmobile::Util::UTF8))
344
338
  end
345
339
  else
346
340
  encoded_without_jpmobile(transfer_encoding)
@@ -366,9 +360,7 @@ module Mail
366
360
 
367
361
  if self.multipart? and @mobile
368
362
  self.parts.each do |part|
369
- part.charset = @mobile.mail_charset(part.charset)
370
363
  part.mobile = @mobile
371
- part.body.charset = part.charset
372
364
  part.body.mobile = @mobile
373
365
  end
374
366
  end
@@ -382,7 +374,7 @@ module Mail
382
374
 
383
375
  def preamble_with_jpmobile
384
376
  if @mobile
385
- Jpmobile::Util.encode(@preamble, @charset)
377
+ Jpmobile::Util.encode(@preamble, @mobile.mail_charset(@charset))
386
378
  else
387
379
  preamble_without_jpmobile
388
380
  end
@@ -390,7 +382,7 @@ module Mail
390
382
 
391
383
  def epilogue_with_jpmobile
392
384
  if @mobile
393
- Jpmobile::Util.encode(@epilogue, @charset)
385
+ Jpmobile::Util.encode(@epilogue, @mobile.mail_charset(@charset))
394
386
  else
395
387
  epilogue_without_jpmobile
396
388
  end
@@ -398,7 +390,7 @@ module Mail
398
390
 
399
391
  def crlf_boundary_with_jpmobile
400
392
  if @mobile
401
- Jpmobile::Util.encode(crlf_boundary_without_jpmobile, @charset)
393
+ Jpmobile::Util.encode(crlf_boundary_without_jpmobile, @mobile.mail_charset(@charset))
402
394
  else
403
395
  crlf_boundary_without_jpmobile
404
396
  end
@@ -406,7 +398,7 @@ module Mail
406
398
 
407
399
  def end_boundary_with_jpmobile
408
400
  if @mobile
409
- Jpmobile::Util.encode(end_boundary_without_jpmobile, @charset)
401
+ Jpmobile::Util.encode(end_boundary_without_jpmobile, @mobile.mail_charset(@charset))
410
402
  else
411
403
  end_boundary_without_jpmobile
412
404
  end
@@ -435,6 +427,17 @@ module Mail
435
427
 
436
428
  alias_method :epilogue_without_jpmobile, :epilogue
437
429
  alias_method :epilogue, :epilogue_with_jpmobile
430
+
431
+ def split!(boundary)
432
+ self.boundary = boundary
433
+ parts = raw_source.split(/(?:\A|\r\n)--#{Regexp.escape(boundary)}(?=(?:--)?\s*$)/)
434
+ # Make the preamble equal to the preamble (if any)
435
+ self.preamble = parts[0].to_s.strip
436
+ # Make the epilogue equal to the epilogue (if any)
437
+ self.epilogue = parts[-1].to_s.sub('--', '').strip
438
+ parts[1...-1].to_a.each { |part| @parts << Mail::Part.new(:body_raw => part, :mobile => @mobile) }
439
+ self
440
+ end
438
441
  end
439
442
 
440
443
  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?
@@ -23,8 +23,8 @@ module Jpmobile
23
23
  }
24
24
 
25
25
  template_paths.map { |template|
26
- handler, format = extract_handler_and_format(template, formats)
27
- contents = File.binread template
26
+ handler, format, variant = extract_handler_and_format_and_variant(template, formats)
27
+ contents = File.binread(template)
28
28
 
29
29
  if format
30
30
  jpmobile_variant = template.match(/.+#{path}(.+)\.#{format.to_sym.to_s}.*$/) ? $1 : ''
@@ -36,7 +36,9 @@ module Jpmobile
36
36
  ActionView::Template.new(contents, File.expand_path(template), handler,
37
37
  :virtual_path => virtual_path,
38
38
  :format => format,
39
- :updated_at => mtime(template))
39
+ :variant => variant,
40
+ :updated_at => mtime(template)
41
+ )
40
42
  }
41
43
  end
42
44
  end
@@ -1,3 +1,3 @@
1
1
  module Jpmobile
2
- VERSION = "4.1.0.rc1"
2
+ VERSION = "4.1.0"
3
3
  end
@@ -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
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: 4.1.0.rc1
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shin-ichiro OGAWA
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-26 00:00:00.000000000 Z
12
+ date: 2014-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -225,6 +225,7 @@ files:
225
225
  - spec/unit/email-fixtures/docomo-jis.eml
226
226
  - spec/unit/email-fixtures/iphone-mail3.eml
227
227
  - spec/unit/email-fixtures/iphone-message.eml
228
+ - spec/unit/email-fixtures/pc-mail-attached-without-subject.eml
228
229
  - spec/unit/email-fixtures/pc-mail-multi.eml
229
230
  - spec/unit/email-fixtures/pc-mail-single.eml
230
231
  - spec/unit/email-fixtures/photo.jpg
@@ -393,9 +394,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
393
394
  version: '0'
394
395
  required_rubygems_version: !ruby/object:Gem::Requirement
395
396
  requirements:
396
- - - ">"
397
+ - - ">="
397
398
  - !ruby/object:Gem::Version
398
- version: 1.3.1
399
+ version: '0'
399
400
  requirements: []
400
401
  rubyforge_project:
401
402
  rubygems_version: 2.2.2
@@ -432,6 +433,7 @@ test_files:
432
433
  - spec/unit/email-fixtures/docomo-jis.eml
433
434
  - spec/unit/email-fixtures/iphone-mail3.eml
434
435
  - spec/unit/email-fixtures/iphone-message.eml
436
+ - spec/unit/email-fixtures/pc-mail-attached-without-subject.eml
435
437
  - spec/unit/email-fixtures/pc-mail-multi.eml
436
438
  - spec/unit/email-fixtures/pc-mail-single.eml
437
439
  - spec/unit/email-fixtures/photo.jpg