Index: Lib/imaplib.py =================================================================== --- Lib/imaplib.py (revision 88087) +++ Lib/imaplib.py (working copy) @@ -1317,6 +1317,9 @@ Returns Python time module tuple. """ + if isinstance(resp, str): + resp = bytes(resp, 'ASCII') + mo = InternalDate.match(resp) if not mo: return None @@ -1362,11 +1365,14 @@ """Convert IMAP4 flags response to python tuple.""" + if isinstance(resp, str): + resp = bytes(resp, 'ASCII') + mo = Flags.match(resp) if not mo: return () - return tuple(mo.group('flags').split()) + return tuple(str(x, 'ASCII') for x in mo.group('flags').split()) def Time2Internaldate(date_time): Index: Lib/test/test_imaplib.py =================================================================== --- Lib/test/test_imaplib.py (revision 88087) +++ Lib/test/test_imaplib.py (working copy) @@ -27,6 +27,16 @@ # The following two should produce the same result (see issue 10941). self.assertEqual(imaplib.Internaldate2tuple(b'25 (INTERNALDATE "01-Apr-2000 19:02:23 -0700")')[0:6], (2000, 4, 1, 19, 2, 23)) self.assertEqual(imaplib.Internaldate2tuple(b'101 (INTERNALDATE "02-Apr-2000 02:02:23 +0000")')[0:6], (2000, 4, 1, 19, 2, 23)) + # Now test with str instead of bytes object + self.assertEqual(imaplib.Internaldate2tuple('25 (INTERNALDATE "01-Apr-2000 19:02:23 -0700")')[0:6], (2000, 4, 1, 19, 2, 23)) + self.assertEqual(imaplib.Internaldate2tuple('101 (INTERNALDATE "02-Apr-2000 02:02:23 +0000")')[0:6], (2000, 4, 1, 19, 2, 23)) + + def test_ParseFlags(self): + self.assertEqual(imaplib.ParseFlags(b'1 (FLAGS (\Answered \Seen))'), + ('\\Answered', '\\Seen')) + # Now test with str instead of bytes object + self.assertEqual(imaplib.ParseFlags('1 (FLAGS (\Answered \Seen))'), + ('\\Answered', '\\Seen')) def test_that_Time2Internaldate_returns_a_result(self): # We can check only that it successfully produces a result,