mms2r 3.3.0 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ ### 3.3.1 / 2011-01-01 (Reverend Aslaug Wartooth (deceased), Toki's dad)
2
+
3
+ * 2 minor enhancements
4
+ * new method #default_html returns the default html attachment
5
+ * #body will return the default plain text, or default stripped html text
6
+
1
7
  ### 3.3.0 / 2010-12-31 (Charles Foster Offdensen - CFO, dethklok)
2
8
 
3
9
  * 1 major enhancement
@@ -10,9 +10,9 @@ module MMS2R
10
10
  # A hash of MMS2R processors keyed by MMS carrier domain.
11
11
 
12
12
  CARRIERS = {}
13
-
13
+
14
14
  ##
15
- # Registers a class as a processor for a MMS domain. Should only be
15
+ # Registers a class as a processor for a MMS domain. Should only be
16
16
  # used in special cases such as MMS2R::Media::Sprint for 'pm.sprint.com'
17
17
 
18
18
  def self.register(domain, processor_class)
@@ -39,7 +39,7 @@ module MMS2R
39
39
  ##
40
40
  # MMS2R library version
41
41
 
42
- VERSION = '3.3.0'
42
+ VERSION = '3.3.1'
43
43
 
44
44
  end
45
45
 
@@ -48,11 +48,24 @@ module MMS2R
48
48
  # Combined w/ the method_missing delegation, this should behave as an enhanced Mail object, more or less.
49
49
  def self.parse raw_mail
50
50
  mail = Mail.new raw_mail
51
- MMS2R::Media.new(mail)
52
- end
51
+ MMS2R::Media.new(mail) end
53
52
 
54
53
  end
55
54
 
55
+ unless Object.respond_to?(:blank?)
56
+ class Object
57
+ def blank?
58
+ if respond_to?(:empty?) && respond_to?(:strip)
59
+ empty? or strip.empty?
60
+ elsif respond_to?(:empty?)
61
+ empty?
62
+ else
63
+ !self
64
+ end
65
+ end
66
+ end
67
+ end
68
+
56
69
  %W{ mail fileutils pathname tmpdir yaml uuidtools iconv exifr }.each do |g|
57
70
  begin
58
71
  gem 'mail', '= 2.2.13' if g == 'mail'
@@ -201,6 +201,7 @@ module MMS2R
201
201
  @exif = nil
202
202
  @default_media = nil
203
203
  @default_text = nil
204
+ @default_html = nil
204
205
 
205
206
  f = File.expand_path(File.join(self.conf_dir(), "aliases.yml"))
206
207
  @aliases = YAML::load_file(f) rescue {}
@@ -257,12 +258,17 @@ module MMS2R
257
258
  end
258
259
 
259
260
  # Convenience method that returns a string including all the text of the
260
- # first text/plain file found. Returns empty string if no body text
261
- # is found.
261
+ # default text/plain file found. If the plain text is blank then it returns
262
+ # stripped down version of the title and body of default text/html. Returns
263
+ # empty string if no body text is found.
262
264
 
263
265
  def body
264
266
  text_file = default_text
265
267
  @body = text_file ? IO.readlines(text_file.path).join.strip : ""
268
+ if @body.blank? && html_file = default_html
269
+ html = Nokogiri::HTML(IO.read(html_file.path))
270
+ @body = (html.xpath("//head/title").map(&:text) + html.xpath("//body/*").map(&:text)).join(" ")
271
+ end
266
272
  @body
267
273
  end
268
274
 
@@ -291,6 +297,18 @@ module MMS2R
291
297
  @default_text ||= attachment(['text/plain'])
292
298
  end
293
299
 
300
+ # Returns a File with the most likely candidate that is html, or nil
301
+ # otherwise. It also adds singleton methods to the File object so it can be
302
+ # used in place of a CGI upload (local_path, original_filename, size, and
303
+ # content_type) such as in conjunction with AttachmentFu. The largest file
304
+ # found in terms of bytes is returned.
305
+ #
306
+ # Returns nil if there are not any text Files found
307
+
308
+ def default_html
309
+ @default_html ||= attachment(['text/html'])
310
+ end
311
+
294
312
  ##
295
313
  # process is a template method and collects all the media in a MMS.
296
314
  # Override helper methods to this template to clean out advertising and/or
@@ -321,6 +321,13 @@ class TestMms2rMedia < Test::Unit::TestCase
321
321
  assert_equal "hello world", mms.body
322
322
  end
323
323
 
324
+ def test_body_when_html
325
+ mms = MMS2R::Media.new stub_mail(:body => '')
326
+ temp_big = temp_text_file("<html><head><title>hello</title></head><body><p>world</p><p>teapot</p><body></html>")
327
+ mms.stubs(:default_html).returns(File.new(temp_big))
328
+ assert_equal "hello world teapot", mms.body
329
+ end
330
+
324
331
  def test_default_text
325
332
  mms = MMS2R::Media.new stub_mail
326
333
  temp_big = temp_text_file("hello world")
@@ -334,6 +341,19 @@ class TestMms2rMedia < Test::Unit::TestCase
334
341
  assert_equal temp_big, mms.default_text.local_path
335
342
  end
336
343
 
344
+ def test_default_html
345
+ mms = MMS2R::Media.new stub_mail(:body => '')
346
+ temp_big = temp_text_file("<html><head><title>hello</title></head><body><p>world</p><p>teapot</p><body></html>")
347
+ temp_small = temp_text_file("<html><head><title>hello</title></head><body>world<body></html>")
348
+ mms.stubs(:media).returns({'text/html' => [temp_small, temp_big]})
349
+
350
+ assert_equal temp_big, mms.default_html.local_path
351
+
352
+ # second time through shouldn't setup the @default_text by calling attachment
353
+ mms.expects(:attachment).never
354
+ assert_equal temp_big, mms.default_html.local_path
355
+ end
356
+
337
357
  def test_default_media
338
358
  mms = MMS2R::Media.new stub_mail
339
359
  #it doesn't matter that these are text files, we just need say they are images
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mms2r
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 3
8
8
  - 3
9
- - 0
10
- version: 3.3.0
9
+ - 1
10
+ version: 3.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Mondragon
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-31 00:00:00 -08:00
18
+ date: 2011-01-01 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency