How to use the imapclient.exceptions 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 / imapclient / imapclient.py View on Github external
Most capabilities do not need to be enabled. This is only
        required for extensions which introduce backwards incompatible
        behaviour. Two capabilities which may require enable are
        ``CONDSTORE`` and ``UTF8=ACCEPT``.

        A list of the requested extensions that were successfully
        enabled on the server is returned.

        Once enabled each extension remains active until the IMAP
        connection is closed.

        See :rfc:`5161` for more details.
        """
        if self._imap.state != 'AUTH':
            raise exceptions.IllegalStateError(
                'ENABLE command illegal in state %s' % self._imap.state
            )

        resp = self._raw_command_untagged(
            b'ENABLE',
            [to_bytes(c) for c in capabilities],
            uid=False,
            response_name='ENABLED',
            unpack=True)
        if not resp:
            return []
        return resp.split()
github mjs / imapclient / imapclient / util.py View on Github external
def assert_imap_protocol(condition, message=None):
    if not condition:
        msg = "Server replied with a response that violates the IMAP protocol"
        if message:
            msg += "{}: {}".format(msg, message)
        raise exceptions.ProtocolError(msg)
github byt3bl33d3r / SprayingToolkit / core / sprayers / imap.py View on Github external
def auth_O365(self, username, password):
        log = logging.getLogger(f"auth_imap_O365({username})")
        try:
            server = imapclient.IMAPClient(self.target, port=self.port, ssl=True, timeout=3)
            server.login(username, password)
            self.valid_accounts.add((username, password))
            log.info(print_good(f"Found credentials: {username}:{password}"))
        except imapclient.exceptions.LoginError:
            log.info(print_bad(f"Authentication failed: {username}:{password} (Login failed)"))
        except Exception as e:
            self.log.error(print_bad(f"Error communicating with the IMAP server"))
            self.log.error(f"    Full error: {e}\n")
github mjs / imapclient / imapclient / imapclient.py View on Github external
system time). This attribute can be changed between ``fetch()``
    calls if required.

    Can be used as a context manager to automatically close opened connections:

    >>> with IMAPClient(host="imap.foo.org") as client:
    ...     client.login("bar@foo.org", "passwd")

    """

    # Those exceptions are kept for backward-compatibility, since
    # previous versions included these attributes as references to
    # imaplib original exceptions
    Error = exceptions.IMAPClientError
    AbortError = exceptions.IMAPClientAbortError
    ReadOnlyError = exceptions.IMAPClientReadOnlyError

    def __init__(self, host, port=None, use_uid=True, ssl=True, stream=False,
                 ssl_context=None, timeout=None):
        if stream:
            if port is not None:
                raise ValueError("can't set 'port' when 'stream' True")
            if ssl:
                raise ValueError("can't use 'ssl' when 'stream' is True")
        elif port is None:
            port = ssl and 993 or 143

        if ssl and port == 143:
            logger.warning("Attempting to establish an encrypted connection "
                           "to a port (143) often used for unencrypted "
                           "connections")
github mjs / imapclient / imapclient / imapclient.py View on Github external
def plain_login(self, identity, password, authorization_identity=None):
        """Authenticate using the PLAIN method (requires server support).
        """
        if not authorization_identity:
            authorization_identity = ""
        auth_string = '%s\0%s\0%s' % (authorization_identity, identity, password)
        try:
            return self._command_and_check('authenticate', 'PLAIN', lambda _: auth_string, unpack=True)
        except exceptions.IMAPClientError as e:
            raise exceptions.LoginError(str(e))