[Nym3-commit] r93 - trunk

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Thu, 05 Aug 2004 16:16:58 +0200


Author: jr
Date: 2004-08-05 16:16:56 +0200 (Thu, 05 Aug 2004)
New Revision: 93

Modified:
   trunk/Common.py
   trunk/Main.py
   trunk/User.py
Log:
- add lifeCycle (Common.py)
- modifu the meaning of markMid (User.py)
- use markMid to finish the processing of Summarize commands (Main.py)


Modified: trunk/Common.py
===================================================================
--- trunk/Common.py	2004-08-05 13:05:42 UTC (rev 92)
+++ trunk/Common.py	2004-08-05 14:16:56 UTC (rev 93)
@@ -9,3 +9,6 @@
 userPolicy = ["SendMsgAfter", "SendSummaryAfter", "EncryptSummaryAfter",
               "MaxSURBsPerDay", "HoldSURBs", "HoldUntilAck",
               "ShutdownPhrase"] 
+
+lifeCycle = { 'nothing-sent' : 0, 'synopsis-sent' : 1,
+              'sent-in-full' : 2, 'deleted' : 3 }

Modified: trunk/Main.py
===================================================================
--- trunk/Main.py	2004-08-05 13:05:42 UTC (rev 92)
+++ trunk/Main.py	2004-08-05 14:16:56 UTC (rev 93)
@@ -10,6 +10,8 @@
 import Common
 import Mail
 
+lifeCycle = Common.lifeCycle
+
 def processIncoming(localpart, msg):
     try:
 	nymuser = User.User(localpart)
@@ -134,7 +136,7 @@
                                 sendList.append(m)
                         ec = nymUser.sendMessage(Message.buildMessage(msgList))
                         if (ec == 0):
-                            nymUser.markMid(sendList,'sent-in-full')
+                            nymUser.markMid(sendList,lifeCycle['sent-in-full'])
                             if(nymUser['HoldUntilAck'] == 'never'):
                                 map(nymUser.delete_msg,sendList)
                             
@@ -145,9 +147,21 @@
                                 
                                 
                     elif (com.ct() == 6):
-                        sendList=nymUser.sendList(com.num,com.after)
-                        #TODO send what is in sendList (list of BF,enc syn)
-                        #TODO modify the state (['sent']='synopsis'
+                        comList = []
+                        sendList = nymUser.sendList(com.num, com.after)
+                        mList = []
+                        for (ml, bf, blob) in sendList:
+                            sumCom = Summary()
+                            sumCom.fromData(bf, blob)
+                            comList.append(sumCom)
+                            mList = mList + ml
+                        ec = nymUser.sendMessage(Message.buildMessage(comList))
+                        if (ec == 0):
+                            nymUser.markMid(mList, lifeCycle['synopsis-sent'])
+                        else:
+                            print "mixminion exited abnormally with error code %d" % ec
+                            sys.exit(2)
+
                     elif (com.ct() == 7):
                         for mid in com.l:
                             nymUser.delete_msg(mid)

Modified: trunk/User.py
===================================================================
--- trunk/User.py	2004-08-05 13:05:42 UTC (rev 92)
+++ trunk/User.py	2004-08-05 14:16:56 UTC (rev 93)
@@ -11,7 +11,7 @@
 from Message import intToStrBE
 
 surb_len = Common.surbLength
-
+lifeCycle = Common.lifeCycle
 class NoSuchUser(Exception): pass
 
 class AlreadySuchUser(Exception): pass
@@ -286,7 +286,7 @@
 
 	# create an index entry for the synopsis
 	self.index[mid] = {'time' : int(time.time()),
-			   'status' : 'nothing-sent' }
+			   'status' : lifeCycle['nothing-sent'] }
 
     def delete_msg(self, mid):
 	"""Delete a stored message. Delete the synopsis if possible"""
@@ -295,13 +295,13 @@
 	if not self.index.has_key(mid): return
 	self.load_mbox()
 	del self.mbox[mid]
-	self.index[mid]['status'] = 'deleted'
+	self.index[mid]['status'] = lifeCycle['deleted']
 	self.load_synbox()
 
 	i, (sl, enc, blurb) = self.getSyn(mid)
 	candelete = True
 	for omid in sl:
-	    if not self.index[omid]['status'] == 'deleted':
+	    if not self.index[omid]['status'] == lifeCycle['deleted']:
 		candelete = False
 		break
 	    if candelete:
@@ -341,26 +341,29 @@
         self.syn[i:j] = [self.blobify(syn[i:j])]
 
     def markMid(self,l,mark):
+        """the status of the mids in l which had a status
+        previous to mark in the lifeCycle are set to mark"""
         self.load_index()
         for e in l:
-            self.index[e]['status'] = mark
+            if (self.index[e]['status'] < mark):
+                self.index[e]['status'] = mark
         
 
     def hasMail(self,mid):
         self.load_index()
         try:
-            return self.index[mid]['status'] != 'deleted' 
+            return self.index[mid]['status'] != lifeCycle['deleted']
         except:
             return False
         
     def sendList(self, num, after):
-        """returns a list of (bf, synblob)
+        """returns a list of (ml, bf, synblob)
         in the process of creating it ca modify the synbox,
         doing some encryption"""
         def lhasMail(midIdx, l):
             return self.mbox.has_key(l[midIdx])
         def addBlob(slist, mlist, ilist, blob):
-            """append to slist (BF,blob)
+            """append to slist (mlist, BF, blob)
             BF is the bitfield obtained from the elements e of ilist
             which verifies : the mid mlist[e] has a mail"""
             def test(midx):