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_decode(self):
for (input, output) in self.tests:
decoded = decode(output)
self.assertIsInstance(decoded, text_type)
self.assertEqual(input, decoded)
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_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'&-'), '&')
logger.warning("set kind=gmail for account %s in your .raindrop for correct settings",
acct_id)
else:
logger.warning("This IMAP server doesn't support XLIST, so performance may suffer")
result = conn.list_folders('', '*')
# quickly scan through the folders list building the ones we will
# process and the order.
logger.info("examining folders")
folders_use = []
# First pass - filter folders we don't care about.
if 'exclude_folders' in self.account.details:
to_exclude = set(o.lower() for o in re.split(", *", self.account.details['exclude_folders']))
else:
to_exclude = set()
for flags, delim, name in result:
name = decode_imap_utf7(name)
ok = True
for flag in (r'\Noselect', r'\AllMail', r'\Trash', r'\Spam'):
if flag in flags:
logger.debug("'%s' has flag %r - skipping", name, flag)
ok = False
break
if ok and self.options.folders and \
name.lower() not in [o.lower() for o in self.options.folders]:
logger.debug('skipping folder %r - not in specified folder list', name)
ok = False
if ok and 'exclude_folders' in self.account.details and \
name.lower() in to_exclude:
logger.debug('skipping folder %r - in exclude list', name)
ok = False
if ok:
folders_use.append((flags, delim, name ))
For convenience the tuple elements may be accessed
positionally or using attributes named *personal*, *other* and
*shared*.
See :rfc:`2342` for more details.
"""
data = self._command_and_check('namespace')
parts = []
for item in parse_response(data):
if item is None:
parts.append(item)
else:
converted = []
for prefix, separator in item:
if self.folder_encode:
prefix = decode_utf7(prefix)
converted.append((prefix, to_unicode(separator)))
parts.append(tuple(converted))
return Namespace(*parts)
def _proc_folder_list(self, folder_data):
# Filter out empty strings and None's.
# This also deals with the special case of - no 'untagged'
# responses (ie, no folders). This comes back as [None].
folder_data = [item for item in folder_data if item not in (b'', None)]
ret = []
parsed = parse_response(folder_data)
for flags, delim, name in chunk(parsed, size=3):
if isinstance(name, (int, long)):
# Some IMAP implementations return integer folder names
# with quotes. These get parsed to ints so convert them
# back to strings.
name = text_type(name)
elif self.folder_encode:
name = decode_utf7(name)
ret.append((flags, delim, name))
return ret
def utf7_decode_sequence(seq):
return [decode_utf7(s) for s in seq]