mms2r 1.1.12 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/History.txt +32 -2
  2. data/Manifest.txt +41 -79
  3. data/README.txt +50 -51
  4. data/Rakefile +3 -2
  5. data/conf/aliases.yml +8 -0
  6. data/conf/message.alltel.com.yml +14 -0
  7. data/conf/messaging.nextel.com.yml +10 -0
  8. data/conf/mms.att.net.yml +9 -0
  9. data/conf/mms.dobson.net.yml +4 -0
  10. data/conf/mms.luxgsm.lu.yml +8 -0
  11. data/conf/mms.myhelio.com.yml +12 -0
  12. data/conf/mms.netcom.no.yml +4 -0
  13. data/conf/mms.o2online.de.yml +8 -0
  14. data/conf/mms.three.co.uk.yml +15 -0
  15. data/conf/mms2r_media.yml +6 -0
  16. data/conf/orangemms.net.yml +13 -0
  17. data/conf/pm.sprint.com.yml +10 -0
  18. data/conf/pxt.vodafone.net.nz.yml +5 -0
  19. data/conf/tmomail.net.yml +16 -0
  20. data/conf/vzwpix.com.yml +8 -0
  21. data/dev_tools/anonymizer.rb +20 -0
  22. data/lib/mms2r.rb +19 -45
  23. data/lib/mms2r/media.rb +288 -300
  24. data/lib/mms2r/media/sprint.rb +189 -0
  25. data/test/fixtures/att-text-01.mail +27 -0
  26. data/test/fixtures/helio-image-01.mail +8 -8
  27. data/test/fixtures/helio-message-01.mail +327 -0
  28. data/test/fixtures/luxgsm-image-01.mail +388 -0
  29. data/test/fixtures/netcom-image-01.mail +556 -0
  30. data/test/fixtures/o2-de-image-01.mail +314 -0
  31. data/test/fixtures/orange-uk-image-01.mail +71 -0
  32. data/test/fixtures/pxt-image-01.mail +118 -0
  33. data/test/fixtures/sprint-broken-image-01.mail +1 -1
  34. data/test/fixtures/sprint-image-01.mail +211 -195
  35. data/test/fixtures/sprint-purged-image-01.mail +1 -1
  36. data/test/fixtures/sprint-two-images-01.mail +231 -198
  37. data/test/fixtures/sprint-video-01.mail +210 -195
  38. data/test/fixtures/three-uk-image-01.mail +1202 -0
  39. data/test/test_helper.rb +39 -0
  40. data/test/{test_mms2r_alltel_media.rb → test_message_alltel_com.rb} +13 -17
  41. data/test/{test_mms2r_nextel_media.rb → test_messaging_nextel_com.rb} +12 -19
  42. data/test/{test_mms2r_sprint_pcs_media.rb → test_messaging_sprintpcs_com.rb} +9 -10
  43. data/test/test_mms2r_media.rb +474 -316
  44. data/test/test_mms_att_net.rb +92 -0
  45. data/test/test_mms_dobson_net.rb +41 -0
  46. data/test/test_mms_luxgsm_lu.rb +50 -0
  47. data/test/test_mms_myhelio_com.rb +60 -0
  48. data/test/test_mms_netcom_no.rb +52 -0
  49. data/test/test_mms_o2online_de.rb +53 -0
  50. data/test/test_mms_three_co_uk.rb +42 -0
  51. data/test/test_orangemms_net.rb +100 -0
  52. data/test/test_pm_sprint_com.rb +201 -0
  53. data/test/test_pxt_vodafone_net_nz.rb +37 -0
  54. data/test/{test_mms2r_t_mobile_media.rb → test_tmomail_net.rb} +8 -19
  55. data/test/{test_mms2r_verizon_media.rb → test_vzwpix_com.rb} +34 -27
  56. data/vendor/plugins/mms2r/lib/autotest/mms2r.rb +16 -11
  57. metadata +128 -157
  58. data/conf/mms2r_alltel_media_ignore.yml +0 -13
  59. data/conf/mms2r_att_media_subject.yml +0 -3
  60. data/conf/mms2r_cingular_me_media_subject.yml +0 -3
  61. data/conf/mms2r_cingular_me_media_transform.yml +0 -7
  62. data/conf/mms2r_dobson_media_ignore.yml +0 -4
  63. data/conf/mms2r_helio_media_ignore.yml +0 -6
  64. data/conf/mms2r_media_ignore.yml +0 -5
  65. data/conf/mms2r_media_subject.yml +0 -3
  66. data/conf/mms2r_my_cingular_media_subject.yml +0 -3
  67. data/conf/mms2r_nextel_media_ignore.yml +0 -11
  68. data/conf/mms2r_orange_france_media_ignore.yml +0 -6
  69. data/conf/mms2r_orange_poland_media_subject.yml +0 -3
  70. data/conf/mms2r_sprint_media_ignore.yml +0 -7
  71. data/conf/mms2r_sprint_media_subject.yml +0 -3
  72. data/conf/mms2r_t_mobile_media_ignore.yml +0 -16
  73. data/conf/mms2r_verizon_media_ignore.yml +0 -4
  74. data/conf/mms2r_verizon_media_transform.yml +0 -5
  75. data/lib/mms2r/alltel_media.rb +0 -10
  76. data/lib/mms2r/att_media.rb +0 -13
  77. data/lib/mms2r/cingular_me_media.rb +0 -23
  78. data/lib/mms2r/dobson_media.rb +0 -13
  79. data/lib/mms2r/helio_media.rb +0 -20
  80. data/lib/mms2r/m_mode_media.rb +0 -13
  81. data/lib/mms2r/my_cingular_media.rb +0 -15
  82. data/lib/mms2r/nextel_media.rb +0 -17
  83. data/lib/mms2r/orange_france_media.rb +0 -10
  84. data/lib/mms2r/orange_poland_media.rb +0 -10
  85. data/lib/mms2r/sprint_media.rb +0 -182
  86. data/lib/mms2r/sprint_pcs_media.rb +0 -16
  87. data/lib/mms2r/t_mobile_media.rb +0 -21
  88. data/lib/mms2r/verizon_media.rb +0 -19
  89. data/lib/mms2r/vtext_media.rb +0 -16
  90. data/lib/vendor/text/format.rb +0 -1466
  91. data/lib/vendor/tmail.rb +0 -3
  92. data/lib/vendor/tmail/address.rb +0 -242
  93. data/lib/vendor/tmail/attachments.rb +0 -39
  94. data/lib/vendor/tmail/base64.rb +0 -71
  95. data/lib/vendor/tmail/config.rb +0 -69
  96. data/lib/vendor/tmail/encode.rb +0 -467
  97. data/lib/vendor/tmail/facade.rb +0 -552
  98. data/lib/vendor/tmail/header.rb +0 -914
  99. data/lib/vendor/tmail/info.rb +0 -35
  100. data/lib/vendor/tmail/loader.rb +0 -1
  101. data/lib/vendor/tmail/mail.rb +0 -447
  102. data/lib/vendor/tmail/mailbox.rb +0 -433
  103. data/lib/vendor/tmail/mbox.rb +0 -1
  104. data/lib/vendor/tmail/net.rb +0 -280
  105. data/lib/vendor/tmail/obsolete.rb +0 -135
  106. data/lib/vendor/tmail/parser.rb +0 -1522
  107. data/lib/vendor/tmail/port.rb +0 -377
  108. data/lib/vendor/tmail/quoting.rb +0 -131
  109. data/lib/vendor/tmail/scanner.rb +0 -41
  110. data/lib/vendor/tmail/scanner_r.rb +0 -263
  111. data/lib/vendor/tmail/stringio.rb +0 -277
  112. data/lib/vendor/tmail/tmail.rb +0 -1
  113. data/lib/vendor/tmail/utils.rb +0 -238
  114. data/test/fixtures/broken_from_spam.mail +0 -80
  115. data/test/fixtures/hello_world_empty_text.mail +0 -7
  116. data/test/fixtures/hello_world_mail_multipart.mail +0 -24
  117. data/test/fixtures/hello_world_mail_plain_no_content_type.mail +0 -7
  118. data/test/fixtures/hello_world_mail_plain_with_content_type.mail +0 -8
  119. data/test/fixtures/simple-with-two-images-two-texts.mail +0 -49
  120. data/test/fixtures/simple_image.mail +0 -19
  121. data/test/fixtures/simple_multipart_alternative.mail +0 -42
  122. data/test/test_mms2r_att_media.rb +0 -54
  123. data/test/test_mms2r_cingular_me_media.rb +0 -51
  124. data/test/test_mms2r_dobson_media.rb +0 -46
  125. data/test/test_mms2r_helio_media.rb +0 -49
  126. data/test/test_mms2r_m_mode_media.rb +0 -36
  127. data/test/test_mms2r_my_cingular_media.rb +0 -31
  128. data/test/test_mms2r_orange_france_media.rb +0 -53
  129. data/test/test_mms2r_orange_poland_media.rb +0 -42
  130. data/test/test_mms2r_sprint_media.rb +0 -269
  131. data/test/test_mms2r_vtext_media.rb +0 -28
@@ -1,54 +0,0 @@
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
- class MMS2R::AttMediaTest < Test::Unit::TestCase
11
- include MMS2R::TestHelper
12
-
13
- def setup
14
- @log = Logger.new(STDOUT)
15
- @log.level = Logger::DEBUG
16
- @log.datetime_format = "%H:%M:%S"
17
- end
18
-
19
- def teardown; end
20
-
21
- def test_simple
22
- mail = TMail::Mail.parse(load_mail('att-image-01.mail').join)
23
- mms = MMS2R::Media.create(mail)
24
- assert_equal(MMS2R::AttMedia, mms.class, "expected a #{MMS2R::AttMedia} and received a #{mms.class}")
25
- mms.process
26
-
27
- assert(mms.media.size == 1)
28
- assert_nil(mms.media['text/plain'])
29
- assert_nil(mms.media['text/html'])
30
- assert_not_nil(mms.media['image/jpeg'][0])
31
- assert_match(/Photo_12.jpg$/, mms.media['image/jpeg'][0])
32
-
33
- assert_file_size(mms.media['image/jpeg'][0], 337)
34
- mms.purge
35
- end
36
-
37
- def test_subject
38
- mail = TMail::Mail.parse(load_mail('att-image-02.mail').join)
39
- mms = MMS2R::Media.create(mail)
40
- assert_equal(MMS2R::AttMedia, mms.class, "expected a #{MMS2R::AttMedia} and received a #{mms.class}")
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(/Photo_12.jpg$/, mms.media['image/jpeg'][0])
48
-
49
- assert_file_size(mms.media['image/jpeg'][0], 337)
50
-
51
- assert_nil mms.subject
52
- mms.purge
53
- end
54
- end
@@ -1,51 +0,0 @@
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
@@ -1,46 +0,0 @@
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_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.body
43
-
44
- mms.purge
45
- end
46
- end
@@ -1,49 +0,0 @@
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::HelioMediaTest < Test::Unit::TestCase
12
- include MMS2R::TestHelper
13
-
14
- def setup
15
- mail = TMail::Mail.parse(load_mail('helio-image-01.mail').join)
16
- @mms = MMS2R::Media.create(mail)
17
- @mms.process
18
- end
19
-
20
- def test_instantiated_class_should_be_helio_media
21
- assert_equal @mms.class, MMS2R::HelioMedia
22
- end
23
-
24
- def test_number_should_return_correct_number
25
- number = @mms.number()
26
- assert_equal number, 7608070850.to_s
27
- end
28
-
29
- def test_subject_should_return_correct_subject
30
- title = @mms.subject()
31
- assert_equal title, "Test image"
32
- end
33
-
34
- def test_body_should_return_correct_body
35
- body = @mms.body()
36
- assert_equal body, "Test image"
37
- end
38
-
39
- def test_attachment_should_return_jpeg
40
- image = @mms.default_media()
41
- assert_not_nil @mms.media['image/jpeg'][0]
42
- assert_match(/0628070005.jpg$/, @mms.media['image/jpeg'][0])
43
- end
44
-
45
- def teardown
46
- @mms.purge
47
- end
48
-
49
- end
@@ -1,36 +0,0 @@
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
- class MMS2R::MModeMediaTest < Test::Unit::TestCase
11
- include MMS2R::TestHelper
12
-
13
- def setup
14
- @log = Logger.new(STDOUT)
15
- @log.level = Logger::DEBUG
16
- @log.datetime_format = "%H:%M:%S"
17
- end
18
-
19
- def teardown; end
20
-
21
- def test_simple
22
- mail = TMail::Mail.parse(load_mail('mmode-image-01.mail').join)
23
- mms = MMS2R::Media.create(mail)
24
- assert_equal(MMS2R::MModeMedia, mms.class, "expected a #{MMS2R::MModeMedia} and received a #{mms.class}")
25
- mms.process
26
-
27
- assert(mms.media.size == 1)
28
- assert_nil(mms.media['text/plain'])
29
- assert_nil(mms.media['text/html'])
30
- assert_not_nil(mms.media['image/jpeg'][0])
31
- assert_match(/picture\(3\).jpg$/, mms.media['image/jpeg'][0])
32
-
33
- assert_file_size(mms.media['image/jpeg'][0], 337)
34
- mms.purge
35
- end
36
- end
@@ -1,31 +0,0 @@
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
- class MMS2R::MyCingularMediaTest < Test::Unit::TestCase
11
- include MMS2R::TestHelper
12
-
13
- def test_image
14
- mail = TMail::Mail.parse(load_mail('mycingular-image-01.mail').join)
15
- mms = MMS2R::Media.create(mail)
16
- assert_equal(MMS2R::MyCingularMedia, mms.class, "expected a #{MMS2R::MyCingularMedia} and received a #{mms.class}")
17
- mms.process
18
-
19
- assert_equal 2, mms.media.size, "Size is #{mms.media.size}"
20
- assert_not_nil mms.media['text/plain']
21
- assert_not_nil mms.media['image/jpeg'][0]
22
- assert_match(/04-18-07_1723.jpg$/, mms.media['image/jpeg'][0])
23
-
24
- assert_equal nil, mms.subject, "Default Cingular subject not stripped"
25
- assert_file_size mms.media['image/jpeg'][0], 337
26
-
27
- assert_equal "Water", IO.readlines(mms.default_text.path).join
28
-
29
- mms.purge
30
- end
31
- end
@@ -1,53 +0,0 @@
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
- class MMS2R::OrangeFranceMediaTest < Test::Unit::TestCase
11
- include MMS2R::TestHelper
12
-
13
- def test_create_should_return_orange_france
14
- mail = TMail::Mail.parse(load_mail('orangefrance-text-and-image.mail').join)
15
- mms = MMS2R::Media.create(mail)
16
- assert_equal MMS2R::OrangeFranceMedia, mms.class, "expected a #{MMS2R::OrangeFranceMedia} and received a #{mms.class}"
17
- end
18
-
19
- def test_empty_subject
20
- mail = TMail::Mail.parse(load_mail('orangefrance-text-and-image.mail').join)
21
- mms = MMS2R::Media.create(mail)
22
- mms.process
23
- assert_nil mms.subject
24
- end
25
-
26
- def test_processed_content
27
- mail = TMail::Mail.parse(load_mail('orangefrance-text-and-image.mail').join)
28
- mms = MMS2R::Media.create(mail)
29
- mms.process
30
-
31
- # there should be one text and one image
32
- assert_equal 2, mms.media.size
33
-
34
- #text
35
- # there is a text banner that Orange attaches but
36
- # that should be ignored
37
- assert_not_nil mms.media['text/plain']
38
- assert_equal 1, mms.media['text/plain'].size
39
- file = mms.media['text/plain'].first
40
- assert File::exist?(file), "file #{file} does not exist"
41
- text = IO.readlines("#{file}").join
42
- assert_match(/Test ma poule/, text)
43
-
44
- # image
45
- assert_not_nil mms.media['image/jpeg']
46
- assert_equal 1, mms.media['image/jpeg'].size
47
- assert_match(/IMAGE.jpeg$/, mms.media['image/jpeg'].first)
48
- assert_file_size mms.media['image/jpeg'].first, 337
49
-
50
- mms.purge
51
- end
52
-
53
- end
@@ -1,42 +0,0 @@
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
- class MMS2R::OrangePolandMediaTest < Test::Unit::TestCase
11
- include MMS2R::TestHelper
12
-
13
- def test_empty_subject
14
- mail = TMail::Mail.parse(load_mail('orangepoland-text-01.mail').join)
15
- mms = MMS2R::Media.create(mail)
16
- assert_equal MMS2R::OrangePolandMedia, mms.class, "expected a #{MMS2R::OrangePolandMedia} and received a #{mms.class}"
17
- mms.process
18
- assert_nil mms.subject
19
- assert_not_nil mms.media['text/plain']
20
- file = mms.media['text/plain'][0]
21
- assert_not_nil file
22
- assert File::exist?(file), "file #{file} does not exist"
23
- text = IO.readlines("#{file}").join
24
- assert_match(/pozdro600/, text)
25
- mms.purge
26
- end
27
-
28
- def test_non_empty_subject
29
- mail = TMail::Mail.parse(load_mail('orangepoland-text-02.mail').join)
30
- mms = MMS2R::Media.create(mail)
31
- assert_equal MMS2R::OrangePolandMedia, mms.class, "expected a #{MMS2R::OrangePolandMedia} and received a #{mms.class}"
32
- mms.process
33
- assert mms.subject, "whazzup"
34
- assert_not_nil mms.media['text/plain']
35
- file = mms.media['text/plain'][0]
36
- assert_not_nil file
37
- assert File::exist?(file), "file #{file} does not exist"
38
- text = IO.readlines("#{file}").join
39
- assert_match(/pozdro600/, text)
40
- mms.purge
41
- end
42
- end
@@ -1,269 +0,0 @@
1
- $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
- require File.dirname(__FILE__) + "/test_helper"
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 = "fixtures/dot.jpg"
18
- res.body = File.open("#{File.dirname(__FILE__)}/#{f}", 'rb') { |file|
19
- file.read
20
- }
21
- end
22
- end
23
-
24
- class BrokenImageServlet < WEBrick::HTTPServlet::AbstractServlet
25
- def do_GET(req, res)
26
- raise
27
- #res['Content-Type'] = "text/html"
28
- #res.code = 404
29
- #res.body = '<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1></body></html>'
30
- end
31
- end
32
-
33
- class PurgedImageServlet < WEBrick::HTTPServlet::AbstractServlet
34
- def do_GET(req, res)
35
- res['Content-Type'] = "text/html"
36
- res.code = 500
37
- res.body = %q!<html>
38
- <head>
39
- <title>Pictures from Sprint: Error</title>
40
- <link rel="STYLESHEET" type="text/css" href="/retailers/PCSNEXTEL/main.css">
41
- </head>
42
-
43
- <body LEFTMARGIN="0" RIGHTMARGIN="0" TOPMARGIN="0" BOTTOMMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">
44
- <table border="0" cellpadding="0" cellspacing="0" bgcolor="#F1F1F1" width="386">
45
- <tr>
46
- We're sorry, this page is not available. We apologize for the inconvenience. Please go to <a href="http://pictures.sprintpcs.com">pictures.sprintpcs.com</a> in case you are using an old bookmark, which is no longer valid.
47
- </td>
48
- </tr>
49
- </table>
50
- </body>
51
- </html>!
52
- end
53
- end
54
-
55
- class SimpleVideoServlet < WEBrick::HTTPServlet::AbstractServlet
56
- def do_GET(req, res)
57
- res['Content-Type'] = "video/quicktime"
58
- f = "fixtures/sprint.mov"
59
- res.body = File.open("#{File.dirname(__FILE__)}/#{f}", 'rb') { |file|
60
- file.read
61
- }
62
- end
63
- end
64
-
65
- class Net::HTTP
66
-
67
- alias :old_do_start :do_start
68
-
69
- def do_start
70
- @started = true
71
- end
72
-
73
- SERVLETS = {
74
- '/mmps' => SimpleImageServlet,
75
- '/simpleimage' => SimpleImageServlet,
76
- '/brokenimage' => BrokenImageServlet,
77
- '/simplevideo' => SimpleVideoServlet
78
- }
79
-
80
- alias :old_request :request
81
-
82
- def request(request, *data, &block)
83
- url = URI.parse(request.path)
84
- path = url.path.gsub('%20', ' ').match(/^\/[^\/]+/)[0]
85
- res = Response.new
86
- request.query = WEBrick::HTTPUtils.parse_query(url.query)
87
- servlet = case
88
- when request.query['HACK'].eql?('VIDEO')
89
- SimpleVideoServlet
90
- when request.query['HACK'].eql?('IMAGE')
91
- SimpleImageServlet
92
- when request.query['HACK'].eql?('BROKEN')
93
- BrokenImageServlet
94
- when request.query['HACK'].eql?('PURGED')
95
- PurgedImageServlet
96
- else
97
- SERVLETS[path]
98
- end
99
- servlet.new({}).send("do_#{request.method}", request, res)
100
- res.code ||= "200"
101
- res
102
- end
103
- end
104
-
105
- class Net::HTTPRequest
106
- attr_accessor :query, :body, :cookies
107
- end
108
-
109
- class Response
110
- include Net::HTTPHeader
111
-
112
- attr_reader :code
113
- attr_accessor :body, :query, :cookies
114
-
115
- def code=(c)
116
- @code = c.to_s
117
- end
118
-
119
- alias :status :code
120
- alias :status= :code=
121
-
122
- def initialize
123
- @header = {}
124
- @body = ''
125
- @code = nil
126
- @query = nil
127
- @cookies = []
128
- end
129
-
130
- def read_body
131
- yield body
132
- end
133
-
134
- def value()
135
- return body if "200".eql?(@code)
136
- raise Net::HTTPError.new('400 Bad Request', 'Good Bye')
137
- end
138
- end
139
-
140
- class MMS2R::SprintMediaTest < Test::Unit::TestCase
141
- include MMS2R::TestHelper
142
-
143
- def setup
144
- @log = Logger.new(STDOUT)
145
- @log.level = Logger::DEBUG
146
- @log.datetime_format = "%H:%M:%S"
147
- end
148
-
149
- def teardown; end
150
-
151
- def test_mms_should_have_text
152
- mail = TMail::Mail.parse(load_mail('sprint-text-01.mail').join)
153
- mms = MMS2R::Media.create(mail)
154
- mms.process
155
- assert_equal 1, mms.media.size
156
- assert_equal 1, mms.media['text/plain'].size
157
- assert_equal 7, mms.default_text.size
158
- text = IO.readlines("#{mms.default_text.path}").join
159
- assert_match(/Tea Pot/, text)
160
- mms.purge
161
- end
162
-
163
- def test_mms_should_have_a_phone_number
164
- mail = TMail::Mail.parse(load_mail('sprint-image-01.mail').join)
165
- mms = MMS2R::Media.create(mail)
166
- mms.process
167
- assert_equal '2068509247', mms.number
168
- mms.purge
169
- end
170
-
171
- def test_should_have_simple_video
172
- mail = TMail::Mail.parse(load_mail('sprint-video-01.mail').join)
173
- mms = MMS2R::Media.create(mail)
174
- mms.process
175
-
176
- assert_equal 1, mms.media.size
177
- assert_nil mms.media['text/plain']
178
- assert_nil mms.media['text/html']
179
- assert_not_nil mms.media['video/quicktime'][0]
180
- assert_match(/000_0123a01234567895_1-0.mov$/, mms.media['video/quicktime'][0])
181
-
182
- assert_file_size mms.media['video/quicktime'][0], 49063
183
-
184
- assert_equal nil, mms.subject, "Default Sprint subject not scrubbed."
185
-
186
- mms.purge
187
- end
188
-
189
- def test_should_have_simple_image
190
- mail = TMail::Mail.parse(load_mail('sprint-image-01.mail').join)
191
- mms = MMS2R::Media.create(mail)
192
- mms.process
193
-
194
- assert_equal 1, mms.media.size
195
- assert_nil mms.media['text/plain']
196
- assert_nil mms.media['text/html']
197
- assert_not_nil mms.media['image/jpeg'][0]
198
- assert_match(/000_0123a01234567890_1-0.jpg$/, mms.media['image/jpeg'][0])
199
-
200
- assert_file_size mms.media['image/jpeg'][0], 337
201
-
202
- assert_equal nil, mms.subject, "Default Sprint subject not scrubbed"
203
-
204
- mms.purge
205
- end
206
-
207
- def test_collect_image_using_block
208
- mail = TMail::Mail.parse(load_mail('sprint-image-01.mail').join)
209
- mms = MMS2R::Media.create(mail)
210
- file_array = nil
211
- mms.process do |k, v|
212
- file_array = v if (k == 'image/jpeg')
213
- assert_not_nil(file = file_array.first)
214
- assert(File::exist?(file), "file #{file} does not exist")
215
- assert(File.basename(file) =~ /000_0123a01234567890_1-0\.jpg/, "file #{file} does not exist")
216
- end
217
- # mms.purge has to be called manually
218
- assert File.exist?(file_array.first)
219
- end
220
-
221
- def test_should_have_two_images
222
- mail = TMail::Mail.parse(load_mail('sprint-two-images-01.mail').join)
223
- mms = MMS2R::Media.create(mail)
224
- mms.process
225
-
226
- assert_equal 1, mms.media.size
227
- assert_nil mms.media['text/plain']
228
- assert_nil mms.media['text/html']
229
- assert_equal 2, mms.media['image/jpeg'].size
230
- assert_not_nil mms.media['image/jpeg'][0]
231
- assert_not_nil mms.media['image/jpeg'][1]
232
- assert_match(/000_0123a01234567890_1-0.jpg$/, mms.media['image/jpeg'][0])
233
- assert_match(/000_0123a01234567890_1-1.jpg$/, mms.media['image/jpeg'][1])
234
-
235
- assert_file_size mms.media['image/jpeg'][0], 337
236
- assert_file_size mms.media['image/jpeg'][1], 337
237
-
238
- assert_equal nil, mms.subject, "Default Sprint subject not scrubbed"
239
-
240
- mms.purge
241
- end
242
-
243
- def test_image_should_be_missing
244
- mail = TMail::Mail.parse(load_mail('sprint-broken-image-01.mail').join)
245
- mms = MMS2R::Media.create(mail)
246
- mms.process
247
-
248
- assert_equal 0, mms.media.size
249
-
250
- mms.purge
251
- end
252
-
253
- def test_image_should_be_purged_from_content_server
254
- mail = TMail::Mail.parse(load_mail('sprint-purged-image-01.mail').join)
255
- mms = MMS2R::Media.create(mail)
256
- mms.process
257
-
258
- assert_equal 0, mms.media.size
259
-
260
- mms.purge
261
- end
262
-
263
- def test_body_should_return_nil_when_there_is_no_user_text
264
- mail = TMail::Mail.parse(load_mail('sprint-image-01.mail').join)
265
- mms = MMS2R::Media.create(mail)
266
- mms.process
267
- assert_equal nil, mms.body
268
- end
269
- end