From bd83b013621b4fd1110368d753ee889600a8f708 Mon Sep 17 00:00:00 2001 From: "kuldeep.k@cisinlabs.com" Date: Fri, 25 Feb 2022 19:18:37 +0530 Subject: [PATCH] Added boolean return to functions & added break based on functions response --- main.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index a852c9f..f4cce94 100644 --- a/main.py +++ b/main.py @@ -32,24 +32,25 @@ class SMTPWebhookApp: def create_new_client(self, response): try: - print("- - - - - CREATING CLIENT - - - - -") mythread.client = smtplib.SMTP(host=SMTP_SERVER_HOST, port=SMTP_SERVER_PORT) mythread.client.starttls() + return True except (smtplib.SMTPException, TimeoutError) as e: soft_return("can't connect") - response = {"status": 500, + response = {"status": 500, # noqa:F841 "message": "some error: {}".format(e)} - print("response1: ", response) + return False def smtp_login(self, response, msg): try: mythread.client.login(msg["From"], FROM_MAIL_PASSWORD) + return True except smtplib.SMTPException as e: soft_return(e) - response = {"status": 500, + response = {"status": 500, # noqa:F841 "message": "some error: {}".format(e)} - print("response2: ", response) + return False def _send_mail(self): @@ -94,14 +95,15 @@ class SMTPWebhookApp: if (c == 1): soft_return("can't connect") - self.create_new_client(response) - self.smtp_login(response, msg) + if not self.create_new_client(response): + break + if not self.smtp_login(response, msg): + break except smtplib.SMTPException as e: soft_return("can't send for some reason") response = {"status": 500, "message": "some error: {}".format(e)} - print("response3: ", response) finally: c += 1