[Nym3-commit] r479 - trunk/nymbaron

zax at conuropsis.org zax at conuropsis.org
Thu Mar 16 14:12:53 CET 2006


Author: zax
Date: 2006-03-16 14:12:52 +0100 (Thu, 16 Mar 2006)
New Revision: 479

Modified:
   trunk/nymbaron/Mail.py
Log:
Introduce MIME handling to relay_prep.  This anonymises potential variations
in client MIME implementations.  At this time, header processing is minimal.


Modified: trunk/nymbaron/Mail.py
===================================================================
--- trunk/nymbaron/Mail.py	2006-03-15 21:28:37 UTC (rev 478)
+++ trunk/nymbaron/Mail.py	2006-03-16 13:12:52 UTC (rev 479)
@@ -171,9 +171,59 @@
     to various rfc822 compliant email routines. body is actually
     an whole message formatted as per E2E-spec, which is kind of
     a castrated RFC822."""
+    # Make a From header and include the nymholder as a real_name.
+    fromhdr = '%s <%s@%s>' % (nym, nym, sname)
+    mainMsg=email.Message.Message()
+    mainMsg["To"] = you
+    mainMsg["From"] = fromhdr
+    if abuse:
+        mainMsg['X-Abuse-Contact'] = abuse
+    # Create a Date header using UTC
+    mainMsg["Date"]=email.Utils.formatdate(localtime=0)
+    # Do we want to generate a Message-ID, or let the MTA handle it?
+    #mainMsg["Message-ID"]=email.Utils.make_msgid()
 
     msg = email.message_from_string(body)
     filter_header(msg)
+    if msg.is_multipart():
+        mainMsg["Mime-version"]="1.0"
+        mainMsg["Content-type"]="Multipart/mixed"
+        mainMsg.preamble="This is a multipart message in MIME format\n"
+        mainMsg.epilogue="" # To ensure that message ends with newline
+        for part in msg.walk():
+            subMsg=email.Message.Message()
+            if part.get_main_type() == "multipart":
+                continue
+            type = part.get_content_type()
+            name = part.get_param("name")
+            desc = part.get('Content-Description')
+            dispos = part.get('Content-Disposition')
+            payload = part.get_payload(decode=1)
+            if type:
+                subMsg["Content-type"] = type
+            if name:
+                subMsg.set_param("name",name)
+            if desc:
+                subMsg.add_header("Content-Description",desc)
+            if dispos:
+                subMsg.add_header("Content-Disposition",dispos)
+            subMsg.set_payload(payload)
+            mainMsg.attach(subMsg)
+    else:
+        payload = msg.get_payload(decode=1)
+        mainMsg.set_payload(payload)
+    return mainMsg.as_string()
+
+def old_relay_prep(nym, you, sname, body, abuse):
+#TODO: This function can be removed once we are happy with relay_prep
+#      which handles repacking of MIME messages
+    """Format a message as a single string that can be passed
+    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['From'] = fromhdr



More information about the Nym3-commit mailing list