[Nym3-commit] r64 - trunk

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Wed, 04 Aug 2004 14:02:32 +0200


Author: jr
Date: 2004-08-04 14:02:31 +0200 (Wed, 04 Aug 2004)
New Revision: 64

Modified:
   trunk/Main.py
   trunk/User.py
Log:
- modify midAfter to sort the result list by time of arrival(User.py)
- add the processing of Summarize message(Main.py)


Modified: trunk/Main.py
===================================================================
--- trunk/Main.py	2004-08-02 21:22:40 UTC (rev 63)
+++ trunk/Main.py	2004-08-04 12:02:31 UTC (rev 64)
@@ -7,6 +7,7 @@
 import Config
 import Message
 import Common
+import Mail
 
 def processIncoming(localpart, msg):
     try:
@@ -111,7 +112,82 @@
 		elif (com.ct() == 6):
 		    pass
 		elif (com.ct() == 7):
-		    pass
+                    def hasMail(midIdx,l):
+                        if(nymUser.mbox.has_key(l[midIdx])):
+                            True
+                        else:
+                            False
+                            
+                    synCnt=0
+                    inter=[]
+		    midList=nymUser.midAfter(com.after)
+                    #TODO take a lock, or wait
+                    nymUser.load_index()
+                    nymUser.load_synbox()
+                    nymUser.load_mbox()
+                    #remove already sent synopsis mid
+                    for m in midList:
+                        if(index[m]['sent'] in ['synopsis','full']):
+                            midList.remove(m)
+                    #we just need the com.num first
+                    midList=midList[:com.num]
+                    
+                    #create a list of blobs containing the mid in midlist
+                    clearList=[]
+                    sendList=[]
+                    #as long as midList isn't empty
+                    while(midList):
+                        #look for the synblob containing midList[0]
+                        for i, (ml, status, synblob) in enumerate(nymUser.syn):
+                            if(midList[0] in ml):
+                                #found
+                                if(status == 'clear'):
+                                    if(clearList == []):
+                                        bInf=i
+                                    clearList.append((ml[0],synblob))
+                                    if(len(clearList) == 16):
+                                        nymUser.syn[bInf:i+1]=[Mail.blobify(clearList)]
+                                        clearList=[]
+                                        (m,s,sy) = nymUser.syn[bInf]
+                                        def test(midx):
+                                            hasMail(midx,m)
+                                        sendList.append(Mail.bf(filter(test,range(len(m)))),sy)
+                                    else:
+                                        bSup=i+1
+                                elif(status == 'encrypted'):
+                                    if(clearList != []):
+                                        nymUser.syn[bInf:bSup]=[Mail.blobify(clearList)] 
+                                        clearList=[]
+                                        (m,s,sy) = nymUser.syn[bInf]
+                                        def test(midx):
+                                            hasMail(midx,m)
+                                        sendList.append(Mail.bf(filter(test,range(len(m)))),sy)
+                                    idxList=[ml.index(midList[0])]
+                                    try:
+                                        j=0
+                                        while(True):
+                                            j=j+1
+                                            idxList.append(ml.index(midList[j]))
+                                            del(midList[j])
+                                    except ValueError:
+                                        pass
+                                    def test(midx):
+                                        hasMail(midx,ml)
+                                    sendList.append(Mail.bf(filter(test,idxList)),synblob)
+                                else:
+                                    #this should not happen
+                                    raise 'Bug'
+                                del(midList[0])
+                            else:
+                                #this should not happen
+                                raise 'Bug'
+                    #if clearList isn't empty
+                    if(clearList != []):
+                        #this should be ok if we have proper locks
+                        nymUser.syn[bInf:bSup]=[Mail.blobify(clearList)] 
+                        (m,s,sy) = nymUser.syn[bInf]
+                        sendList.append(Mail.bf(range(len(m))),sy)
+                    #send what is in sendList (list of BF,enc syn)        
 		elif (com.ct() == 8):
 		    if(com.opt in Common.userPolicy):
 			nymUser.data[com.opt] = com.val

Modified: trunk/User.py
===================================================================
--- trunk/User.py	2004-08-02 21:22:40 UTC (rev 63)
+++ trunk/User.py	2004-08-04 12:02:31 UTC (rev 64)
@@ -47,13 +47,22 @@
 	raise "Not Found"
 
     def midAfter(self, mid):
-	"""Retrieve mids of messages that came after message `mid'"""
+	"""Retrieve mids of messages that came after message `mid'
+        the elements of the output are ordered by ascending
+        order of arrival time"""
+        def aux(l,msg):
+            for i, e in enumerate(l):
+                if(self.index[msg][time] < self.index[e][time]):
+                    l.insert(i,msg)
+                    return l
+            l.append(msg)
+        
 	self.load_index()
 	midtime = self.index[mid][time]
 
 	ret = []
 	for msg in self.index.keys():
-	    if self.index[msg][time] >= midtime: ret.append(msg)
+	    if self.index[msg][time] >= midtime: aux(ret,msg)
 	return ret
     
     def save_data(self):