[Nym3-commit] r94 - in trunk: . doc

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Thu, 05 Aug 2004 17:35:37 +0200


Author: jr
Date: 2004-08-05 17:35:34 +0200 (Thu, 05 Aug 2004)
New Revision: 94

Modified:
   trunk/Config.py
   trunk/Mail.py
   trunk/Main.py
   trunk/doc/nym-spec.txt
Log:
- correct some incoherence (doc/nym-spec.txt)
- add the server name (Config.py)
- add the RELAY function (Main.py and Mail.py)


Modified: trunk/Config.py
===================================================================
--- trunk/Config.py	2004-08-05 14:16:56 UTC (rev 93)
+++ trunk/Config.py	2004-08-05 15:35:34 UTC (rev 94)
@@ -1,6 +1,8 @@
 # $Id$
 
 #path = '/var/lib/nym3'
+serverName = 'nymserv.komite.net'
+
 path = '.'
 
 default_settings = { 'quota' : 10 * 2**20, 'usage' : 0,

Modified: trunk/Mail.py
===================================================================
--- trunk/Mail.py	2004-08-05 14:16:56 UTC (rev 93)
+++ trunk/Mail.py	2004-08-05 15:35:34 UTC (rev 94)
@@ -5,6 +5,7 @@
 import base64
 import string
 import Common
+import Config
 
 slen = 180
 midLen = Common.midLength
@@ -31,6 +32,23 @@
 	
     return res + 'X-Octets: ' + repr(len(msg)) + "\n" + body
 
+def tmpFileMsg(body):
+    """write body in a temp file name and return the name of that file
+    """
+    while True:
+        try:
+            fname = '/tmp/' + Mail.mid2filename(Mail.genMid())
+            fname = string.strip(fname)
+            f = open(fname, 'w') #change w so that it creates the file if it does not exist an raise an error otherwise
+            f.write(body)
+            f.close()
+            break
+        except:
+            pass
+    return fname
+	
+    
+
 def bf(l):
     """take a list of index and generate a bitfield
     the k-bit is set to 1 if k is in l
@@ -42,6 +60,21 @@
         t[q] = t[q] | (1 << r)
     return chr(t[0])+chr(t[1])
 
+def b2s(c):
+    """return a string of length 2 representing the byte c in hex"""
+    i = ord(c)
+    (q, r) = divmod(i, 16)
+    return hex(q)[2:] + hex(r)[2:]
+
+def relay(nym,rt,ri,body):
+    """relay the e-mail in body according to the routing type rt
+    and the routing info ri for the nymholder of nym"""
+    b = 'From: ' + nym + '@' + Config.serverName + "\n" + body
+    fname = tmpFileMsg(b) #TODO we can avoid the tempfile with some fd manipultation : exec mixminion, write b in its stdin
+    ec = os.system("mixminion -t 0x" + b2s(rt[1]) + b2s(rt[0]) + ":" + ri + " -i " + fname)
+    os.unlink(fname)
+    return ec
+                   
 def genMid(length = midLen):
     ret = oldestMid
     while ret == oldestMid:

Modified: trunk/Main.py
===================================================================
--- trunk/Main.py	2004-08-05 14:16:56 UTC (rev 93)
+++ trunk/Main.py	2004-08-05 15:35:34 UTC (rev 94)
@@ -124,7 +124,11 @@
                     elif (com.ct() == 3):
                         nymUser.setKeys(com.kid,com.kenc)
                     elif (com.ct() == 4):
-                        pass
+                        ec = Mail.relay(com.rt,com.ri,com.body)
+                        if (ec != 0):
+                            print "mixminion exited abnormally with error code %d" % ec
+                            sys.exit(2)
+                            
                     elif (com.ct() == 5):
                         msgList = []
                         sendList = []

Modified: trunk/doc/nym-spec.txt
===================================================================
--- trunk/doc/nym-spec.txt	2004-08-05 14:16:56 UTC (rev 93)
+++ trunk/doc/nym-spec.txt	2004-08-05 15:35:34 UTC (rev 94)
@@ -75,7 +75,7 @@
    4.4.1.   CREATED [0x00]
    4.4.2.   STATUS [0x01]
    4.4.3.   SUMMARY [0x02]
-   4.4.4.   MSGS [0x03]
+   4.4.4.   MSG [0x03]
    4.4.5.   DROPPED [0x04]
    4.4.6    ERROR [0x05]
    5.       Filtering and abuse prevention
@@ -593,15 +593,15 @@
    of the size of the immediately following CD field.
 
    The following values for CT are recognized:
-        0x00 : CREATE  (Create a new nym)
-        0x01 : CREATE2 (Confirm a new nym)
-        0x02 : SURB    (Supply the nymserver with new set of SURBs)
-        0x03 : NEWPK   (Set or replace public keys)
-        0x04 : RELAY   (Send an email to a recipient)
-        0x05 : GET     (Retrieve a list of emails)
-        0x06 : SUMMARY (Retrieve a list of synopses)
-        0x07 : DELETE  (Expunge a list of emails from the nymserver)
-        0x08 : POLICY  (Adjust user settings)
+        0x00 : CREATE    (Create a new nym)
+        0x01 : CREATE2   (Confirm a new nym)
+        0x02 : SURB      (Supply the nymserver with new set of SURBs)
+        0x03 : NEWPK     (Set or replace public keys)
+        0x04 : RELAY     (Send an email to a recipient)
+        0x05 : GET       (Retrieve a list of emails)
+        0x06 : SUMMARIZE (Retrieve a list of synopses)
+        0x07 : DELETE    (Expunge a list of emails from the nymserver)
+        0x08 : POLICY    (Adjust user settings)
 
 4.3.1. CREATE [0x00]
 
@@ -765,7 +765,7 @@
         0x00 : CREATED  (Acknowledge a new nym)
         0x01 : STATUS   (Acknowledge messages and describe status)
         0x02 : SUMMARY  (Describe pending emails)
-        0x03 : MSGS     (Send emails to the client)
+        0x03 : MSG     (Send emails to the client)
         0x04 : DROPPED  (Tell the client about dropped emails)
         0x05 : ERROR    (Tell the client about an error condition)