Fix for UnstructuredField which responds to Content-Field #470

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
@davycardinaal

Recently received an e-mail which had the following content-type for an attachment:

Content-Type: unknown/unknown;
    charset=iso-8859-1;
    name=IMSTP19.gif

After receiving the e-mail I perform a to string on the Mail object to generate a unique hash. Something like the following:

Mail::POP3.new(settings).find_and_delete(count: 25) do |msg| 
  receive(msg)
  process_email_key(Digest::SHA1.hexdigest(msg.to_s))
end

When I received the e-mail with the content-type I noticed above I got the following error

undefined method `string' for unknown/unknown; name="image.gif":Mail::UnstructuredField

The private method get_order_value() in lib/mail/parts_list.rb assumes that the Field is a Mail::ContentTypeField when the part responds_to content-type. But with the content-type used in this e-mail the field is a Mail::UnstructuredField.

The part[:content_type].string raises an error because there's no string method for an UnstructuredField.

@jeremy

This comment has been minimized.

Show comment Hide comment
@jeremy

jeremy Dec 17, 2012

Collaborator

👍

Collaborator

jeremy commented Dec 17, 2012

👍

@@ -44,7 +44,7 @@ def sort!(order)
private
def get_order_value(part, order)
- if part.respond_to?(:content_type)
+ if part.respond_to?(:content_type) && part[:content_type].field.is_a?(Mail::ContentTypeField)

This comment has been minimized.

Show comment Hide comment
@jeremy

jeremy Jan 19, 2013

Collaborator

Perhaps check for respond_to?(:string) rather than the specific field class.

@jeremy

jeremy Jan 19, 2013

Collaborator

Perhaps check for respond_to?(:string) rather than the specific field class.

+ content_type 'unknown/unknown; name="image.gif"'
+ end
+
+ Mail::PartsList.new.send(:get_order_value, part, [])

This comment has been minimized.

Show comment Hide comment
@jeremy

jeremy Jan 19, 2013

Collaborator

Can you test this without calling in to a private method? Spec something concrete, like checking the expected parts ordering, rather than an implicit spec that no exception is raised.

@jeremy

jeremy Jan 19, 2013

Collaborator

Can you test this without calling in to a private method? Spec something concrete, like checking the expected parts ordering, rather than an implicit spec that no exception is raised.

@jeremy jeremy closed this in ba06563 Jan 28, 2013

@davycardinaal

This comment has been minimized.

Show comment Hide comment
@davycardinaal

davycardinaal Feb 5, 2013

Thanks!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment