[Checkins] SVN: zc.fauxmailer/branches/dev/s support encoded headers and multipart messages. Tests would probably be a good idea soon. :-/

Gary Poster gary at zope.com
Thu Jun 26 16:47:14 EDT 2008


Log message for revision 87814:
  support encoded headers and multipart messages. Tests would probably be a good idea soon. :-/

Changed:
  U   zc.fauxmailer/branches/dev/setup.py
  U   zc.fauxmailer/branches/dev/src/zc/fauxmailer/__init__.py

-=-
Modified: zc.fauxmailer/branches/dev/setup.py
===================================================================
--- zc.fauxmailer/branches/dev/setup.py	2008-06-26 20:01:28 UTC (rev 87813)
+++ zc.fauxmailer/branches/dev/setup.py	2008-06-26 20:47:10 UTC (rev 87814)
@@ -3,7 +3,7 @@
 setup(
     name = "zc.fauxmailer",
     description = "Simple printing mailer for development",
-    version = "1.1",
+    version = "1.2",
     license = "ZPL",
     packages = find_packages('src'),
     include_package_data = True,

Modified: zc.fauxmailer/branches/dev/src/zc/fauxmailer/__init__.py
===================================================================
--- zc.fauxmailer/branches/dev/src/zc/fauxmailer/__init__.py	2008-06-26 20:01:28 UTC (rev 87813)
+++ zc.fauxmailer/branches/dev/src/zc/fauxmailer/__init__.py	2008-06-26 20:47:10 UTC (rev 87814)
@@ -15,6 +15,7 @@
 """
 
 import email
+import email.Header
 import sys
 
 import zope.interface
@@ -26,14 +27,34 @@
 
     def send(self, fromaddr, toaddrs, message_string):
         message = email.message_from_string(message_string)
-        print  '='*70
+        print '='*70
         print 'From', fromaddr
-        print  'To', toaddrs
-        print  '-'*70
+        print 'To', toaddrs
+        print '-'*70
         for h in message.keys():
             for v in message.get_all(h):
-                print  "%s: %s" % (h, v)
-            
-        print  message.get_payload(decode=True)
-        print  '='*70
+                # we want to decode encoded headers, showing the encoding.
+                # we also want to simplify the display, both for backwards
+                # compatibility and for ease of reading in tests
+                decoded = []
+                raw = email.Header.decode_header(v)
+                if isinstance(raw, tuple):
+                    raw = [raw]
+                for info in raw:
+                    if info[1] is None:
+                        decoded.append(info[0])
+                    else:
+                        decoded.append(info)
+                if len(decoded) == 1:
+                    decoded = decoded[0]
+                print "%s: %s" % (h, decoded)
+        if message.is_multipart():
+            # show each part
+            for m in message.get_payload():
+                print '.'*70
+                print 'Content-Type:', m.get_content_type()
+                print m.get_payload(decode=True)
+        else:
+            print message.get_payload(decode=True)
+        print '='*70
         sys.stdout.flush()



More information about the Checkins mailing list