[Nym3-commit] r60 - trunk

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Mon, 02 Aug 2004 22:14:24 +0200


Author: laurent
Date: 2004-08-02 22:14:23 +0200 (Mon, 02 Aug 2004)
New Revision: 60

Modified:
   trunk/Main.py
   trunk/User.py
Log:
Factor code, better synopsis storage.


Modified: trunk/Main.py
===================================================================
--- trunk/Main.py	2004-08-02 15:53:27 UTC (rev 59)
+++ trunk/Main.py	2004-08-02 20:14:23 UTC (rev 60)
@@ -7,7 +7,6 @@
 import Config
 import Message
 import Common
-import Crypto
 
 def processIncoming(localpart, msg):
     try:

Modified: trunk/User.py
===================================================================
--- trunk/User.py	2004-08-02 15:53:27 UTC (rev 59)
+++ trunk/User.py	2004-08-02 20:14:23 UTC (rev 60)
@@ -36,8 +36,15 @@
 
     def encKey(self):
         return self.data['encKey']
+
+    def getSynList(self, l):
+	"""Retrieve a blurb consisting of the synopsis of the
+	   requested synopsis mid. May contain unwanted synopsis
+	   too."""
+	index = Config.path + os.sep + self.data['username'] + '.idx'
+
     
-    def save(self):
+    def save_data(self):
 	f = open(self.datafile, 'w') # TODO : Locks?
 	pickle.dump(self.data, f)
 	f.close()
@@ -97,10 +104,8 @@
         f = open(fname, "w") #TODO check that this truncate the file (the file must be empty after that
         f.close()
         self.data['nSurbs'] = 0
-        
-    def store(self, msg):
-	"Store an incoming message"
-	syn = Mail.synopsize(msg)
+
+    def load_mbox(self):
 	mbox = Config.path + os.sep + self.data['username'] + '.mbox'
 	try:
 	    f = open(mbox, 'r') # TODO : Locks?
@@ -108,13 +113,14 @@
 	    f.close()
 	except IOError:
 	    self.mbox = {}
-	mid = Mail.genMid()
-	while self.mbox.has_key(mid): mid = Mail.genMid()
-	self.mbox[mid] = msg # TODO : this is where we're supposed to crypt.
+
+    def save_mbox(self):
+	mbox = Config.path + os.sep + self.data['username'] + '.mbox'
 	f = open(mbox, 'w') # TODO : Locks?
 	pickle.dump(self.mbox, f)
 	f.close()
-
+	
+    def load_synbox(self):
 	synbox = Config.path + os.sep + self.data['username'] + '.syn'
 	try:
 	    f = open(synbox, 'r') # TODO : Locks?
@@ -122,12 +128,48 @@
 	    f.close()
 	except IOError:
 	    self.syn = []
-	self.syn.append({'time' : int(time.time()), 'encrypted' : 0,
-			 'mid' : mid, 'synopsis' : syn})
+
+    def save_synbox(self):
+	synbox = Config.path + os.sep + self.data['username'] + '.syn'
 	f = open(synbox, 'w') # TODO : Locks?
 	pickle.dump(self.syn, f)
 	f.close()
+    
+    def load_index(self):
+	index = Config.path + os.sep + self.data['username'] + '.idx'
+	try:
+	    f = open(index, 'r') # TODO : Locks?
+	    self.index = pickle.load(f)
+	    f.close()
+	except IOError:
+	    self.index = {}
+    
+    def save_index(self):
+	index = Config.path + os.sep + self.data['username'] + '.idx'
+	f = open(index, 'w') # TODO : Locks?
+	pickle.dump(self.index, f)
+	f.close()
+        
+    def store(self, msg):
+	"Store an incoming message"
+	syn = Mail.synopsize(msg)
+	# Store the mail.
+	self.load_mbox()
+	mid = Mail.genMid()
+	while self.mbox.has_key(mid): mid = Mail.genMid()
+	self.mbox[mid] = msg # TODO : this is where we're supposed to crypt.
+	self.save_mbox()
 
+	# store the synopsis
+	self.load_synbox()
+	self.syn.append([[mid], 'clear', syn])
+	self.save_synbox()
+
+	# create an index entry for the synopsis
+	self.load_index()
+	self.index[mid] = {'time' : int(time.time()), 'sent' : 'nothing' }
+	self.save_index()
+
     def setKeys(self,kid,kenc):
 	self.data['idKey']=kid
 	self.data['encKey']=kenc