From: Thierry Parmentelat Date: Fri, 3 Nov 2023 13:06:28 +0000 (+0100) Subject: cosmetic changes in sendmail.py - please the linter X-Git-Url: http://git.onelab.eu/?p=plcapi.git;a=commitdiff_plain;h=6bef7b35eec76ff66332cb20f58eb7703c2116f9 cosmetic changes in sendmail.py - please the linter --- diff --git a/PLC/sendmail.py b/PLC/sendmail.py index a1f2f3e..86cee36 100644 --- a/PLC/sendmail.py +++ b/PLC/sendmail.py @@ -1,14 +1,20 @@ -import os +""" +sendmail.py - Send email messages +""" + +# import os import sys -import pprint +# import pprint from email.mime.text import MIMEText from email.header import Header from smtplib import SMTP from PLC.Logger import logger -from PLC.Faults import * +from PLC.Faults import PLCAPIError +# from PLC.Faults import * + -def sendmail(api, To, Subject, Body, From = None, Cc = None, Bcc = None): +def sendmail(api, To, Subject, Body, From=None, Cc=None, Bcc=None): """ Uses sendmail (must be installed and running locally) to send a message to the specified recipients. If the API is running under @@ -37,7 +43,7 @@ def sendmail(api, To, Subject, Body, From = None, Cc = None, Bcc = None): # Unicode subject headers are automatically encoded correctly msg['Subject'] = Subject - def encode_addresses(addresses, header_name = None): + def encode_addresses(addresses, header_name=None): """ Unicode address headers are automatically encoded by email.Header, but not correctly. The correct way is to put the @@ -57,7 +63,7 @@ def sendmail(api, To, Subject, Body, From = None, Cc = None, Bcc = None): for addr in addresses: if isinstance(addr, tuple): (name, addr) = addr - h = Header(name, charset = api.encoding, header_name = header_name) + h = Header(name, charset=api.encoding, header_name=header_name) header.append('"%s" <%s>' % (h, addr)) else: header.append(addr) @@ -73,7 +79,7 @@ def sendmail(api, To, Subject, Body, From = None, Cc = None, Bcc = None): to_addrs += cc_addrs if Bcc is not None: - (unused, bcc_addrs) = encode_addresses(Bcc, 'Bcc') + (_, bcc_addrs) = encode_addresses(Bcc, 'Bcc') to_addrs += bcc_addrs # Needed to pass some spam filters @@ -87,8 +93,11 @@ def sendmail(api, To, Subject, Body, From = None, Cc = None, Bcc = None): s = SMTP() s.connect() - rejected = s.sendmail(from_addrs[0], to_addrs, msg.as_string(), rcpt_options = ["NOTIFY=NEVER"]) s.close() + rejected = s.sendmail( + from_addrs[0], to_addrs, + msg.as_string(), rcpt_options=["NOTIFY=NEVER"]) if rejected: - raise PLCAPIError("Error sending message to " + ", ".join(list(rejected.keys()))) + raise PLCAPIError("Error sending message to " + + ", ".join(list(rejected.keys())))