Exemple #1
0
async def load_old_jobs(file_manager, peer_map, scheduler):
    logger = logging.getLogger("ModernRelay.log")
    for job_file in file_manager.get_files():
        result = await file_manager.open_file(job_file)
        if result:
            envelope, peer = result
        else:
            logger.warning(
                f"Job file({job_file}) could not be loaded as it is probably misformatted!"
            )
            continue
        session = Session(loop=asyncio.get_event_loop())
        session.authenticated = True
        session.peer = (peer, )
        try:
            parse_peer(session, peer_map)
        except RelayRefusedException:
            logger.warning(
                f"Unable to match file({job_file}), IP({session.peer[0]}) to an allowed peer!"
            )
            continue

        scheduler.add_job(func=send_mail_from_disk,
                          trigger='interval',
                          seconds=30,
                          args=[job_file, file_manager, scheduler, session],
                          misfire_grace_time=None,
                          coalesce=True,
                          next_run_time=datetime.now() + timedelta(seconds=30),
                          id=job_file.name)
Exemple #2
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'
Exemple #3
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'
Exemple #4
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'
Exemple #5
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'
Exemple #6
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'
Exemple #7
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'
Exemple #8
0
 def session_auth(self, event_loop):
     sess = Session(loop=event_loop)
     sess.peer = ('172.16.129.64', 64160)
     sess.extended_smtp = True
     return sess