From 79aa834870827f802b314b3dd238dbddf25abb69 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Sun, 18 Jun 2023 18:18:53 +0200 Subject: [PATCH] remail: Unify send_mail() No need for two functions. Signed-off-by: Thomas Gleixner --- remail/mail.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/remail/mail.py b/remail/mail.py index 4ec3eaa..5e178a1 100644 --- a/remail/mail.py +++ b/remail/mail.py @@ -106,11 +106,16 @@ def send_smtp(msg, to, sender): server.send_message(msg, sender, [to]) server.quit() -def msg_deliver(msg, account, mfrom, sender, use_smtp): +def send_mail(msg, account, mfrom, sender, listheaders, use_smtp): ''' - Deliver the message. Replace or set the mandatory headers, sanitize - and order them properly to make gmail happy. + Send mail to the account. Make sure that the message is correct and all + required headers and only necessary headers are in the outgoing mail. ''' + + # Add the list headers + for key, val in listheaders.items(): + msg_set_header(msg, key, val) + msg_set_header(msg, 'From', encode_addr(mfrom)) msg_set_header(msg, 'To', encode_addr(account.addr)) msg_set_header(msg, 'Return-path', sender) @@ -128,18 +133,6 @@ def msg_deliver(msg, account, mfrom, sender, use_smtp): else: print(msg.as_string()) -def send_mail(msg_out, account, mfrom, sender, listheaders, use_smtp): - ''' - Send mail to the account. Make sure that the message - is correct and all required headers and only necessary - headers are in the outgoing mail. - ''' - # Add the list headers - for key, val in listheaders.items(): - msg_out[key] = val - - msg_deliver(msg_out, account, mfrom, sender, use_smtp) - # Minimal check for a valid email address re_mail = re.compile('^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$')