From 7ec65747fb8f910347b6465abed9a79a73a04e08 Mon Sep 17 00:00:00 2001 From: Stefano Marinelli Date: Thu, 12 Oct 2023 08:46:43 +0200 Subject: [PATCH] Modified the code to deal with a no-sender or no-subject situation --- NotiMail.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NotiMail.py b/NotiMail.py index 009662c..3fbcb91 100644 --- a/NotiMail.py +++ b/NotiMail.py @@ -146,6 +146,9 @@ class Notifier: def send_notification(mail_from, mail_subject): try: ntfy_url = config['NTFY']['NtfyURL'] + # Check if mail_subject and mail_from are None and replace them with default strings + mail_subject = mail_subject if mail_subject is not None else "No Subject" + mail_from = mail_from if mail_from is not None else "Unknown Sender" # Sanitize mail_subject and mail_from to ensure they only contain characters that can be encoded in 'latin-1' sanitized_subject = mail_subject.encode('latin-1', errors='replace').decode('latin-1') sanitized_from = mail_from.encode('latin-1', errors='replace').decode('latin-1') @@ -162,6 +165,7 @@ class Notifier: except requests.RequestException as e: print(f"An error occurred: {str(e)}") + class IMAPHandler: def __init__(self, host, email_user, email_pass): self.host = host