Reproduce:
read mail with empty Content-Type header and then call #content_type and you'll get
/usr/lib/ruby/gems/1.8/gems/rmail-1.0.0/lib/rmail/header.rb:537:in `content_type': undefined method `downcase'
for nil:NilClass (NoMethodError)
Fix:
- def content_type(default = nil)
+ def content_type(default = 'text/plain')
if value = self['content-type']
- value.strip.split(/\s*;\s*/)[0].downcase
+ value.strip.split(/\s*;\s*/)[0].downcase rescue default
else
if block_given?
Based on RFC 2045, if anything goes wrong with Content-Type, text/plain should be assumed. In this case the default
is overridable.
5.2. Content-Type Defaults
Default RFC 822 messages without a MIME Content-Type header are taken
by this protocol to be plain text in the US-ASCII character set,
which can be explicitly specified as:
Content-type: text/plain; charset=us-ascii
This default is assumed if no Content-Type header field is specified.
It is also recommend that this default be assumed when a
syntactically invalid Content-Type header field is encountered. |