mirror of
https://github.com/draga79/NotiMail.git
synced 2024-09-19 19:14:19 +02:00
Modified the code to deal with a no-sender or no-subject situation
This commit is contained in:
parent
f6b161d0ac
commit
7ec65747fb
1 changed files with 4 additions and 0 deletions
|
@ -146,6 +146,9 @@ class Notifier:
|
||||||
def send_notification(mail_from, mail_subject):
|
def send_notification(mail_from, mail_subject):
|
||||||
try:
|
try:
|
||||||
ntfy_url = config['NTFY']['NtfyURL']
|
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'
|
# 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_subject = mail_subject.encode('latin-1', errors='replace').decode('latin-1')
|
||||||
sanitized_from = mail_from.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:
|
except requests.RequestException as e:
|
||||||
print(f"An error occurred: {str(e)}")
|
print(f"An error occurred: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
class IMAPHandler:
|
class IMAPHandler:
|
||||||
def __init__(self, host, email_user, email_pass):
|
def __init__(self, host, email_user, email_pass):
|
||||||
self.host = host
|
self.host = host
|
||||||
|
|
Loading…
Reference in a new issue