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_none_special_case(self):
self.assertEqual(parse_fetch_response([None]), {})
def test_FLAGS(self):
self.assertEqual(parse_fetch_response([b'23 (FLAGS (\Seen Stuff))']),
{23: {b'SEQ': 23, b'FLAGS': (br'\Seen', b'Stuff')}})
def test_ENVELOPE(self):
envelope_str = (b'1 (ENVELOPE ( '
b'"Sun, 24 Mar 2013 22:06:10 +0200" '
b'"subject" '
b'(("name" NIL "address1" "domain1.com")) ' # from (name and address)
b'((NIL NIL "address2" "domain2.com")) ' # sender (just address)
b'(("name" NIL "address3" "domain3.com") NIL) ' # reply to
b'NIL' # to (no address)
b'((NIL NIL "address4" "domain4.com") ' # cc
b'("person" NIL "address4b" "domain4b.com")) '
b'NIL ' # bcc
b'"" '
b'""))')
output = parse_fetch_response([envelope_str], normalise_times=False)
self.assertSequenceEqual(output[1][b'ENVELOPE'],
Envelope(
datetime(2013, 3, 24, 22, 6, 10, tzinfo=FixedOffset(120)),
b"subject",
(Address(b"name", None, b"address1", b"domain1.com"),),
(Address(None, None, b"address2", b"domain2.com"),),
(Address(b"name", None, b"address3", b"domain3.com"),),
None,
(Address(None, None, b"address4", b"domain4.com"),
Address(b"person", None, b"address4b", b"domain4b.com")),
None, b"", b""
)
def test_ENVELOPE_with_empty_addresses(self):
envelope_str = (b'1 (ENVELOPE ( '
b'NIL '
b'"subject" '
b'(("name" NIL "address1" "domain1.com") NIL) '
b'(NIL (NIL NIL "address2" "domain2.com")) '
b'(("name" NIL "address3" "domain3.com") NIL ("name" NIL "address3b" "domain3b.com")) '
b'NIL'
b'((NIL NIL "address4" "domain4.com") '
b'("person" NIL "address4b" "domain4b.com")) '
b'NIL "" ""))')
output = parse_fetch_response([envelope_str], normalise_times=False)
self.assertSequenceEqual(output[1][b'ENVELOPE'],
Envelope(
None,
b"subject",
(Address(b"name", None, b"address1", b"domain1.com"),),
(Address(None, None, b"address2", b"domain2.com"),),
(Address(b"name", None, b"address3", b"domain3.com"),
Address(b"name", None, b"address3b", b"domain3b.com")),
None,
(Address(None, None, b"address4", b"domain4.com"),
Address(b"person", None, b"address4b", b"domain4b.com")),
None, b"", b""
)
def test_simple_pairs(self):
self.assertEqual(parse_fetch_response([b'23 (ABC 123 StUfF "hello")']),
{23: {b'ABC': 123,
b'STUFF': b'hello',
b'SEQ': 23}})
if not messages:
return {}
args = [
'FETCH',
join_message_ids(messages),
seq_to_parenstr_upper(data),
seq_to_parenstr_upper(modifiers) if modifiers else None
]
if self.use_uid:
args.insert(0, 'UID')
tag = self._imap._command(*args)
typ, data = self._imap._command_complete('FETCH', tag)
self._checkok('fetch', typ, data)
typ, data = self._imap._untagged_response(typ, data, 'FETCH')
return parse_fetch_response(data, self.normalise_times, self.use_uid)
*cmd* is the STORE command to use (eg. '+FLAGS').
"""
if not messages:
return {}
if silent:
cmd += b".SILENT"
data = self._command_and_check('store',
join_message_ids(messages),
cmd,
seq_to_parenstr(flags),
uid=True)
if silent:
return None
return self._filter_fetch_dict(parse_fetch_response(data),
fetch_key)