[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r20922: {projects} Keep a record of failed mails in a dump file for later inves (in projects/gettor: . lib/gettor)



Author: kaner
Date: 2009-11-08 08:37:44 -0500 (Sun, 08 Nov 2009)
New Revision: 20922

Modified:
   projects/gettor/GetTor.py
   projects/gettor/README
   projects/gettor/TODO
   projects/gettor/lib/gettor/config.py
   projects/gettor/lib/gettor/packages.py
   projects/gettor/lib/gettor/utils.py
   projects/gettor/sample-gettorrc
Log:
Keep a record of failed mails in a dump file for later investigation


Modified: projects/gettor/GetTor.py
===================================================================
--- projects/gettor/GetTor.py	2009-11-08 12:40:26 UTC (rev 20921)
+++ projects/gettor/GetTor.py	2009-11-08 13:37:44 UTC (rev 20922)
@@ -32,10 +32,12 @@
     - Send reply. Use all information gathered from the request and pass
       it on to the reply class/method to decide what to do."""
         
+    rawMessage = ""
     log.info("Processing mail..")
     # Retrieve request from stdin
     try:
         request = gettor.requests.requestMail(conf)
+        rawMessage = request.getRawMessage()
         replyTo, lang, pack, split, sig, cmdAddr = request.parseMail()
         log.info("Request from %s package %s, lang %s, split %s, cmdaddr %s" \
                     % (replyTo, pack, lang, split, cmdAddr))
@@ -44,18 +46,25 @@
         log.error("Parsing the request failed.")
         log.error("Here is the exception I saw: %s" % sys.exc_info()[0])
         log.error("Detail: %s" % e) 
+        # Keep a copy of the failed email for later reference
+        gettor.utils.dumpMessage(conf, rawMessage)
         return False
 
     # Ok, information aquired. Initiate reply sequence
     try:
         reply = gettor.responses.Response(conf, replyTo, lang, pack, split, \
                                             sig, cmdAddr)
-        reply.sendReply()
+        if not reply.sendReply():
+            log.error("Sending reply failed. We'll keep a record of this mail")
+            gettor.utils.dumpMessage(conf, rawMessage)
+            return False
         return True
     except Exception, e:
         log.error("Sending the reply failed.")
         log.error("Here is the exception I saw: %s" % sys.exc_info()[0])
         log.error("Detail: %s" %e)
+        # Keep a copy of the failed email for later reference
+        gettor.utils.dumpMessage(conf, rawMessage)
         raise
         return False
 

Modified: projects/gettor/README
===================================================================
--- projects/gettor/README	2009-11-08 12:40:26 UTC (rev 20921)
+++ projects/gettor/README	2009-11-08 13:37:44 UTC (rev 20922)
@@ -141,6 +141,7 @@
     logFile         = /home/gettor/gettor/logs/logfile
     localeDir       =  /home/gettor/gettor/i18n/
     cmdPassFile     = /home/gettor/gettor/pass
+    dumpFile        = /home/gettor/gettor/failedmails
 
 You can leave any of these lines out, and it will choose a suitable
 default.
@@ -165,6 +166,7 @@
 localeDir:     This is where the 'en/LC_MESSAGES/gettor.mo' or
                'whateverlang/LC_MESSAGES/gettor.mo' should go
 cmdPassFile:   The file containing the hashed command password
+dumpFile:      All failed mails are recorded here
 
 WHAT'S DKIM / WHY DKIM?
 -----------------------

Modified: projects/gettor/TODO
===================================================================
--- projects/gettor/TODO	2009-11-08 12:40:26 UTC (rev 20921)
+++ projects/gettor/TODO	2009-11-08 13:37:44 UTC (rev 20922)
@@ -4,20 +4,16 @@
   (multi-part download, etc.).
 - Write spec for how locale requests shall be formatted and parsed
 - Implement test (-t switch) functionality
-- Fix setup.py installer!
 - Split (at least) tiger bundle into several smaller archives to avoid ~20MB
 - Add more translations
     - Freeze messages for translation
     - Put po files into pootle for translation
 - Add GetTor to GetTor and it will be able to distribute itself
-- Better exception catching when the local SMTP rejects the email
-    - Perhaps we want to email the admin of GetTor with the error?
-    - Perhaps we want to respond to the user with a useful message?
 - Add torbutton (Mike, please sign torbutton and populate a proper .asc)
 - Fix rsync to follow symlinks properly. We want the data not a link to data.
-- Add a nice little note about the size of the files users may request
 - Strip HTML mails (!)
 - Remove 'localhost:25' to send mail and use '/usr/bin/sendmail' instead
   (suggested by weasel)
-- Think about adding a mail queue for outgoing mails that got a SMTP error
-  while trying to be sent. This way no mail gets lost
+- Package names that are sent out to the user are currently hard-coded. Return
+  to a more dynamic approach, also: Add a nice little note about the size of 
+  the files users may request

Modified: projects/gettor/lib/gettor/config.py
===================================================================
--- projects/gettor/lib/gettor/config.py	2009-11-08 12:40:26 UTC (rev 20921)
+++ projects/gettor/lib/gettor/config.py	2009-11-08 13:37:44 UTC (rev 20922)
@@ -26,6 +26,8 @@
      logFile = /dev/null
      localeDir = /usr/share/locale
      delayAlert = True
+     cmdPassFile = /var/lib/gettor/pass
+     dumpFile = /var/lib/gettor/dump
 
  Note that you can set from none to any of these values in your config file.
  Values you dont provide will be taken from the defaults in 'useConf'.
@@ -50,6 +52,8 @@
  delayAlert:    If set to True (the default), a message will be sent to any
                 user who has properly requested a package. The message confirms
                 that a package was selected and will be sent.
+ cmdPassFile:   Where our forward command password resides
+ dumpFile:      Where failed mails get stored
 
  If no valid config file is provided to __init__, gettorConf will try to use
  '~/.gettorrc' as default config file. If that fails, the default values from
@@ -96,6 +100,7 @@
                         "logFile":      ("/dev/null",               "global"),
                         "localeDir":    ("/usr/share/locale",       "global"),
                         "cmdPassFile":  ("/var/lib/gettor/cmdpass", "global"),
+                        "dumpFile":     ("/var/lib/gettor/dump",    "global"),
                         "delayAlert":   (True,                    "global")}
 
         # One ConfigParser instance to read the actual values from config
@@ -178,6 +183,9 @@
     def getDelayAlert(self):
         return self.useConf["delayAlert"][0]
 
+    def getDumpFile(self):
+        return self.useConf["dumpFile"][0]
+
 if __name__ == "__main__" :
     c = Config()
     print "# This is a suitable default configuration. Tune to fit your needs."

Modified: projects/gettor/lib/gettor/packages.py
===================================================================
--- projects/gettor/lib/gettor/packages.py	2009-11-08 12:40:26 UTC (rev 20921)
+++ projects/gettor/lib/gettor/packages.py	2009-11-08 13:37:44 UTC (rev 20922)
@@ -16,22 +16,13 @@
 import subprocess
 import gettor.gtlog
 import gettor.config
+import gettor.utils
 import re
 
 __all__ = ["Packages"]
 
 log = gettor.gtlog.getLogger()
 
-# XXX
-def createDir(path):
-    try:
-        log.info("Creating directory %s.." % path)
-        os.makedirs(path)
-    except OSError, e:
-        log.error("Failed to create directory %s: %s" % (path, e))
-        return False
-    return True
-
 class Packages:
     #                "bundle name": ("single file regex", "split file regex")
     packageRegex = { "windows-bundle": ("vidalia-bundle-.*.exe$", "vidalia-bundle-.*_split"),
@@ -50,14 +41,14 @@
         try:
             entry = os.stat(self.distDir)
         except OSError, e:
-            if not createDir(self.distDir):
+            if not gettor.utils.createDir(self.distDir):
                 log.error("Bad dist dir %s: %s" % (self.distDir, e))
                 raise IOError
         self.packDir = config.getPackDir()
         try:
             entry = os.stat(self.packDir)
         except OSError, e:
-            if not createDir(self.packDir):
+            if not gettor.utils.createDir(self.packDir):
                 log.error("Bad pack dir %s: %s" % (self.packDir, e))
                 raise IOError
 

Modified: projects/gettor/lib/gettor/utils.py
===================================================================
--- projects/gettor/lib/gettor/utils.py	2009-11-08 12:40:26 UTC (rev 20921)
+++ projects/gettor/lib/gettor/utils.py	2009-11-08 13:37:44 UTC (rev 20922)
@@ -14,6 +14,7 @@
 import os
 import subprocess
 import hashlib
+import datetime
 
 import gettor.gtlog
 import gettor.blacklist
@@ -31,6 +32,27 @@
         return False
     return True
 
+def dumpMessage(conf, message):
+    """Dump a message to our dumpfile"""
+    dumpFile = conf.getDumpFile()
+    # Be nice: Create dir if it's not there
+    dumpDir = os.path.dirname(dumpFile)
+    if not os.access(dumpDir, os.W_OK):
+        if not createDir(dumpDir):
+            log.error("Could not create dump dir")
+            return False
+    try:
+        fd = open(dumpFile, 'a')
+        now = datetime.datetime.now()
+        prefix = "Failed mail at %s:\n" % now.strftime("%Y-%m-%d %H:%M:%S")
+        fd.write(prefix)
+        fd.write(message)
+        fd.close
+        return True
+    except Exception, e:
+        log.error("Creating dump entry failed: %s" % e)
+        return False
+
 def installTranslations(conf, localeSrcdir):
     """Install all translation files to 'dir'"""
     log.info("Installing translation files..")
@@ -212,6 +234,12 @@
     log.info("Setting command password")
     passwordHash = str(hashlib.sha1(password).hexdigest())
     cmdPassFile = conf.getCmdPassFile()
+    # Be nice: Create dir if it's not there
+    passDir = os.path.dirname(cmdPassFile)
+    if not os.access(passDir, os.W_OK):
+        if not createDir(passDir):
+            log.error("Could not create pass dir")
+            return False
     try:
         fd = open(cmdPassFile, 'w')
         fd.write(passwordHash)

Modified: projects/gettor/sample-gettorrc
===================================================================
--- projects/gettor/sample-gettorrc	2009-11-08 12:40:26 UTC (rev 20921)
+++ projects/gettor/sample-gettorrc	2009-11-08 13:37:44 UTC (rev 20922)
@@ -2,13 +2,15 @@
 # ~/.gettorrc
 #
 [global]
-stateDir    = /tmp/
-blstatedir  = /tmp/bl/
-wlstatedir  = /tmp/wl/
-distdir     = /tmp/distdir/
-packdir     = /tmp/packdir/
-locale      = en
-delayalert  = True
-logSubSystem= stdout
-logFile     = /tmp/logfile
-localDir    = /tmp/i18n/
+stateDir        = /tmp/gettor
+blstatedir      = /tmp/gettor/bl/
+wlstatedir      = /tmp/gettor/wl/
+distdir         = /tmp/gettor/distdir/
+packdir         = /tmp/gettor/packdir/
+locale          = en
+delayalert      = True
+logSubSystem    = stdout
+logFile         = /tmp/gettor/logfile
+localDir        = /tmp/gettor/i18n/
+cmdPassFile     = /tmp/gettor/pass
+dumpFile        = /tmp/gettor/dumpfile