[Nym3-commit] r435 - trunk/nymbaron/Server

jr at conuropsis.org jr at conuropsis.org
Sun Dec 4 01:17:19 CET 2005


Author: jr
Date: 2005-12-04 01:17:18 +0100 (Sun, 04 Dec 2005)
New Revision: 435

Modified:
   trunk/nymbaron/Server/Main.py
   trunk/nymbaron/Server/User.py
Log:
- add clean-surbs [server]


Modified: trunk/nymbaron/Server/Main.py
===================================================================
--- trunk/nymbaron/Server/Main.py	2005-12-03 22:18:50 UTC (rev 434)
+++ trunk/nymbaron/Server/Main.py	2005-12-04 00:17:18 UTC (rev 435)
@@ -309,6 +309,7 @@
 	print usage_string
 	sys.exit(1)
     #TODO load the config file here?
+    
     if args[1] == "deliver":
 	parser = OptionParser(usage =
 	"""nymbarond deliver [options]
@@ -324,6 +325,7 @@
 	    sys.exit(1)
 	processIncoming(options.nym, readMessage(options.file))
 	sys.exit(0)
+    
     if args[1] == "process":
 	parser = OptionParser(usage =
 	"""nymbarond process [options]
@@ -344,6 +346,14 @@
 	    else:
 		sys.stderr.write("Unable to find valid control message")
 	sys.exit(0)
+    
+    if args[1] == "clean-surbs":
+	mapAccount(config, User.User.clean_surbs)
+	sys.exit(0)
+
+    if args[1] == "encode-synopses":
+	sys.exit(0)
+    
     if args[1] == "help":
 	print usage_string
 	sys.exit(0)

Modified: trunk/nymbaron/Server/User.py
===================================================================
--- trunk/nymbaron/Server/User.py	2005-12-03 22:18:50 UTC (rev 434)
+++ trunk/nymbaron/Server/User.py	2005-12-04 00:17:18 UTC (rev 435)
@@ -28,7 +28,9 @@
     This module contains methods of storing, accessing and editing user account
     information."""
 
+import re
 import os
+import sys
 import nymbaron.Server.Config as Config
 import nymbaron.Mail as Mail
 import nymbaron.Crypto as Crypto
@@ -36,6 +38,7 @@
 import pickle
 import string
 import time
+import calendar
 import mixminion.Common
 from nymbaron.Message import intToStrBE
 import mixminion.Crypto as _cr
@@ -97,15 +100,42 @@
     return max
 
 def check_surb(surb):
-    """Returns True if the surb is usable, False if it was already used"""
+    """Returns True if the surb is usable, False if it was already used or is
+    out of date"""
     fname = '/tmp/' + Mail.mid2filename(Mail.genMid())
     fname = string.strip(fname)
     f = open(fname, 'w')
     f.write(surb)
     f.close()
-    ec = os.system("mixminion inspect-surb " + fname + " |grep 'Used: no'")
-    os.unlink(fname)
-    return ec == 0
+    (outr, outw) = os.pipe()
+    if os.fork() == 0:
+	sys.stdin.close()
+	os.close(outr)
+	os.dup2(outw, sys.stdout.fileno())
+	os.execlp("mixminion", "mixminion", "inspect-surb", fname)
+	sys.exit(0)
+    else:
+	os.close(outw)
+	foo = os.fdopen(outr)
+	out = foo.read()
+	foo.close() #TODO do we need to close outr?
+	os.wait()
+	os.unlink(fname)
+	try:
+	    expDate = re.search("Expires at: (.*)\n", out).group(1)
+	    used = re.search("Used: (.*)[\n$]", out).group(1)
+	    eD = time.strptime(expDate, "%Y-%m-%d %H:%M:%S GMT")
+	    return calendar.timegm(eD) > time.time() and used == "no"
+	except AttributeError, inst:
+	    sys.stderr.write("Bug\n")
+	    print inst
+	    sys.exit(2)
+	except ValueError:
+	    #TODO temporary cruft, we should get the expiracy date through the
+	    #library
+	    sys.stderr.write("Wrong date format, unable to determine expiracy" +
+		    " date\n")
+	    sys.exit(2)
     
 class User:
     """Hold user data. Specifically, this means:
@@ -372,14 +402,18 @@
 	f.close()
 	surbs = parseReplyBlocks(buffer)
 	goods = []
+	nr = 0
 	for surb in surbs:
 	    surbp = surb.pack() #the value of surb as a string
 	    if check_surb(surbp):
 		goods.append(surbp)
+	    else:
+		nr = nr + 1
 	f = open(self.surbfile(), "w")
 	for surbp in goods:
 	    f.write(surbp)
 	self.data['nSurbs'] = len(goods)
+	print "%d surbs removed" % nr
 	f.close()
 
     def addSurbs(self, newsurbs):



More information about the Nym3-commit mailing list