How to use the imapclient.response_types.Address function in IMAPClient

To help you get started, we’ve selected a few IMAPClient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mjs / imapclient / tests / test_response_parser.py View on Github external
def test_Address_str(self):
        self.assertEqual(str(Address(b"Mary Jane", None, b"mary", b"jane.org")),
                         "Mary Jane ")

        self.assertEqual(str(Address("Mary Jane", None, "mary", "jane.org")),
                         "Mary Jane ")

        self.assertEqual(str(Address("Anonymous", None, "undisclosed-recipients", None)),
                         "Anonymous ")

        self.assertEqual(str(Address(None, None, None, "undisclosed-recipients")),
                         "undisclosed-recipients")
github mjs / imapclient / tests / test_response_parser.py View on Github external
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""
        )
github mjs / imapclient / tests / test_response_parser.py View on Github external
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""
        )
github mjs / imapclient / tests / test_response_parser.py View on Github external
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""
        )
github mjs / imapclient / tests / test_response_parser.py View on Github external
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""
        )
github mjs / imapclient / tests / test_response_parser.py View on Github external
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""
        )
github mjs / imapclient / tests / test_response_parser.py View on Github external
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""
        )
github mjs / imapclient / imapclient / response_parser.py View on Github external
try:
            dt = parse_to_datetime(envelope_response[0], normalise=normalise_times)
        except ValueError:
            pass

    subject = envelope_response[1]

    # addresses contains a tuple of addresses
    # from, sender, reply_to, to, cc, bcc headers
    addresses = []
    for addr_list in envelope_response[2:8]:
        addrs = []
        if addr_list:
            for addr_tuple in addr_list:
                if addr_tuple:
                    addrs.append(Address(*addr_tuple))
            addresses.append(tuple(addrs))
        else:
            addresses.append(None)

    return Envelope(
        dt, subject, *addresses,
        in_reply_to=envelope_response[8],
        message_id=envelope_response[9]
    )
github izderadicka / imap_detach / src / imap_detach / mail_info.py View on Github external
def format_addresses(adr):
    def faddr(a):
        if not a.mailbox:
            return ''
        if not a.host:
            return decode(a.mailbox)
        return decode(a.mailbox + b'@' + a.host)
    if not adr:
        return ''
    if isinstance(adr, (Address)):
        return faddr(adr)
    elif isinstance(adr, (tuple, list)):
        return ', '.join(map(lambda x:faddr(x),adr ))
    raise ValueError('Invalid address type')