[Nym3-commit] r89 - trunk

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Thu, 05 Aug 2004 14:22:19 +0200


Author: jr
Date: 2004-08-05 14:22:17 +0200 (Thu, 05 Aug 2004)
New Revision: 89

Modified:
   trunk/Main.py
   trunk/Message.py
   trunk/User.py
Log:
- add the processing of GET and DELETE in processMessage (Main.py)
- add some accessors getMail, hasMail(User.py)
- correct some bugs : [time] -> ['time'], nymUser -> self(User.py)
- getSyn raise ValueError if the mid can't be found(User.py)


Modified: trunk/Main.py
===================================================================
--- trunk/Main.py	2004-08-05 11:07:36 UTC (rev 88)
+++ trunk/Main.py	2004-08-05 12:22:17 UTC (rev 89)
@@ -30,6 +30,8 @@
     - verifies signature
     - parse the message into header + sequence on control commands
     - run appropriate actions"""
+    #TODO prendre le numero de sequence pour pouvoir l'aquitter
+    
     def MyException(Exception): pass
     
     sr = Message.StrReader(msg)
@@ -122,16 +124,32 @@
                     elif (com.ct() == 4):
                         pass
                     elif (com.ct() == 5):
-                        pass
+                        msgList = []
+                        for m in com.l:
+                            if nymUser.hasMail(m):
+                                msgCom = Msg()
+                                msgCom.fromData(m,nymUser.getMail(m))
+                                msgList.append(msgCom)
+                        ec = nymUser.sendMessage(Message.buildMessage(msgList))
+                        if (ec == 0):
+                            #TODO acquitte le message
+                            nymUser.markMid(com.l)
+                        else:
+                            print "mixminion exited abnormally with error code %d" % ec
+                            sys.exit(2)
+                        
+                                
+                                
                     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'
                     elif (com.ct() == 7):
-                        for mid in com.l: pass
+                        for mid in com.l:
+                            nymUser.delete_msg(mid)
                     elif (com.ct() == 8):
                         if(com.opt in Common.userPolicy):
-                            nymUser.data[com.opt] = com.val
+                            nymUser[com.opt] = com.val
                     else:
                         pass
     except Message.ParseError, inst:

Modified: trunk/Message.py
===================================================================
--- trunk/Message.py	2004-08-05 11:07:36 UTC (rev 88)
+++ trunk/Message.py	2004-08-05 12:22:17 UTC (rev 89)
@@ -757,7 +757,7 @@
 		"""Build a empty Msg object"""
 		pass
 	def fromData(self,mid,msg):
-		"""Fill a Msg Object from a Mid (str onf length midLength) and an encrypted msg (str)"""
+		"""Fill a Msg Object from a Mid (str of length midLength) and an encrypted msg (str)"""
 		if(len(mid) != midLength):
 			raise BadArgument("Msg.fromData : mid has not the good length")
 		if(midLength + len(msg) >= pow(256,3)):

Modified: trunk/User.py
===================================================================
--- trunk/User.py	2004-08-05 11:07:36 UTC (rev 88)
+++ trunk/User.py	2004-08-05 12:22:17 UTC (rev 89)
@@ -77,7 +77,7 @@
             self._abort = True
 
     def timecmp(self, a, b):
-        return cmp(self.index[a][time], self.index[b][time])
+        return cmp(self.index[a]['time'], self.index[b]['time'])
 
     def quota(self):
 	return self.data['quota']
@@ -123,20 +123,29 @@
 	self.load_synbox()
 	for i, (midlist, status, synblob) in enumerate(self.syn):
 	    if mid in midlist: return i, (midlist, status, synblob)
-	raise "Not Found"
+	raise ValueError()
 
+    def getMail(self, mid):
+        """Retrieve an encrypted mail from the mbox
+        raise ValueError if the mail cannot be found"""
+        self.load_mbox()
+        try:
+            return self.mbox[mid]
+        except:
+            raise ValueError()
+        
     def midAfter(self, mid):
 	"""Retrieve mids of messages that came after message `mid'
         the elements of the output are ordered by ascending
         order of arrival time"""
 	self.load_index()
-	midtime = self.index[mid][time]
+	midtime = self.index[mid]['time']
 
 	ret = []
 	if mid == oldestMid: ret = self.index.keys()
 	else:
 	    for msg in self.index.keys():
-		if self.index[msg][time] >= midtime: ret.append(msg)
+		if self.index[msg]['time'] >= midtime: ret.append(msg)
 	ret.sort(self.timecmp)
 	return ret
     
@@ -149,7 +158,7 @@
     def surbfile(self):
 	return Config.path + os.sep + self.data['username'] + '.surbs'
 
-    def relay(self, msg):
+    def send(self, msg):
 	fname = '/tmp/' + Mail.mid2filename(Mail.genMid())
 	# TODO : chose a temp file.
 	fname = string.strip(fname)
@@ -331,26 +340,32 @@
         self.load_synbox()
         self.syn[i:j]=[self.blobify(syn[i:j])]
 
+    def hasMail(self,mid):
+        self.load_index()
+        try:
+            return self.idx[mid]['status'] != 'deleted' 
+        except:
+            return False
+        
     def sendList(self, num, after):
         """returns a list of (bf, synblob)
         in the process of creating it ca modify the synbox,
         doing some encryption"""
-        def hasMail(midIdx, l):
+        def lhasMail(midIdx, l):
             return self.mbox.has_key(l[midIdx])
         def addBlob(slist, mlist, ilist, blob):
             """append to slist (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):
-                hasMail(midx, mlist)
-            slist.append(Mail.bf(filter(test, ilist)), sy)
-	    # WTF IS sy ?? TODO.
+                lhasMail(midx, mlist)
+            slist.append(Mail.bf(filter(test, ilist)), blob)
         #the list of the mid after "after"
-        midList = nymUser.midAfter(after)
+        midList = self.midAfter(after)
         #load the structures
-        self._load_index()
-        self._load_synbox()
-        self._load_mbox()
+        self.load_index()
+        self.load_synbox()
+        self.load_mbox()
         #we just need the num first
         midList = midList[:num]
                     
@@ -407,7 +422,7 @@
         #if clearList isn't empty
         if (not clearListEmpty):
             self.encryptSyn(bInf, bSup) 
-            (m, _, sy) = nymUser.syn[bInf]
+            (m, _, sy) = self.syn[bInf]
             addBlob(sendList, m, range(len(m)), sy)
         return sendList