add more docstrings
[logparse.git] / logparse / mail.py
index 26a402e44eacd14b5d353e34623c9808016becdf..82e3ddbabc08087da7351e88637da58735f37a5b 100644 (file)
@@ -1,9 +1,12 @@
-#
-#   email.py
-#
-#   This module is essentially a wrapper for Python's premailer and whatever
-#   the default mail handler is.
-#
+"""
+This module is essentially a wrapper for Python's premailer and whatever the 
+default mail transfer is (usually Postfix). Note that the premailer package 
+(https://pypi.org/project/premailer/) is required for style embedding.
+
+This module provides the following methods:
+    - `mailprep`:   embed CSS styles into inline HTML tags
+    - `sendmail`:   send HTML or plaintext email using default mail handler
+"""
 
 import logging
 logger = logging.getLogger(__name__)
@@ -13,7 +16,13 @@ import premailer
 from email.mime.text import MIMEText
 import subprocess
 
+
 def mailprep(htmlin, stylesheet):
+    """
+    Embed CSS styles from a file into inline HTML tags. Requires the premailer
+    package (https://pypi.org/project/premailer/).
+    """
+
     logger.debug("Converting stylesheet " + stylesheet + " to inline tags")
     if not isfile(stylesheet):
         logger.warning("Cannot read stylesheet {}: file does not exist".format(stylesheet))
@@ -25,6 +34,12 @@ def mailprep(htmlin, stylesheet):
 
 
 def sendmail(mailbin, body, recipient, subject, html=True, sender=""):
+    """
+    Prepare and send an email in either HTML or plain text format. The default
+    MTA path is usually correct, but can be modified in the config option
+    "mailbin" in the [mail] section.
+    """
+
     logger.debug("Sending email")
     msg = MIMEText(body, 'html' if html else 'plain')
     if sender:
@@ -39,12 +54,6 @@ def sendmail(mailbin, body, recipient, subject, html=True, sender=""):
         logger.debug("sendmail output: {}".format(stdout))
         logger.info("Sent email to {0}".format(recipient))
         return 0
-#    except TimeoutExpired:
-#        mailproc.kill()
-#        stdout = mailproc.communicate()
-#        logger.debug("Timeout expired: {}".format(stdout))
-#        raise subprocess.TimeoutError
     except Exception as e:
         mailproc.kill()
         logger.warning("Failed to send message: {0}".format(str(e)))
-#        raise ChildProcessError