[or-cvs] r17949: {projects} Strip unrelevant parts from email addresses when black/white (projects/gettor)

kaner at seul.org kaner at seul.org
Tue Jan 6 13:06:15 UTC 2009


Author: kaner
Date: 2009-01-06 08:06:15 -0500 (Tue, 06 Jan 2009)
New Revision: 17949

Modified:
   projects/gettor/gettor_blacklist.py
   projects/gettor/gettor_responses.py
Log:
Strip unrelevant parts from email addresses when black/whitelisting
Fix default filename argument in cunstructMessage


Modified: projects/gettor/gettor_blacklist.py
===================================================================
--- projects/gettor/gettor_blacklist.py	2009-01-06 12:03:01 UTC (rev 17948)
+++ projects/gettor/gettor_blacklist.py	2009-01-06 13:06:15 UTC (rev 17949)
@@ -6,6 +6,7 @@
 
 import hashlib
 import os
+import re
 import gettor_config
 import gettor_log
 
@@ -24,7 +25,8 @@
 
     def lookupListEntry(self, address):
         """Check to see if we have a list entry for the given address."""
-        entry = self.listDir + "/" + str(hashlib.sha1(address).hexdigest())
+        emailonly = self.stripEmail(address)
+        entry = self.listDir + "/" + str(hashlib.sha1(emailonly).hexdigest())
         try:
             entry = os.stat(entry)
         except OSError:
@@ -32,7 +34,8 @@
         return True
 
     def createListEntry(self, address):
-        entry = self.listDir + "/" + str(hashlib.sha1(address).hexdigest())
+        emailonly = self.stripEmail(address)
+        entry = self.listDir + "/" + str(hashlib.sha1(emailonly).hexdigest())
         if self.lookupListEntry(address) == False:
             try:
                 fd = open(entry, 'w')
@@ -46,7 +49,8 @@
             return False
 
     def removeListEntry(self, address):
-        entry = self.listDir + "/" + str(hashlib.sha1(address).hexdigest())
+        emailonly = self.stripEmail(address)
+        entry = self.listDir + "/" + str(hashlib.sha1(emailonly).hexdigest())
         if (self.lookupListEntry(address) == True):
             try:
                 os.unlink(entry)
@@ -70,6 +74,13 @@
                     return False
         return True
 
+    def stripEmail(self, address):
+        '''Strip "Bart Foobar <bart at foobar.net>" to "<bart at foobar.net">'''
+        match = re.search('<.*?>', address)
+        if match is not None:
+            return match.group()
+        return address
+
 def blackListtests(address):
     """ This is a basic evaluation of our blacklist functionality """
     bwlist = BWList("/tmp/") 

Modified: projects/gettor/gettor_responses.py
===================================================================
--- projects/gettor/gettor_responses.py	2009-01-06 12:03:01 UTC (rev 17948)
+++ projects/gettor/gettor_responses.py	2009-01-06 13:06:15 UTC (rev 17949)
@@ -100,7 +100,7 @@
 
         return status
 
-    def constructMessage(self, messageText, ourAddress, recipient, fileName):
+    def constructMessage(self, messageText, ourAddress, recipient, fileName=None):
         """ Construct a multi-part mime message, including only the first part
         with plaintext."""
 



More information about the tor-commits mailing list