[Nym3-commit] r481 - trunk/nymbaron

zax at conuropsis.org zax at conuropsis.org
Thu Mar 16 18:26:12 CET 2006


Author: zax
Date: 2006-03-16 18:26:11 +0100 (Thu, 16 Mar 2006)
New Revision: 481

Modified:
   trunk/nymbaron/Mail.py
Log:
Extend logging to email module


Modified: trunk/nymbaron/Mail.py
===================================================================
--- trunk/nymbaron/Mail.py	2006-03-16 15:05:51 UTC (rev 480)
+++ trunk/nymbaron/Mail.py	2006-03-16 17:26:11 UTC (rev 481)
@@ -37,6 +37,7 @@
 import sys
 import tempfile
 import email
+import logging
 
 slen = 128
 """The length of a summary in bytes"""
@@ -46,6 +47,8 @@
 
 random.seed(None)
 
+mail_logger = logging.getLogger("nymbaron.auxiliary")
+
 oldestMid = chr(0) * midLen
 """Special value of a mid, older than any othany other mid"""
 
@@ -171,11 +174,13 @@
     to various rfc822 compliant email routines. body is actually
     an whole message formatted as per E2E-spec, which is kind of
     a castrated RFC822."""
+    
     # Make a From header and include the nymholder as a real_name.
     fromhdr = '%s <%s@%s>' % (nym, nym, sname)
     mainMsg = email.Message.Message()
     mainMsg["To"] = you
     mainMsg["From"] = fromhdr
+    mail_logger.debug("Creating outgoing message from %s to %s" % (nym, you))
     if abuse:
         mainMsg['X-Abuse-Contact'] = abuse
     # Create a Date header using UTC
@@ -186,6 +191,7 @@
     msg = email.message_from_string(body)
     filter_header(msg)
     if msg.is_multipart():
+        mail_logger.info("Repackaging multipart MIME message")
         mainMsg["Mime-version"] = "1.0"
         mainMsg["Content-type"] = "Multipart/mixed"
         mainMsg.preamble = "This is a multipart message in MIME format\n"
@@ -242,6 +248,7 @@
     from_addr = nym + '@' + sname
     # Send the message to the designated smtp server
     # TODO Need some error handling when logging gets enabled
+    mail_logger.debug("Sending outgoing message through smtplib")
     mailserver = smtplib.SMTP(smtphost)
     #mailserver.set_debuglevel(1)
     mailserver.sendmail(from_addr, [rcpt], payload)
@@ -251,11 +258,12 @@
     """ Depreciated in favour of using Python smtplib, but this
     works fine on systems with sendmail"""
     # TODO Need some error handling when logging gets enabled
+    mail_logger.debug("Sending outgoing message using %s" % sm)
     p = os.popen("%s -t" % sm, "w")
     p.write(payload)
     status = p.close()
     if status:
-        print "Sendmail failed with status", status
+        mail_logger.warn("%s returned error %s" % (sm, status))
         sys.exit(2)
 
 def genMid(length = midLen):



More information about the Nym3-commit mailing list