mms2r 3.4.1 → 3.5.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.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ ### 3.5.0 / 2011-12-01 (Dr. Milminiman Lamilim Swimwambli - Marriage expert)
2
+
3
+ * 1 major bug fix
4
+ * In Ruby 1.9.X MMS2R::Media::Sprint was not fetching content from Sprint's
5
+ CDN correctly because the implementation of Net::HTTP in 1.9.X passes a
6
+ User-Agent header of "Ruby" to which Sprint responds with a fake 500 -
7
+ with help from James McGrath
8
+
1
9
  ### 3.4.1 / 2011-11-06 (Fatty Ding-Dongs, Dethklok foster child)
2
10
 
3
11
  * 2 major enhancements
data/conf/mms2r_media.yml CHANGED
@@ -72,5 +72,5 @@ device_types:
72
72
  software:
73
73
  :blackberry: !ruby/regexp /^Rim Exif/i
74
74
  filenames:
75
- :iphone: !ruby/regexp /^photo\.(JPG|PNG)$/i
75
+ :iphone: !ruby/regexp /^photo\.(JPG|PNG)$/
76
76
  :video: !ruby/regexp /\.3gp$/
data/lib/mms2r.rb CHANGED
@@ -39,8 +39,12 @@ module MMS2R
39
39
  ##
40
40
  # MMS2R library version
41
41
 
42
- VERSION = '3.4.1'
42
+ VERSION = '3.5.0'
43
43
 
44
+ ##
45
+ # Spoof User-Agent, primarily for the Sprint CDN
46
+
47
+ USER_AGENT = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C28 Safari/419.3"
44
48
  end
45
49
 
46
50
  # Simple convenience function to make it a one-liner:
@@ -130,17 +130,21 @@ module MMS2R
130
130
  srcs.each do |src|
131
131
  begin
132
132
 
133
- url = URI.parse(CGI.unescapeHTML(src))
133
+ uri = URI.parse(CGI.unescapeHTML(src))
134
134
  unless @is_video
135
135
  query={}
136
- url.query.split('&').each{|a| p=a.split('='); query[p[0]] = p[1]}
136
+ uri.query.split('&').each{|a| p=a.split('='); query[p[0]] = p[1]}
137
137
  query.delete_if{|k, v| k == 'limitsize' or k == 'squareoutput' }
138
- url.query = query.map{|k,v| "#{k}=#{v}"}.join("&")
138
+ uri.query = query.map{|k,v| "#{k}=#{v}"}.join("&")
139
139
  end
140
140
  # sprint is a ghetto, they expect to see & for video request
141
- url.query = url.query.gsub(/&/, "&") if @is_video
141
+ uri.query = uri.query.gsub(/&/, "&") if @is_video
142
142
 
143
- res = Net::HTTP.get_response(url)
143
+ connection = Net::HTTP.new(uri.host, uri.port)
144
+ response, content = connection.get(
145
+ uri.request_uri,
146
+ { "User-Agent" => MMS2R::Media::USER_AGENT }
147
+ )
144
148
  rescue StandardError => err
145
149
  log("#{self.class} processing error, #{$!}", :error)
146
150
  next
@@ -148,19 +152,19 @@ module MMS2R
148
152
 
149
153
  # if the Sprint content server uses response code 500 when the content is purged
150
154
  # the content type will text/html and the body will be the message
151
- if res.content_type == 'text/html' && res.code == "500"
155
+ if response.content_type == 'text/html' && response.code == "500"
152
156
  log("Sprint content server returned response code 500", :error)
153
157
  next
154
158
  end
155
159
 
156
160
  # setup the file path and file
157
161
  base = /\/RECIPIENT\/([^\/]+)\//.match(src)[1]
158
- type = res.content_type
162
+ type = response.content_type
159
163
  file_name = "#{base}-#{cnt}.#{self.class.default_ext(type)}"
160
164
  file = File.join(msg_tmp_dir(),File.basename(file_name))
161
165
 
162
166
  # write it and add it to the media hash
163
- type, file = sprint_write_file(type, res.body, file)
167
+ type, file = sprint_write_file(type, content, file)
164
168
  add_file(type, file) unless type.nil? || file.nil?
165
169
  cnt = cnt + 1
166
170
  end
@@ -43,6 +43,10 @@ class TestMms2rMedia < Test::Unit::TestCase
43
43
  end
44
44
  end
45
45
 
46
+ def test_faux_user_agent
47
+ assert_equal "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C28 Safari/419.3", MMS2R::Media::USER_AGENT
48
+ end
49
+
46
50
  def test_class_parse
47
51
  mms = mail('generic.mail')
48
52
  assert_equal ['noreply@rubyforge.org'], mms.from
@@ -4,23 +4,37 @@ class TestPmSprintCom < Test::Unit::TestCase
4
4
  include MMS2R::TestHelper
5
5
 
6
6
  def mock_sprint_image(message_id)
7
- uri = URI.parse('http://pictures.sprintpcs.com//mmps/RECIPIENT/001_2066c7013e7ca833_1/2?wm=1&ext=.jpg&iconifyVideo=true&inviteToken=PE5rJ5PdYzzwk7V7zoXU&outquality=90')
8
- res = mock()
9
- body = mock()
10
- res.expects(:content_type).at_least_once.returns('image/jpeg')
11
- res.expects(:body).once.returns(body)
12
- res.expects(:code).never
13
- Net::HTTP.expects(:get_response).once.returns res
7
+ response = mock('response')
8
+ body = mock('body')
9
+ connection = mock('connection')
10
+ response.expects(:content_type).twice.returns('image/jpeg')
11
+ response.expects(:code).never
12
+ Net::HTTP.expects(:new).with('pictures.sprintpcs.com', 80).once.returns connection
13
+ connection.expects(:get).with(
14
+ # 1.9.2
15
+ # '//mmps/RECIPIENT/001_2066c7013e7ca833_1/2?inviteToken=PE5rJ5PdYzzwk7V7zoXU&outquality=90&ext=.jpg&iconifyVideo=true&wm=1'
16
+ # 1.8.7
17
+ # '//mmps/RECIPIENT/001_2066c7013e7ca833_1/2?wm=1&ext=.jpg&outquality=90&iconifyVideo=true&inviteToken=PE5rJ5PdYzzwk7V7zoXU'
18
+ kind_of(String),
19
+ { "User-Agent" => MMS2R::Media::USER_AGENT }
20
+ ).once.returns([response, body])
14
21
  end
15
22
 
16
23
  def mock_sprint_purged_image(message_id)
17
- uri = URI.parse('http://pictures.sprintpcs.com//mmps/RECIPIENT/001_2066c7013e7ca833_1/2?wm=1&ext=.jpg&iconifyVideo=true&inviteToken=PE5rJ5PdYzzwk7V7zoXU&outquality=90')
18
- res = mock()
19
- body = mock()
20
- res.expects(:content_type).once.returns('text/html')
21
- res.expects(:code).once.returns('500')
22
- res.expects(:body).never
23
- Net::HTTP.expects(:get_response).once.returns res
24
+ response = mock('response')
25
+ body = mock('body')
26
+ connection = mock('connection')
27
+ response.expects(:content_type).once.returns('text/html')
28
+ response.expects(:code).once.returns('500')
29
+ Net::HTTP.expects(:new).with('pictures.sprintpcs.com', 80).once.returns connection
30
+ connection.expects(:get).with(
31
+ # 1.9.2
32
+ # '//mmps/RECIPIENT/001_2066c7013e7ca833_1/2?inviteToken=PE5rJ5PdYzzwk7V7zoXU&outquality=90&ext=.jpg&iconifyVideo=true&wm=1'
33
+ # 1.8.7
34
+ # '//mmps/RECIPIENT/001_2066c7013e7ca833_1/2?wm=1&ext=.jpg&outquality=90&iconifyVideo=true&inviteToken=PE5rJ5PdYzzwk7V7zoXU'
35
+ kind_of(String),
36
+ { "User-Agent" => MMS2R::Media::USER_AGENT }
37
+ ).once.returns([response, body])
24
38
  end
25
39
 
26
40
  def test_mms_should_have_text
@@ -50,14 +64,16 @@ class TestPmSprintCom < Test::Unit::TestCase
50
64
  def test_should_have_simple_video
51
65
  mail = mail('sprint-video-01.mail')
52
66
 
53
- uri = URI.parse(
54
- 'http://pictures.sprintpcs.com//mmps/RECIPIENT/000_259e41e851be9b1d_1/2?inviteToken=lEvrJnPVY5UfOYmahQcx&amp;iconifyVideo=true&amp;wm=1&amp;limitsize=125,125&amp;outquality=90&amp;squareoutput=255,255,255&amp;ext=.jpg&amp;iconifyVideo=true&amp;wm=1')
55
- res = mock()
56
- body = mock()
57
- res.expects(:content_type).at_least_once.returns('video/quicktime')
58
- res.expects(:body).once.returns(body)
59
- res.expects(:code).never
60
- Net::HTTP.expects(:get_response).once.returns res
67
+ response = mock('response')
68
+ body = mock('body')
69
+ connection = mock('connection')
70
+ response.expects(:content_type).twice.returns('video/quicktime')
71
+ response.expects(:code).never
72
+ Net::HTTP.expects(:new).with('pictures.sprintpcs.com', 80).once.returns connection
73
+ connection.expects(:get).with(
74
+ kind_of(String),
75
+ { "User-Agent" => MMS2R::Media::USER_AGENT }
76
+ ).once.returns([response, body])
61
77
 
62
78
  mms = MMS2R::Media.new(mail)
63
79
  assert_equal '2068675309', mms.number
@@ -126,22 +142,39 @@ class TestPmSprintCom < Test::Unit::TestCase
126
142
  def test_should_have_two_images
127
143
  mail = mail('sprint-two-images-01.mail')
128
144
 
129
- uri1 = URI.parse('http://pictures.sprintpcs.com/mmps/RECIPIENT/001_104058d23d79fb6a_1/2?wm=1&ext=.jpg&iconifyVideo=true&inviteToken=5E1rJSPk5hYDkUnY7op0&outquality=90')
130
- res1 = mock()
131
- body1 = mock()
132
- res1.expects(:content_type).at_least_once.returns('image/jpeg')
133
- res1.expects(:body).once.returns(body1)
134
- res1.expects(:code).never
135
- Net::HTTP.expects(:get_response).returns res1
136
-
137
- uri2 = URI.parse('http://pictures.sprintpcs.com/mmps/RECIPIENT/001_104058d23d79fb6a_1/3?wm=1&ext=.jpg&iconifyVideo=true&inviteToken=5E1rJSPk5hYDkUnY7op0&outquality=90')
138
-
139
- res2 = mock()
140
- body2 = mock()
141
- res2.expects(:content_type).at_least_once.returns('image/jpeg')
142
- res2.expects(:body).once.returns(body2)
143
- res2.expects(:code).never
144
- Net::HTTP.expects(:get_response).returns res2
145
+ response = mock('response')
146
+ body = mock('body')
147
+ connection = mock('connection')
148
+ response.expects(:content_type).times(4).returns('image/jpeg')
149
+ response.expects(:code).never
150
+ Net::HTTP.expects(:new).with('pictures.sprintpcs.com', 80).twice.returns connection
151
+ connection.expects(:get).with(
152
+ kind_of(String),
153
+ { "User-Agent" => MMS2R::Media::USER_AGENT }
154
+ ).twice.returns([response, body])
155
+
156
+ # response1 = mock('response1')
157
+ # body1 = mock('body1')
158
+ # connection1 = mock('connection1')
159
+ # response1.expects(:content_type).at_least_once.returns('image/jpeg')
160
+ # response1.expects(:code).never
161
+ # Net::HTTP.expects(:new).with('pictures.sprintpcs.com', 80).once.returns connection1
162
+ # connection1.expects(:get).with(
163
+ # kind_of(String),
164
+ # { "User-Agent" => MMS2R::Media::USER_AGENT }
165
+ # ).once.returns([response1, body1])
166
+
167
+ # response2 = mock('response2')
168
+ # body2 = mock('body2')
169
+ # connection2 = mock('connection2')
170
+ # response2.expects(:content_type).at_least_once.returns('image/jpeg')
171
+ # response2.expects(:code).never
172
+ # Net::HTTP.expects(:new).with('pictures.sprintpcs.com', 80).once.returns connection2
173
+ # connection2.expects(:get).with(
174
+ # kind_of(String),
175
+ # { "User-Agent" => MMS2R::Media::USER_AGENT }
176
+ # ).once.returns([response2, body2])
177
+
145
178
  mms = MMS2R::Media.new(mail)
146
179
  assert_equal '2068675309', mms.number
147
180
  assert_equal "pm.sprint.com", mms.carrier
metadata CHANGED
@@ -1,130 +1,109 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mms2r
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.5.0
5
5
  prerelease:
6
- segments:
7
- - 3
8
- - 4
9
- - 1
10
- version: 3.4.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Mike Mondragon
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-06 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-12-02 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: nokogiri
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &20713980 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 15
29
- segments:
30
- - 1
31
- - 4
32
- - 4
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 1.4.4
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: mail
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *20713980
25
+ - !ruby/object:Gem::Dependency
26
+ name: mail
27
+ requirement: &20712840 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 19
45
- segments:
46
- - 2
47
- - 2
48
- - 10
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
49
32
  version: 2.2.10
50
33
  type: :runtime
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: uuidtools
54
34
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *20712840
36
+ - !ruby/object:Gem::Dependency
37
+ name: uuidtools
38
+ requirement: &20711600 !ruby/object:Gem::Requirement
56
39
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 9
61
- segments:
62
- - 2
63
- - 1
64
- - 1
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
65
43
  version: 2.1.1
66
44
  type: :runtime
67
- version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- name: exifr
70
45
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *20711600
47
+ - !ruby/object:Gem::Dependency
48
+ name: exifr
49
+ requirement: &20710280 !ruby/object:Gem::Requirement
72
50
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 17
77
- segments:
78
- - 1
79
- - 0
80
- - 3
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
81
54
  version: 1.0.3
82
55
  type: :runtime
83
- version_requirements: *id004
84
- - !ruby/object:Gem::Dependency
85
- name: hoe
86
56
  prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *20710280
58
+ - !ruby/object:Gem::Dependency
59
+ name: hoe
60
+ requirement: &20708940 !ruby/object:Gem::Requirement
88
61
  none: false
89
- requirements:
62
+ requirements:
90
63
  - - ~>
91
- - !ruby/object:Gem::Version
92
- hash: 27
93
- segments:
94
- - 2
95
- - 12
96
- version: "2.12"
64
+ - !ruby/object:Gem::Version
65
+ version: '2.12'
97
66
  type: :development
98
- version_requirements: *id005
99
- description: |-
100
- == DESCRIPTION
101
-
67
+ prerelease: false
68
+ version_requirements: *20708940
69
+ description: ! '== DESCRIPTION
70
+
71
+
102
72
  MMS2R by Mike Mondragon
73
+
103
74
  http://mms2r.rubyforge.org/
75
+
104
76
  https://github.com/monde/mms2r
77
+
105
78
  https://github.com/monde/mms2r/issues
79
+
106
80
  http://peepcode.com/products/mms2r-pdf
107
-
81
+
82
+
108
83
  MMS2R is a library that decodes the parts of an MMS message to disk while
84
+
109
85
  stripping out advertising injected by the mobile carriers. MMS messages are
86
+
110
87
  multipart email and the carriers often inject branding into these messages. Use
88
+
111
89
  MMS2R if you want to get at the real user generated content from a MMS without
90
+
112
91
  having to deal with the cruft from the carriers.
113
-
92
+
93
+
114
94
  If MMS2R is not aware of a particular carrier no extra processing is done to the
115
- MMS other than decoding and consolidating its media.
116
- email:
95
+
96
+ MMS other than decoding and consolidating its media.'
97
+ email:
117
98
  - mikemondragon@gmail.com
118
99
  executables: []
119
-
120
100
  extensions: []
121
-
122
- extra_rdoc_files:
101
+ extra_rdoc_files:
123
102
  - History.txt
124
103
  - Manifest.txt
125
104
  - README.TMail.txt
126
105
  - README.txt
127
- files:
106
+ files:
128
107
  - .gitignore
129
108
  - Gemfile
130
109
  - Gemfile.lock
@@ -312,39 +291,31 @@ files:
312
291
  - .gemtest
313
292
  homepage: https://github.com/monde/mms2r
314
293
  licenses: []
315
-
316
294
  post_install_message:
317
- rdoc_options:
295
+ rdoc_options:
318
296
  - --main
319
297
  - README.txt
320
- require_paths:
298
+ require_paths:
321
299
  - lib
322
- required_ruby_version: !ruby/object:Gem::Requirement
300
+ required_ruby_version: !ruby/object:Gem::Requirement
323
301
  none: false
324
- requirements:
325
- - - ">="
326
- - !ruby/object:Gem::Version
327
- hash: 3
328
- segments:
329
- - 0
330
- version: "0"
331
- required_rubygems_version: !ruby/object:Gem::Requirement
302
+ requirements:
303
+ - - ! '>='
304
+ - !ruby/object:Gem::Version
305
+ version: '0'
306
+ required_rubygems_version: !ruby/object:Gem::Requirement
332
307
  none: false
333
- requirements:
334
- - - ">="
335
- - !ruby/object:Gem::Version
336
- hash: 3
337
- segments:
338
- - 0
339
- version: "0"
308
+ requirements:
309
+ - - ! '>='
310
+ - !ruby/object:Gem::Version
311
+ version: '0'
340
312
  requirements: []
341
-
342
313
  rubyforge_project: mms2r
343
314
  rubygems_version: 1.8.10
344
315
  signing_key:
345
316
  specification_version: 3
346
317
  summary: Extract user media from MMS (and not carrier cruft)
347
- test_files:
318
+ test_files:
348
319
  - test/test_orangemms_net.rb
349
320
  - test/test_waw_plspictures_com.rb
350
321
  - test/test_mediamessaging_o2_co_uk.rb