From ff8d1d3129e6cb8041605fe360561daccac208a6 Mon Sep 17 00:00:00 2001 From: Tony Arkles Date: Sat, 6 Oct 2012 11:54:48 -0600 Subject: [PATCH 1/6] Adding a test suite for IMAP MessageSets, including two that fail and should pass --- test/net/imap/test_imap_messageset.rb | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/net/imap/test_imap_messageset.rb 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 From 589922315f521a9fb7fb941dd924052cdf1abd66 Mon Sep 17 00:00:00 2001 From: Tony Arkles Date: Sat, 6 Oct 2012 11:56:36 -0600 Subject: [PATCH 2/6] Added the ability to pass arbitrary string ranges (e.g. "1:*" to imap fetch) --- lib/net/imap.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/net/imap.rb b/lib/net/imap.rb index ab77be4fb98f78..4b9c15813ff5be 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 From f17ed14e967e9b49db443d2d3882cad51b4dd51d Mon Sep 17 00:00:00 2001 From: Tony Arkles Date: Sat, 6 Oct 2012 13:58:28 -0600 Subject: [PATCH 3/6] Merging in changes from topic/imap_speed_improvements, from 40a2902e94d60f26fc9b8688e388f45a3f908c1b to ab3823c60abfda6ca8ca8a4171b0bf075e34d542 --- lib/net/imap.rb | 21 +++++++++++++++++++++ test/net/imap/test_imap_response_parser.rb | 13 +++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/net/imap.rb b/lib/net/imap.rb index 4b9c15813ff5be..2acf4b8a4518f5 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -2034,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 @@ -2403,6 +2411,19 @@ 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 + match(T_SPACE) env = envelope match(T_SPACE) diff --git a/test/net/imap/test_imap_response_parser.rb b/test/net/imap/test_imap_response_parser.rb index 0231ed436bdd69..51d8e88afa4f29 100644 --- a/test/net/imap/test_imap_response_parser.rb +++ b/test/net/imap/test_imap_response_parser.rb @@ -152,4 +152,17 @@ 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 < Date: Sat, 6 Oct 2012 16:07:34 -0600 Subject: [PATCH 4/6] Merging in changes from topic/imap_speed_improvements, just ab3823c60abfda6ca8ca8a4171b0bf075e34d542 this time --- lib/net/imap.rb | 11 +++++++++++ test/net/imap/test_imap_response_parser.rb | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/lib/net/imap.rb b/lib/net/imap.rb index 2acf4b8a4518f5..f4b33ec772f331 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -2424,6 +2424,17 @@ def body_type_msg 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) diff --git a/test/net/imap/test_imap_response_parser.rb b/test/net/imap/test_imap_response_parser.rb index 51d8e88afa4f29..3341e24298e47d 100644 --- a/test/net/imap/test_imap_response_parser.rb +++ b/test/net/imap/test_imap_response_parser.rb @@ -163,6 +163,12 @@ def test_msg_delivery_status # minimal test case to demonstrate it assert_parseable < Date: Fri, 12 Oct 2012 21:16:05 -0600 Subject: [PATCH 5/6] Adding support for (BODY ("MIXED")) This seems like a strange message body, but Gmail returns it to me for a few messages. --- lib/net/imap.rb | 4 ++++ test/net/imap/test_imap_response_parser.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/net/imap.rb b/lib/net/imap.rb index f4b33ec772f331..b61e2af9675978 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -2476,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_response_parser.rb b/test/net/imap/test_imap_response_parser.rb index 3341e24298e47d..5b37a201fff388 100644 --- a/test/net/imap/test_imap_response_parser.rb +++ b/test/net/imap/test_imap_response_parser.rb @@ -169,6 +169,12 @@ def test_msg_delivery_status def test_msg_with_message_rfc822_attachment assert_parseable < Date: Fri, 12 Oct 2012 21:37:29 -0600 Subject: [PATCH 6/6] Adding bug tag to test case --- test/net/imap/test_imap_response_parser.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/net/imap/test_imap_response_parser.rb b/test/net/imap/test_imap_response_parser.rb index 5b37a201fff388..d7fe1d74116895 100644 --- a/test/net/imap/test_imap_response_parser.rb +++ b/test/net/imap/test_imap_response_parser.rb @@ -172,6 +172,7 @@ def test_msg_with_message_rfc822_attachment EOF end + # [Bug #7153] def test_msg_body_mixed 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