From bd6bb6c0b26168833ff9027611a3febc6eeca91b Mon Sep 17 00:00:00 2001 From: shugo Date: Wed, 17 Oct 2012 06:18:14 +0000 Subject: * lib/net/imap.rb: fix Net::IMAP::ResponseParser to accept message/delivery-status ([ruby-core:47920] [Bug #7146]), message/rfc822 attachments ([ruby-core:47921] [Bug #7147]), and (BODY ("MIXED")) ([ruby-core:47951] [Bug #7153]). * test/net/imap/test_imap_response_parser.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/net/imap.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'lib') diff --git a/lib/net/imap.rb b/lib/net/imap.rb index ab77be4fb9..c51a2954e5 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -2033,6 +2033,14 @@ module Net end end + class BodyTypeExtension < Struct.new(:media_type, :subtype, + :params, :content_id, + :description, :encoding, :size) + def multipart? + return false + end + end + class ResponseParser # :nodoc: def initialize @str = nil @@ -2402,6 +2410,30 @@ module Net mtype, msubtype = media_type match(T_SPACE) param, content_id, desc, enc, size = body_fields + + # If this is not message/rfc822, we shouldn't apply the RFC822 spec + # to it. + # We should handle anything other than message/rfc822 using + # multipart extension data [rfc3501] (i.e. the data itself won't be + # returned, we would have to retrieve it with BODYSTRUCTURE instead + # of with BODY + if "#{mtype}/#{msubtype}" != 'MESSAGE/RFC822' then + return BodyTypeExtension.new(mtype, msubtype, + param, content_id, + desc, enc, size) + end + + # Also, sometimes a message/rfc822 is included as a large + # attachment instead of having all of the other details + # (e.g. attaching a .eml file to an email) + + token = lookahead + if token.symbol == T_RPAR then + return BodyTypeMessage.new(mtype, msubtype, param, content_id, + desc, enc, size, nil, nil, nil, nil, + nil, nil, nil) + end + match(T_SPACE) env = envelope match(T_SPACE) @@ -2443,6 +2475,10 @@ module Net def media_type mtype = case_insensitive_string + token = lookahead + if token.symbol != T_SPACE + return mtype, nil + end match(T_SPACE) msubtype = case_insensitive_string return mtype, msubtype -- cgit v1.2.3