[前][次][番号順一覧][スレッド一覧]

ruby-changes:25188

From: shugo <ko1@a...>
Date: Wed, 17 Oct 2012 15:18:26 +0900 (JST)
Subject: [ruby-changes:25188] shugo:r37240 (trunk): * lib/net/imap.rb: fix Net::IMAP::ResponseParser to accept

shugo	2012-10-17 15:18:14 +0900 (Wed, 17 Oct 2012)

  New Revision: 37240

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37240

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/lib/net/imap.rb
    trunk/test/net/imap/test_imap_response_parser.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37239)
+++ ChangeLog	(revision 37240)
@@ -1,3 +1,12 @@
+Wed Oct 17 15:08:13 2012  Shugo Maeda  <shugo@r...>
+
+	* 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@r...>
 
 	* test/ruby/test_hash.rb (TestHash#test_dup_equality): added a new test
Index: lib/net/imap.rb
===================================================================
--- lib/net/imap.rb	(revision 37239)
+++ lib/net/imap.rb	(revision 37240)
@@ -2033,6 +2033,14 @@
       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 @@
         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 @@
 
       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
Index: test/net/imap/test_imap_response_parser.rb
===================================================================
--- test/net/imap/test_imap_response_parser.rb	(revision 37239)
+++ test/net/imap/test_imap_response_parser.rb	(revision 37240)
@@ -152,4 +152,32 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]