[Nym3-commit] r145 - in trunk/nym3: . Client

laurent at komite.net laurent at komite.net
Tue Dec 28 22:45:18 CET 2004


Author: laurent
Date: 2004-12-28 22:45:16 +0100 (Tue, 28 Dec 2004)
New Revision: 145

Modified:
   trunk/nym3/Client/testcurses.py
   trunk/nym3/Mail.py
Log:
Add small test vector for synbox_tab.


Modified: trunk/nym3/Client/testcurses.py
===================================================================
--- trunk/nym3/Client/testcurses.py	2004-12-28 20:45:43 UTC (rev 144)
+++ trunk/nym3/Client/testcurses.py	2004-12-28 21:45:16 UTC (rev 145)
@@ -1,6 +1,7 @@
 import curses
 import curses.wrapper
 import curses.ascii
+import re
 
 month  = ["Jan", "Fev", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
               "Oct", "Nov", "Dec"]
@@ -20,6 +21,14 @@
     "Abus de notation."
     ]
 
+syn1 = { 'mid': '2' * 20, 'read_status': 'unread',
+	 'fetch_status': None, 'synopsis':
+	 "From: Laurent\nDate:Tue, 28 Dec 2004 22:41:53 +0100\nSubject: 42" }
+
+syn2 = { 'mid': '3' * 20, 'read_status': 'read',
+	 'fetch_status': 'delete', 'synopsis':
+	 "From: Marsux\nDate:Tue, 28 Dec 2004 22:42:17 +0100\nSubject: Mu?" }
+
 class Tab:
     """the table used to get lines displayed in a scrolling window"""
     def size(self):
@@ -54,7 +63,7 @@
 			    for this message was already sent."""
     
     def __init__(self):
-	self.synlist = [];
+	self.synlist = [syn1, syn2] # TODO: testing only
 	pass
 
     def view(self, i):
@@ -79,9 +88,22 @@
 	# and take the flags into account to.
 	assert(i < len(self.synlist))
 	syn = self.synlist[i]
-	sfrom, sdate, subject = self.extract(syn)
+	sfrom, sdate, subject = self.extract(syn, 'From', 'Date', 'Subject')
 	return "%s %s %s" % (sdate, sfrom, subject)
 
+    def extract(self, syn, *h):
+	"""Get most important header of a mail"""
+	#TODO: this is not RFC2822-compliant
+	a = re.search("""\n\n""", syn['synopsis'])
+	if a: headers = syn['synopsis'][:a.start(0)]
+	else: headers = syn['synopsis']
+	ret = []
+	for i in h:
+	    a = re.search('^' + i + ':(.*)$', headers, re.M)
+	    if a: ret.append(a.group(1))
+	    else: ret.append('')
+	return tuple(ret)
+    
     def fetch(self, l):
 	"""Schedule every entry listed in l for retrieval"""
 	for i in l:
@@ -94,7 +116,17 @@
     
     def process_pending(self):
 	"""Gather pending control commands to the server"""
-	pass
+	delete_list = []
+	fetch_list = []
+	ret = ""
+	for i in self.synlist:
+	    if i['fetch_status'] == 'delete': delete_list.append(i['mid'])
+	    if i['fetch_status'] == 'fetch': fetch_list.append(i['mid'])
+	getC = Message.Get()
+	getC.fromData(fetch_list)
+	deleteC = Message.Delete()
+	deleteC.fromData(delete_list)
+	return str(getC) + str(deleteC)
 
 class Screen_ctx:
     """ this class holds all the information relative to the content and the
@@ -217,7 +249,7 @@
     curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_CYAN)
     #status bar
     curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLUE)
-    ctx = Screen_ctx(stdscr, Ex_tab())
+    ctx = Screen_ctx(stdscr, Synbox_tab())
     ctx.execute()
 
 curses.wrapper(func)

Modified: trunk/nym3/Mail.py
===================================================================
--- trunk/nym3/Mail.py	2004-12-28 20:45:43 UTC (rev 144)
+++ trunk/nym3/Mail.py	2004-12-28 21:45:16 UTC (rev 145)
@@ -26,6 +26,7 @@
 def synopsize(msg):
     """Synopsizes a message : keeps a set of headers and the beginning of
     the body of the mail"""
+    #TODO: this is not RFC2822-compliant
     vheaders = [ 'Cc', 'From', 'Date', 'In-Reply-To', 'Sender',
 		 'Message-Id', 'References', 'Return-Path', 'Subject',
 		 'To', 'X-Anonymous', 'X-Spam-Level']



More information about the Nym3-commit mailing list