mms2r 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +54 -0
  3. data/README.txt +81 -0
  4. data/Rakefile +30 -0
  5. data/conf/mms2r_cingularmedia_transform.yml +6 -0
  6. data/conf/mms2r_sprintmedia_ignore.yml +10 -0
  7. data/conf/mms2r_tmobilemedia_ignore.yml +17 -0
  8. data/conf/mms2r_verizonmedia_ignore.yml +3 -0
  9. data/lib/mms2r.rb +3 -0
  10. data/lib/mms2r/cingular_media.rb +11 -0
  11. data/lib/mms2r/media.rb +345 -0
  12. data/lib/mms2r/mmode_media.rb +13 -0
  13. data/lib/mms2r/sprint_media.rb +50 -0
  14. data/lib/mms2r/tmobile_media.rb +11 -0
  15. data/lib/mms2r/verizon_media.rb +11 -0
  16. data/lib/mms2r/version.rb +12 -0
  17. data/lib/vendor/text/format.rb +1466 -0
  18. data/lib/vendor/tmail.rb +3 -0
  19. data/lib/vendor/tmail/address.rb +242 -0
  20. data/lib/vendor/tmail/attachments.rb +39 -0
  21. data/lib/vendor/tmail/base64.rb +71 -0
  22. data/lib/vendor/tmail/config.rb +69 -0
  23. data/lib/vendor/tmail/encode.rb +467 -0
  24. data/lib/vendor/tmail/facade.rb +552 -0
  25. data/lib/vendor/tmail/header.rb +914 -0
  26. data/lib/vendor/tmail/info.rb +35 -0
  27. data/lib/vendor/tmail/loader.rb +1 -0
  28. data/lib/vendor/tmail/mail.rb +447 -0
  29. data/lib/vendor/tmail/mailbox.rb +433 -0
  30. data/lib/vendor/tmail/mbox.rb +1 -0
  31. data/lib/vendor/tmail/net.rb +280 -0
  32. data/lib/vendor/tmail/obsolete.rb +135 -0
  33. data/lib/vendor/tmail/parser.rb +1522 -0
  34. data/lib/vendor/tmail/port.rb +377 -0
  35. data/lib/vendor/tmail/quoting.rb +131 -0
  36. data/lib/vendor/tmail/scanner.rb +41 -0
  37. data/lib/vendor/tmail/scanner_r.rb +263 -0
  38. data/lib/vendor/tmail/stringio.rb +277 -0
  39. data/lib/vendor/tmail/tmail.rb +1 -0
  40. data/lib/vendor/tmail/utils.rb +238 -0
  41. data/test/files/dot.jpg +0 -0
  42. data/test/files/sprint-image-01.mail +195 -0
  43. data/test/files/sprint-text-01.mail +8 -0
  44. data/test/files/sprint-video-01.mail +195 -0
  45. data/test/files/sprint.mov +0 -0
  46. data/test/files/verizon-image-01.mail +815 -0
  47. data/test/files/verizon-text-01.mail +11 -0
  48. data/test/files/verizon-video-01.mail +336 -0
  49. data/test/test_mms2r_cingular.rb +52 -0
  50. data/test/test_mms2r_media.rb +311 -0
  51. data/test/test_mms2r_mmode.rb +52 -0
  52. data/test/test_mms2r_sprint.rb +154 -0
  53. data/test/test_mms2r_tmobile.rb +169 -0
  54. data/test/test_mms2r_verizon.rb +74 -0
  55. metadata +130 -0
@@ -0,0 +1,52 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'test/unit'
3
+ require 'rubygems'
4
+ require 'mms2r'
5
+ require 'mms2r/media'
6
+ require 'tmail/mail'
7
+ require 'logger'
8
+
9
+ class MMS2RMModeTest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @log = Logger.new(STDOUT)
13
+ @log.level = Logger::DEBUG
14
+ @log.datetime_format = "%H:%M:%S"
15
+
16
+ msg = <<EOF
17
+ Message-ID: <0000000.0000000000001.JavaMail.faalala@lalalala03>
18
+ Mime-Version: 1.0
19
+ From: 12068675309@mmode.com
20
+ To: tommytutone@example.com
21
+ Date: Thu, 11 Jan 2007 02:28:22 -0500
22
+ Subject: image test
23
+ Content-Type: multipart/related; type="multipart/alternative";
24
+ boundary="----=_Part_1224755_98719.1162204830872"; start="<SMIL.TXT>"
25
+ X-Mms-Delivery-Report: no
26
+
27
+ ------=_Part_1224755_98719.1162204830872
28
+ Content-Type: image/gif; name=foo.gif
29
+ Content-Transfer-Encoding: base64
30
+ Content-Disposition: attachment; filename=foo.gif
31
+ Content-ID: <foo.gif>
32
+
33
+ R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
34
+ ------=_Part_1224755_98719.1162204830872--
35
+
36
+ EOF
37
+ @simple_image_mail = TMail::Mail.parse(msg)
38
+ end
39
+
40
+ def teadown; end
41
+
42
+ def test_simple
43
+ mms = MMS2R::Media.create(@simple_image_mail)
44
+ assert_equal(MMS2R::MModeMedia, mms.class, "expected a #{MMS2R::MModeMedia} and received a #{mms.class}")
45
+ mms.process
46
+ assert_not_nil(mms.media['image/gif'])
47
+ file = mms.media['image/gif'][0]
48
+ assert_not_nil(file)
49
+ assert(File::exist?(file), "file #{file} does not exist")
50
+ mms.purge
51
+ end
52
+ end
@@ -0,0 +1,154 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require 'test/unit'
4
+ require 'webrick'
5
+ require 'net/http'
6
+ require 'rubygems'
7
+ require 'mms2r'
8
+ require 'mms2r/media'
9
+ require 'tmail/mail'
10
+ require 'logger'
11
+
12
+ # this style of test was inspired by WWW::Mechanize
13
+
14
+ class SimpleImageServlet < WEBrick::HTTPServlet::AbstractServlet
15
+ def do_GET(req, res)
16
+ res['Content-Type'] = "image/jpeg"
17
+ f = "files/dot.jpg"
18
+ res.body = File.open("#{File.dirname(__FILE__)}/#{f}", 'rb') { |file|
19
+ file.read
20
+ }
21
+ end
22
+ end
23
+
24
+ class SimpleVideoServlet < WEBrick::HTTPServlet::AbstractServlet
25
+ def do_GET(req, res)
26
+ res['Content-Type'] = "video/quicktime"
27
+ f = "files/sprint.mov"
28
+ res.body = File.open("#{File.dirname(__FILE__)}/#{f}", 'rb') { |file|
29
+ file.read
30
+ }
31
+ end
32
+ end
33
+
34
+ class Net::HTTP
35
+
36
+ alias :old_do_start :do_start
37
+
38
+ def do_start
39
+ @started = true
40
+ end
41
+
42
+ SERVLETS = {
43
+ '/simpleimage' => SimpleImageServlet,
44
+ '/simplevideo' => SimpleVideoServlet
45
+ }
46
+
47
+ alias :old_request :request
48
+
49
+ def request(request, *data, &block)
50
+ url = URI.parse(request.path)
51
+ path = url.path.gsub('%20', ' ').match(/^\/[^\/]+/)[0]
52
+ res = Response.new
53
+ request.query = WEBrick::HTTPUtils.parse_query(url.query)
54
+ SERVLETS[path].new({}).send("do_#{request.method}", request, res)
55
+ res.code ||= "200"
56
+ res
57
+ end
58
+ end
59
+
60
+ class Net::HTTPRequest
61
+ attr_accessor :query, :body, :cookies
62
+ end
63
+
64
+ class Response
65
+ include Net::HTTPHeader
66
+
67
+ attr_reader :code
68
+ attr_accessor :body, :query, :cookies
69
+
70
+ def code=(c)
71
+ @code = c.to_s
72
+ end
73
+
74
+ alias :status :code
75
+ alias :status= :code=
76
+
77
+ def initialize
78
+ @header = {}
79
+ @body = ''
80
+ @code = nil
81
+ @query = nil
82
+ @cookies = []
83
+ end
84
+
85
+ def read_body
86
+ yield body
87
+ end
88
+ end
89
+
90
+ class MMS2RSprintTest < Test::Unit::TestCase
91
+
92
+ def setup
93
+ @log = Logger.new(STDOUT)
94
+ @log.level = Logger::DEBUG
95
+ @log.datetime_format = "%H:%M:%S"
96
+ end
97
+
98
+ def teadown; end
99
+
100
+ def test_simple_video
101
+ mail = TMail::Mail.parse(load_mail('sprint-video-01.mail').join)
102
+ mms = MMS2R::Media.create(mail)
103
+ mms.process
104
+
105
+ assert(mms.media.size == 1)
106
+ assert_nil(mms.media['text/plain'])
107
+ assert_nil(mms.media['text/html'])
108
+ assert_not_nil(mms.media['video/quicktime'][0])
109
+ assert_match(/000_0123a01234567895_1.mov$/, mms.media['video/quicktime'][0])
110
+
111
+ file = mms.media['video/quicktime'][0]
112
+ assert_not_nil(file)
113
+ assert(File::exist?(file), "file #{file} does not exist")
114
+ assert(File::size(file) == 49063, "file #{file} not 49063 byts")
115
+ mms.purge
116
+ end
117
+
118
+ def test_simple_image
119
+ mail = TMail::Mail.parse(load_mail('sprint-image-01.mail').join)
120
+ mms = MMS2R::Media.create(mail,@logger)
121
+ mms.process
122
+
123
+ assert(mms.media.size == 1)
124
+ assert_nil(mms.media['text/plain'])
125
+ assert_nil(mms.media['text/html'])
126
+ assert_not_nil(mms.media['image/jpeg'][0])
127
+ assert_match(/000_0123a01234567890_1.jpg$/, mms.media['image/jpeg'][0])
128
+
129
+ file = mms.media['image/jpeg'][0]
130
+ assert_not_nil(file)
131
+ assert(File::exist?(file), "file #{file} does not exist")
132
+ assert(File::size(file) == 337, "file #{file} not 337 byts")
133
+ mms.purge
134
+ end
135
+
136
+ def test_simple_text
137
+ mail = TMail::Mail.parse(load_mail('sprint-text-01.mail').join)
138
+ mms = MMS2R::Media.create(mail)
139
+ assert_equal(MMS2R::SprintMedia, mms.class, "expected a #{MMS2R::SprintMedia} and received a #{mms.class}")
140
+ mms.process
141
+ assert_not_nil(mms.media['text/plain'])
142
+ file = mms.media['text/plain'][0]
143
+ assert_not_nil(file)
144
+ assert(File::exist?(file), "file #{file} does not exist")
145
+ text = IO.readlines("#{file}").join
146
+ assert_match(/hello world/, text)
147
+ mms.purge
148
+ end
149
+
150
+ private
151
+ def load_mail(file)
152
+ IO.readlines("#{File.dirname(__FILE__)}/files/#{file}")
153
+ end
154
+ end
@@ -0,0 +1,169 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'test/unit'
3
+ require 'rubygems'
4
+ require 'mms2r'
5
+ require 'mms2r/media'
6
+ require 'tmail/mail'
7
+ require 'logger'
8
+
9
+ class MMS2RTMobileTest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @log = Logger.new(STDOUT)
13
+ @log.level = Logger::DEBUG
14
+ @log.datetime_format = "%H:%M:%S"
15
+
16
+ msg = <<EOF
17
+ Message-ID: <10234453.0093232090000.JavaMail.mms@lalaaa05>
18
+ From: 2068675309@tmomail.net
19
+ To: tommytutone@example.com
20
+ Subject: ads are bad
21
+ Date: Fri, 29 Dec 2006 17:48:41 -0800
22
+ Mime-Version: 1.0
23
+ Content-Type: multipart/related; type="text/html";
24
+ boundary="----=_Part_6032807_21271850.1167443321223"
25
+ Importance: Normal
26
+ X-MMS-Message-Type: MM4_forward.REQ
27
+ X-Priority: 3
28
+
29
+ ------=_Part_6032807_21271850.1167443321223
30
+ Content-Type: text/html
31
+ Content-Transfer-Encoding: quoted-printable
32
+ Content-ID: <0000>
33
+ Content-Disposition: inline
34
+
35
+ <html>
36
+ <head>
37
+ =09=09<title>T-Mobile</title>=20
38
+ =09=09<!--
39
+ =09=09=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
40
+ =09=09If you can read this text, but much of the message below seems unread=
41
+ able, you might be using an e-mail program that does not work with HTML.
42
+
43
+ =09=09=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D-->
44
+ =09=09<style type=3D"text/css">
45
+ <!--
46
+
47
+ =09=09.footer {
48
+ =09=09=09font-family: Arial, Helvetica, sans-serif;
49
+ =09=09=09font-size: 11px;
50
+ =09=09=09color: #555555;
51
+ =09=09=09text-decoration: none;
52
+ =09=09}
53
+ =09=09.normal {
54
+ =09=09=09font-family: Arial, Helvetica, sans-serif;
55
+ =09=09=09font-size: 10px;
56
+ =09=09=09color: #555555;
57
+ =09=09=09text-decoration: none;
58
+ =09=09}
59
+
60
+ =09=09-->
61
+ =09=09</style>
62
+ =09</head>
63
+ =09<body marginwidth=3D"0" marginheight=3D"0" leftmargin=3D"0" topmargin=3D=
64
+ "0" bgcolor=3D"#ffffff">
65
+ =09=09<table border=3D"0" width=3D"600" cellspacing=3D"0" cellpadding=3D"0"=
66
+ >
67
+ =09=09=09<tr>
68
+ =09=09=09=09<td width=3D"20" rowspan=3D"8"><img src=3D"cid:tmobilespace.gif=
69
+ " width=3D"20" height=3D"20"></td>
70
+ =09=09=09=09<td width=3D"600" colspan=3D"2"><img src=3D"cid:tmobilespace.gi=
71
+ f" width=3D"600" height=3D"20"></td>
72
+ =09=09=09=09<td width=3D"20" rowspan=3D"8"><img src=3D"cid:tmobilespace.gif=
73
+ " width=3D"20" height=3D"20"></td>
74
+ =09=09=09</tr>
75
+ =09=09=09<tr>
76
+ =09=09=09=09<td width=3D"600" colspan=3D"2"><img src=3D"cid:dottedline600.g=
77
+ if" width=3D"600"></td>
78
+ =09=09=09</tr>
79
+ =09=09=09<tr>
80
+ =09=09=09=09<td width=3D"370">
81
+ =09=09=09=09 <!-- presentation starts here -->
82
+ =09=09=09=09 <table border=3D0><tr><tr><td colspan=3D1 align=3D"Left"><IM=
83
+ G align=3Dbaseline alt=3D"" border=3D0 hspace=3D0 src=3D"cid:280"></td></tr=
84
+ ></tr><TR><TD width=3D350 colSpan=3D1><IMG height=3D30 src=3D"cid:tmobilesp=
85
+ ace.gif" width=3D350></TD></TR><TR><TD width=3D350 colSpan=3D4><IMG src=3D=
86
+ "cid:dottedline350.gif" width=3D350></TD></TR><TR><TR><TD width=3D350 colS=
87
+ pan=3D4><IMG height=3D30 src=3D"cid:tmobilespace.gif" width=3D350></TD></T=
88
+ R></table>=20
89
+ =09=09=09=09 <!-- presentation ends here -->
90
+ =09=09=09=09</td>
91
+ =09=09=09=09<td width=3D"240" bgcolor=3D"#f2f2f2"><BR></td>
92
+ =09=09=09</tr>
93
+ <tr>
94
+ =09=09=09=09<td width=3D"600" colspan=3D"2"><img src=3D"cid:tmobilelogo.gif=
95
+ " width=3D"600" height=3D"45"></td>
96
+ </tr>
97
+ <tr>
98
+ =09=09=09=09<td width=3D"600" colspan=3D"2"><img src=3D"cid:tmobilespace.gi=
99
+ f" width=3D"600" height=3D"10"></td>
100
+ =09=09=09</tr>
101
+ =09=09=09<tr>
102
+ =09=09=09=09<td width=3D"600" colspan=3D"2"><span class=3D"footer">This mes=
103
+ sage was sent from a T-Mobile wireless phone.
104
+ </span></td>
105
+ </tr>
106
+ <tr>
107
+ =09=09=09=09<td width=3D"600" colspan=3D"2"><img src=3D"cid:tmobilespace.gi=
108
+ f" width=3D"600" height=3D"40"></td>
109
+ </tr>
110
+ </table>
111
+ </body></html>
112
+
113
+ ------=_Part_6032807_21271850.1167443321223
114
+ Content-Type: image/jpeg; name=12-01-06_1234.jpg
115
+ Content-Transfer-Encoding: base64
116
+ Content-Location: 12-01-06_1234.jpg
117
+ Content-ID: <280>
118
+
119
+ R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
120
+ ------=_Part_6032807_21271850.1167443321223
121
+ Content-Type: image/gif; name=audio.gif
122
+ Content-Transfer-Encoding: base64
123
+ Content-Disposition: attachment; filename=audio.gif
124
+ Content-ID: <audio.gif>
125
+
126
+ R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
127
+ ------=_Part_6032807_21271850.1167443321223
128
+ Content-Type: image/gif; name=dottedline600.gif
129
+ Content-Transfer-Encoding: base64
130
+ Content-Disposition: attachment; filename=dottedline600.gif
131
+ Content-ID: <dottedline600.gif>
132
+
133
+ R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
134
+ ------=_Part_6032807_21271850.1167443321223
135
+ Content-Type: image/gif; name=tmobilelogo.gif
136
+ Content-Transfer-Encoding: base64
137
+ Content-Disposition: attachment; filename=tmobilelogo.gif
138
+ Content-ID: <tmobilelogo.gif>
139
+
140
+ R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
141
+ ------=_Part_6032807_21271850.1167443321223
142
+ Content-Type: image/gif; name=tmobilespace.gif
143
+ Content-Transfer-Encoding: base64
144
+ Content-Disposition: attachment; filename=tmobilespace.gif
145
+ Content-ID: <tmobilespace.gif>
146
+
147
+ R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
148
+ ------=_Part_6032807_21271850.1167443321223
149
+ Content-Type: image/gif; name=video.gif
150
+ Content-Transfer-Encoding: base64
151
+ Content-Disposition: attachment; filename=video.gif
152
+ Content-ID: <video.gif>
153
+
154
+ R0lGODlhAQABAIAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
155
+ ------=_Part_6032807_21271850.1167443321223--
156
+ EOF
157
+ @simple_image_mail = TMail::Mail.parse(msg)
158
+ end
159
+
160
+ def teadown; end
161
+
162
+ def test_ignore_simple_image
163
+ mms = MMS2R::Media.create(@simple_image_mail)
164
+ mms.process
165
+ assert(mms.media.size == 1)
166
+ assert(File.basename(mms.media['image/jpeg'][0]).eql?('12-01-06_1234.jpg'))
167
+ mms.purge
168
+ end
169
+ end
@@ -0,0 +1,74 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ require 'test/unit'
4
+ require 'rubygems'
5
+ require 'mms2r'
6
+ require 'mms2r/media'
7
+ require 'tmail/mail'
8
+ require 'logger'
9
+
10
+ class MMS2RVerizonTest < Test::Unit::TestCase
11
+
12
+ def setup
13
+ @log = Logger.new(STDOUT)
14
+ @log.level = Logger::DEBUG
15
+ @log.datetime_format = "%H:%M:%S"
16
+ end
17
+
18
+ def teadown; end
19
+
20
+ def test_simple_video
21
+ mail = TMail::Mail.parse(load_mail('verizon-video-01.mail').join)
22
+ mms = MMS2R::Media.create(mail,@logger)
23
+ mms.process
24
+
25
+ assert(mms.media.size == 1)
26
+ assert_nil(mms.media['text/plain'])
27
+ assert_nil(mms.media['text/html'])
28
+ assert_not_nil(mms.media['video/3gpp2'][0])
29
+ assert_match(/012345_67890.3g2$/, mms.media['video/3gpp2'][0])
30
+
31
+ file = mms.media['video/3gpp2'][0]
32
+ assert_not_nil(file)
33
+ assert(File::exist?(file), "file #{file} does not exist")
34
+ assert(File::size(file) == 16553, "file #{file} not 16553 byts")
35
+ mms.purge
36
+ end
37
+
38
+ def test_simple_image
39
+ mail = TMail::Mail.parse(load_mail('verizon-image-01.mail').join)
40
+ mms = MMS2R::Media.create(mail,@logger)
41
+ mms.process
42
+
43
+ assert(mms.media.size == 1)
44
+ assert_nil(mms.media['text/plain'])
45
+ assert_nil(mms.media['text/html'])
46
+ assert_not_nil(mms.media['image/jpeg'][0])
47
+ assert_match(/IMAGE_00004.jpg$/, mms.media['image/jpeg'][0])
48
+
49
+ file = mms.media['image/jpeg'][0]
50
+ assert_not_nil(file)
51
+ assert(File::exist?(file), "file #{file} does not exist")
52
+ assert(File::size(file) == 41983, "file #{file} not 41983 byts")
53
+ mms.purge
54
+ end
55
+
56
+ def test_simple_text
57
+ mail = TMail::Mail.parse(load_mail('verizon-text-01.mail').join)
58
+ mms = MMS2R::Media.create(mail)
59
+ assert_equal(MMS2R::VerizonMedia, mms.class, "expected a #{MMS2R::VerizonMedia} and received a #{mms.class}")
60
+ mms.process
61
+ assert_not_nil(mms.media['text/plain'])
62
+ file = mms.media['text/plain'][0]
63
+ assert_not_nil(file)
64
+ assert(File::exist?(file), "file #{file} does not exist")
65
+ text = IO.readlines("#{file}").join
66
+ assert_match(/hello world/, text)
67
+ mms.purge
68
+ end
69
+
70
+ private
71
+ def load_mail(file)
72
+ IO.readlines("#{File.dirname(__FILE__)}/files/#{file}")
73
+ end
74
+ end