remail: Unify send_mail()

No need for two functions.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This commit is contained in:
Thomas Gleixner 2023-06-18 18:18:53 +02:00
parent c3b13e47f7
commit 79aa834870

View file

@ -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,})+$')