cosmetic changes in sendmail.py - please the linter
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 3 Nov 2023 13:06:28 +0000 (14:06 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 3 Nov 2023 13:06:28 +0000 (14:06 +0100)
PLC/sendmail.py

index a1f2f3e..86cee36 100644 (file)
@@ -1,14 +1,20 @@
-import os
+"""
+sendmail.py - Send email messages
+"""
+
+# import os
 import sys
 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 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
     """
     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
 
     # 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
         """
         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
         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)
                 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:
         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
         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()
 
     s = SMTP()
     s.connect()
-    rejected = s.sendmail(from_addrs[0], to_addrs, msg.as_string(), rcpt_options = ["NOTIFY=NEVER"])
     s.close()
     s.close()
+    rejected = s.sendmail(
+        from_addrs[0], to_addrs,
+        msg.as_string(), rcpt_options=["NOTIFY=NEVER"])
 
     if rejected:
 
     if rejected:
-        raise PLCAPIError("Error sending message to " + ", ".join(list(rejected.keys())))
+        raise PLCAPIError("Error sending message to "
+                          + ", ".join(list(rejected.keys())))