diff --git a/lib/net/imap.rb b/lib/net/imap.rb index ab77be4fb98f78..b61e2af9675978 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -1534,7 +1534,7 @@ def initialize(data) def format_internal(data) case data - when "*" + when String return data when Integer if data == -1 @@ -1556,6 +1556,7 @@ def format_internal(data) def validate_internal(data) case data when "*" + when String when Integer ensure_nz_number(data) when Range @@ -2033,6 +2034,14 @@ def media_subtype 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 +2411,30 @@ def body_type_msg 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 +2476,10 @@ def body_type_mpart 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 diff --git a/test/net/imap/test_imap_messageset.rb b/test/net/imap/test_imap_messageset.rb new file mode 100644 index 00000000000000..5b28adadc5e3ef --- /dev/null +++ b/test/net/imap/test_imap_messageset.rb @@ -0,0 +1,66 @@ +require 'net/imap' +require 'test/unit' + + +class IMAPTestStub + def initialize + @strings = [] + end + def put_string(s) + @strings << s + end + attr_accessor :strings +end + +class IMAPMessageSetTest < Test::Unit::TestCase + + ### Validation Tests + + def assert_messageset_ok_with(set) + ms = Net::IMAP::MessageSet.new(set) + assert_nothing_raised do + ms.validate + end + end + + def test_allows_integer + assert_messageset_ok_with 1 + end + def test_allows_range + assert_messageset_ok_with 1..5 + end + def test_allows_array + assert_messageset_ok_with [1,2,3,8] + end + def test_allows_string_range + assert_messageset_ok_with "1:*" + end + + + ### Formatting Tests + + def assert_formats_as(expected, from) + ms = Net::IMAP::MessageSet.new(from) + fake_imap = IMAPTestStub.new + ms.send_data(fake_imap) + assert_equal(expected, fake_imap.strings[0]) + end + + def test_formats_integer + assert_formats_as "1", 1 + end + def test_formats_negative_one_as_star + assert_formats_as "*", -1 + end + def test_formats_range + assert_formats_as '1:5', 1..5 + end + + def test_formats_array + assert_formats_as '1,2,5', [1,2,5] + end + + def test_formats_string_range + assert_formats_as '1:*', '1:*' + end +end diff --git a/test/net/imap/test_imap_response_parser.rb b/test/net/imap/test_imap_response_parser.rb index 0231ed436bdd69..d7fe1d74116895 100644 --- a/test/net/imap/test_imap_response_parser.rb +++ b/test/net/imap/test_imap_response_parser.rb @@ -152,4 +152,30 @@ def test_body_type_attachment 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 + + 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 < pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy