[Nym3-commit] r475 - trunk/nymbaron

laurent at conuropsis.org laurent at conuropsis.org
Mon Mar 13 23:04:07 CET 2006


Author: laurent
Date: 2006-03-13 23:04:07 +0100 (Mon, 13 Mar 2006)
New Revision: 475

Modified:
   trunk/nymbaron/Mail.py
Log:
Rewrite the relay commands to do what's intended.


Modified: trunk/nymbaron/Mail.py
===================================================================
--- trunk/nymbaron/Mail.py	2006-03-13 22:02:44 UTC (rev 474)
+++ trunk/nymbaron/Mail.py	2006-03-13 22:04:07 UTC (rev 475)
@@ -37,7 +37,7 @@
 import string
 import sys
 import tempfile
-from email.MIMEText import MIMEText
+import email
 
 slen = 128
 """The length of a summary in bytes"""
@@ -50,8 +50,8 @@
 oldestMid = chr(0) * midLen
 """Special value of a mid, older than any othany other mid"""
 
-forbidden_headers = ['from', 'received', 'sender', 'reply-to', 'return-path',
-                    'user-agent']
+forbidden_headers = ['From', 'Received', 'Sender', 'Reply-to', 'Return-Path',
+                    'User-Agent']
 """The list of headers that are removed from a message before it is relayed"""
 #TODO complete this list, how do we process msgid? remove and add another one?
 
@@ -163,55 +163,39 @@
     return hex(q)[2:] + hex(r)[2:]
 
 def filter_header(msg):
-    par = email.Parser.HeaderParser() 
-    message = par.parsestr(msg)
     for h in forbidden_headers:
-        if message.has_key(h):
-            del message[h]
-    return message.as_string()
+        if msg.has_key(h):
+            del msg[h]
 
-def relay(nym, rt, ri, sname, body):
-    #TODO: This function is unused at this time and can probably be removed
-    """relay the e-mail in body according to the routing type rt
-    and the routing info ri for the nymholder of nym"""
-    body = filter_header(body)
-    b = 'From: ' + nym + '@' + sname + "\n\n" + body
-    fname = tmpFileMsg(b) #TODO we can avoid the tempfile with some fd manipultation : exec mixminion, write b in its stdin
-    mixcmd = "mixminion send -t 0x" + b2s(rt[0]) + b2s(rt[1]) + ":" + ri + " -i " + fname
-    print mixcmd
-    ec = os.system(mixcmd)
-    # TODO : debugging cruft
-    #os.unlink(fname)
-    print "Raw relayed message left in " + fname
-    return ec
-
 def relay_prep(nym, you, sname, body, abuse):
     """Format a message as a single string that can be passed
-    to various rfc822 compliant email routines"""
+    to various rfc822 compliant email routines. body is actually
+    an whole message formatted as per E2E-spec, which is kind of
+    a castrated RFC822."""
 
+    msg = email.message_from_string(body)
+    filter_header(msg)
     # Make a From header and include the nymholder as a real_name.
-    fromhdr = '%s <%s@%s>' % (nym,nym,sname)
-
-    msg = MIMEText(body)
+    fromhdr = '%s <%s@%s>' % (nym, nym, sname)
     msg['From'] = fromhdr
     msg['To'] = you
-    # TODO Headers such as Subject,  References etc. need to be read from
-    # either config or from the incoming relay message.
-    msg['Subject'] = 'Type-III Pseudonym Message'
     if abuse:
         msg['X-Abuse-Contact'] = abuse
+    # TODO : Reconstruct MIME message because separators
+    # reduce the anonymity set. It could also be the nymop
+    # policy to filter them out.
     return msg.as_string()
 
-def relay_smtp(nym, you, sname, payload, timeout, smtphost):
+def relay_smtp(nym, rcpt, sname, payload, timeout, smtphost):
     """ Relay an email message through Python's internal
     smtplib library."""
     socket.setdefaulttimeout(timeout)
-    me = nym + '@' + sname
+    from_addr = nym + '@' + sname
     # Send the message to the designated smtp server
     # TODO Need some error handling when logging gets enabled
     mailserver = smtplib.SMTP(smtphost)
     #mailserver.set_debuglevel(1)
-    mailserver.sendmail(me, [you], payload)
+    mailserver.sendmail(from_addr, [rcpt], payload)
     mailserver.quit()
 
 def relay_sendmail(payload, sm):



More information about the Nym3-commit mailing list