mms2r 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,22 @@
1
+ == 1.0.2 / 2007-03-07
2
+
3
+ * Reorganized tests and fixtures
4
+ * Added carriers:
5
+ * Cingular => cingularme.com
6
+ * Nextel => messaging.nextel.com
7
+ * Verizon => vtext.com
8
+
9
+ == 1.0.2 / 2007-03-07
10
+
11
+ * Flubbed RubyForge release ... do not use this.
12
+
1
13
  == 1.0.0 / 2007-03-06
2
14
 
3
15
  * Birthday!
16
+ * AT&T/Cingular => mmode.com
17
+ * Cingular => mms.mycingular.com
18
+ * Sprint => pm.sprint.com
19
+ * Sprint => messaging.sprintpcs.com
20
+ * T-Mobile => tmomail.net
21
+ * Verizon => vzwpix.com
4
22
 
data/Manifest.txt CHANGED
@@ -3,6 +3,7 @@ Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
5
  conf/mms2r_cingularmedia_transform.yml
6
+ conf/mms2r_nextelmedia_ignore.yml
6
7
  conf/mms2r_sprintmedia_ignore.yml
7
8
  conf/mms2r_tmobilemedia_ignore.yml
8
9
  conf/mms2r_verizonmedia_ignore.yml
@@ -10,6 +11,7 @@ lib/mms2r.rb
10
11
  lib/mms2r/cingular_media.rb
11
12
  lib/mms2r/media.rb
12
13
  lib/mms2r/mmode_media.rb
14
+ lib/mms2r/nextel_media.rb
13
15
  lib/mms2r/sprint_media.rb
14
16
  lib/mms2r/tmobile_media.rb
15
17
  lib/mms2r/verizon_media.rb
@@ -38,17 +40,28 @@ lib/vendor/tmail/scanner_r.rb
38
40
  lib/vendor/tmail/stringio.rb
39
41
  lib/vendor/tmail/tmail.rb
40
42
  lib/vendor/tmail/utils.rb
43
+ test/files/cingularme-text-01.mail
41
44
  test/files/dot.jpg
45
+ test/files/hello_world_mail_multipart.mail
46
+ test/files/hello_world_mail_plain_no_content_type.mail
47
+ test/files/hello_world_mail_plain_with_content_type.mail
48
+ test/files/mmode-image-01.mail
49
+ test/files/nextel-image-01.mail
50
+ test/files/simple_image.mail
51
+ test/files/simple_multipart_alternative.mail
42
52
  test/files/sprint-image-01.mail
43
53
  test/files/sprint-text-01.mail
44
54
  test/files/sprint-video-01.mail
45
55
  test/files/sprint.mov
56
+ test/files/tmobile-image-01.mail
46
57
  test/files/verizon-image-01.mail
47
58
  test/files/verizon-text-01.mail
48
59
  test/files/verizon-video-01.mail
60
+ test/files/vtext-text-01.mail
49
61
  test/test_mms2r_cingular.rb
50
62
  test/test_mms2r_media.rb
51
63
  test/test_mms2r_mmode.rb
64
+ test/test_mms2r_nextel.rb
52
65
  test/test_mms2r_sprint.rb
53
66
  test/test_mms2r_tmobile.rb
54
67
  test/test_mms2r_verizon.rb
data/README.txt CHANGED
@@ -8,47 +8,67 @@ http://mms2r.rubyforge.org/
8
8
 
9
9
  MMS2R is a library that decodes the parts of an MMS message to disk while
10
10
  stripping out advertising injected by the cellphone carriers. MMS messages are
11
- multipart email and the carriers often inject branding into these messages.
11
+ multipart email and the carriers often inject branding into these messages. Use
12
+ MMS2R if you want to get at the real user generated content from a MMS without
13
+ having to deal with the garbage from the carriers.
12
14
 
13
15
  If MMS2R is not aware of a particular carrier no extra processing is done
14
16
  to the MMS other than decoding and consolidating its media.
15
17
 
16
18
  Contact the author to add additional carriers to be processed by the library.
17
19
 
18
- == FEATURES/PROBLEMS:
19
-
20
20
  Corpus of carriers currently processed by MMS2R:
21
21
 
22
22
  * AT&T/Cingular => mmode.com
23
23
  * Cingular => mms.mycingular.com
24
+ * Cingular => cingularme.com
25
+ * Nextel => messaging.nextel.com
24
26
  * Sprint => pm.sprint.com
25
27
  * Sprint => messaging.sprintpcs.com
26
28
  * T-Mobile => tmomail.net
27
29
  * Verizon => vzwpix.com
28
-
30
+ * Verizon => vtext.com
31
+
32
+ == FEATURES/PROBLEMS:
33
+
34
+ TMail from 1.3.1 of ActionMailer is shipped as a vendor library with MMS2R
35
+
29
36
  == SYNOPSIS:
30
37
 
31
38
  require 'rubygems'
32
39
  require 'mms2r'
40
+ require 'mms2r/media'
33
41
  require 'tmail'
34
- media = TMail::Media.parse(IO.readlines("mymail.file").join)
35
- mms = MMS2R::Media.create(mail,Logger.new(STDOUT))
42
+ require 'fileutils'
43
+
44
+ media = TMail::Media.parse(IO.readlines("sample-MMS.file").join)
45
+ mms = MMS2R::Media.create(media,Logger.new(STDOUT))
46
+
47
+ # process finds all the media in a MMS, strips advertsing, then
48
+ # writes the user generated media to disk
36
49
  mms.process
37
- # mms.media is a hash that is indexed by mime-type
38
- # the mime-type key returns an array of filepaths
39
- # to media in the MMS that was of that type
40
- mms.media['image/jpeg'].each {|f| puts "${f}"}
41
- mms.media['text/plain'].each {|f| puts "${f}"}
42
- text = File.open(mms.media['text/plain'][0], 'rb') { |file|
43
- file.read
44
- }
50
+
51
+ # mms.media is a hash that is indexed by mime-type.
52
+ # The mime-type key returns an array of filepaths
53
+ # to media in the MMS that is of that type
54
+ mms.media['image/jpeg'].each {|f| puts "#{f}"}
55
+ mms.media['text/plain'].each {|f| puts "#{f}"}
56
+
57
+ # print the text (assumes MMS had text)
58
+ text = IO.readlines(mms.media['text/plain'][0]).join
45
59
  puts text
60
+
61
+ # save the image (assumes MMS had a jpeg)
62
+ FileUtils.cp mms.media['image/jpeg'][0], '/some/where/use/ful', :verbose => true
63
+
64
+ puts "does the MMS have video? #{!mms.media['video/quicktime'].nil?}"
65
+
46
66
  #remove the media that was put to temporary disk
47
- #mms.purge
67
+ mms.purge
48
68
 
49
69
  == REQUIREMENTS:
50
70
 
51
- * TMail
71
+ * RCov
52
72
  * Hpricot
53
73
 
54
74
  == INSTALL:
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ Hoe.new('mms2r', MMS2R::Media::VERSION) do |p|
13
13
  p.author = 'Mike Mondragon'
14
14
  p.email = 'mike@mondragon.cc'
15
15
  p.summary = 'Extract media from MMS '
16
- p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
16
+ p.description = p.paragraphs_of('README.txt', 2..8).join("\n\n")
17
17
  p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
18
18
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
19
19
  p.extra_deps << ['hpricot']
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  text/plain:
3
- "--\n\
3
+ "\n--\n\
4
4
  ===============================================\n\
5
5
  Brought to you by, Cingular Wireless Messaging\n\
6
- http://www.CingularMe.COM/\n ": ""
6
+ http://www.CingularMe.COM/": ""
@@ -0,0 +1,5 @@
1
+ ---
2
+ text/plain:
3
+ - This is an MMS message. 2006 Sprint Nextel. All rights reserved.
4
+ text/html:
5
+ - <center>This is an MMS message. <br><center> 2006 Sprint Nextel. All rights reserved</center>
data/lib/mms2r/media.rb CHANGED
@@ -10,6 +10,7 @@ require 'mms2r'
10
10
  require 'mms2r/version'
11
11
  require 'mms2r/cingular_media'
12
12
  require 'mms2r/mmode_media'
13
+ require 'mms2r/nextel_media'
13
14
  require 'mms2r/sprint_media'
14
15
  require 'mms2r/tmobile_media'
15
16
  require 'mms2r/verizon_media'
@@ -56,10 +57,13 @@ module MMS2R
56
57
 
57
58
  CARRIER_CLASSES = {
58
59
  'mms.mycingular.com' => MMS2R::CingularMedia,
60
+ 'cingularme.com' => MMS2R::CingularMedia,
59
61
  'mmode.com' => MMS2R::MModeMedia,
62
+ 'messaging.nextel.com' => MMS2R::NextelMedia,
60
63
  'pm.sprint.com' => MMS2R::SprintMedia,
61
64
  'messaging.sprintpcs.com' => MMS2R::SprintMedia,
62
65
  'tmomail.net' => MMS2R::TMobileMedia,
66
+ 'vtext.com' => MMS2R::VerizonMedia,
63
67
  'vzwpix.com' => MMS2R::VerizonMedia
64
68
  }
65
69
 
@@ -111,30 +115,35 @@ module MMS2R
111
115
  # if the part is not base64 encoded.
112
116
  part.base64_decode
113
117
  file = temp_file(part)
114
- content = part.body
115
- content = transform_text(self.class.part_type?(part),content) if self.class.main_type?(part).eql?('text')
118
+ if self.class.main_type?(part).eql?('text')
119
+ type, content = transform_text(part)
120
+ else
121
+ type = self.class.part_type?(part)
122
+ content = part.body
123
+ end
116
124
  @logger.info("#{self.class} writing file #{file}") unless @logger.nil?
117
125
  File.open(file,'w'){ |f|
118
126
  f.write(content)
119
127
  }
120
- type = self.class.part_type?(part)
121
128
  return type, file
122
129
  end
123
130
 
124
131
  ##
125
132
  # Helper for process_media template method to transform text.
126
133
 
127
- def transform_text(type,text)
134
+ def transform_text(part)
135
+ type = self.class.part_type?(part)
136
+ text = part.body
128
137
  f = "#{self.class.name.downcase.gsub(/::/,'_')}_transform.yml"
129
138
  yf = File.join(self.class.conf_dir(), "#{f}")
130
- return text unless File::exist?(yf)
139
+ return type, text unless File::exist?(yf)
131
140
  h = YAML::load_file(yf)
132
141
  a = h[type]
133
- return text if a.nil?
142
+ return type, text if a.nil?
134
143
  a.each do |from,to|
135
144
  text.gsub!(/#{from}/m,to)
136
145
  end
137
- text
146
+ return type, text
138
147
  end
139
148
 
140
149
  ##
@@ -210,6 +219,14 @@ module MMS2R
210
219
  parts = Array.new()
211
220
  parts << @mail
212
221
  end
222
+ parts.each do |p|
223
+ if self.class.part_type?(p).eql?('multipart/alternative')
224
+ part = parts.delete(p)
225
+ part.parts.each do |mp|
226
+ parts << mp
227
+ end
228
+ end
229
+ end
213
230
  parts.each do |p|
214
231
  t = self.class.part_type?(p)
215
232
  unless ignore_media?(t,p)
@@ -0,0 +1,11 @@
1
+ require 'mms2r'
2
+ require 'mms2r/media'
3
+
4
+ module MMS2R
5
+
6
+ ##
7
+ # Nextel version of MMS2R::Media
8
+
9
+ class MMS2R::NextelMedia < MMS2R::Media
10
+ end
11
+ end
@@ -22,8 +22,7 @@ module MMS2R
22
22
  part.base64_decode
23
23
  if self.class.part_type?(part).eql?('text/plain')
24
24
  file_name = filename?(part)
25
- type = 'text/plain'
26
- content = transform_text(type,part.body)
25
+ type, content = transform_text(part)
27
26
  elsif self.class.part_type?(part).eql?('text/html')
28
27
  doc = Hpricot(part.body)
29
28
  trs = doc.search("/html/body//tr")
data/lib/mms2r/version.rb CHANGED
@@ -6,7 +6,7 @@ module MMS2R
6
6
  ##
7
7
  # MMS2R Library version
8
8
 
9
- VERSION = '1.0.0'
9
+ VERSION = '1.0.2'
10
10
 
11
11
  end
12
12
  end
@@ -0,0 +1,13 @@
1
+ From: 2068675309@cingularme.com
2
+ To: tommytutone@example.com
3
+ Subject:
4
+ X-OPWV-Extra-Message-Type: MO
5
+ Message-Id: <01234567890123.ABCD4567.foobar01.cingularme.com@cingularme.com>
6
+ Date: Wed, 7 Feb 2007 00:39:36 -0500
7
+
8
+ hello world
9
+
10
+ --
11
+ ===============================================
12
+ Brought to you by, Cingular Wireless Messaging
13
+ http://www.CingularMe.COM/
@@ -0,0 +1,17 @@
1
+ Message-Id: <00000000000002.0123456789@mx.mms.example.com>
2
+ Mime-Version: 1.0
3
+ From: 2068675309@mms.example.com
4
+ To: tommytutone@example.com
5
+ Subject: text only
6
+ Date: Thu, 11 Jan 2007 02:28:22 -0500
7
+ Content-Type: multipart/mixed; boundary="----=_Part_1061064_5544954.1168500502466"
8
+
9
+ ------=_Part_1061064_5544954.1168500502466
10
+ Content-Type: text/plain; charset=utf-8
11
+ Content-Transfer-Encoding: base64
12
+ Content-Location: hello_world.txt
13
+ Content-Disposition: inline
14
+
15
+ aGVsbG8gd29ybGQ=
16
+ ------=_Part_1061064_5544954.1168500502466--
17
+
@@ -0,0 +1,7 @@
1
+ From:2068675309@mms.example.com
2
+ To:tommytutone@example.com
3
+ Subject: text only
4
+ Message-Id: <00000000000001.0123456789@mx.mms.example.com>
5
+ Date: Wed, 10 Jan 2007 08:18:30 -0600 (CST)
6
+
7
+ hello world
@@ -0,0 +1,8 @@
1
+ From:2068675309@mms.example.com
2
+ To:tommytutone@example.com
3
+ Subject: text only
4
+ Message-Id: <00000000000001.0123456789@mx.mms.example.com>
5
+ Content-Type: text/plain; charset=utf-8
6
+ Date: Wed, 10 Jan 2007 08:18:30 -0600 (CST)
7
+
8
+ hello world
@@ -0,0 +1,36 @@
1
+ Message-Id: <0123456.7890123456789.JavaMail.foot@st-09>
2
+ Date: Sat, 16 Sep 2006 08:05:47 -0600 (GMT-06:00)
3
+ From: 12068675309@mmode.com
4
+ To: tommytutone@example.com
5
+ Subject: Picture(3).jpg
6
+ Mime-Version: 1.0
7
+ Content-Type: multipart/mixed;
8
+ boundary="----=_Part_012345_678901.1231231231239"
9
+ X-Mms-Delivery-Report: no
10
+ X-Mms-Delivery-Time: Sat, 16 Sep 2006 08:05:47 -0600 (GMT-06:00)
11
+ X-Mms-MMS-Version: 1.0
12
+ X-Mms-Message-Class: Personal
13
+ X-Mms-Message-Type: m-send-req
14
+ X-Mms-Message-Size: 33774
15
+ X-Mms-Read-Reply: no
16
+ X-Mms-Sender-Visibility: Show
17
+ X-Mms-Transaction-ID: 3-1fac@mms.mmode.com
18
+ X-Mms-Message-ID: 12345678@mms.mmode.com
19
+ X-Priority: 3
20
+
21
+ ------=_Part_012345_678901.1231231231239
22
+ Content-Type: image/jpeg; name="picture(3).jpg"
23
+ Content-Transfer-Encoding: base64
24
+ Content-ID: <picture(3).jpg>
25
+ Content-Location: picture(3).jpg
26
+ Content-Disposition: attachment
27
+
28
+ /9j/4AAQSkZJRgABAQEASABIAAD/4QAWRXhpZgAATU0AKgAAAAgAAAAAAAD//gAXQ3JlYXRl
29
+ ZCB3aXRoIFRoZSBHSU1Q/9sAQwAFAwQEBAMFBAQEBQUFBgcMCAcHBwcPCwsJDBEPEhIRDxER
30
+ ExYcFxMUGhURERghGBodHR8fHxMXIiQiHiQcHh8e/9sAQwEFBQUHBgcOCAgOHhQRFB4eHh4e
31
+ Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e/8AAEQgAAQAB
32
+ AwEiAAIRAQMRAf/EABUAAQEAAAAAAAAAAAAAAAAAAAAH/8QAFBABAAAAAAAAAAAAAAAAAAAA
33
+ AP/EABUBAQEAAAAAAAAAAAAAAAAAAAcI/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQAC
34
+ EQMRAD8AlgA6WW//2Q==
35
+ ------=_Part_012345_678901.1231231231239--
36
+
@@ -0,0 +1,46 @@
1
+ Content-Type: multipart/related; boundary="01ab23456c78qwerty_0000"; type="multipart/alternative"
2
+ To: <tommytutone@example.com>
3
+ Date: Sun, 04 Feb 2007 05:38:37 GMT
4
+ From: 2068675309@messaging.nextel.com
5
+ Sender: "2068675309" <2068675309@messaging.nextel.com>
6
+ X-Priority: 3
7
+ MIME-Version: 1.0
8
+ Message-Id: <01234567890123.ABCD4567.fofofo03.messaging.nextel.com@fofozzzz>
9
+
10
+ This is a multi-part message in MIME format.
11
+
12
+ --01ab23456c78qwerty_0000
13
+ Content-Type: multipart/alternative; boundary="abcd_0123456789_abcdefg"
14
+
15
+
16
+ --abcd_0123456789_abcdefg
17
+ Content-Type: text/plain; charset="utf-8"
18
+
19
+ This is an MMS message. 2006 Sprint Nextel. All rights reserved.
20
+
21
+ --abcd_0123456789_abcdefg
22
+ Content-Type: text/html; charset="utf-8"
23
+
24
+ <html><body>
25
+
26
+ <center>This is an MMS message. <br><center> 2006 Sprint Nextel. All rights reserved</center><br><img src="cid:Jan15_0001.jpg.jpg" border="0" alt="Jan15_0001.jpg"><p>
27
+ <p><br><p>
28
+ </center>
29
+ </body></html>
30
+
31
+ --abcd_0123456789_abcdefg--
32
+
33
+ --01ab23456c78qwerty_0000
34
+ Content-ID: <Jan15_0001.jpg.jpg>
35
+ Content-Type: image/jpeg; name="Jan15_0001.jpg"
36
+ Content-Disposition: inline; filename="Jan15_0001.jpg"
37
+ Content-Transfer-Encoding: base64
38
+
39
+ /9j/4AAQSkZJRgABAQEASABIAAD/4QAWRXhpZgAATU0AKgAAAAgAAAAAAAD//gAXQ3JlYXRl
40
+ ZCB3aXRoIFRoZSBHSU1Q/9sAQwAFAwQEBAMFBAQEBQUFBgcMCAcHBwcPCwsJDBEPEhIRDxER
41
+ ExYcFxMUGhURERghGBodHR8fHxMXIiQiHiQcHh8e/9sAQwEFBQUHBgcOCAgOHhQRFB4eHh4e
42
+ Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e/8AAEQgAAQAB
43
+ AwEiAAIRAQMRAf/EABUAAQEAAAAAAAAAAAAAAAAAAAAH/8QAFBABAAAAAAAAAAAAAAAAAAAA
44
+ AP/EABUBAQEAAAAAAAAAAAAAAAAAAAcI/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQAC
45
+ EQMRAD8AlgA6WW//2Q==
46
+ --01ab23456c78qwerty_0000--
@@ -0,0 +1,19 @@
1
+ Mime-Version: 1.0
2
+ Message-Id: <00000000000001.0123456789@mx.mms.example.com>
3
+ Date: Sun, 29 Oct 2006 20:40:30 -0800 (PST)
4
+ To: tommytutone@example.com
5
+ From: 2068675309@mms.example.com
6
+ Subject: image test
7
+ Content-Type: multipart/related; type="multipart/alternative";
8
+ boundary="----=_Part_1224755_98719.1162204830872"; start="<SMIL.TXT>"
9
+ X-Mms-Delivery-Report: no
10
+
11
+ ------=_Part_1224755_98719.1162204830872
12
+ Content-Type: image/gif; name=spacer.gif
13
+ Content-Transfer-Encoding: base64
14
+ Content-Disposition: attachment; filename=spacer.gif
15
+ Content-ID: <spacer.gif>
16
+
17
+ R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
18
+ ------=_Part_1224755_98719.1162204830872--
19
+