mms2r 3.8.2 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ ### 3.9.0 / 2012-10-18 (Jean-Pierre - A French chef)
2
+
3
+ * 1 minor enhancement
4
+ * refined character encoding capability with 1.8 rubies and 1.9 rubies.
5
+
1
6
  ### 3.8.2 / 2012-08-21 (Seth - Pickles The Drummer's brother)
2
7
 
3
8
  * 2 minor enhancements
@@ -105,7 +105,7 @@ OUT
105
105
 
106
106
  end
107
107
 
108
- %W{ yaml mail fileutils pathname tmpdir yaml digest/sha1 iconv exifr }.each do |g|
108
+ %W{ yaml mail fileutils pathname tmpdir yaml digest/sha1 exifr }.each do |g|
109
109
  begin
110
110
  require g
111
111
  rescue LoadError
@@ -265,18 +265,21 @@ module MMS2R
265
265
 
266
266
  def body
267
267
  text_file = default_text
268
- @body = text_file ? IO.readlines(text_file.path).join.strip : ""
269
- @body.force_encoding("ISO-8859-1") if RUBY_VERSION >= "1.9" && @body.encoding == "ASCII-8BIT"
270
268
 
271
- begin
272
- ic = Iconv.new('UTF-8', 'ISO-8859-1' )
269
+ if RUBY_VERSION < "1.9"
270
+ @body = text_file ? IO.read(text_file.path).strip : ""
271
+ require 'iconv'
272
+ ic = Iconv.new('UTF-8', 'ISO-8859-1')
273
273
  @body = ic.iconv(@body)
274
274
  @body << ic.iconv(nil)
275
275
  ic.close
276
- rescue Exception => e
276
+ else
277
+ @body = text_file ? IO.read(text_file.path, :mode => "rb").strip : ""
278
+ @body = @body.chars.select{|i| i.valid_encoding?}.join
277
279
  end
278
280
 
279
- if @body.blank? && html_file = default_html
281
+ if @body.blank? &&
282
+ html_file = default_html
280
283
  html = Nokogiri::HTML(IO.read(html_file.path))
281
284
  @body = (html.xpath("//head/title").map(&:text) + html.xpath("//body/*").map(&:text)).join(" ")
282
285
  end
@@ -402,7 +405,6 @@ module MMS2R
402
405
  if part.part_type? =~ /^text\// ||
403
406
  part.part_type? == 'application/smil'
404
407
  type, content = transform_text_part(part)
405
- mode = 'wb'
406
408
  else
407
409
  if part.part_type? == 'application/octet-stream'
408
410
  type = type_from_filename(filename?(part))
@@ -410,12 +412,11 @@ module MMS2R
410
412
  type = part.part_type?
411
413
  end
412
414
  content = part.body.decoded
413
- mode = 'wb' # open with binary bit for Windows for non text
414
415
  end
415
416
  return type, nil if content.nil? || content.empty?
416
417
 
417
418
  log("#{self.class} writing file #{file}", :info)
418
- File.open(file, mode){ |f| f.write(content) }
419
+ File.open(file, 'wb'){ |f| f.write(content) }
419
420
  return type, file
420
421
  end
421
422
 
@@ -443,26 +444,25 @@ module MMS2R
443
444
  # See the transform section in the discussion of the built-in
444
445
  # configuration.
445
446
 
446
- def transform_text(type, text, original_encoding = 'ISO-8859-1')
447
+ def transform_text(type, text)
447
448
  return type, text if !config['transform'] || !(transforms = config['transform'][type])
448
449
 
449
- begin
450
- ic = Iconv.new('UTF-8', original_encoding )
451
- utf_t = ic.iconv(text)
452
- utf_t << ic.iconv(nil)
450
+ if RUBY_VERSION < "1.9"
451
+ require 'iconv'
452
+ ic = Iconv.new('UTF-8', 'ISO-8859-1')
453
+ text = ic.iconv(text)
454
+ text << ic.iconv(nil)
453
455
  ic.close
454
- rescue Exception => e
455
- utf_t = text
456
456
  end
457
457
 
458
458
  transforms.each do |transform|
459
459
  next unless transform.size == 2
460
460
  p = transform.first
461
461
  r = transform.last
462
- utf_t = utf_t.gsub(p, r) rescue utf_t
462
+ text = text.gsub(p, r) rescue text
463
463
  end
464
464
 
465
- return type, utf_t
465
+ return type, text
466
466
  end
467
467
 
468
468
  ##
@@ -6,11 +6,11 @@ module MMS2R
6
6
  end
7
7
 
8
8
  def self.minor
9
- 8
9
+ 9
10
10
  end
11
11
 
12
12
  def self.patch
13
- 2
13
+ 0
14
14
  end
15
15
 
16
16
  def self.pre
@@ -1 +1 @@
1
- {"totalMediaItems":2,"shareType":"normal","nomediaItem":"false","isOnlyVideo":null,"creationDate":"May 31, 2012","from":"(513)545-0000","offset":null,"externalMessageId":"XXXXXXXXXXXXXXXXXX","Results":[{"elementID":"0","hasVoiceCaption":false,"URL":{"elementID":"0","indexCount":0,"audio":null,"thumb":"\/retailers\/PCSNEXTEL\/ui-refresh\/images\/background\/slide_no_media_90x90.gif","annotationVoiceID":null,"image":"\/retailers\/PCSNEXTEL\/ui-refresh\/images\/background\/slide_no_media_90x90.gif","video":null},"description":"First text content. ","mediaItemNum":0,"isDRMProtected":false,"externalMessageId":"XXXXXXXXXXXXXXXXXX","mediaType":"TEXT","restOperation":"false","folderFullName":"\/RECIPIENT"},{"elementID":"3","hasVoiceCaption":false,"URL":{"elementID":"3","indexCount":1,"audio":"","thumb":"http:\/\/pictures.sprintpcs.com:80\/mmps\/048_0736849c3f1a9d27_1\/3.jpg?partExt=.jpg&&&outquality=90&ext=.jpg&&size=40,40&squareoutput=255,255,255&aspectcrop=0.5,0.5,1.0,1.0,1.0","annotationVoiceID":null,"image":"http:\/\/pictures.sprintpcs.com:80\/mmps\/048_0736849c3f1a9d27_1\/3.jpg?partExt=.jpg&&&outquality=90&ext=.jpg","video":""},"description":"Second text content. ","mediaItemNum":1,"isDRMProtected":false,"externalMessageId":"XXXXXXXXXXXXXXXXXX","mediaType":"IMAGE","restOperation":"false","folderFullName":"\/RECIPIENT"}],"invite":null,"tmemo":null,"toAddress":"textinsubmit@gmail.com","mediaIndex":0,"subject":"New Message","isDRMProtected":false,"expirationDate":"Expires in 57 Days","voiceURL":null,"guest":"true","folderFullName":"\/RECIPIENT"}
1
+ {"totalMediaItems":2,"shareType":"normal","nomediaItem":"false","isOnlyVideo":null,"creationDate":"May 31, 2012","from":"(513)545-0000","offset":null,"externalMessageId":"XXXXXXXXXXXXXXXXXX","Results":[{"elementID":"0","hasVoiceCaption":false,"URL":{"elementID":"0","indexCount":0,"audio":null,"thumb":"\/retailers\/PCSNEXTEL\/ui-refresh\/images\/background\/slide_no_media_90x90.gif","annotationVoiceID":null,"image":"\/retailers\/PCSNEXTEL\/ui-refresh\/images\/background\/slide_no_media_90x90.gif","video":null},"description":"First text content.","mediaItemNum":0,"isDRMProtected":false,"externalMessageId":"XXXXXXXXXXXXXXXXXX","mediaType":"TEXT","restOperation":"false","folderFullName":"\/RECIPIENT"},{"elementID":"3","hasVoiceCaption":false,"URL":{"elementID":"3","indexCount":1,"audio":"","thumb":"http:\/\/pictures.sprintpcs.com:80\/mmps\/048_0736849c3f1a9d27_1\/3.jpg?partExt=.jpg&&&outquality=90&ext=.jpg&&size=40,40&squareoutput=255,255,255&aspectcrop=0.5,0.5,1.0,1.0,1.0","annotationVoiceID":null,"image":"http:\/\/pictures.sprintpcs.com:80\/mmps\/048_0736849c3f1a9d27_1\/3.jpg?partExt=.jpg&&&outquality=90&ext=.jpg","video":""},"description":"Second text content. ","mediaItemNum":1,"isDRMProtected":false,"externalMessageId":"XXXXXXXXXXXXXXXXXX","mediaType":"IMAGE","restOperation":"false","folderFullName":"\/RECIPIENT"}],"invite":null,"tmemo":null,"toAddress":"textinsubmit@gmail.com","mediaIndex":0,"subject":"New Message","isDRMProtected":false,"expirationDate":"Expires in 57 Days","voiceURL":null,"guest":"true","folderFullName":"\/RECIPIENT"}
@@ -6,21 +6,9 @@ class TestInvalidByteSeqOutlook < Test::Unit::TestCase
6
6
  def test_bad_outlook
7
7
  mail = mail('invalid-byte-seq-outlook.mail')
8
8
  mms = MMS2R::Media.new(mail)
9
- body = mms.body
10
- =begin
11
9
 
12
- assert_equal "+919812345678", mms.number
13
- assert_equal "1nbox.net", mms.carrier
14
- assert_equal 2, mms.media.size
15
-
16
- assert_not_nil mms.media['text/plain']
17
- assert_equal 1, mms.media['text/plain'].size
18
- assert_equal "testing123456789012", open(mms.media['text/plain'].first).read
19
-
20
- assert_not_nil mms.media['image/jpeg']
21
- assert_equal 1, mms.media['text/plain'].size
22
- assert_match(/@003\.jpg$/, mms.media['image/jpeg'].first)
23
- =end
10
+ assert_equal "RE: Issue 14794:Don M. says.. Aaron - I completed RNS Test Question 3, which was done as a 'Cargo Control Number' query. H", mms.subject
11
+ assert_match /Don Doe said less than a minute ago/im, mms.body
24
12
 
25
13
  mms.purge
26
14
  end
@@ -14,7 +14,7 @@ class TestMessagingSprintpcsCom < Test::Unit::TestCase
14
14
  file = mms.media['text/plain'][0]
15
15
  assert_not_nil file
16
16
  assert File::exist?(file), "file #{file} does not exist"
17
- text = IO.readlines("#{file}").join
17
+ text = IO.read("#{file}")
18
18
  assert_match(/hello world/, text)
19
19
  mms.purge
20
20
  end
@@ -233,20 +233,16 @@ class TestMms2rMedia < Test::Unit::TestCase
233
233
  file = mms.media['text/plain'][0]
234
234
  assert_not_nil file
235
235
  assert_equal true, File::exist?(file)
236
- text_lines = IO.readlines("#{file}")
237
- text = text_lines.join
238
-
239
- # ASCII-8BIT -> D'ici un mois G\xE9orgie
240
- # UTF-8 -> D'ici un mois Géorgie
241
-
242
236
  if RUBY_VERSION < "1.9"
243
- assert_equal("sample email message Fwd: sub D'ici un mois Géorgie", mms.subject)
244
- assert_equal("D'ici un mois Géorgie body", text_lines.first.strip)
237
+ text = IO.read("#{file}")
245
238
  else
246
- assert_equal(Iconv.new('UTF-8', 'ISO-8859-1').iconv("sample email message Fwd: sub D'ici un mois Géorgie"), mms.subject)
247
- assert_equal(Iconv.new('UTF-8', 'ISO-8859-1').iconv("D'ici un mois G\xE9orgie body"), text_lines.first.strip)
239
+ text = IO.read("#{file}", :mode => "rb")
248
240
  end
249
241
 
242
+ # ASCII-8BIT -> D'ici un mois G\xE9orgie
243
+ # UTF-8 -> D'ici un mois Géorgie
244
+
245
+ assert_equal("sample email message Fwd: sub D'ici un mois Géorgie", mms.subject)
250
246
  end
251
247
 
252
248
  def test_subject
@@ -103,7 +103,7 @@ class TestMmsAttNet < Test::Unit::TestCase
103
103
  assert_equal "example.com", mms.carrier
104
104
 
105
105
  assert_not_nil mms.media['text/plain']
106
- assert_equal "Hello world", IO.readlines(mms.media['text/plain'].first).join.strip
106
+ assert_equal "Hello world", IO.read(mms.media['text/plain'].first).strip
107
107
 
108
108
  assert_not_nil mms.media['image/jpeg'].first
109
109
  assert_match(/\/BC-WAKE\.jpg$/, mms.media['image/jpeg'].first)
@@ -118,7 +118,7 @@ class TestMmsAttNet < Test::Unit::TestCase
118
118
  assert_equal 2, mms.media.size
119
119
 
120
120
  assert_not_nil mms.media['text/plain']
121
- assert_match(/^Testing memorymail from my blackberry and at&t.$/, IO.readlines(mms.media['text/plain'].first).join.strip)
121
+ assert_match(/^Testing memorymail from my blackberry and at&t.$/, IO.read(mms.media['text/plain'].first).strip)
122
122
 
123
123
  assert_not_nil mms.media['image/jpeg'].first
124
124
  assert_match(/IMG00367.jpg/, mms.media['image/jpeg'].first)
@@ -48,7 +48,7 @@ class TestMmsMycricketCom < Test::Unit::TestCase
48
48
 
49
49
  file = mms.media['text/plain'].first
50
50
  assert_equal true, File::exist?(file), "file #{file} does not exist"
51
- text = IO.readlines("#{file}").join
51
+ text = IO.read("#{file}")
52
52
  assert_match(/Hello World/, text)
53
53
 
54
54
  assert_match(/02-14-08_2114.jpg$/, mms.media['image/jpeg'].first)
@@ -24,7 +24,7 @@ class TestMmsUsccNet < Test::Unit::TestCase
24
24
  file = mms.media['text/plain'][0]
25
25
  assert_not_nil file
26
26
  assert_equal true, File::exist?(file)
27
- text = IO.readlines("#{file}").join
27
+ text = IO.read("#{file}")
28
28
  assert_match(/This is what i do at work most the day/, text)
29
29
 
30
30
  mms.purge
@@ -58,7 +58,7 @@ class TestOrangemmsNet < Test::Unit::TestCase
58
58
  assert_equal 1, mms.media['text/plain'].size
59
59
  file = mms.media['text/plain'].first
60
60
  assert File::exist?(file), "file #{file} does not exist"
61
- text = IO.readlines("#{file}").join
61
+ text = IO.read("#{file}")
62
62
  assert_match(/Test ma poule/, text)
63
63
 
64
64
  # image
@@ -100,7 +100,7 @@ class TestOrangemmsNet < Test::Unit::TestCase
100
100
  file = mms.media['text/plain'][0]
101
101
  assert_not_nil file
102
102
  assert File::exist?(file), "file #{file} does not exist"
103
- text = IO.readlines("#{file}").join
103
+ text = IO.read("#{file}")
104
104
  assert_match(/pozdro600/, text)
105
105
  mms.purge
106
106
  end
@@ -242,7 +242,7 @@ class TestPmSprintCom < Test::Unit::TestCase
242
242
  assert_equal 2, mms.media['text/plain'].size
243
243
 
244
244
  # test that the message was extracted from the ajax response
245
- message = IO.readlines(mms.media['text/plain'].first).join("")
245
+ message = IO.read(mms.media['text/plain'].first)
246
246
  assert_equal "First text content.", message
247
247
 
248
248
  # test that the &nbsp; was removed ()
@@ -20,7 +20,7 @@ class TestPxtVodafoneNetNz < Test::Unit::TestCase
20
20
  file = @mms.media['text/plain'][0]
21
21
  assert_not_nil(file)
22
22
  assert(File::exist?(file), "file #{file} does not exist")
23
- text = IO.readlines("#{file}").join
23
+ text = IO.read("#{file}")
24
24
  assert_match(/Kia ora ano Luke/, text)
25
25
 
26
26
  assert_match(/Kia ora ano Luke/, @mms.body)
@@ -37,7 +37,7 @@ class TestTmomailNet < Test::Unit::TestCase
37
37
  file = mms.media['text/plain'][0]
38
38
  assert_not_nil file
39
39
  assert File::exist?(file), "file #{file} does not exist"
40
- text = IO.readlines("#{file}").join
40
+ text = IO.read("#{file}")
41
41
  assert_equal "Lillies", text.strip
42
42
 
43
43
  mms.purge
@@ -19,7 +19,7 @@ class TestUnicelCom < Test::Unit::TestCase
19
19
  assert_equal 337, File.size(image)
20
20
 
21
21
  file = mms.media['text/plain'][0]
22
- text = IO.readlines("#{file}").join
22
+ text = IO.read("#{file}")
23
23
  assert_match(/2068675309/, text)
24
24
 
25
25
  mms.purge
@@ -79,7 +79,7 @@ www.verizonwireless.com/getitnow/getpix.}
79
79
  assert_not_nil file
80
80
  assert_equal true, File::exist?(file)
81
81
 
82
- text = IO.readlines("#{file}").join
82
+ text = IO.read("#{file}")
83
83
  assert_match(/hello world/, text)
84
84
  mms.purge
85
85
  end
@@ -102,7 +102,7 @@ www.verizonwireless.com/getitnow/getpix.}
102
102
  file = mms.media['text/plain'][0]
103
103
  assert_not_nil file
104
104
  assert_equal true, File::exist?(file)
105
- text = IO.readlines("#{file}").join
105
+ text = IO.read("#{file}")
106
106
  assert_no_match(/Regexp.escape(@ad_old)/, text)
107
107
  assert_no_match(/Regexp.escape@greet/, text)
108
108
  assert_equal "? Weird", text
@@ -139,7 +139,7 @@ www.verizonwireless.com/getitnow/getpix.}
139
139
  file = mms.media['text/plain'][0]
140
140
  assert_not_nil file
141
141
  assert_equal true, File::exist?(file)
142
- text = IO.readlines("#{file}").join
142
+ text = IO.read("#{file}")
143
143
  assert_match(/hello world/, text)
144
144
  mms.purge
145
145
  end
@@ -151,7 +151,7 @@ www.verizonwireless.com/getitnow/getpix.}
151
151
  assert_equal 'yahoo.com', mms.carrier
152
152
 
153
153
  assert_not_nil mms.media['text/plain']
154
- assert_equal "Wonderful picture!", IO.readlines(mms.media['text/plain'].first).join.strip
154
+ assert_equal "Wonderful picture!", IO.read(mms.media['text/plain'].first).strip
155
155
 
156
156
  assert_not_nil mms.media['image/jpeg'].first
157
157
  assert_match(/\/IMG00016\.jpg$/, mms.media['image/jpeg'].first)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mms2r
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.2
4
+ version: 3.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-22 00:00:00.000000000 Z
12
+ date: 2012-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -375,18 +375,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
375
375
  - - ! '>='
376
376
  - !ruby/object:Gem::Version
377
377
  version: '0'
378
- segments:
379
- - 0
380
- hash: 4273706323397208345
381
378
  required_rubygems_version: !ruby/object:Gem::Requirement
382
379
  none: false
383
380
  requirements:
384
381
  - - ! '>='
385
382
  - !ruby/object:Gem::Version
386
383
  version: '0'
387
- segments:
388
- - 0
389
- hash: 4273706323397208345
390
384
  requirements: []
391
385
  rubyforge_project: mms2r
392
386
  rubygems_version: 1.8.23