summaryrefslogtreecommitdiff
path: root/lib/net
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-17 06:18:14 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-17 06:18:14 +0000
commitbd6bb6c0b26168833ff9027611a3febc6eeca91b (patch)
treee5833d59c5b0ffdbe5f8ba2dc078d2146609a941 /lib/net
parentc4e63346d241af300594804cb54351817c496a4d (diff)
* 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
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/imap.rb36
1 files changed, 36 insertions, 0 deletions
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