From 90beddd823534160affb9c5f1c0770407af204f4 Mon Sep 17 00:00:00 2001 From: Israel Figueroa Date: Mon, 2 Oct 2023 16:38:46 -0300 Subject: [PATCH] make the container reboot --- mayordomo/__init__.py | 1 + mayordomo/smtpd.py | 37 +++++++++++++++++-------------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/mayordomo/__init__.py b/mayordomo/__init__.py index cb04feb..fd51acf 100644 --- a/mayordomo/__init__.py +++ b/mayordomo/__init__.py @@ -208,6 +208,7 @@ async def cleanupSent(): except: await log.error('Traceback {}'.format(traceback.format_exc())) + raise('Error al leer correos pendientes. Reiniciando servicio.') return returnvalue diff --git a/mayordomo/smtpd.py b/mayordomo/smtpd.py index 8ea498f..c723a5e 100644 --- a/mayordomo/smtpd.py +++ b/mayordomo/smtpd.py @@ -15,34 +15,31 @@ class ilabHandler: async def handle_HELO(self, server, session, envelope, hostname): ip, port = session.peer await log.info(u"HELO '{}'".format(hostname)) - + origen = await get_origen(ip, hostname) origen.sesiones = origen.sesiones + 1 - + await log.info(u"Cliente '{}' en su {} visita".format(hostname, origen.sesiones)) await db.commit() - + session.host_name = 'smtp.vpc.ilab.cl' - + return '250 smtp.vpc.ilab.cl' - + async def handle_RCPT(self, server, session, envelope, address, rcpt_options): await log.info(u"RCPT '{}'".format(address)) - valid = False - try: - valid = await validate_direccion(address) - except BaseException as e: - await log.error('Traceback {}'.format(traceback.format_exc())) - + + valid = await validate_direccion(address) + if valid is None: await log.error(u"RCPT ERROR '{}' inválido".format(address)) return '501 5.5.4 destinatario invalido' - + envelope.rcpt_tos.append(address) - + return '250 OK' - + async def handle_DATA(self, server, session, envelope): # await log.debug(u"DATA FROM '{}'".format(envelope.mail_from)) # await log.debug(u"DATA RCPT TOs '{}'".format(', '.join(envelope.rcpt_tos))) @@ -52,25 +49,25 @@ class ilabHandler: # data = envelope.content # type: bytes ip, port = session.peer origen = await get_origen(ip, session.host_name) - + try: dbremitente = await validate_direccion(str(envelope.mail_from)) dbcarta = Carta(remitente=dbremitente, contenido=envelope.content.decode('utf-8')) db.add(dbcarta) await db.commit() - + for destinatario in envelope.rcpt_tos: dbdestinatario = await validate_direccion(str(destinatario)) dest = Destinatario(correo=dbdestinatario, carta=dbcarta, enviado=0, intentos=0) db.add(dest) - + origen.recibidos = origen.recibidos + 1 - + await db.commit() await log.info(u"Correo: '{}'->'{}'".format(envelope.mail_from, ', '.join(envelope.rcpt_tos))) - + except: await log.error('Traceback {}'.format(traceback.format_exc())) return '500 Error interno, reintentelo' - + return '250 OK'