Index: lib/net/imap.rb
===================================================================
--- lib/net/imap.rb	(revision 12632)
+++ lib/net/imap.rb	(working copy)
@@ -1509,6 +1509,7 @@
     # Net::IMAP::ResponseCode represents response codes.
     # 
     #   resp_text_code  ::= "ALERT" / "PARSE" /
+    #                       "BADCHARSET" [SPACE "(" astring *(SP astring ")"]/
     #                       "PERMANENTFLAGS" SPACE "(" #(flag / "\*") ")" /
     #                       "READ-ONLY" / "READ-WRITE" / "TRYCREATE" /
     #                       "UIDVALIDITY" SPACE nz_number /
@@ -2757,6 +2758,14 @@
         when /\A(?:PERMANENTFLAGS)\z/n
           match(T_SPACE)
           result = ResponseCode.new(name, flag_list)
+        when /\A(?:BADCHARSET)\z/n
+          token = lookahead
+          if token.symbol == T_RBRA
+            result = ResponseCode.new(name, nil)
+          else
+            match(T_SPACE)
+            result = ResponseCode.new(name, flag_list)
+          end
         when /\A(?:UIDVALIDITY|UIDNEXT|UNSEEN)\z/n
           match(T_SPACE)
           result = ResponseCode.new(name, number)
Index: test/net/imap/test_imap.rb
===================================================================
--- test/net/imap/test_imap.rb	(revision 12632)
+++ test/net/imap/test_imap.rb	(working copy)
@@ -8,4 +8,21 @@
     assert_equal("OK", r.name)
     assert_equal("NOMODSEQ", r.data.code.name)
   end
+
+  def test_parse_badcharset_nooption
+    parser = Net::IMAP::ResponseParser.new
+    r = parser.parse(%Q'A01 NO [BADCHARSET] FOO not supported\r\n')
+    assert_equal("NO", r.name)
+    assert_equal("BADCHARSET", r.data.code.name)
+    assert_equal(nil, r.data.code.data)
+
+  end
+
+  def test_parse_badcharset_option
+    parser = Net::IMAP::ResponseParser.new
+    r = parser.parse(%Q'A01 NO [BADCHARSET ("FII" "FEE")] FOO not supported\r\n')
+    assert_equal("NO", r.name)
+    assert_equal("BADCHARSET", r.data.code.name)
+    assert_equal(%w[FII FEE], r.data.code.data)
+  end
 end
