async def connect(self, host, port=993, timeout=30, ssl=True): self.runt.confirm(('storm', 'inet', 'imap', 'connect')) ssl = await s_stormtypes.tobool(ssl) host = await s_stormtypes.tostr(host) port = await s_stormtypes.toint(port) timeout = await s_stormtypes.toint(timeout, noneok=True) if ssl: imap_cli = aioimaplib.IMAP4_SSL(host=host, port=port, timeout=timeout) else: imap_cli = aioimaplib.IMAP4(host=host, port=port, timeout=timeout) async def fini(): # call protocol.logout() so fini() doesn't hang await asyncio.wait_for(imap_cli.protocol.logout(), 5) self.runt.snap.onfini(fini) try: await imap_cli.wait_hello_from_server() except asyncio.TimeoutError: raise s_exc.StormRuntimeError(mesg='Timed out waiting for IMAP server hello.') from None return ImapServer(self.runt, imap_cli)
async def connect(self): imap_client = aioimaplib.IMAP4_SSL(host=self.mail_host, port=self.mail_port, ssl_context=self.ctx) await imap_client.wait_hello_from_server() result, lines = await imap_client.login(self.user, self.pw) if result != "OK": logger.debug(f"Could not login to {self.user}") logger.debug(f"{result}, {lines}") return imap_client
def connection(self): """Return a connection to the server, establishing it if necessary.""" import aioimaplib if self._connection is None: try: self._connection = aioimaplib.IMAP4_SSL( self._server, self._port) yield from self._connection.wait_hello_from_server() yield from self._connection.login(self._user, self._password) yield from self._connection.select(self._folder) self._does_push = self._connection.has_capability('IDLE') except (aioimaplib.AioImapException, asyncio.TimeoutError): self._connection = None return self._connection