def server_protocol(self, server: Server, argtext: str) -> RequestProtocolGenerator: #log = logger.getChild ( 'DataRequest._server_protocol' ) if not server.client_hostname and server.pedantic: raise ResponseEvent(503, 'Say HELO first') if argtext and server.pedantic: raise ResponseEvent( 501, 'Syntax error (no parameters allowed) RFC5321#4.3.2') if not server.auth_uid: raise ResponseEvent(513, 'Must authenticate') if not server.mail_from: raise ResponseEvent(503, 'no from address received yet') if not server.rcpt_to: raise ResponseEvent(503, 'no rcpt address(es) received yet') yield ResponseEvent(354, 'Start mail input; end with <CRLF>.<CRLF>') event1 = NeedDataEvent() while True: yield from event1.go() line = event1.data or b'' if line == b'.\r\n': break elif line[0:1] == b'.': server.data.append(line[1:]) else: server.data.append(line) event2 = CompleteEvent(server.mail_from, server.rcpt_to, server.data) server.reset( ) # is this correct? reset even if we're going to return an error? yield event2 _, code, message = event2._accepted() yield ResponseEvent(code, message)
def client_protocol ( self, client: Client ) -> RequestProtocolGenerator: event = NeedDataEvent() yield from client_util.send_recv_ok ( 'CAPA\r\n', event ) # +OK Capability list follows lines: List[bytes] = [ event.data or b'' ] while event.data != b'.\r\n': yield from event.go() lines.append ( event.data or b'' ) r = CapaResponse.parse_multi ( *lines ) r.capa = {} for line in r.lines: capa_name, *capa_params = line.split ( ' ', 1 ) r.capa[capa_name] = capa_params[0].rstrip() if capa_params else '' raise r
def client_protocol(self, client: Client) -> RequestProtocolGenerator: log = logger.getChild('EhloRequest.client_protocol') yield from client_util.send(f'EHLO {self.domain}\r\n') event = NeedDataEvent() lines: List[str] = [] esmtp_features: Dict[str, str] = {} esmtp_auth: Set[str] = set() while True: yield from client_util.recv_ok(event) assert isinstance(event.response, Response) tmp: Opt[Response] = event.response assert tmp is not None lines.append(tmp.lines[0]) if isinstance(tmp, SuccessResponse): for line in lines[1:]: if line.startswith('AUTH '): for auth in line.split(' ')[1:]: esmtp_auth.add(auth) else: name, *args = line.split(' ', 1) esmtp_features[name] = args[0] if args else '' r = EhloResponse(tmp.code, *lines) r.esmtp_features = esmtp_features r.esmtp_auth = esmtp_auth raise r
def server_protocol(self, server: Server, moreargtext: str) -> RequestProtocolGenerator: log = logger.getChild('AuthPlainRequest._server_protocol') try: if not (authtext := moreargtext): yield ResponseEvent(334, '') yield from (event := NeedDataEvent()).go() authtext = b2s(event.data or b'').rstrip() _, uid, pwd = b64_decode_str(authtext).split('\0')
def client_protocol(self, client: Client) -> RequestProtocolGenerator: #log = logger.getChild ( 'ExpnRequest.client_protocol' ) yield from client_util.send(f'{self._verb} {self.mailbox}\r\n') event = NeedDataEvent() lines: List[str] = [] while True: yield from client_util.recv_ok(event) assert isinstance(event.response, Response) tmp: Opt[Response] = event.response assert tmp is not None lines.append(tmp.lines[0]) if isinstance(tmp, SuccessResponse): raise self.responsecls(tmp.code, *lines)
def server_protocol(self, server: Server, moreargtext: str) -> RequestProtocolGenerator: log = logger.getChild('AuthLoginRequest._server_protocol') if moreargtext and server.pedantic: raise ResponseEvent(501, 'Syntax error (no extra parameters allowed)') event = NeedDataEvent() try: yield ResponseEvent(334, b64_encode_str('Username:'******'')).rstrip() yield ResponseEvent(334, b64_encode_str('Password:'******'')).rstrip() except Exception as e: log.debug(f'{e=}') yield ResponseEvent(501, 'malformed auth input RFC4616#2') else: yield from self._on_authenticate(server, uid, pwd)
def client_protocol ( self, client: Client ) -> RequestProtocolGenerator: #log = logger.getChild ( 'GreetingRequest.client_protocol' ) event = NeedDataEvent() yield from client_util.recv_ok ( event ) assert isinstance ( event.response, Response ) raise GreetingResponse ( event.response.message )