[tor-commits] [gettor/master] Debugging improvements

ilv at torproject.org ilv at torproject.org
Tue Nov 3 19:31:30 UTC 2015


commit e35c09f55571c1b1966c263643a38eaeb94c8a9a
Author: ilv <ilv at users.noreply.github.com>
Date:   Mon Aug 3 15:08:29 2015 -0300

    Debugging improvements
---
 process_email.py |   41 +++++++++++++++++++++++++++++++++++++++++
 smtp_demo.py     |   22 ----------------------
 2 files changed, 41 insertions(+), 22 deletions(-)

diff --git a/process_email.py b/process_email.py
new file mode 100644
index 0000000..504b5dd
--- /dev/null
+++ b/process_email.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+import logging
+
+import gettor.smtp
+
+def main():
+    logging_level = 'INFO'
+    logging_file = '/path/to/gettor/log/process_email.log'
+    logging_format = '[%(levelname)s] %(asctime)s - %(message)s'
+    date_format = "%Y-%m-%d" # %H:%M:%S
+
+    logging.basicConfig(
+        format=logging_format,
+        datefmt=date_format,
+        filename = logging_file,
+        level = logging_level
+    )
+
+    logging.debug("New email received")
+    logging.debug("Creating new SMTP object")
+    
+    try:
+        service = gettor.smtp.SMTP('/path/to/gettor/smtp.cfg')
+        incoming = sys.stdin.read()
+        service.process_email(incoming)
+        logging.debug("Email processed sucessfully")
+    except gettor.smtp.ConfigError as e:
+        logging.error("Configuration error: %s" % str(e))        
+    except gettor.smtp.SendEmailError as e:
+        logging.error("SMTP not working: %s" % str(e))
+    except gettor.smtp.InternalError as e:
+        logging.error("Core module not working: %s" % str(e))
+    except Exception as e:
+        # in case something unexpected happens
+        logging.critical("Unexpected error: %s" % str(e))
+
+if __name__ == '__main__':
+    main()
diff --git a/smtp_demo.py b/smtp_demo.py
deleted file mode 100644
index 0ec341e..0000000
--- a/smtp_demo.py
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/env python
-import sys
-
-import gettor.smtp
-
-service = gettor.smtp.SMTP()
-
-# For now we simulate mails reading from stdin
-# In linux test as follows:
-# $ python smtp_demo.py < email.eml
-
-incoming = sys.stdin.read()
-try:
-    print "Email received!"
-    service.process_email(incoming)
-    print "Email sent!"
-except gettor.smtp.ConfigError as e:
-    print "Misconfiguration: " + str(e)
-except gettor.smtp.SendEmailError as e:
-    print "SMTP not working: " + str(e)
-except gettor.smtp.InternalError as e:
-    print "Core module not working: " + str(e)





More information about the tor-commits mailing list