예제 #1
0
    def factory(self):
        """``CustomIdentController`` factory.

        Overrides ``super.factory()``.
        Creates an aiosmtpd server object.

        Returns:
            Returns the server object.
        """

        server = Server(self.handler)
        server.hostname = self.ident_hostname
        server.__ident__ = self.ident
        return server
예제 #2
0
    def getter(test_obj: "_TestProxyProtocolCommon", *args, **kwargs):
        kwargs["loop"] = loop
        kwargs["proxy_protocol_timeout"] = proxy_timeout
        protocol = SMTPServer(handler, *args, **kwargs)
        protocol.connection_made(transport)

        def runner(stop_after: float = DEFAULT_AUTOCANCEL):
            loop.call_later(stop_after, protocol._handler_coroutine.cancel)
            with suppress(asyncio.CancelledError):
                loop.run_until_complete(protocol._handler_coroutine)

        test_obj.protocol = protocol
        test_obj.runner = runner
        test_obj.transport = transport
예제 #3
0
 def factory(self):
     """Allow subclasses to customize the handler/server creation."""
     return SMTP(self.handler,
                 loop=self.loop,
                 data_size_limit=config.max_data_size,
                 tls_context=get_tls_context() if config.use_tls else None,
                 require_starttls=config.use_tls)
예제 #4
0
 def factory(self):
     """Allow subclasses to customize the handler/server creation."""
     ssl = self.ssl_context
     if self.startSSL:
         ssl = get_server_context(self.certfile, self.keyfile)
     return SMTP(self.handler, enable_SMTPUTF8=self.enable_SMTPUTF8, require_starttls=self.startSSL,
                 authenticate=self.authenticate, tls_context=ssl, decode_data=True, timeout=self.timeout)
예제 #5
0
 def get_server(self):
     return SMTP(
         handler=self,
         hostname=self.host,
         enable_SMTPUTF8=True,
         loop=self.loop,
     )
예제 #6
0
 async def test_handle_DATA(self):
     self.handler.verify_dkim = False
     server = SMTP(self.handler)
     response = await self.handler.handle_DATA(
         self.server,
         Session(server.loop),
         self.envelope
     )
     assert response == '250 Message accepted for delivery'
예제 #7
0
 async def test_handle_DATA_fail_dkim(self):
     self.handler.verify_dkim = True
     server = SMTP(self.handler)
     response = await self.handler.handle_DATA(
         self.server,
         Session(server.loop),
         self.envelope
     )
     assert response == '550 DKIM validation failed'
예제 #8
0
    def factory(self) -> SMTP:
        use_starttls = self.config.use_starttls
        context = self._get_ssl_context() if use_starttls else None

        return SMTP(handler=self.handler,
                    require_starttls=self.config.use_starttls,
                    auth_required=self.config.enforce_auth,
                    auth_require_tls=self.config.auth_require_tls,
                    tls_context=context,
                    authenticator=self._authenticator)
예제 #9
0
    def setup_method(self, method):
        self.handler = ExampleHandler('gmail.com', verify_spf=True)
        self.envelope = Envelope()
        self.envelope.content = b"""From: Cate Person <*****@*****.**>
To: Dave Person <*****@*****.**>
Subject: A test
Message-ID: <bee>

Hi Dave, this is Cate."""
        self.server = SMTP(self.handler)
예제 #10
0
파일: service.py 프로젝트: webkom/lego
 def factory(self):
     context = None
     if settings.SMTP_SSL_ENABLE:
         context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
         context.load_cert_chain(settings.SMTP_SSL_CERTIFICATE,
                                 settings.SMTP_SSL_KEY)
     return SMTP(
         self.handler,
         require_starttls=False,
         tls_context=context,
     )
예제 #11
0
 async def test_handle_MAIL_no_spf(self):
     server = SMTP(self.handler)
     session = Session(server.loop)
     session.peer = ['127.0.0.1', 65000]
     response = await self.handler.handle_MAIL(
         self.server,
         session,
         self.envelope,
         '*****@*****.**',
         []
     )
     assert response == '550 SPF validation failed'
예제 #12
0
    async def test_handle_RCPT_decline(self):
        # In this test, the message data comes in as bytes.
        server = SMTP(self.handler)

        response = await self.handler.handle_RCPT(
            self.server,
            Session(server.loop),
            self.envelope,
            '*****@*****.**',
            []
        )
        assert response == '550 not relaying to that domain'
예제 #13
0
    async def test_handle_RCPT(self):
        # In this test, the message data comes in as bytes.
        server = SMTP(self.handler)

        response = await self.handler.handle_RCPT(
            self.server,
            Session(server.loop),
            self.envelope,
            '*****@*****.**',
            []
        )
        assert response == '250 OK'
예제 #14
0
def smtp_server(event_loop, unused_tcp_port, handler, server_tls_context, tls):
    smtp = SMTP(handler, require_starttls=tls, tls_context=server_tls_context)
    server = event_loop.run_until_complete(
        event_loop.create_server(lambda: smtp, port=unused_tcp_port))
    yield smtp
    server.close()
    event_loop.run_until_complete(server.wait_closed())

    # The server leaves tasks running so cancel them
    for task in all_tasks(event_loop):
        task.cancel()
        with suppress(Exception):
            event_loop.run_until_complete(task)
예제 #15
0
 async def test_handle_MAIL_spf(self):
     server = SMTP(self.handler)
     session = Session(server.loop)
     session.peer = ['209.85.220.69', 65000]
     session.host_name = 'gmail.com'
     response = await self.handler.handle_MAIL(
         self.server,
         session,
         Envelope(),
         '*****@*****.**',
         []
     )
     assert response == '250 OK'
예제 #16
0
 def factory(self):
     """Used to define greater data size limit"""
     return SMTP(self.handler, data_size_limit=99999999999, decode_data=False)
예제 #17
0
 async def handle_NOOP(self, server: Server, session: Sess_, envelope, arg):
     self.ssl_existed = session.ssl is not None
     self.result = server.eof_received()
     return "250 OK"
예제 #18
0
 def test_special_max_command_size_limit(self):
     server = Server(Sink())
     server.command_size_limits['DATA'] = 1024
     self.assertEqual(server.max_command_size_limit, 1024)
예제 #19
0
 def test_special_max_command_size_limit(self):
     server = Server(Sink())
     server.command_size_limits['DATA'] = 1024
     self.assertEqual(server.max_command_size_limit, 1024)
예제 #20
0
파일: test_smtp.py 프로젝트: J08nY/aiosmtpd
 def factory(self):
     server = Server(self.handler)
     server.__ident__ = 'Identifying SMTP v2112'
     return server
예제 #21
0
 def _get_protocol(self, *args, **kwargs):
     protocol = Server(*args, loop=self.loop, **kwargs)
     protocol.connection_made(self.transport)
     return protocol
예제 #22
0
 def factory(self):
     return SMTP(self.handler, ssl_context=get_context())
예제 #23
0
 def factory(self):
     return SMTP(self.handler,
                 require_starttls=False,
                 tls_context=get_context())
예제 #24
0
from smtpx import CrazySrvHandler
from web import web_start

from aiosmtpd.controller import Controller
from aiosmtpd.smtp import SMTP
import configparser

if __name__ == "__main__":
    cf = configparser.ConfigParser()
    cf.read("cfg.ini")

    smtpd_host = cf.get("smtpd", "host")
    smtpd_port = cf.getint("smtpd", "port")

    rest_host = smtpd_host
    rest_port = cf.getint("rest", "port")

    handler = CrazySrvHandler()
    controller = Controller(handler, hostname=smtpd_host, port=smtpd_port)
    controller.factory = lambda: SMTP(handler, enable_SMTPUTF8=True)

    try:
        controller.start()
        web_start(rest_host, rest_port)
    except KeyboardInterrupt:
        print("Shutting down")
    finally:
        controller.stop()
예제 #25
0
 def test_special_max_command_size_limit(self):
     server = Server(Sink())
     server.command_size_limits["DATA"] = 1024
     assert server.max_command_size_limit == 1024
예제 #26
0
 def factory(self):
     """Allow subclasses to customize the handler/server creation."""
     return SMTP(self.handler)
예제 #27
0
 def _get_protocol(self, *args, **kwargs):
     protocol = Server(*args, loop=self.loop, **kwargs)
     protocol.connection_made(self.transport)
     return protocol
예제 #28
0
 def factory(self):
     server = Server(self.handler)
     server.__ident__ = 'Identifying SMTP v2112'
     return server
예제 #29
0
파일: app.py 프로젝트: kappactf/mailbox
handler = MailHandler()

@handler.default_route
def process(message, dkim, spf):
    send_message(message, dkim, spf)


if __name__ == "__main__":
    loop = asyncio.get_event_loop()

    ssl_context = None

    if os.path.exists("keys/host.crt") and os.path.exists("keys/host.key"):
        ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
        ssl_context.load_cert_chain("keys/host.crt", "keys/host.key")

    controller = Controller(handler, hostname=SMTP_HOST, port=SMTP_PORT)

    controller.factory = lambda: SMTP(handler, enable_SMTPUTF8=True, tls_context=ssl_context)
    controller.start()

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        controller.stop()
        loop.stop()
        loop.close()

예제 #30
0
 def factory(self):
     """Allow subclasses to customize the handler/server creation."""
     return SMTP(self.handler,
                 enable_SMTPUTF8=self.enable_SMTPUTF8,
                 **self.server_kwargs)
예제 #31
0
 def factory(self):
     return SMTP(self.handler,
                 decode_data=True,
                 auth_required=True,
                 auth_require_tls=False,
                 auth_method=auth)
예제 #32
0
 def factory(self):
     return SMTP(self.handler)
예제 #33
0
 def factory(self):
     server = Server(self.handler)
     server.hostname = self.ident_hostname
     server.__ident__ = self.ident
     return server