mms2r 2.4.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/.gitignore +1 -0
  2. data/History.txt +5 -0
  3. data/Manifest.txt +1 -1
  4. data/README.txt +12 -9
  5. data/Rakefile +11 -10
  6. data/conf/mobile.indosat.net.id.yml +1 -1
  7. data/conf/waw.plspictures.com.yml +1 -1
  8. data/lib/mail_ext.rb +37 -0
  9. data/lib/mms2r.rb +7 -5
  10. data/lib/mms2r/media.rb +29 -35
  11. data/lib/mms2r/media/sprint.rb +19 -19
  12. data/mms2r.gemspec +23 -17
  13. data/test/fixtures/att-blackberry-02.mail +5 -6
  14. data/test/fixtures/att-iphone-01.mail +3 -3
  15. data/test/fixtures/dobson-image-01.mail +3 -3
  16. data/test/fixtures/maroctelecom-france-mms-01.mail +4 -4
  17. data/test/fixtures/mycingular-image-01.mail +3 -3
  18. data/test/fixtures/nextel-image-02.mail +2 -2
  19. data/test/fixtures/orangepoland-text-01.mail +2 -1
  20. data/test/fixtures/orangepoland-text-02.mail +2 -1
  21. data/test/fixtures/pics.cingularme.com-image-01.mail +0 -1
  22. data/test/fixtures/sasktel-image-01.mail +4 -4
  23. data/test/fixtures/sprint-broken-image-01.mail +1 -1
  24. data/test/fixtures/sprint-text-01.mail +1 -1
  25. data/test/fixtures/tmobile-blackberry-02.mail +4 -4
  26. data/test/test_1nbox_net.rb +16 -19
  27. data/test/test_bell_canada.rb +8 -13
  28. data/test/test_bellsouth_net.rb +5 -10
  29. data/test/test_helper.rb +16 -11
  30. data/test/test_mediamessaging_o2_co_uk.rb +21 -17
  31. data/test/test_messaging_nextel_com.rb +18 -12
  32. data/test/test_messaging_sprintpcs_com.rb +4 -8
  33. data/test/test_mms2r_media.rb +153 -143
  34. data/test/test_mms_3ireland_ie.rb +4 -9
  35. data/test/test_mms_ae.rb +12 -12
  36. data/test/test_mms_alltel_com.rb +14 -15
  37. data/test/test_mms_att_net.rb +35 -27
  38. data/test/test_mms_dobson_net.rb +9 -11
  39. data/test/test_mms_luxgsm_lu.rb +23 -17
  40. data/test/test_mms_mobileiam_ma.rb +4 -10
  41. data/test/test_mms_mtn_co_za.rb +4 -9
  42. data/test/test_mms_mycricket_com.rb +9 -9
  43. data/test/test_mms_myhelio_com.rb +18 -14
  44. data/test/test_mms_netcom_no.rb +19 -17
  45. data/test/test_mms_o2online_de.rb +20 -18
  46. data/test/test_mms_three_co_uk.rb +14 -14
  47. data/test/test_mms_vodacom4me_co_za.rb +24 -24
  48. data/test/test_mobile_indosat_net_id.rb +6 -9
  49. data/test/test_msg_telus_com.rb +5 -10
  50. data/test/test_orangemms_net.rb +25 -17
  51. data/test/test_pm_sprint_com.rb +37 -22
  52. data/test/test_pxt_vodafone_net_nz.rb +7 -11
  53. data/test/test_rci_rogers_com.rb +3 -8
  54. data/test/test_sms_sasktel_com.rb +2 -7
  55. data/test/test_tmomail_net.rb +25 -23
  56. data/test/test_unicel_com.rb +8 -12
  57. data/test/test_vmpix_com.rb +14 -13
  58. data/test/test_vzwpix_com.rb +24 -14
  59. data/test/test_waw_plspictures_com.rb +2 -7
  60. metadata +77 -26
  61. data/lib/tmail_ext.rb +0 -22
data/test/test_helper.rb CHANGED
@@ -1,8 +1,14 @@
1
+ require 'rubygems'
1
2
  require 'set'
2
3
  require 'net/http'
3
4
  require 'net/https'
4
5
  require 'pp'
5
6
  require 'exifr'
7
+ require 'tempfile'
8
+ require 'test/unit'
9
+ require 'mocha'
10
+ require File.join(File.dirname(__FILE__), "..", "lib", "mms2r")
11
+
6
12
  begin require 'redgreen'; rescue LoadError; end
7
13
 
8
14
  module MMS2R
@@ -14,28 +20,27 @@ module MMS2R
14
20
  assert(File::size(file) == size, "file #{file} is #{File::size(file)} bytes, not #{size} bytes")
15
21
  end
16
22
 
17
- def load_mail(file)
18
- IO.readlines(mail_fixture(file))
19
- end
20
-
21
23
  def mail_fixture(file)
22
24
  "#{File.dirname(__FILE__)}/fixtures/#{file}"
23
25
  end
24
26
 
27
+ def mail(name)
28
+ Mail.read(mail_fixture(name))
29
+ end
30
+
25
31
  def smart_phone_mock(model_text = 'iPhone', jpeg = true)
26
32
  mail = mock('mail')
27
- mail.expects(:header).at_least_once.returns({'return-path' => '<joe@null.example.com>'})
28
33
  mail.expects(:from).at_least_once.returns(['joe@example.com'])
34
+ mail.expects(:return_path).at_least_once.returns('<joe@example.com>')
29
35
  mail.expects(:message_id).returns('abcd0123')
30
36
  mail.expects(:multipart?).returns(true)
37
+
31
38
  part = mock('part')
32
39
  part.expects(:part_type?).at_least_once.returns("image/#{jpeg ? 'jpeg' : 'tiff'}")
33
- part.expects(:sub_header).with('content-type', 'name').returns(nil)
34
- part.expects(:sub_header).with('content-disposition', 'filename').returns(nil)
35
- part.expects("[]".to_sym).with('content-location').at_least_once.returns("Photo_12.#{jpeg ? 'jpg' : 'tif'}")
36
- part.expects(:main_type).with('text').returns(nil)
37
- part.expects(:content_type).at_least_once.returns("image/#{jpeg ? 'jpeg' : 'tiff'}")
38
- part.expects(:body).at_least_once.returns('abc')
40
+ part.expects(:body).at_least_once.returns(Mail::Body.new('abc'))
41
+ part.expects(:multipart?).at_least_once.returns(false)
42
+ part.expects(:filename).returns("foo.#{jpeg ? 'jpg' : 'tif'}")
43
+
39
44
  mail.expects(:parts).returns([part])
40
45
  exif = mock('exif')
41
46
  exif.expects(:model).at_least_once.returns(model_text)
@@ -1,52 +1,56 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "mms2r")
2
1
  require File.join(File.dirname(__FILE__), "test_helper")
3
- require 'test/unit'
4
- require 'rubygems'
5
- require 'mocha'
6
- gem 'tmail', '>= 1.2.1'
7
- require 'tmail'
8
2
 
9
3
  class TestMediamessagingO2CoUk < Test::Unit::TestCase
10
4
  include MMS2R::TestHelper
11
5
 
12
6
  def test_subject
13
- mail = TMail::Mail.parse(load_mail('mediamessaging_o2_co_uk-image-01.mail').join)
7
+ mail = mail('mediamessaging_o2_co_uk-image-01.mail')
14
8
  mms = MMS2R::Media.new(mail)
9
+ assert_equal "+2068675309", mms.number
10
+ assert_equal "mediamessaging.o2.co.uk", mms.carrier
15
11
  assert_equal "Office pic", mms.subject
16
12
  mms.purge
17
13
  end
18
14
 
19
15
  def test_image
20
- mail = TMail::Mail.parse(load_mail('mediamessaging_o2_co_uk-image-01.mail').join)
16
+ mail = mail('mediamessaging_o2_co_uk-image-01.mail')
21
17
  mms = MMS2R::Media.new(mail)
22
-
18
+ assert_equal "+2068675309", mms.number
19
+ assert_equal "mediamessaging.o2.co.uk", mms.carrier
20
+
23
21
  assert_equal 2, mms.media.size
24
22
  assert_not_nil mms.media['text/plain']
25
23
  assert_equal 1, mms.media['text/plain'].size
26
24
  assert_not_nil mms.media['image/jpeg']
27
25
  assert_equal 1, mms.media['image/jpeg'].size
28
26
  assert mms.media['image/jpeg'].detect{|f| File.size(f) == 337}
29
-
27
+
30
28
  mms.purge
31
29
  end
32
30
 
33
31
  def test_default_media_should_return_user_generated_content
34
- mail = TMail::Mail.parse(load_mail('mediamessaging_o2_co_uk-image-01.mail').join)
32
+ mail = mail('mediamessaging_o2_co_uk-image-01.mail')
35
33
  mms = MMS2R::Media.new(mail)
34
+ assert_equal "+2068675309", mms.number
35
+ assert_equal "mediamessaging.o2.co.uk", mms.carrier
36
+
36
37
  file = mms.default_media
37
38
  assert_equal 337, file.size
38
-
39
+
39
40
  mms.purge
40
- end
41
+ end
41
42
 
42
43
  def test_default_text_should_return_user_generated_content
43
- mail = TMail::Mail.parse(load_mail('mediamessaging_o2_co_uk-image-01.mail').join)
44
+ mail = mail('mediamessaging_o2_co_uk-image-01.mail')
44
45
  mms = MMS2R::Media.new(mail)
46
+ assert_equal "+2068675309", mms.number
47
+ assert_equal "mediamessaging.o2.co.uk", mms.carrier
48
+
45
49
  file = mms.default_text
46
50
  assert_equal 10, file.size
47
51
  assert_equal "Office pic", file.read
48
-
52
+
49
53
  mms.purge
50
- end
51
-
54
+ end
55
+
52
56
  end
@@ -1,17 +1,13 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "mms2r")
2
1
  require File.join(File.dirname(__FILE__), "test_helper")
3
- require 'test/unit'
4
- require 'rubygems'
5
- require 'mocha'
6
- gem 'tmail', '>= 1.2.1'
7
- require 'tmail'
8
2
 
9
3
  class TestMessagingNextelCom < Test::Unit::TestCase
10
4
  include MMS2R::TestHelper
11
5
 
12
6
  def test_simple_text_is_nil
13
- mail = TMail::Mail.parse(load_mail('nextel-image-01.mail').join)
7
+ mail = mail('nextel-image-01.mail')
14
8
  mms = MMS2R::Media.new(mail)
9
+ assert_equal "2068675309", mms.number
10
+ assert_equal "messaging.nextel.com", mms.carrier
15
11
 
16
12
  assert_nil mms.default_text
17
13
 
@@ -19,8 +15,10 @@ class TestMessagingNextelCom < Test::Unit::TestCase
19
15
  end
20
16
 
21
17
  def test_simple_default_media
22
- mail = TMail::Mail.parse(load_mail('nextel-image-01.mail').join)
18
+ mail = mail('nextel-image-01.mail')
23
19
  mms = MMS2R::Media.new(mail)
20
+ assert_equal "2068675309", mms.number
21
+ assert_equal "messaging.nextel.com", mms.carrier
24
22
 
25
23
  file = mms.default_media
26
24
  assert_file_size file, 337
@@ -32,8 +30,10 @@ class TestMessagingNextelCom < Test::Unit::TestCase
32
30
  end
33
31
 
34
32
  def test_simple_image1
35
- mail = TMail::Mail.parse(load_mail('nextel-image-01.mail').join)
33
+ mail = mail('nextel-image-01.mail')
36
34
  mms = MMS2R::Media.new(mail)
35
+ assert_equal "2068675309", mms.number
36
+ assert_equal "messaging.nextel.com", mms.carrier
37
37
 
38
38
  assert_equal 1, mms.media.size
39
39
  assert_nil mms.media['text/plain']
@@ -47,8 +47,10 @@ class TestMessagingNextelCom < Test::Unit::TestCase
47
47
  end
48
48
 
49
49
  def test_simple_image2
50
- mail = TMail::Mail.parse(load_mail('nextel-image-02.mail').join)
50
+ mail = mail('nextel-image-02.mail')
51
51
  mms = MMS2R::Media.new(mail)
52
+ assert_equal "2068675309", mms.number
53
+ assert_equal "messaging.nextel.com", mms.carrier
52
54
 
53
55
  assert_equal 1, mms.media.size
54
56
  assert_nil mms.media['text/plain']
@@ -62,8 +64,10 @@ class TestMessagingNextelCom < Test::Unit::TestCase
62
64
  end
63
65
 
64
66
  def test_simple_image3
65
- mail = TMail::Mail.parse(load_mail('nextel-image-03.mail').join)
67
+ mail = mail('nextel-image-03.mail')
66
68
  mms = MMS2R::Media.new(mail)
69
+ assert_equal "2068675309", mms.number
70
+ assert_equal "messaging.nextel.com", mms.carrier
67
71
 
68
72
  assert_equal 1, mms.media.size
69
73
  assert_nil mms.media['text/plain']
@@ -77,8 +81,10 @@ class TestMessagingNextelCom < Test::Unit::TestCase
77
81
  end
78
82
 
79
83
  def test_simple_image4
80
- mail = TMail::Mail.parse(load_mail('nextel-image-04.mail').join)
84
+ mail = mail('nextel-image-04.mail')
81
85
  mms = MMS2R::Media.new(mail)
86
+ assert_equal "2068675309", mms.number
87
+ assert_equal "messaging.nextel.com", mms.carrier
82
88
 
83
89
  assert_equal 1, mms.media.size
84
90
  assert_nil mms.media['text/plain']
@@ -1,17 +1,13 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "mms2r")
2
1
  require File.join(File.dirname(__FILE__), "test_helper")
3
- require 'test/unit'
4
- require 'rubygems'
5
- require 'mocha'
6
- gem 'tmail', '>= 1.2.1'
7
- require 'tmail'
8
2
 
9
3
  class TestMessagingSprintpcsCom < Test::Unit::TestCase
10
4
  include MMS2R::TestHelper
11
5
 
12
6
  def test_simple_text
13
- mail = TMail::Mail.parse(load_mail('sprint-pcs-text-01.mail').join)
7
+ mail = mail('sprint-pcs-text-01.mail')
14
8
  mms = MMS2R::Media.new(mail)
9
+ assert_equal "2068675309", mms.number
10
+ assert_equal "messaging.sprintpcs.com", mms.carrier
15
11
 
16
12
  assert_equal 1, mms.media.size
17
13
  assert_not_nil mms.media['text/plain']
@@ -22,5 +18,5 @@ class TestMessagingSprintpcsCom < Test::Unit::TestCase
22
18
  assert_match(/hello world/, text)
23
19
  mms.purge
24
20
  end
25
-
21
+
26
22
  end
@@ -1,11 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "..", "lib", "mms2r")
2
1
  require File.join(File.dirname(__FILE__), "test_helper")
3
- require 'tempfile'
4
- require 'test/unit'
5
- require 'rubygems'
6
- require 'mocha'
7
- gem 'tmail', '>= 1.2.1'
8
- require 'tmail'
9
2
 
10
3
  class TestMms2rMedia < Test::Unit::TestCase
11
4
  include MMS2R::TestHelper
@@ -34,30 +27,29 @@ class TestMms2rMedia < Test::Unit::TestCase
34
27
  MMS2R::Media.conf_dir = @oldconfdir
35
28
  end
36
29
 
37
- def stub_mail(*keys)
38
- attrs = {
39
- :message_id => '123',
40
- :from => ['joe@example.com'],
41
- :multipart? => false,
42
- :parts => [],
43
- :main_type => 'text',
44
- :content_type => 'text/plain',
45
- :part_type? => 'text/plain',
46
- :sub_header => 'message.txt',
47
-
30
+ def stub_mail(vals = {})
31
+ attrs = {
32
+ :from => 'joe@example.com',
33
+ :to => 'jane@example.com',
34
+ :subject => 'This is a test email',
48
35
  :body => 'a',
49
- :header => {}
50
- }.except(keys)
51
- stub('mail', attrs)
36
+ }.merge(vals)
37
+
38
+ Mail.new do
39
+ from attrs[:from]
40
+ to attrs[:to]
41
+ subject attrs[:subject]
42
+ body attrs[:body]
43
+ end
52
44
  end
53
45
 
54
46
  def test_class_parse
55
- mms = MMS2R.parse(load_mail('generic.mail').join)
47
+ mms = mail('generic.mail')
56
48
  assert_equal ['noreply@rubyforge.org'], mms.from
57
49
  end
58
50
 
59
51
  def temp_text_file(text)
60
- tf = Tempfile.new("test" + Time.now.to_f.to_s)
52
+ tf = Tempfile.new("test" + rand.to_s)
61
53
  tf.puts(text)
62
54
  tf.close
63
55
  tf.path
@@ -108,7 +100,7 @@ class TestMms2rMedia < Test::Unit::TestCase
108
100
  end
109
101
 
110
102
  def test_instance_initialize_config
111
- mms = MMS2R::Media.new(stub_mail())
103
+ mms = MMS2R::Media.new stub_mail
112
104
  config = mms.initialize_config(nil)
113
105
 
114
106
  # test defaults shipped in mms2r_media.yml
@@ -131,8 +123,8 @@ class TestMms2rMedia < Test::Unit::TestCase
131
123
 
132
124
  def test_create_with_default_processor
133
125
  mail = mock()
134
- mail.expects(:header).at_least_once.returns({})
135
126
  mail.expects(:from).at_least_once.returns(['joe@unknown.example.com'])
127
+ mail.expects(:return_path).at_least_once.returns('joe@unknown.example.com')
136
128
  mms = MMS2R::Media.create(mail)
137
129
  assert_equal [MMS2R::Media, 'unknown.example.com'] , mms
138
130
  end
@@ -140,8 +132,8 @@ class TestMms2rMedia < Test::Unit::TestCase
140
132
  def test_create_with_special_processor
141
133
  MMS2R.register('null.example.com', MMS2R::Media::NullCarrier)
142
134
  mail = mock()
143
- mail.expects(:header).at_least_once.returns({})
144
135
  mail.expects(:from).at_least_once.returns(['joe@null.example.com'])
136
+ mail.expects(:return_path).at_least_once.returns('joe@null.example.com')
145
137
  mms = MMS2R::Media.create(mail)
146
138
  assert_equal [MMS2R::Media::NullCarrier, 'null.example.com'], mms
147
139
  end
@@ -149,22 +141,22 @@ class TestMms2rMedia < Test::Unit::TestCase
149
141
  def test_create_with_special_processor_and_return_path
150
142
  MMS2R.register('null.example.com', MMS2R::Media::NullCarrier)
151
143
  mail = mock()
152
- mail.expects(:header).at_least_once.returns({'return-path' => '<joe@null.example.com>'})
153
144
  mail.expects(:from).at_least_once.returns([])
145
+ mail.expects(:return_path).at_least_once.returns('joe@null.example.com')
154
146
  mms = MMS2R::Media.create(mail)
155
147
  assert_equal [MMS2R::Media::NullCarrier, 'null.example.com'], mms
156
148
  end
157
149
 
158
150
  def test_create_should_fail_gracefully_with_broken_from
159
151
  mail = mock()
160
- mail.expects(:header).at_least_once.returns({})
161
152
  mail.expects(:from).at_least_once.returns(nil)
153
+ mail.expects(:return_path).at_least_once.returns('joe@unknown.example.com')
162
154
  assert_nothing_raised { MMS2R::Media.create(mail) }
163
155
  end
164
156
 
165
157
  def test_aliased_new_returns_custom_processor_instance
166
158
  MMS2R.register('null.example.com', MMS2R::Media::NullCarrier)
167
- mail = stub_mail(:from)
159
+ mail = stub_mail
168
160
  mail.expects(:from).at_least_once.returns(['joe@null.example.com'])
169
161
 
170
162
  mms = MMS2R::Media.new(mail)
@@ -174,46 +166,45 @@ class TestMms2rMedia < Test::Unit::TestCase
174
166
  end
175
167
 
176
168
  def test_aliased_new_returns_default_processor_instance
177
- mms = MMS2R::Media.new(stub_mail())
169
+ mms = MMS2R::Media.new stub_mail
178
170
  assert_not_nil mms
179
171
  assert_equal true, mms.respond_to?(:process)
180
172
  assert_equal MMS2R::Media, mms.class
181
173
  end
182
174
 
183
175
  def test_lazy_process_option
184
- mms = MMS2R::Media.new(stub_mail(), :process => :lazy)
176
+ mms = MMS2R::Media.new stub_mail, :process => :lazy
185
177
  mms.expects(:process).never
186
178
  end
187
179
 
188
180
  def test_logger_option
189
181
  logger = mock()
190
182
  logger.expects(:info).at_least_once
191
- mms = MMS2R::Media.new(stub_mail(), :logger => logger)
183
+ mms = MMS2R::Media.new stub_mail, :logger => logger
192
184
  end
193
185
 
194
186
  def test_default_processor_initialize_tries_to_open_config_for_carrier
195
187
  f = File.join(MMS2R::Media.conf_dir, 'example.com.yml')
196
188
  YAML.expects(:load_file).once.with(f)
197
- mms = MMS2R::Media.new(stub_mail())
189
+ mms = MMS2R::Media.new stub_mail
198
190
  end
199
191
 
200
192
  def test_mms_phone_number
201
- mail = stub_mail()
193
+ mail = stub_mail
202
194
  mail.stubs(:from).returns(['2068675309@example.com'])
203
195
  mms = MMS2R::Media.new(mail)
204
196
  assert_equal '2068675309', mms.number
205
197
  end
206
-
198
+
207
199
  def test_mms_phone_number_from_config
208
- mail = stub_mail()
209
- mail.stubs(:header).returns({'from' => TMail::AddressHeader.new('from', '"+2068675309" <BCVOZH@mms.vodacom4me.co.za>')})
200
+ mail = stub_mail(:from => '"+2068675309" <TESTER@mms.vodacom4me.co.za>')
210
201
  mms = MMS2R::Media.new(mail)
211
202
  mms.expects(:config).once.returns({'number' => ['from', '/^([^\s]+)\s.*/', '\1']})
212
203
  assert_equal '+2068675309', mms.number
213
204
  end
214
205
 
215
206
  def test_mms_phone_number_with_errors
216
- mail = stub_mail(:from)
207
+ mail = stub_mail
217
208
  mail.stubs(:from).returns(nil)
218
209
  mms = MMS2R::Media.new(mail)
219
210
  assert_nothing_raised do
@@ -222,7 +213,7 @@ class TestMms2rMedia < Test::Unit::TestCase
222
213
  end
223
214
 
224
215
  def test_transform_text
225
- mail = stub_mail()
216
+ mail = stub_mail
226
217
  mail.stubs(:from).returns(nil)
227
218
  mms = MMS2R::Media.new(mail)
228
219
 
@@ -243,7 +234,7 @@ class TestMms2rMedia < Test::Unit::TestCase
243
234
  # has a bad regexp
244
235
  mms.expects(:config).once.returns({'transform' => {type => [['(hello)', 'world']]}})
245
236
  assert_equal result, mms.transform_text(type, text)
246
-
237
+
247
238
  # matches in config
248
239
  mms.expects(:config).once.returns({'transform' => {type => [['/(hello)/', 'world']]}})
249
240
  assert_equal [type, 'world'], mms.transform_text(type, text)
@@ -263,7 +254,7 @@ class TestMms2rMedia < Test::Unit::TestCase
263
254
  end
264
255
 
265
256
  def test_transform_text_to_utf8
266
- mail = TMail::Mail.load(mail_fixture('iconv-fr-text-01.mail'))
257
+ mail = mail('iconv-fr-text-01.mail')
267
258
  mms = MMS2R::Media.new(mail)
268
259
 
269
260
  assert_equal 2, mms.media.size
@@ -274,15 +265,16 @@ class TestMms2rMedia < Test::Unit::TestCase
274
265
  assert_equal true, File::exist?(file)
275
266
  text = IO.readlines("#{file}").join
276
267
  #assert_match(/D'ici un mois Géorgie/, text)
277
- assert_match(/D'ici un mois G\303\203\302\251orgie/, text)
278
- assert_equal("sample email message Fwd: sub D'ici un mois G\303\203\302\251orgie",
279
- mms.subject)
268
+ assert_match(/D'ici un mois G\303\251orgie/, text)
269
+ assert_match(/D'ici un mois Géorgie/, text)
270
+ assert_equal("sample email message Fwd: sub D'ici un mois G\303\251orgie", mms.subject)
271
+ assert_equal("sample email message Fwd: sub D'ici un mois Géorgie", mms.subject)
280
272
  mms.purge
281
273
  end
282
274
 
283
275
  def test_subject
284
276
  s = 'hello world'
285
- mail = stub_mail()
277
+ mail = stub_mail
286
278
  mail.stubs(:subject).returns(s)
287
279
  mms = MMS2R::Media.new(mail)
288
280
  assert_equal s, mms.subject
@@ -293,7 +285,7 @@ class TestMms2rMedia < Test::Unit::TestCase
293
285
  end
294
286
 
295
287
  def test_subject_with_bad_mail_subject
296
- mail = stub_mail()
288
+ mail = stub_mail
297
289
  mail.stubs(:subject).returns(nil)
298
290
  mms = MMS2R::Media.new(mail)
299
291
  assert_equal '', mms.subject
@@ -301,7 +293,7 @@ class TestMms2rMedia < Test::Unit::TestCase
301
293
 
302
294
  def test_subject_with_subject_ignored
303
295
  s = 'hello world'
304
- mail = stub_mail()
296
+ mail = stub_mail
305
297
  mail.stubs(:subject).returns(s)
306
298
  mms = MMS2R::Media.new(mail)
307
299
  mms.stubs(:config).returns({'ignore' => {'text/plain' => [s]}})
@@ -310,7 +302,7 @@ class TestMms2rMedia < Test::Unit::TestCase
310
302
 
311
303
  def test_subject_with_subject_transformed
312
304
  s = 'Default Subject: hello world'
313
- mail = stub_mail()
305
+ mail = stub_mail
314
306
  mail.stubs(:subject).returns(s)
315
307
  mms = MMS2R::Media.new(mail)
316
308
  mms.stubs(:config).returns(
@@ -320,29 +312,29 @@ class TestMms2rMedia < Test::Unit::TestCase
320
312
  end
321
313
 
322
314
  def test_attachment_should_return_nil_if_files_for_type_are_not_found
323
- mms = MMS2R::Media.new(stub_mail())
315
+ mms = MMS2R::Media.new stub_mail
324
316
  mms.stubs(:media).returns({})
325
317
  assert_nil mms.send(:attachment, ['text'])
326
318
  end
327
319
 
328
320
  def test_attachment_should_return_nil_if_empty_files_are_found
329
- mms = MMS2R::Media.new(stub_mail())
321
+ mms = MMS2R::Media.new stub_mail
330
322
  mms.stubs(:media).returns({'text/plain' => [Tempfile.new('test')]})
331
323
  assert_nil mms.send(:attachment, ['text'])
332
324
  end
333
325
 
334
326
  def test_type_from_filename(filename)
335
- mms = MMS2R::Media.new(stub_mail())
327
+ mms = MMS2R::Media.new stub_mail
336
328
  assert_equal 'image/jpeg', mms.send(:type_from_filename, "example.jpg")
337
329
  end
338
330
 
339
331
  def test_type_from_filename_should_be_nil(filename)
340
- mms = MMS2R::Media.new(stub_mail())
332
+ mms = MMS2R::Media.new stub_mail
341
333
  assert_nil mms.send(:type_from_filename, "example.example")
342
334
  end
343
335
 
344
336
  def test_attachment_should_return_duck_typed_file
345
- mms = MMS2R::Media.new(stub_mail())
337
+ mms = MMS2R::Media.new stub_mail
346
338
  temp_big = temp_text_file("hello world")
347
339
  size = File.size(temp_text_file("hello world"))
348
340
  temp_small = temp_text_file("hello")
@@ -358,20 +350,20 @@ class TestMms2rMedia < Test::Unit::TestCase
358
350
  end
359
351
 
360
352
  def test_empty_body
361
- mms = MMS2R::Media.new(stub_mail())
353
+ mms = MMS2R::Media.new stub_mail
362
354
  mms.stubs(:default_text).returns(nil)
363
355
  assert_equal "", mms.body
364
356
  end
365
357
 
366
358
  def test_body
367
- mms = MMS2R::Media.new(stub_mail())
359
+ mms = MMS2R::Media.new stub_mail
368
360
  temp_big = temp_text_file("hello world")
369
361
  mms.stubs(:default_text).returns(File.new(temp_big))
370
362
  assert_equal "hello world", mms.body
371
363
  end
372
364
 
373
365
  def test_default_text
374
- mms = MMS2R::Media.new(stub_mail())
366
+ mms = MMS2R::Media.new stub_mail
375
367
  temp_big = temp_text_file("hello world")
376
368
  temp_small = temp_text_file("hello")
377
369
  mms.stubs(:media).returns({'text/plain' => [temp_small, temp_big]})
@@ -384,7 +376,7 @@ class TestMms2rMedia < Test::Unit::TestCase
384
376
  end
385
377
 
386
378
  def test_default_media
387
- mms = MMS2R::Media.new(stub_mail())
379
+ mms = MMS2R::Media.new stub_mail
388
380
  #it doesn't matter that these are text files, we just need say they are images
389
381
  temp_big = temp_text_file("hello world")
390
382
  temp_small = temp_text_file("hello")
@@ -398,7 +390,7 @@ class TestMms2rMedia < Test::Unit::TestCase
398
390
  end
399
391
 
400
392
  def test_default_media_treats_image_and_video_equally
401
- mms = MMS2R::Media.new(stub_mail())
393
+ mms = MMS2R::Media.new stub_mail
402
394
  #it doesn't matter that these are text files, we just need say they are images
403
395
  temp_big_image = temp_text_file("hello world")
404
396
  temp_small_image = temp_text_file("hello")
@@ -415,22 +407,22 @@ class TestMms2rMedia < Test::Unit::TestCase
415
407
  assert_equal temp_big_video, mms.default_media.local_path
416
408
  end
417
409
 
418
- def test_default_media_treats_gif_and_jpg_equally
419
- #it doesn't matter that these are text files, we just need say they are images
420
- temp_big = temp_text_file("hello world")
421
- temp_small = temp_text_file("hello")
410
+ #def test_default_media_treats_gif_and_jpg_equally
411
+ # #it doesn't matter that these are text files, we just need say they are images
412
+ # temp_big = temp_text_file("hello world")
413
+ # temp_small = temp_text_file("hello")
422
414
 
423
- mms = MMS2R::Media.new(stub_mail())
424
- mms.stubs(:media).returns({'image/jpeg' => [temp_big], 'image/gif' => [temp_small]})
425
- assert_equal temp_big, mms.default_media.local_path
415
+ # mms = MMS2R::Media.new stub_mail
416
+ # mms.stubs(:media).returns({'image/jpeg' => [temp_big], 'image/gif' => [temp_small]})
417
+ # assert_equal temp_big, mms.default_media.local_path
426
418
 
427
- mms = MMS2R::Media.new(stub_mail())
428
- mms.stubs(:media).returns({'image/gif' => [temp_big], 'image/jpg' => [temp_small]})
429
- assert_equal temp_big, mms.default_media.local_path
430
- end
419
+ # mms = MMS2R::Media.new stub_mail
420
+ # mms.stubs(:media).returns({'image/gif' => [temp_big], 'image/jpg' => [temp_small]})
421
+ # assert_equal temp_big, mms.default_media.local_path
422
+ #end
431
423
 
432
424
  def test_purge
433
- mms = MMS2R::Media.new(stub_mail())
425
+ mms = MMS2R::Media.new stub_mail
434
426
  mms.purge
435
427
  assert_equal false, File.exist?(mms.media_dir)
436
428
  end
@@ -438,43 +430,43 @@ class TestMms2rMedia < Test::Unit::TestCase
438
430
  def test_ignore_media_by_filename_equality
439
431
  name = 'foo.txt'
440
432
  type = 'text/plain'
441
- mms = MMS2R::Media.new(stub_mail())
433
+ mms = MMS2R::Media.new stub_mail
442
434
  mms.stubs(:config).returns({'ignore' => {type => [name]}})
443
435
 
444
436
  # type is not in the ingore
445
- part = stub(:sub_header => name, :body => 'a')
437
+ part = stub(:body => Mail::Body.new('a'))
446
438
  assert_equal false, mms.ignore_media?('text/test', part)
447
439
  # type and filename are in the ingore
448
- part = stub(:sub_header => name)
440
+ part = stub(:filename => name, :body => Mail::Body.new('a'))
449
441
  assert_equal true, mms.ignore_media?(type, part)
450
442
  # type but not file name are in the ignore
451
- part = stub(:sub_header => 'bar.txt', :body => 'a')
443
+ part = stub(:filename => 'bar.txt', :body => Mail::Body.new('a'))
452
444
  assert_equal false, mms.ignore_media?(type, part)
453
445
  end
454
446
 
455
447
  def test_filename
456
- name = 'x' * 300 + '.txt'
457
- mms = MMS2R::Media.new(stub_mail())
458
- part = stub(:sub_header => name, :content_type => 'text/plain')
459
- assert_equal 'x' * 251 + '.txt', mms.filename?(part)
448
+ name = 'foo.txt'
449
+ mms = MMS2R::Media.new stub_mail
450
+ part = stub(:filename => name)
451
+ assert_equal 'foo.txt', mms.filename?(part)
460
452
  end
461
453
 
462
454
  def test_long_filename
463
- name = 'foo.txt'
464
- mms = MMS2R::Media.new(stub_mail())
465
- part = stub(:sub_header => name, :content_type => 'text/plain')
466
- assert_equal 'foo.txt', mms.filename?(part)
455
+ name = 'x' * 300 + '.txt'
456
+ mms = MMS2R::Media.new stub_mail
457
+ part = stub(:filename => name)
458
+ assert_equal 'x' * 251 + '.txt', mms.filename?(part)
467
459
  end
468
460
 
469
461
  def test_filename_when_file_extension_missing_part
470
462
  name = 'foo'
471
- mms = MMS2R::Media.new(stub_mail())
472
- part = stub(:sub_header => name, :content_type => 'text/plain', :part_type? => 'text/plain')
463
+ mms = MMS2R::Media.new stub_mail
464
+ part = stub(:filename => name, :content_type => 'text/plain', :part_type? => 'text/plain')
473
465
  assert_equal 'foo.txt', mms.filename?(part)
474
466
 
475
467
  name = 'foo.janky'
476
- mms = MMS2R::Media.new(stub_mail())
477
- part = stub(:sub_header => name, :content_type => 'text/plain', :part_type? => 'text/plain')
468
+ mms = MMS2R::Media.new stub_mail
469
+ part = stub(:filename => name, :content_type => 'text/plain', :part_type? => 'text/plain')
478
470
  assert_equal 'foo.janky.txt', mms.filename?(part)
479
471
  end
480
472
 
@@ -482,17 +474,17 @@ class TestMms2rMedia < Test::Unit::TestCase
482
474
  name = 'foo.txt'
483
475
  regexp = '/foo\.txt/i'
484
476
  type = 'text/plain'
485
- mms = MMS2R::Media.new(stub_mail())
477
+ mms = MMS2R::Media.new stub_mail
486
478
  mms.stubs(:config).returns({'ignore' => {type => [regexp, 'nil.txt']}})
487
479
 
488
480
  # type is not in the ingore
489
- part = stub(:sub_header => name, :body => 'a')
481
+ part = stub(:filename => name, :body => Mail::Body.new('a'))
490
482
  assert_equal false, mms.ignore_media?('text/test', part)
491
483
  # type and regexp for the filename are in the ingore
492
- part = stub(:sub_header => name)
484
+ part = stub(:filename => name)
493
485
  assert_equal true, mms.ignore_media?(type, part)
494
486
  # type but not regexp for filename are in the ignore
495
- part = stub(:sub_header => 'bar.txt', :body => 'a')
487
+ part = stub(:filename => 'bar.txt', :body => Mail::Body.new('a'))
496
488
  assert_equal false, mms.ignore_media?(type, part)
497
489
  end
498
490
 
@@ -501,37 +493,37 @@ class TestMms2rMedia < Test::Unit::TestCase
501
493
  content = "aaaaaaahello worldbbbbbbbbb"
502
494
  regexp = '/.*Hello World.*/i'
503
495
  type = 'text/plain'
504
- mms = MMS2R::Media.new(stub_mail())
496
+ mms = MMS2R::Media.new stub_mail
505
497
  mms.stubs(:config).returns({'ignore' => {type => ['nil.txt', regexp]}})
506
498
 
507
- part = stub(:sub_header => name, :body => content)
499
+ part = stub(:filename => name, :body => Mail::Body.new(content))
508
500
 
509
501
  # type is not in the ingore
510
502
  assert_equal false, mms.ignore_media?('text/test', part)
511
503
  # type and regexp for the content are in the ingore
512
504
  assert_equal true, mms.ignore_media?(type, part)
513
505
  # type but not regexp for content are in the ignore
514
- part = stub(:sub_header => name, :body => 'no teapots')
506
+ part = stub(:filename => name, :body => Mail::Body.new('no teapots'))
515
507
  assert_equal false, mms.ignore_media?(type, part)
516
508
  end
517
509
 
518
510
  def test_ignore_media_when_file_content_is_empty
519
- mms = MMS2R::Media.new(stub_mail())
511
+ mms = MMS2R::Media.new stub_mail
520
512
 
521
513
  # there is no conf but the part's body is empty
522
- part = stub(:sub_header => 'foo.txt', :body => "")
514
+ part = stub(:filename => 'foo.txt', :body => Mail::Body.new)
523
515
  assert_equal true, mms.ignore_media?('text/test', part)
524
516
 
525
517
  # there is no conf but the part's body is white space
526
- part = stub(:sub_header => 'foo.txt', :body => "\t\n\t\n ")
518
+ part = stub(:filename => 'foo.txt', :body => Mail::Body.new("\t\n\t\n "))
527
519
  assert_equal true, mms.ignore_media?('text/test', part)
528
520
  end
529
521
 
530
522
  def test_add_file
531
523
  MMS2R.register('null.example.com', MMS2R::Media::NullCarrier)
532
- mail = stub_mail()
524
+ mail = stub_mail
533
525
  mail.stubs(:from).returns(['joe@null.example.com'])
534
-
526
+
535
527
  mms = MMS2R::Media.new(mail)
536
528
  mms.stubs(:media).returns({})
537
529
 
@@ -544,16 +536,16 @@ class TestMms2rMedia < Test::Unit::TestCase
544
536
 
545
537
  def test_temp_file
546
538
  name = 'foo.txt'
547
- mms = MMS2R::Media.new(stub_mail())
548
- part = stub(:sub_header => name)
539
+ mms = MMS2R::Media.new stub_mail
540
+ part = stub(:filename => name)
549
541
  assert_equal name, File.basename(mms.temp_file(part))
550
542
  end
551
543
 
552
544
  def test_process_media_for_text
553
545
  name = 'foo.txt'
554
- mms = MMS2R::Media.new(stub_mail())
546
+ mms = MMS2R::Media.new stub_mail
555
547
  mms.stubs(:transform_text_part).returns(['text/plain', nil])
556
- part = stub(:sub_header => name, :content_type => 'text/plain', :part_type? => 'text/plain', :main_type => 'text')
548
+ part = stub(:filename => name, :content_type => 'text/plain', :part_type? => 'text/plain', :main_type => 'text')
557
549
 
558
550
  assert_equal ['text/plain', nil], mms.process_media(part)
559
551
 
@@ -566,9 +558,9 @@ class TestMms2rMedia < Test::Unit::TestCase
566
558
 
567
559
  def test_process_media_with_empty_text
568
560
  name = 'foo.txt'
569
- mms = MMS2R::Media.new(stub_mail())
561
+ mms = MMS2R::Media.new stub_mail
570
562
  mms.stubs(:transform_text_part).returns(['text/plain', nil])
571
- part = stub(:sub_header => name, :content_type => 'text/plain', :part_type? => 'text/plain', :main_type => 'text')
563
+ part = stub(:filename => name, :content_type => 'text/plain', :part_type? => 'text/plain', :main_type => 'text')
572
564
 
573
565
  assert_equal ['text/plain', nil], mms.process_media(part)
574
566
 
@@ -579,9 +571,9 @@ class TestMms2rMedia < Test::Unit::TestCase
579
571
 
580
572
  def test_process_media_for_application_smil
581
573
  name = 'foo.txt'
582
- mms = MMS2R::Media.new(stub_mail())
574
+ mms = MMS2R::Media.new stub_mail
583
575
  mms.stubs(:transform_text_part).returns(['application/smil', nil])
584
- part = stub(:sub_header => name, :content_type => 'application/smil', :part_type? => 'application/smil', :main_type => 'application')
576
+ part = stub(:filename => name, :content_type => 'application/smil', :part_type? => 'application/smil', :main_type => 'application')
585
577
 
586
578
  assert_equal ['application/smil', nil], mms.process_media(part)
587
579
 
@@ -594,8 +586,8 @@ class TestMms2rMedia < Test::Unit::TestCase
594
586
 
595
587
  def test_process_media_for_application_octet_stream_when_image
596
588
  name = 'fake.jpg'
597
- mms = MMS2R::Media.new(stub_mail())
598
- part = stub(:sub_header => name, :content_type => 'application/octet-stream', :part_type? => 'application/octet-stream', :body => "data", :main_type => 'application')
589
+ mms = MMS2R::Media.new stub_mail
590
+ part = stub(:filename => name, :content_type => 'application/octet-stream', :part_type? => 'application/octet-stream', :body => Mail::Body.new("data"), :main_type => 'application')
599
591
  result = mms.process_media(part)
600
592
  assert_equal 'image/jpeg', result.first
601
593
  assert_match(/fake\.jpg$/, result.last)
@@ -604,14 +596,12 @@ class TestMms2rMedia < Test::Unit::TestCase
604
596
 
605
597
  def test_process_media_for_all_other_media
606
598
  name = 'foo.txt'
607
- mms = MMS2R::Media.new(stub_mail())
608
- part = stub(:sub_header => name, :content_type => 'faux/text', :part_type? => 'faux/text', :body => nil)
609
- part.expects(:main_type).with('text').returns('faux')
599
+ mms = MMS2R::Media.new stub_mail
600
+ part = stub(:filename => name, :main_type => 'faux', :part_type? => 'faux/text', :body => Mail::Body.new(nil))
610
601
 
611
602
  assert_equal ['faux/text', nil], mms.process_media(part)
612
603
 
613
- part = stub(:sub_header => name, :content_type => 'faux/text', :part_type? => 'faux/text', :body => 'hello world')
614
- part.expects(:main_type).with('text').returns('faux')
604
+ part = stub(:filename => name, :main_type => 'faux', :part_type? => 'faux/text', :body => Mail::Body.new('hello world'))
615
605
  result = mms.process_media(part)
616
606
  assert_equal 'faux/text', result.first
617
607
  assert_equal 'hello world', IO.read(result.last)
@@ -619,20 +609,19 @@ class TestMms2rMedia < Test::Unit::TestCase
619
609
  end
620
610
 
621
611
  def test_process
622
- mms = MMS2R::Media.new(stub_mail())
612
+ mms = MMS2R::Media.new stub_mail
623
613
  assert_equal 1, mms.media.size
624
614
  assert_not_nil mms.media['text/plain']
625
615
  assert_equal 1, mms.media['text/plain'].size
626
- assert_equal 'message.txt', File.basename(mms.media['text/plain'].first)
627
616
  assert_equal true, File.exist?(mms.media['text/plain'].first)
628
617
  assert_equal 1, File.size(mms.media['text/plain'].first)
629
618
  mms.purge
630
619
  end
631
620
 
632
621
  def test_process_with_multipart_double_parts
633
- mail = TMail::Mail.parse(load_mail('apple-double-image-01.mail').join)
622
+ mail = mail('apple-double-image-01.mail')
634
623
  mms = MMS2R::Media.new(mail)
635
-
624
+
636
625
  assert_equal 2, mms.media.size
637
626
 
638
627
  assert_not_nil mms.media['application/applefile']
@@ -648,12 +637,19 @@ class TestMms2rMedia < Test::Unit::TestCase
648
637
  end
649
638
 
650
639
  def test_process_with_multipart_alternative_parts
651
- mail = stub_mail()
652
- plain = stub(:sub_header => 'message.txt', :content_type => 'text/plain', :part_type? => 'text/plain', :body => 'a', :main_type => 'text')
653
- html = stub(:sub_header => 'message.html', :content_type => 'text/html', :part_type? => 'text/html', :body => 'a', :main_type => 'text')
654
- multi = stub(:content_type => 'multipart/alternative', :part_type? => 'multipart/alternative', :parts => [plain, html])
655
- mail.stubs(:multipart?).returns(true)
656
- mail.stubs(:parts).returns([multi])
640
+ mail = stub_mail
641
+
642
+ plain = stub('plain', :filename => 'message.txt', :content_type => 'text/plain', :part_type? => 'text/plain', :body => Mail::Body.new('a'), :main_type => 'text')
643
+ plain.stubs(:multipart?).at_least_once.returns(false)
644
+
645
+ html = stub('html', :filename => 'message.html', :content_type => 'text/html', :part_type? => 'text/html', :body => Mail::Body.new('a'), :main_type => 'text')
646
+ html.stubs(:multipart?).at_least_once.returns(false)
647
+
648
+ multi = stub('multi', :content_type => 'multipart/alternative', :part_type? => 'multipart/alternative', :parts => [plain, html])
649
+ multi.stubs(:multipart?).at_least_once.returns(true)
650
+
651
+ mail.stubs(:multipart?).at_least_once.returns(true)
652
+ mail.stubs(:parts).at_least_once.returns([multi])
657
653
 
658
654
  # the multipart/alternative should get flattend to text and html
659
655
  mms = MMS2R::Media.new(mail)
@@ -673,12 +669,20 @@ class TestMms2rMedia < Test::Unit::TestCase
673
669
  end
674
670
 
675
671
  def test_process_when_media_is_ignored
676
- mail = stub_mail()
677
- plain = stub(:sub_header => 'message.txt', :content_type => 'text/plain', :part_type? => 'text/plain', :body => '')
678
- html = stub(:sub_header => 'message.html', :content_type => 'text/html', :part_type? => 'text/html', :body => '')
679
- multi = stub(:content_type => 'multipart/alternative', :part_type? => 'multipart/alternative', :parts => [plain, html])
680
- mail.stubs(:multipart?).returns(true)
681
- mail.stubs(:parts).returns([multi])
672
+ mail = stub_mail
673
+ plain = stub('plain', :filename => 'message.txt', :content_type => 'text/plain', :part_type? => 'text/plain', :body => Mail::Body.new(''), :main_type => 'text')
674
+ plain.stubs(:multipart?).at_least_once.returns(false)
675
+
676
+ html = stub('html', :filename => 'message.html', :content_type => 'text/html', :part_type? => 'text/html', :body => Mail::Body.new(''), :main_type => 'text')
677
+ html.stubs(:multipart?).at_least_once.returns(false)
678
+
679
+
680
+ multi = stub('multi', :content_type => 'multipart/alternative', :part_type? => 'multipart/alternative', :parts => [plain, html])
681
+ multi.stubs(:multipart?).at_least_once.returns(true)
682
+
683
+ mail.stubs(:multipart?).at_least_once.returns(true)
684
+ mail.stubs(:parts).at_least_once.returns([multi])
685
+
682
686
  mms = MMS2R::Media.new(mail, :process => :lazy)
683
687
  mms.stubs(:config).returns({'ignore' => {'text/plain' => ['message.txt'],
684
688
  'text/html' => ['message.html']}})
@@ -690,12 +694,19 @@ class TestMms2rMedia < Test::Unit::TestCase
690
694
  end
691
695
 
692
696
  def test_process_when_yielding_to_a_block
693
- mail = stub_mail()
697
+ mail = stub_mail
694
698
 
695
- plain = stub(:sub_header => 'message.txt', :content_type => 'text/plain', :part_type? => 'text/plain', :body => 'a', :main_type => 'text')
696
- html = stub(:sub_header => 'message.html', :content_type => 'text/html', :part_type? => 'text/html', :body => 'b', :main_type => 'text')
697
- mail.stubs(:multipart?).returns(true)
698
- mail.stubs(:parts).returns([plain, html])
699
+ plain = stub('plain', :filename => 'message.txt', :content_type => 'text/plain', :part_type? => 'text/plain', :body => Mail::Body.new('a'), :main_type => 'text')
700
+ plain.stubs(:multipart?).at_least_once.returns(false)
701
+
702
+ html = stub('html', :filename => 'message.html', :content_type => 'text/html', :part_type? => 'text/html', :body => Mail::Body.new('b'), :main_type => 'text')
703
+ html.stubs(:multipart?).at_least_once.returns(false)
704
+
705
+ multi = stub('multi', :content_type => 'multipart/alternative', :part_type? => 'multipart/alternative', :parts => [plain, html])
706
+ multi.stubs(:multipart?).at_least_once.returns(true)
707
+
708
+ mail.stubs(:multipart?).at_least_once.returns(true)
709
+ mail.stubs(:parts).at_least_once.returns([multi])
699
710
 
700
711
  # the multipart/alternative should get flattend to text and html
701
712
  mms = MMS2R::Media.new(mail)
@@ -712,16 +723,16 @@ class TestMms2rMedia < Test::Unit::TestCase
712
723
 
713
724
  def test_domain_from_return_path
714
725
  mail = mock()
715
- mail.expects(:header).at_least_once.returns({'return-path' => '<joe@null.example.com>'})
716
726
  mail.expects(:from).at_least_once.returns([])
727
+ mail.expects(:return_path).at_least_once.returns('joe@null.example.com')
717
728
  domain = MMS2R::Media.domain(mail)
718
729
  assert_equal 'null.example.com', domain
719
730
  end
720
731
 
721
732
  def test_domain_from_from
722
733
  mail = mock()
723
- mail.expects(:header).at_least_once.returns({})
724
734
  mail.expects(:from).at_least_once.returns(['joe@null.example.com'])
735
+ mail.expects(:return_path).at_least_once.returns('joe@null.example.com')
725
736
  domain = MMS2R::Media.domain(mail)
726
737
  assert_equal 'null.example.com', domain
727
738
  end
@@ -730,14 +741,14 @@ class TestMms2rMedia < Test::Unit::TestCase
730
741
  f = File.join(MMS2R::Media.conf_dir, 'from.yml')
731
742
  YAML.expects(:load_file).once.with(f).returns(['example.com'])
732
743
  mail = mock()
733
- mail.expects(:header).at_least_once.returns({'return-path' => '<joe@null.example.com>'})
734
744
  mail.expects(:from).at_least_once.returns(['joe@example.com'])
745
+ mail.expects(:return_path).at_least_once.returns('joe@null.example.com')
735
746
  domain = MMS2R::Media.domain(mail)
736
747
  assert_equal 'example.com', domain
737
748
  end
738
749
 
739
750
  def test_unknown_device_type
740
- mail = TMail::Mail.load(mail_fixture('generic.mail'))
751
+ mail = mail('generic.mail')
741
752
  mms = MMS2R::Media.new(mail)
742
753
  assert_equal :unknown, mms.device_type?
743
754
  assert_equal false, mms.is_mobile?
@@ -747,7 +758,7 @@ class TestMms2rMedia < Test::Unit::TestCase
747
758
  iphones = ['att-iphone-01.mail',
748
759
  'iphone-image-01.mail']
749
760
  iphones.each do |iphone|
750
- mail = TMail::Mail.load(mail_fixture(iphone))
761
+ mail = mail(iphone)
751
762
  mms = MMS2R::Media.new(mail)
752
763
  assert_equal :iphone, mms.device_type?, "fixture #{iphone} was not a iphone"
753
764
  assert_equal true, mms.is_mobile?
@@ -761,7 +772,7 @@ class TestMms2rMedia < Test::Unit::TestCase
761
772
  end
762
773
 
763
774
  def test_exif_load_error
764
- mms = MMS2R::Media.new(stub_mail())
775
+ mms = MMS2R::Media.new stub_mail
765
776
  mms.expects(:require).with('exifr').raises(LoadError)
766
777
 
767
778
  assert_equal :unknown, mms.device_type?
@@ -825,15 +836,14 @@ class TestMms2rMedia < Test::Unit::TestCase
825
836
  'verizon-blackberry.mail',
826
837
  'verizon-blackberry.mail']
827
838
  berries.each do |berry|
828
- mail = TMail::Mail.load(mail_fixture(berry))
829
- mms = MMS2R::Media.new(mail)
839
+ mms = MMS2R::Media.new(mail(berry))
830
840
  assert_equal :blackberry, mms.device_type?, "fixture #{berry} was not a blackberrry"
831
841
  assert_equal true, mms.is_mobile?
832
842
  end
833
843
  end
834
844
 
835
845
  def test_handset_device_type
836
- mail = TMail::Mail.load(mail_fixture('att-image-01.mail'))
846
+ mail = mail('att-image-01.mail')
837
847
  mms = MMS2R::Media.new(mail)
838
848
  assert_equal :handset, mms.device_type?
839
849
  assert_equal true, mms.is_mobile?