Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_printable_singletons(self):
"""
The IMAP4 modified UTF-7 implementation encodes all printable
characters which are in ASCII using the corresponding ASCII byte.
"""
# All printables represent themselves
for o in list(range(0x20, 0x26)) + list(range(0x27, 0x7f)):
self.assertEqual(int2byte(o), encode(unichr(o)))
self.assertEqual(unichr(o), decode(int2byte(o)))
self.assertEqual(encode('&'), b'&-')
self.assertEqual(encode('&'), b'&-')
self.assertEqual(decode(b'&-'), '&')
def test_encode(self):
for (input, output) in self.tests:
encoded = encode(input)
self.assertIsInstance(encoded, binary_type)
self.assertEqual(encoded, output)
def test_printable_singletons(self):
"""
The IMAP4 modified UTF-7 implementation encodes all printable
characters which are in ASCII using the corresponding ASCII byte.
"""
# All printables represent themselves
for o in list(range(0x20, 0x26)) + list(range(0x27, 0x7f)):
self.assertEqual(int2byte(o), encode(unichr(o)))
self.assertEqual(unichr(o), decode(int2byte(o)))
self.assertEqual(encode('&'), b'&-')
self.assertEqual(encode('&'), b'&-')
self.assertEqual(decode(b'&-'), '&')
else:
logger.info("logging into account %r via oauth", details['id'])
if do_oauth:
xoauth_string = xoauth.GenerateXOauthStringFromAcctInfo('imap', details)
try:
ret._imap.authenticate('XOAUTH', lambda x: xoauth_string)
except ret.Error, exc:
raise IMAP4AuthException(account.OAUTH, exc.args[0])
else:
if 'username' not in details or 'password' not in details:
raise ValueError, "Account has no username or password"
# XXX - is this encoding of 'username' correct? We've already determined
# experimentally it is *not* correct for the password...
try:
ret.login(encode_imap_utf7(details['username']), details['password'])
except ret.Error, exc:
raise IMAP4AuthException(account.PASSWORD, exc.args[0])
account.reportStatus(brat.EVERYTHING, brat.GOOD)
return ret
def _normalise_folder(self, folder_name):
if isinstance(folder_name, binary_type):
folder_name = folder_name.decode('ascii')
if self.folder_encode:
folder_name = encode_utf7(folder_name)
return _quote(folder_name)
def _normalise_labels(self, labels):
if isinstance(labels, (text_type, binary_type)):
labels = (labels,)
return [_quote(encode_utf7(l)) for l in labels]