Bugs: Browse | Submit New | Admin

[#27282] Empty Content-Type header breaks RMail::Header#content_type

Date:
2009-10-12 21:26
Priority:
3
Submitted By:
Tero Tilus (tero)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
Empty Content-Type header breaks RMail::Header#content_type

Detailed description
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.

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item