mms2r 1.0.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/History.txt +19 -1
  2. data/Manifest.txt +38 -19
  3. data/README.txt +40 -8
  4. data/Rakefile +2 -2
  5. data/conf/mms2r_cingular_me_media_subject.yml +3 -0
  6. data/conf/{mms2r_cingularmedia_transform.yml → mms2r_cingular_me_media_transform.yml} +1 -0
  7. data/conf/mms2r_dobson_media_ignore.yml +4 -0
  8. data/conf/mms2r_media_ignore.yml +4 -0
  9. data/conf/mms2r_media_subject.yml +3 -0
  10. data/conf/mms2r_my_cingular_media_subject.yml +3 -0
  11. data/conf/mms2r_nextel_media_ignore.yml +11 -0
  12. data/conf/mms2r_sprint_media_ignore.yml +5 -0
  13. data/conf/mms2r_sprint_media_subject.yml +3 -0
  14. data/conf/{mms2r_tmobilemedia_ignore.yml → mms2r_t_mobile_media_ignore.yml} +2 -5
  15. data/conf/mms2r_verizon_media_ignore.yml +4 -0
  16. data/conf/mms2r_verizon_media_transform.yml +6 -0
  17. data/dev_tools/debug_sprint_hpricot_parsing.rb +82 -0
  18. data/lib/mms2r.rb +61 -0
  19. data/lib/mms2r/cingular_me_media.rb +23 -0
  20. data/lib/mms2r/dobson_media.rb +4 -5
  21. data/lib/mms2r/{mmode_media.rb → m_mode_media.rb} +4 -4
  22. data/lib/mms2r/media.rb +283 -160
  23. data/lib/mms2r/my_cingular_media.rb +15 -0
  24. data/lib/mms2r/nextel_media.rb +9 -3
  25. data/lib/mms2r/sprint_media.rb +137 -29
  26. data/lib/mms2r/sprint_pcs_media.rb +16 -0
  27. data/lib/mms2r/t_mobile_media.rb +21 -0
  28. data/lib/mms2r/verizon_media.rb +11 -3
  29. data/lib/mms2r/vtext_media.rb +16 -0
  30. data/test/files/cingularme-text-02.mail +14 -0
  31. data/test/files/hello_world_empty_text.mail +6 -0
  32. data/test/files/hello_world_mail_multipart.mail +7 -0
  33. data/test/files/{cingular-image-01.mail → mycingular-image-01.mail} +0 -0
  34. data/test/files/simple-with-two-images-two-texts.mail +49 -0
  35. data/test/files/{sprint-image-02.mail → sprint-broken-image-01.mail} +1 -1
  36. data/test/files/sprint-image-01.mail +1 -1
  37. data/test/files/sprint-pcs-text-01.mail +8 -0
  38. data/test/files/sprint-text-01.mail +195 -8
  39. data/test/files/sprint-two-images-01.mail +198 -0
  40. data/test/files/sprint-video-01.mail +1 -1
  41. data/test/files/verizon-image-02.mail +1 -1
  42. data/test/files/vtext-text-01.mail +1 -1
  43. data/test/test_mms2r_cingular_me_media.rb +51 -0
  44. data/test/test_mms2r_dobson_media.rb +46 -0
  45. data/test/{test_mms2r_mmode.rb → test_mms2r_m_mode_media.rb} +1 -1
  46. data/test/test_mms2r_media.rb +160 -74
  47. data/test/test_mms2r_my_cingular_media.rb +31 -0
  48. data/test/test_mms2r_nextel_media.rb +100 -0
  49. data/test/test_mms2r_sprint_media.rb +221 -0
  50. data/test/test_mms2r_sprint_pcs_media.rb +27 -0
  51. data/test/{test_mms2r_tmobile.rb → test_mms2r_t_mobile_media.rb} +13 -13
  52. data/test/test_mms2r_verizon_media.rb +96 -0
  53. data/test/test_mms2r_vtext_media.rb +28 -0
  54. data/vendor/plugins/mms2r/lib/autotest/discover.rb +3 -0
  55. data/vendor/plugins/mms2r/lib/autotest/mms2r.rb +33 -0
  56. metadata +62 -37
  57. data/conf/mms2r_nextelmedia_ignore.yml +0 -10
  58. data/conf/mms2r_sprintmedia_ignore.yml +0 -10
  59. data/conf/mms2r_verizonmedia_ignore.yml +0 -3
  60. data/conf/mms2r_verizonmedia_transform.yml +0 -3
  61. data/lib/mms2r/cingular_media.rb +0 -11
  62. data/lib/mms2r/tmobile_media.rb +0 -11
  63. data/lib/mms2r/version.rb +0 -12
  64. data/test/test_mms2r_cingular.rb +0 -58
  65. data/test/test_mms2r_dobson.rb +0 -36
  66. data/test/test_mms2r_nextel.rb +0 -132
  67. data/test/test_mms2r_sprint.rb +0 -174
  68. data/test/test_mms2r_verizon.rb +0 -102
@@ -0,0 +1,198 @@
1
+ Message-ID: <01264567.13213243210987.JavaMail.jrewqreos@lalal09>
2
+ From: "someuser@pm.sprint.com" <someuser@pm.sprint.com>
3
+ To: tommytutone@example.com
4
+ Subject: You have new Picture Mail!
5
+ MIME-Version: 1.0
6
+ Content-Type: multipart/alternative;
7
+ boundary="----=_Part_012345_67890123.4567890123456"
8
+ X-Priority: 3
9
+ X-MSMail-Priority: Normal
10
+ Importance: Normal
11
+
12
+ ------=_Part_012345_67890123.4567890123456
13
+ Content-Type: text/plain; charset=us-ascii
14
+ Content-Transfer-Encoding: 7bit
15
+
16
+ You have new Picture Mail!
17
+
18
+ Click Go/View to see now.
19
+ http://pictures.sprintpcs.com/?mivt=helloworld0123456789&shareName=MMS
20
+
21
+ _abcedef
22
+
23
+
24
+ ------=_Part_012345_67890123.4567890123456
25
+ Content-Type: text/html
26
+ Content-Transfer-Encoding: 7bit
27
+
28
+ <html>
29
+ <head><title>You have new Picture Mail!</title>
30
+ <!-- lsPictureMail-Share-helloworld0123456789-comment
31
+ &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF&#45;8&quot;?&gt;
32
+ &lt;shareMessage&gt;
33
+ &lt;messageContents type=&quot;PICTURE&quot;&gt;
34
+ &lt;messageText&gt;&lt;/messageText&gt;
35
+ &lt;mediaItems&gt;
36
+ &lt;mediaItem id=&quot;1&quot;&gt;
37
+ &lt;title&gt;&lt;/title&gt;
38
+ &amp;lt;url&amp;gt;http://pictures.sprintpcs.com/getMMBOXMessageMedia?id=Xw1004H8sLv6S3x76lVPYvc9HWuygho0mqG1a5IEKWLR8s8O0GEqXAmk5gW%2FZUWGqyw0fwJJvr7U%0AtWtQs5%2FZA7tmYNq7KKkBMqlL64JVNH%2BGkNKbb8WqPL%2FsrHZdYUVet3SRzN1GfrfUo%2BpWfjCBBg%3D%3D%0A&amp;lt;/url&amp;gt;
39
+
40
+ &lt;urlExpiration&gt;2007&#45;03&#45;11T21:14:27Z&lt;/urlExpiration&gt;
41
+ &lt;/mediaItem&gt;
42
+ &lt;/mediaItems&gt;
43
+ &lt;/messageContents&gt;
44
+ &lt;/shareMessage&gt;
45
+
46
+ -->
47
+ <!-- lsPictureMail-UserInfo-helloworld0123456789-comment
48
+ &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF&#45;8&quot;?&gt;
49
+ &lt;UserInfo timestamp=&quot;2007&#45;03&#45;04T21:14:27.96+00:00&quot; originating_from_address=&quot;someuser@pm.sprint.com&quot;&gt;&lt;credential name=&quot;MDN&quot;&gt;2068509247&lt;/credential&gt;&lt;/UserInfo&gt;
50
+ -->
51
+ </head>
52
+ <body marginheight="0" marginwidth="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
53
+ <table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" >
54
+ <tr>
55
+ <td VALIGN="top" colspan="2" width="100%">
56
+ <table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#FFE100">
57
+ <tr>
58
+ <td><a href="http://www.sprintpcs.com"><img src="http://pictures.sprintpcs.com/retailers/PCSNEXTEL/images/logos/togetherWithNextel.gif" alt="" border="0" /></a></td>
59
+ </tr>
60
+ </table>
61
+ </td>
62
+ </tr>
63
+ <tr>
64
+ <td VALIGN="top" colspan="2">
65
+ <table border="0" cellpadding="0" cellspacing="0" width="590" bgcolor="#FFFFFF">
66
+ <tr>
67
+ <td><br/><p><img src="http://pictures.sprintpcs.com/images/x.gif" border="0" width="10"/><font face="trebuchet ms, Helvetica, Arial, Verdana" size="2"><b>You have a Picture Mail from someuser@pm.sprint.com</b></font><br/><br/></p></td>
68
+ </tr>
69
+ </table>
70
+ </td>
71
+ </tr>
72
+ <tr>
73
+ <td colspan="2">
74
+ <table border="0" width="590" cellpadding="0" cellspacing="0">
75
+ <tr>
76
+ <td width="10">&nbsp;</td>
77
+ <td width="280" valign="top">
78
+ <table border="0" cellpadding="0" style="border:1px solid #9C9A9C;">
79
+ <tr>
80
+ <td>
81
+ <table border="0" bgcolor="#ffffff" cellpadding="0" cellspacing="7" style="table-layout:fixed">
82
+ <tr>
83
+ <td align="center">
84
+ <img src="http://localhost:99163/mmps/RECIPIENT/000_0123a01234567890_1/2.2?inviteToken=helloworld0123456789&amp;limitsize=258,258&amp;outquality=90&amp;squareoutput=255,255,255&amp;ext=.jpg&amp;iconifyVideo=true&amp;wm=1&amp;HACK=IMAGE"/>
85
+ </td>
86
+ <td align="center">
87
+ <img src="http://localhost:99163/mmps/RECIPIENT/000_0123a01234567890_1/2.3?inviteToken=helloworld0123456789&amp;limitsize=258,258&amp;outquality=90&amp;squareoutput=255,255,255&amp;ext=.jpg&amp;iconifyVideo=true&amp;wm=1&amp;HACK=IMAGE"/>
88
+ </td>
89
+ </tr>
90
+ </table>
91
+ </td>
92
+ </tr>
93
+ </table>
94
+ </td>
95
+ <td width="20">&nbsp;</td>
96
+ <td VALIGN="top" align="right" width="280">
97
+ <table border="0" cellpadding="0" cellspacing="0" width="280" style="table-layout:fixed">
98
+ <tr>
99
+ <td><p><font face="trebuchet ms, Helvetica, Arial, Verdana" size="2"><b>Message:</b></font></p></td>
100
+ </tr>
101
+ <tr>
102
+ <td><pre style="overflow:auto; font:normal 10pt trebuchet ms; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;"></pre></td>
103
+ </tr>
104
+ <tr>
105
+ <td><img src="http://pictures.sprintpcs.com/images/x.gif" border="0" height="15"/></td>
106
+ </tr>
107
+ <tr>
108
+ <td width="280">
109
+ <div style="padding-left:10px; padding-top:4px; padding-bottom:4px; color:white; background-color:#59639C; font: bold 10pt trebuchet ms" width="280">
110
+ Options
111
+ </div>
112
+ <div style="padding:10px; background-color:#f1f1f1; font: normal 10pt trebuchet ms" width="280">
113
+ <a target="_blank" style="color: #148AB2;" href="http://pictures.sprintpcs.com/share.do?invite=helloworld0123456789&amp;shareName=MMS&amp;messageState=RETRIEVED">View Picture</a><br/>
114
+ <a target="_blank" style="color: #148AB2;" href="http://pictures.sprintpcs.com/share.do?invite=helloworld0123456789&amp;shareName=PRINT">Order Prints and Gifts</a><br/>
115
+ <a target="_blank" style="color: #148AB2;" href="http://pictures.sprintpcs.com/share.do?invite=helloworld0123456789&amp;shareName=REPLY">Reply to Sender</a><br/>
116
+ <a target="_blank" style="color: #148AB2;" href="http://pictures.sprintpcs.com/share.do?invite=helloworld0123456789&amp;shareName=REPLYTOALL">Reply to All</a><br/>
117
+ <a target="_blank" style="color: #148AB2;" href="http://pictures.sprintpcs.com/share.do?invite=helloworld0123456789&amp;shareName=FORWARD">Forward</a><br/><br/>
118
+ Send and receive Pictures and Videos through Picture Mail<sup>SM</sup>. For more information go to <a target="_blank" style="color: #148AB2;" href="http://www.sprint.com/picturemail">www.sprint.com/picturemail.</a>
119
+ </div>
120
+ </td>
121
+ </tr>
122
+ </table>
123
+ </td>
124
+ </tr>
125
+ </table>
126
+ </td>
127
+ </tr>
128
+ <tr>
129
+ <td colspan="2">
130
+ <img src="http://pictures.sprintpcs.com/images/x.gif" width="5" height="15"/>
131
+ </td>
132
+ </tr>
133
+ <tr>
134
+ <td align="left" colspan="2" width="590">
135
+ <table cellpadding="0" cellspacing="0" align="left" bgcolor="#FFFFFF">
136
+ <tr>
137
+ <td width="10">&nbsp;</td>
138
+ <td width="580">
139
+ <table cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="#FFFFFF">
140
+ <tr>
141
+ <!-- AdJuggler 5.0 request
142
+ Ad Spot: email_picture-mail-invitation_1_120x85
143
+ Channel: Undefined
144
+ Ad Dimension: 120x85
145
+ Category: Undefined
146
+ Sub-category: Undefined
147
+ -->
148
+ <td width="120"><a href="http://banners.pictures.sprintpcs.com/servlet/ajrotator/361/0/clickCGI?zone=1"><img src="http://banners.pictures.sprintpcs.com/servlet/ajrotator/361/0/viewCGI?zone=1&amp;dim=135" border="0"/></a></td>
149
+ <td width="30"></td>
150
+ <!-- AdJuggler 5.0 request
151
+ Ad Spot: email_picture-mail-invitation_2_120x85
152
+ Channel: Undefined
153
+ Ad Dimension: 120x85
154
+ Category: Undefined
155
+ Sub-category: Undefined
156
+ -->
157
+ <td width="120"><a href="http://banners.pictures.sprintpcs.com/servlet/ajrotator/362/0/clickCGI?zone=1"><img src="http://banners.pictures.sprintpcs.com/servlet/ajrotator/362/0/viewCGI?zone=1&amp;dim=135" border="0"/></a></td>
158
+ <td width="30"></td>
159
+ <!-- AdJuggler 5.0 request
160
+ Ad Spot: email_picture-mail-invitation_3_120x85
161
+ Channel: Undefined
162
+ Ad Dimension: 120x85
163
+ Category: Undefined
164
+ Sub-category: Undefined
165
+ -->
166
+ <td width="120"><a href="http://banners.pictures.sprintpcs.com/servlet/ajrotator/363/0/clickCGI?zone=1"><img src="http://banners.pictures.sprintpcs.com/servlet/ajrotator/363/0/viewCGI?zone=1&amp;dim=135" border="0"/></a></td>
167
+ </tr>
168
+ </table>
169
+ </td>
170
+ </tr>
171
+ </table>
172
+ </td>
173
+ </tr>
174
+ <tr>
175
+ <td VALIGN="top" colspan="2" width="590">
176
+ <img src="http://pictures.sprintpcs.com/images/x.gif" height="5"/>
177
+ </td>
178
+ </tr>
179
+ <tr>
180
+ <td VALIGN="top" colspan="2" width="100%">
181
+ <table width="100%" border="0" cellspacing="0" cellpadding="0">
182
+ <tr>
183
+ <td bgcolor="#f1f1f1" align="left"><img src="http://pictures.sprintpcs.com/images/x.gif" border="0" width="385" height="15"/><span style="font-family:trebuchet ms, Helvetica, Arial, Verdana; Font-size: 11px; Color: #000000">&#169; 2007 Sprint Nextel. All rights reserved.</span></td>
184
+ </tr>
185
+ <tr>
186
+ <td bgcolor="#f1f1f1" width="100%"><img src="http://pictures.sprintpcs.com/images/x.gif" border="0" width="20" height="5"/><a href="http://www.verisign.com"><img src="http://pictures.sprintpcs.com/retailers/PCSNEXTEL/images/logos/verisign.jpg" alt="VeriSign's Home Page" border="0" /></a></td>
187
+ </tr>
188
+ <tr>
189
+ <td bgcolor="#f1f1f1" width="100%"><img src="http://pictures.sprintpcs.com/images/x.gif" border="0" height="10"/></td>
190
+ </tr>
191
+ </table>
192
+ </td>
193
+ </tr>
194
+ </table>
195
+ </body>
196
+ </html><!-- picture_mail_arrived -->
197
+
198
+ ------=_Part_012345_67890123.4567890123456--
@@ -81,7 +81,7 @@ Content-Transfer-Encoding: 7bit
81
81
  <table border="0" bgcolor="#ffffff" cellpadding="0" cellspacing="7" style="table-layout:fixed">
82
82
  <tr>
83
83
  <td align="center">
84
- <img src="http://localhost:99163/simplevideo/RECIPIENT/000_0123a01234567895_1/2?inviteToken=helloworld0123456789&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"/>
84
+ <img src="http://localhost:99163/mmps/RECIPIENT/000_0123a01234567895_1/2?inviteToken=helloworld0123456789&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&amp;HACK=VIDEO"/>
85
85
  </td>
86
86
  </tr>
87
87
  </table>
@@ -30,7 +30,7 @@ www.verizonwireless.com/getitnow/getpix.
30
30
 
31
31
  To learn how you can record videos with your wireless phone visit www.verizonwireless.com/getitnow/getflix.
32
32
 
33
- To play video messages sent to email, QuickTime� 6.5 or higher is required. Visit www.apple.com/quicktime/download to download the free player or upgrade your existing QuickTime� Player. Note: During the download
33
+ To play video messages sent to email, QuickTime� 6.5 or higher is required. Visit www.apple.com/quicktime/download to download the free player or upgrade your existing QuickTime� Player. Note: During the download
34
34
  process when asked to choose an installation type (Minimum, Recommended or Custom), select Minimum for faster download.
35
35
 
36
36
  --__CONTENT_77888_PART_BOUNDARY__99922233__
@@ -2,7 +2,7 @@ Date: Sat, 24 Feb 2007 13:25:29 -0500 (EST)
2
2
  Message-ID: <01234567.8901234567890.JavaMail.fooo@njbd-lalal3>
3
3
  From: 2068675309@vtext.com
4
4
  To: tommytutone@example.com
5
- Subject: some text
5
+ Subject: hello world
6
6
  Mime-Version: 1.0
7
7
  Content-Type: text/plain; charset=utf-8
8
8
  Content-Transfer-Encoding: 7bit
@@ -0,0 +1,51 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require File.dirname(__FILE__) + "/test_helper"
3
+ require 'test/unit'
4
+ require 'rubygems'
5
+ require 'mms2r'
6
+ require 'mms2r/media'
7
+ require 'tmail/mail'
8
+ require 'logger'
9
+
10
+
11
+ class MMS2R::CingularMeMediaTest < Test::Unit::TestCase
12
+ include MMS2R::TestHelper
13
+
14
+ def setup
15
+ @ad = "\n--\n===============================================\nBrought to you by, Cingular Wireless Messaging\nhttp://www.CingularMe.COM/"
16
+ @greet = "Brought to you by, Cingular Wireless Messaging"
17
+ end
18
+
19
+ def test_clean_text_ad1
20
+ mail = TMail::Mail.parse(load_mail('cingularme-text-01.mail').join)
21
+ mms = MMS2R::Media.create(mail)
22
+ assert_equal MMS2R::CingularMeMedia, mms.class, "expected a #{MMS2R::CingularMeMedia} and received a #{mms.class}"
23
+ mms.process
24
+ assert_not_nil mms.media['text/plain']
25
+ file = mms.media['text/plain'][0]
26
+ assert_not_nil file
27
+ assert File::exist?(file), "file #{file} does not exist"
28
+ text = IO.readlines("#{file}").join
29
+ assert !text.match(@ad), "found ad in text"
30
+ assert !text.match(@greet), "found ad in text"
31
+ assert_equal "hello world", text
32
+ mms.purge
33
+ end
34
+
35
+ def test_clean_text_ad2
36
+ mail = TMail::Mail.parse(load_mail('cingularme-text-02.mail').join)
37
+ mms = MMS2R::Media.create(mail)
38
+ assert_equal MMS2R::CingularMeMedia, mms.class, "expected a #{MMS2R::CingularMeMedia} and received a #{mms.class}"
39
+ mms.process
40
+ assert_not_nil mms.media['text/plain']
41
+ file = mms.media['text/plain'][0]
42
+ assert_not_nil file
43
+ assert File::exist?(file), "file #{file} does not exist"
44
+ text = IO.readlines("#{file}").join
45
+ assert !text.match(@ad), "found ad in text"
46
+ assert !text.match(@greet), "found ad in text"
47
+ assert_equal "hello world\nfoo bar", text
48
+ mms.purge
49
+ end
50
+
51
+ end
@@ -0,0 +1,46 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require File.dirname(__FILE__) + "/test_helper"
3
+ require 'test/unit'
4
+ require 'rubygems'
5
+ require 'mms2r'
6
+ require 'mms2r/media'
7
+ require 'tmail/mail'
8
+ require 'logger'
9
+
10
+
11
+ class MMS2R::DobsonMediaTest < Test::Unit::TestCase
12
+ include MMS2R::TestHelper
13
+
14
+ def test_dobson_image
15
+ mail = TMail::Mail.parse(load_mail('dobson-image-01.mail').join)
16
+ mms = MMS2R::Media.create(mail)
17
+ assert_equal mms.class, MMS2R::DobsonMedia
18
+
19
+ mms.process
20
+
21
+ assert_equal 2, mms.media.size, "Size is #{mms.media.size}"
22
+ assert_not_nil mms.media['text/plain']
23
+ assert_equal nil, mms.media['application/smil'] # dobson phones have weird SMIL that can be ignored.
24
+ assert_not_nil mms.media['image/jpeg'][0]
25
+ assert_match(/04-18-07_1723.jpg$/, mms.media['image/jpeg'][0])
26
+
27
+ assert_file_size mms.media['image/jpeg'][0], 337
28
+
29
+ file = mms.media['text/plain'][0]
30
+ assert_not_nil file
31
+ assert File::exist?(file), "file #{file} does not exist"
32
+ text = IO.readlines("#{file}").join
33
+ assert_equal "Body", text.strip
34
+ mms.purge
35
+ end
36
+
37
+ def test_get_body_should_return_user_text
38
+ mail = TMail::Mail.parse(load_mail('dobson-image-01.mail').join)
39
+ mms = MMS2R::Media.create(mail)
40
+ mms.process
41
+
42
+ assert_equal 'Body', mms.get_body
43
+
44
+ mms.purge
45
+ end
46
+ end
@@ -7,7 +7,7 @@ require 'mms2r/media'
7
7
  require 'tmail/mail'
8
8
  require 'logger'
9
9
 
10
- class MMS2RMModeTest < Test::Unit::TestCase
10
+ class MMS2R::MModeMediaTest < Test::Unit::TestCase
11
11
  include MMS2R::TestHelper
12
12
 
13
13
  def setup
@@ -5,11 +5,10 @@ require 'rubygems'
5
5
  require 'yaml'
6
6
  require 'fileutils'
7
7
  require 'mms2r'
8
- require 'mms2r/media'
9
8
  require 'tmail/mail'
10
9
  require 'logger'
11
10
 
12
- class MMS2RMediaTest < Test::Unit::TestCase
11
+ class MMS2R::MediaTest < Test::Unit::TestCase
13
12
  include MMS2R::TestHelper
14
13
 
15
14
  class MMS2R::FakeCarrier < MMS2R::Media; end
@@ -19,16 +18,16 @@ class MMS2RMediaTest < Test::Unit::TestCase
19
18
 
20
19
  CARRIER_TO_CLASS = {
21
20
  'mms2r.media' => MMS2R::Media,
22
- 'mms.mycingular.com' => MMS2R::CingularMedia,
23
- 'cingularme.com' => MMS2R::CingularMedia,
21
+ 'cingularme.com' => MMS2R::CingularMeMedia,
22
+ 'mms.dobson.net' => MMS2R::DobsonMedia,
24
23
  'mmode.com' => MMS2R::MModeMedia,
24
+ 'mms.mycingular.com' => MMS2R::MyCingularMedia,
25
25
  'messaging.nextel.com' => MMS2R::NextelMedia,
26
26
  'pm.sprint.com' => MMS2R::SprintMedia,
27
- 'messaging.sprintpcs.com' => MMS2R::SprintMedia,
27
+ 'messaging.sprintpcs.com' => MMS2R::SprintPcsMedia,
28
28
  'tmomail.net' => MMS2R::TMobileMedia,
29
- 'vtext.com' => MMS2R::VerizonMedia,
30
- 'vzwpix.com' => MMS2R::VerizonMedia,
31
- 'mms.dobson.net' => MMS2R::DobsonMedia
29
+ 'vtext.com' => MMS2R::VtextMedia,
30
+ 'vzwpix.com' => MMS2R::VerizonMedia
32
31
  }
33
32
 
34
33
  def use_temp_dirs
@@ -57,21 +56,25 @@ class MMS2RMediaTest < Test::Unit::TestCase
57
56
  MMS2R::Media.conf_dir = @oldconfdir
58
57
  end
59
58
 
59
+ def test_version
60
+ assert MMS2R::Media::VERSION > '0.0.1'
61
+ end
62
+
60
63
  def test_collect_text_multipart_alternative
61
64
  mail = TMail::Mail.parse(load_mail('simple_multipart_alternative.mail').join)
62
65
  mms = MMS2R::Media.create(mail)
63
66
  mms.process
64
- assert_not_nil(mms.media['text/plain'])
65
- assert(mms.media.size == 3)
66
- assert(mms.media['text/plain'].size == 1)
67
- assert(mms.media['text/html'].size == 1)
68
- assert(mms.media['image/gif'].size == 1)
67
+ assert_not_nil mms.media['text/plain']
68
+ assert_equal 3, mms.media.size
69
+ assert_equal 1, mms.media['text/plain'].size
70
+ assert_equal 1, mms.media['text/html'].size
71
+ assert_equal 1, mms.media['image/gif'].size
69
72
 
70
73
  file = mms.media['text/plain'][0]
71
- assert_not_nil(file)
72
- assert(File::exist?(file), "file #{file} does not exist")
74
+ assert_not_nil file
75
+ assert File::exist?(file), "file #{file} does not exist"
73
76
  text = IO.readlines("#{file}").join
74
- assert_match(/This is an MMS message. Hello World./, text)
77
+ assert_equal "This is an MMS message. Hello World.", text
75
78
  mms.purge
76
79
  end
77
80
 
@@ -79,26 +82,39 @@ class MMS2RMediaTest < Test::Unit::TestCase
79
82
  mail = TMail::Mail.parse(load_mail('simple_image.mail').join)
80
83
  mms = MMS2R::Media.create(mail)
81
84
  mms.process
82
- assert_not_nil(mms.media['image/gif'])
83
- assert(mms.media.size == 1)
84
- file = mms.media['image/gif'][0]
85
- assert_not_nil(file)
86
- assert(File::exist?(file), "file #{file} does not exist")
87
- assert(File.basename(file) =~ /spacer\.gif/, "file #{file} does not exist")
85
+ assert_not_nil mms.media['image/gif']
86
+ assert_equal 1, mms.media.size
87
+ file = mms.media['image/gif'].first
88
+ assert_not_nil file
89
+ assert File::exist?(file), "file #{file} does not exist"
90
+ assert File.basename(file) =~ /spacer\.gif/, "file #{file} does not exist"
88
91
  mms.purge
89
92
  end
90
93
 
94
+ def test_collect_simple_image_using_block
95
+ mail = TMail::Mail.parse(load_mail('simple_image.mail').join)
96
+ mms = MMS2R::Media.create(mail)
97
+ file_array = nil
98
+ mms.process do |k, v|
99
+ file_array = v if (k == 'image/gif')
100
+ assert_not_nil(file = file_array.first)
101
+ assert(File::exist?(file), "file #{file} does not exist")
102
+ assert(File.basename(file) =~ /spacer\.gif/, "file #{file} does not exist")
103
+ end
104
+ assert !File.exist?(file_array.first)
105
+ end
106
+
91
107
  def test_collect_text_plain
92
108
  mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_no_content_type.mail').join)
93
109
  mms = MMS2R::Media.create(mail)
94
110
  mms.process
95
- assert_not_nil(mms.media['text/plain'])
96
- assert(mms.media.size == 1)
111
+ assert_not_nil mms.media['text/plain']
112
+ assert_equal 1, mms.media.size
97
113
  file = mms.media['text/plain'][0]
98
- assert_not_nil(file)
99
- assert(File::exist?(file), "file #{file} does not exist")
114
+ assert_not_nil file
115
+ assert File::exist?(file), "file #{file} does not exist"
100
116
  text = IO.readlines("#{file}").join
101
- assert_match(/hello world/, text)
117
+ assert_equal "hello world", text
102
118
  mms.purge
103
119
  end
104
120
 
@@ -106,13 +122,14 @@ class MMS2RMediaTest < Test::Unit::TestCase
106
122
  mail = TMail::Mail.parse(load_mail('hello_world_mail_multipart.mail').join)
107
123
  mms = MMS2R::Media.create(mail)
108
124
  mms.process
109
- assert_not_nil(mms.media['text/plain'])
110
- assert(mms.media.size == 1)
125
+ assert_not_nil mms.media['text/plain']
126
+ assert_not_nil mms.media['application/smil']
127
+ assert_equal 2, mms.media.size
111
128
  file = mms.media['text/plain'][0]
112
- assert_not_nil(file)
113
- assert(File::exist?(file), "file #{file} does not exist")
129
+ assert_not_nil file
130
+ assert File::exist?(file), "file #{file} does not exist"
114
131
  text = IO.readlines("#{file}").join
115
- assert_match(/hello world/, text)
132
+ assert_equal "hello world", text
116
133
  mms.purge
117
134
  end
118
135
 
@@ -124,9 +141,9 @@ class MMS2RMediaTest < Test::Unit::TestCase
124
141
  mms = MMS2R::Media.create(mail)
125
142
  mms.process
126
143
  file = mms.media['text/plain'][0]
127
- assert(File::exist?(file), "file #{file} does not exist")
144
+ assert File::exist?(file), "file #{file} does not exist"
128
145
  mms.purge
129
- assert(!File::exist?(file), "file #{file} should not exist!")
146
+ assert !File::exist?(file), "file #{file} should not exist!"
130
147
  end
131
148
 
132
149
  def test_custom_media_carrier
@@ -136,7 +153,7 @@ class MMS2RMediaTest < Test::Unit::TestCase
136
153
  mail = TMail::Mail.new
137
154
  mail.from = ["#{JENNYSNUMER}@#{host}"]
138
155
  mms = MMS2R::Media.create(mail)
139
- assert_equal(cls, mms.class, "expected a #{cls} and received a #{mms.class}")
156
+ assert_equal cls, mms.class, "expected a #{cls} and received a #{mms.class}"
140
157
  end
141
158
 
142
159
  def test_create
@@ -144,10 +161,10 @@ class MMS2RMediaTest < Test::Unit::TestCase
144
161
  mail = TMail::Mail.new
145
162
  mail.from = ["#{JENNYSNUMER}@#{car}"]
146
163
  mms = MMS2R::Media.create(mail)
147
- assert_equal(cls, mms.class, "expected a #{cls} and received a #{mms.class}")
164
+ assert_equal cls, mms.class, "expected a #{cls} and received a #{mms.class}"
148
165
  mms = MMS2R::Media.create(mail)
149
- assert_equal(cls, mms.class, "expected a #{cls} and received a #{mms.class}")
150
- assert_equal(car, mms.carrier, "expected a #{car} and received a #{mms.carrier}")
166
+ assert_equal cls, mms.class, "expected a #{cls} and received a #{mms.class}"
167
+ assert_equal car, mms.carrier, "expected a #{car} and received a #{mms.carrier}"
151
168
  }
152
169
  end
153
170
 
@@ -156,20 +173,20 @@ class MMS2RMediaTest < Test::Unit::TestCase
156
173
  mail = TMail::Mail.new
157
174
  mail.from = ["#{JENNYSNUMER}@#{car}"]
158
175
  mms = MMS2R::Media.create(mail,@log)
159
- assert_equal(cls, mms.class, "expected a #{cls} and received a #{mms.class}")
176
+ assert_equal cls, mms.class, "expected a #{cls} and received a #{mms.class}"
160
177
  }
161
178
  end
162
179
 
163
180
  def test_tmp_dir
164
181
  use_temp_dirs()
165
182
  MMS2R::Media.tmp_dir = @tmpdir
166
- assert(MMS2R::Media.tmp_dir.eql?(@tmpdir))
183
+ assert MMS2R::Media.tmp_dir.eql?(@tmpdir)
167
184
  end
168
185
 
169
186
  def test_conf_dir
170
187
  use_temp_dirs()
171
188
  MMS2R::Media.conf_dir = @confdir
172
- assert(MMS2R::Media.conf_dir.eql?(@confdir))
189
+ assert MMS2R::Media.conf_dir.eql?(@confdir)
173
190
  end
174
191
 
175
192
  def test_transform_text
@@ -183,18 +200,72 @@ class MMS2RMediaTest < Test::Unit::TestCase
183
200
  mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_no_content_type.mail').join)
184
201
  mms = MMS2R::Media.create(mail)
185
202
  mms.process
186
- assert_not_nil(mms.media['text/plain'])
203
+ assert_not_nil mms.media['text/plain']
187
204
  file = mms.media['text/plain'][0]
188
- assert_not_nil(file)
189
- assert(File::exist?(file), "file #{file} does not exist")
205
+ assert_not_nil file
206
+ assert File::exist?(file), "file #{file} does not exist"
207
+ text = IO.readlines("#{file}").join
208
+ assert_equal "foo bar", text
209
+ mms.purge
210
+ end
211
+
212
+ def test_transform_text_for_application_smil
213
+ use_temp_dirs()
214
+ t={"Water" => "Juice"}
215
+ h={'application/smil' => t}
216
+ f = File.join(MMS2R::Media.conf_dir, 'mms2r_media_transform.yml')
217
+ File.open(f, 'w') do |out|
218
+ YAML.dump(h, out)
219
+ end
220
+ mail = TMail::Mail.parse(load_mail('hello_world_mail_multipart.mail').join)
221
+ mms = MMS2R::Media.create(mail)
222
+ mms.process
223
+ assert_not_nil mms.media['application/smil']
224
+ file = mms.media['application/smil'][0]
225
+ assert_not_nil file
226
+ assert File::exist?(file), "file #{file} does not exist"
190
227
  text = IO.readlines("#{file}").join
191
- assert_match(/foo bar/, text)
228
+ assert_equal "Juice", text
229
+ mms.purge
230
+ end
231
+
232
+ def test_mms_with_two_images_should_get_media_to_largest_file
233
+ mail = TMail::Mail.parse(load_mail('simple-with-two-images-two-texts.mail').join)
234
+ mms = MMS2R::Media.create(mail)
235
+ mms.process
236
+ file = mms.get_media
237
+ assert_equal 'big.jpg', file.original_filename
238
+ mms.purge
239
+ end
240
+
241
+ def test_mms_with_two_texts_should_get_text_to_largest_file
242
+ mail = TMail::Mail.parse(load_mail('simple-with-two-images-two-texts.mail').join)
243
+ mms = MMS2R::Media.create(mail)
244
+ mms.process
245
+ file = mms.get_text
246
+ assert_equal 'big.txt', file.original_filename
247
+ mms.purge
248
+ end
249
+
250
+ def test_mms_should_have_a_phone_number
251
+ mail = TMail::Mail.parse(load_mail('hello_world_empty_text.mail').join)
252
+ mms = MMS2R::Media.create(mail)
253
+ mms.process
254
+ assert_equal '2068675309', mms.get_number
255
+ mms.purge
256
+ end
257
+
258
+ def test_transform_text_should_ignore_empty_text_parts
259
+ mail = TMail::Mail.parse(load_mail('hello_world_empty_text.mail').join)
260
+ mms = MMS2R::Media.create(mail)
261
+ mms.process
262
+ assert_equal 0, mms.media.size
192
263
  mms.purge
193
264
  end
194
265
 
195
266
  def test_ignore_text
196
267
  use_temp_dirs()
197
- a=["hello world"]
268
+ a=[/^hello world$/]
198
269
  h={'text/plain' => a}
199
270
  f = File.join(MMS2R::Media.conf_dir, 'mms2r_media_ignore.yml')
200
271
  File.open(f, 'w') do |out|
@@ -203,8 +274,8 @@ class MMS2RMediaTest < Test::Unit::TestCase
203
274
  mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_no_content_type.mail').join)
204
275
  mms = MMS2R::Media.create(mail)
205
276
  mms.process
206
- assert(mms.media['text/plain'].nil?)
207
- assert(mms.media.size == 0)
277
+ assert mms.media['text/plain'].nil?
278
+ assert_equal 0, mms.media.size
208
279
  mms.purge
209
280
  end
210
281
 
@@ -219,8 +290,8 @@ class MMS2RMediaTest < Test::Unit::TestCase
219
290
  mail = TMail::Mail.parse(load_mail('simple_image.mail').join)
220
291
  mms = MMS2R::Media.create(mail)
221
292
  mms.process
222
- assert(mms.media['image/gif'].nil?)
223
- assert(mms.media.size == 0)
293
+ assert mms.media['image/gif'].nil?
294
+ assert_equal 0, mms.media.size
224
295
  mms.purge
225
296
  end
226
297
 
@@ -235,8 +306,8 @@ class MMS2RMediaTest < Test::Unit::TestCase
235
306
  mail = TMail::Mail.parse(load_mail('simple_image.mail').join)
236
307
  mms = MMS2R::Media.create(mail)
237
308
  mms.process
238
- assert(mms.media['image/gif'].size == 1)
239
- assert(mms.media.size == 1)
309
+ assert_equal 1, mms.media['image/gif'].size
310
+ assert_equal 1, mms.media.size
240
311
  mms.purge
241
312
  end
242
313
 
@@ -245,66 +316,81 @@ class MMS2RMediaTest < Test::Unit::TestCase
245
316
  mid1_a="1234abcd"
246
317
  mid2_b="<01234567.0123456789012.JavaMail.fooba@foo-bars999>"
247
318
  mid2_a="012345670123456789012JavaMailfoobafoo-bars999"
248
- assert(MMS2R::Media.safe_message_id(mid1_b).eql?(mid1_a))
249
- assert(MMS2R::Media.safe_message_id(mid2_b).eql?(mid2_a))
319
+ assert MMS2R::Media.safe_message_id(mid1_b).eql?(mid1_a)
320
+ assert MMS2R::Media.safe_message_id(mid2_b).eql?(mid2_a)
250
321
  end
251
322
 
252
323
  def default_ext
253
- assert(MMS2R::Media.default_ext('text').nil?)
254
- assert(MMS2R::Media.default_ext('text/plain').eql?('plain'))
255
- assert(MMS2R::Media.default_ext('image/jpeg').eql?('jpeg'))
256
- assert(MMS2R::Media.default_ext('video/mp4').eql?('mp4'))
324
+ assert MMS2R::Media.default_ext('text').nil?
325
+ assert MMS2R::Media.default_ext('text/plain').eql?('plain')
326
+ assert MMS2R::Media.default_ext('image/jpeg').eql?('jpeg')
327
+ assert MMS2R::Media.default_ext('video/mp4').eql?('mp4')
257
328
  end
258
329
 
259
330
  def test_part_type
260
331
  mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_no_content_type.mail').join)
261
- assert(MMS2R::Media.part_type?(mail).eql?('text/plain'))
332
+ assert MMS2R::Media.part_type?(mail).eql?('text/plain')
262
333
  mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_with_content_type.mail').join)
263
- assert(MMS2R::Media.part_type?(mail).eql?('text/plain'))
334
+ assert MMS2R::Media.part_type?(mail).eql?('text/plain')
264
335
  mail = TMail::Mail.parse(load_mail('hello_world_mail_multipart.mail').join)
265
- assert(MMS2R::Media.part_type?(mail.parts[0]).eql?('text/plain'))
336
+ assert MMS2R::Media.part_type?(mail.parts[0]).eql?('text/plain')
266
337
  mail = TMail::Mail.parse(load_mail('simple_image.mail').join)
267
- assert(MMS2R::Media.part_type?(mail.parts[0]).eql?('image/gif'))
338
+ assert MMS2R::Media.part_type?(mail.parts[0]).eql?('image/gif')
268
339
  end
269
340
 
270
341
  def test_main_type
271
342
  mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_no_content_type.mail').join)
272
- assert(MMS2R::Media.main_type?(mail).eql?('text'))
343
+ assert MMS2R::Media.main_type?(mail).eql?('text')
273
344
  mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_with_content_type.mail').join)
274
- assert(MMS2R::Media.main_type?(mail).eql?('text'))
345
+ assert MMS2R::Media.main_type?(mail).eql?('text')
275
346
  mail = TMail::Mail.parse(load_mail('hello_world_mail_multipart.mail').join)
276
- assert(MMS2R::Media.main_type?(mail.parts[0]).eql?('text'))
347
+ assert MMS2R::Media.main_type?(mail.parts[0]).eql?('text')
277
348
  mail = TMail::Mail.parse(load_mail('simple_image.mail').join)
278
- assert(MMS2R::Media.main_type?(mail.parts[0]).eql?('image'))
349
+ assert MMS2R::Media.main_type?(mail.parts[0]).eql?('image')
279
350
  end
280
351
 
281
352
  def test_sub_type
282
353
  mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_no_content_type.mail').join)
283
- assert(MMS2R::Media.sub_type?(mail).eql?('plain'))
354
+ assert MMS2R::Media.sub_type?(mail).eql?('plain')
284
355
  mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_with_content_type.mail').join)
285
- assert(MMS2R::Media.sub_type?(mail).eql?('plain'))
356
+ assert MMS2R::Media.sub_type?(mail).eql?('plain')
286
357
  mail = TMail::Mail.parse(load_mail('hello_world_mail_multipart.mail').join)
287
- assert(MMS2R::Media.sub_type?(mail.parts[0]).eql?('plain'))
358
+ assert MMS2R::Media.sub_type?(mail.parts[0]).eql?('plain')
288
359
  mail = TMail::Mail.parse(load_mail('simple_image.mail').join)
289
- assert(MMS2R::Media.sub_type?(mail.parts[0]).eql?('gif'))
360
+ assert MMS2R::Media.sub_type?(mail.parts[0]).eql?('gif')
290
361
  end
291
362
 
292
363
  def test_get_subject
293
- subjects = [nil, '', 'Multimedia message', '(no subject)', 'You have new Picture Mail!']
364
+ subjects = [nil, '', '(no subject)']
294
365
 
366
+ mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_no_content_type.mail').join)
295
367
  subjects.each{|s|
296
- mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_no_content_type.mail').join)
297
368
  mail.subject = s
298
369
  mms = MMS2R::Media.create(mail)
299
370
  mms.process
300
- assert_equal(nil, mms.get_subject)
371
+ assert_equal '', mms.get_subject, "Default subject not scrubbed."
301
372
  mms.purge
302
373
  }
303
374
 
304
375
  mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_no_content_type.mail').join)
305
376
  mms = MMS2R::Media.create(mail)
306
377
  mms.process
307
- assert_equal('text only', mms.get_subject)
378
+ assert_equal 'text only', mms.get_subject
308
379
  mms.purge
309
380
  end
381
+
382
+ def test_get_body
383
+ mail = TMail::Mail.parse(load_mail('hello_world_mail_plain_no_content_type.mail').join)
384
+ mms = MMS2R::Media.create(mail)
385
+ mms.process
386
+ assert_equal 'hello world', mms.get_body
387
+ mms.purge
388
+ end
389
+
390
+ def test_yaml_file_name
391
+ assert_equal 'mms2r_my_cingular_media_subject.yml', MMS2R::Media.yaml_file_name(MMS2R::MyCingularMedia,:subject)
392
+ assert_equal 'mms2r_t_mobile_media_subject.yml', MMS2R::Media.yaml_file_name(MMS2R::TMobileMedia,:subject)
393
+ assert_equal 'mms2r_media_ignore.yml', MMS2R::Media.yaml_file_name(MMS2R::MyCingularMedia.superclass,:ignore)
394
+ assert_equal 'mms2r_media_transform.yml', MMS2R::Media.yaml_file_name(MMS2R::Media,:transform)
395
+ end
310
396
  end