commit 142f3888a478376de068d5b5bf5ccdbf710e7c87
parent 003a28032593275a04fa07a65d4438ff221dd6b2
Author: Gaudenz Steinlin <gaudenz@soziologie.ch>
Date: Thu, 17 Feb 2011 15:36:27 +0100
Be more cautious about invalid content-type headers
The original RMail code calls value.strip.split(/\s*;\s*/)[0].downcase
without checking if split returned an element. This monkey patches the
relevant function for sup to catch this error.
Signed-off-by: Hamish Downer
Diffstat:
1 file changed, 25 insertions(+), 0 deletions(-)
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -111,6 +111,31 @@ module RMail
# end
end
end
+
+ class Header
+ ## Be more cautious about invalid content-type headers
+ ## the original RMail code calls
+ ## value.strip.split(/\s*;\s*/)[0].downcase
+ ## without checking if split returned an element
+
+ # This returns the full content type of this message converted to
+ # lower case.
+ #
+ # If there is no content type header, returns the passed block is
+ # executed and its return value is returned. If no block is passed,
+ # the value of the +default+ argument is returned.
+ def content_type(default = nil)
+ if value = self['content-type'] and ct = value.strip.split(/\s*;\s*/)[0]
+ return ct.downcase
+ else
+ if block_given?
+ yield
+ else
+ default
+ end
+ end
+ end
+ end
end
class Range