зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
c4e63346d2
Коммит
bd6bb6c0b2
|
@ -1,3 +1,12 @@
|
|||
Wed Oct 17 15:08:13 2012 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* 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.
|
||||
|
||||
Wed Oct 17 11:04:48 2012 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* test/ruby/test_hash.rb (TestHash#test_dup_equality): added a new test
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -152,4 +152,32 @@ EOF
|
|||
assert_equal("Fw_ ____ _____ ____.eml",
|
||||
response.data.attr["BODYSTRUCTURE"].parts[1].body.param["FILENAME"])
|
||||
end
|
||||
|
||||
def assert_parseable(s)
|
||||
parser = Net::IMAP::ResponseParser.new
|
||||
parser.parse(s.gsub(/\n/, "\r\n").taint)
|
||||
end
|
||||
|
||||
# [Bug #7146]
|
||||
def test_msg_delivery_status
|
||||
# This was part of a larger response that caused crashes, but this was the
|
||||
# minimal test case to demonstrate it
|
||||
assert_parseable <<EOF
|
||||
* 4902 FETCH (BODY (("MESSAGE" "DELIVERY-STATUS" NIL NIL NIL "7BIT" 324) "REPORT"))
|
||||
EOF
|
||||
end
|
||||
|
||||
# [Bug #7147]
|
||||
def test_msg_with_message_rfc822_attachment
|
||||
assert_parseable <<EOF
|
||||
* 5441 FETCH (BODY ((("TEXT" "PLAIN" ("CHARSET" "iso-8859-1") NIL NIL "QUOTED-PRINTABLE" 69 1)("TEXT" "HTML" ("CHARSET" "iso-8859-1") NIL NIL "QUOTED-PRINTABLE" 455 12) "ALTERNATIVE")("MESSAGE" "RFC822" ("NAME" "ATT00026.eml") NIL NIL "7BIT" 4079755) "MIXED"))
|
||||
EOF
|
||||
end
|
||||
|
||||
# [Bug #7153]
|
||||
def test_msg_body_mixed
|
||||
assert_parseable <<EOF
|
||||
* 1038 FETCH (BODY ("MIXED"))
|
||||
EOF
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче