Created
June 24, 2015 16:42
-
-
Save xcombelle/4a77006596a56cc09d2d to your computer and use it in GitHub Desktop.
imap_stream_diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/imap_stream.py b/imap_stream.py | |
| index f96ea9d..b009bba 100644 | |
| --- a/imap_stream.py | |
| +++ b/imap_stream.py | |
| @@ -8,7 +8,7 @@ import ssl | |
| import logging | |
| import functools | |
| -import pyparsing | |
| +#import pyparsing | |
| import config | |
| import imapParser | |
| @@ -37,6 +37,7 @@ def capability(connection): | |
| ''' | |
| Let's display the capabilities of our system | |
| ''' | |
| + print ("in capability") | |
| cap_clear = connection.conf['server']['capabilities_clear'] | |
| cap_tls = connection.conf['server']['capabilities_tls'] | |
| # We need to write a continuation request | |
| @@ -113,12 +114,18 @@ def starttls(connection): | |
| , 'cipher': tls_sock.cipher() | |
| , 'peercert': tls_sock.getpeercert() | |
| , 'sslcontext': context} | |
| - | |
| - transport = asyncio.Transport(extra=extra) | |
| - connection.reader = asyncio.StreamReader() | |
| - connection.reader.set_transport = transport | |
| - protocol = asyncio.StreamReaderProtocol(connection.reader, functools.partial(imap_connection, conf=connection.conf), loop=loop) | |
| - connection.writer = asyncio.StreamWriter(transport, protocol, connection.reader, loop) | |
| + connection.reader, connection.writer = yield from asyncio.open_connection(sock=tls_sock, loop=loop) | |
| + #transport = asyncio.BaseTransport(extra=extra) | |
| + #connection.reader = asyncio.StreamReader() | |
| + #connection.reader.set_transport(transport) | |
| + #print(transport) | |
| + #print(extra) | |
| + | |
| + | |
| + #protocol = asyncio.StreamReaderProtocol(connection.reader, functools.partial(imap_connection, conf=connection.conf), loop=loop) | |
| + #connection.writer = asyncio.StreamWriter(transport, protocol, connection.reader, loop) | |
| + | |
| + | |
| print('S: Swapping done') | |
| @@ -143,28 +150,37 @@ def imap_connection(client_reader, client_writer, conf): | |
| # We need to grant our users | |
| client_writer.write(u"* OK IMAP4rev1 server with python 3.4 asyncio.Streams\r\n".encode('utf-7')) | |
| - yield from client_writer.drain() | |
| + yield from connection.writer.drain() | |
| - while not client_reader.at_eof(): | |
| - data = yield from client_reader.readline() | |
| + while not connection.reader.at_eof(): | |
| + print("ici") | |
| + data = b"" | |
| + print (connection.reader) | |
| + print(dir(connection.reader)) | |
| + print(dir(connection.reader._transport)) | |
| + #print(connection.reader._transport.extra) | |
| + #while not data.endswith(b"\n"): | |
| + data = yield from connection.reader.readline() | |
| + print (data) | |
| data = data.decode() | |
| print(u'C: {}'.format(data)) | |
| try: | |
| parsed_data = imapParser.command.parseString(data) | |
| except pyparsing.ParseException as e: | |
| - client_writer.write(u"* BAD {}".format(data).encode('utf-7')) | |
| + connection.writer.write(u"* BAD {}".format(data).encode('utf-7')) | |
| print(u"S: * BAD {}".format(data)) | |
| - yield from client_writer.drain() | |
| + yield from connection.writer.drain() | |
| continue | |
| connection.command = parsed_data | |
| tag = parsed_data['tag'] | |
| command = parsed_data['command'] | |
| + | |
| if command not in COMMANDS: | |
| - reader_write(u"{} BAD {} NOT SUPPORTED\r\n".format(tag, command).encode('utf-7')) | |
| + connection.writer.write(u"{} BAD {} NOT SUPPORTED\r\n".format(tag, command).encode('utf-7')) | |
| print(u"S: {} BAD {} NOT SUPPORTED\r\n".format(tag, command)) | |
| - yield from client_writer.drain() | |
| + yield from connection.writer.drain() | |
| else: | |
| yield from COMMANDS[command.upper()](connection) | |
| @@ -184,9 +200,9 @@ def start(conf): | |
| loop.run_until_complete(stream_serv.wait_closed()) | |
| if __name__ == "__main__": | |
| - cmd = argparse.ArgumentDefaultsHelpFormatter(dscription="Start the IMAP4rev1 server") | |
| - cmd.add_argument(['-c', '--config'], default="./config.ini") | |
| - args = cmd.parse_args() | |
| - start(confi = args['config']) | |
| +# cmd = argparse.ArgumentDefaultsHelpFormatter(description="Start the IMAP4rev1 server") | |
| +# cmd.add_argument(['-c', '--config'], default="./config.ini") | |
| +# args = cmd.parse_args() | |
| + start(conf = "./config.ini") | |
| # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 autoindent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment