[Checkins] SVN: lovely.mail/trunk/ attachment fix

Bernd Dorn bernd.dorn at lovelysystems.com
Thu Aug 6 04:18:16 EDT 2009


Log message for revision 102503:
  attachment fix

Changed:
  _U  lovely.mail/trunk/
  U   lovely.mail/trunk/CHANGES.txt
  U   lovely.mail/trunk/buildout.cfg
  U   lovely.mail/trunk/src/lovely/mail/README.txt
  U   lovely.mail/trunk/src/lovely/mail/__init__.py

-=-

Property changes on: lovely.mail/trunk
___________________________________________________________________
Added: svn:ignore
   + bin
build
dist
develop-eggs
eggs
parts
.installed.cfg


Modified: lovely.mail/trunk/CHANGES.txt
===================================================================
--- lovely.mail/trunk/CHANGES.txt	2009-08-06 07:48:07 UTC (rev 102502)
+++ lovely.mail/trunk/CHANGES.txt	2009-08-06 08:18:15 UTC (rev 102503)
@@ -5,6 +5,8 @@
 After
 =====
 
+ - handle attachments according to their type
+
 2009/07/30 0.3.0
 ================
 

Modified: lovely.mail/trunk/buildout.cfg
===================================================================
--- lovely.mail/trunk/buildout.cfg	2009-08-06 07:48:07 UTC (rev 102502)
+++ lovely.mail/trunk/buildout.cfg	2009-08-06 08:18:15 UTC (rev 102503)
@@ -5,6 +5,7 @@
 
 [test]
 recipe = zc.recipe.testrunner
+defaults = ['--auto-color']
 eggs = lovely.mail [test]
 
 

Modified: lovely.mail/trunk/src/lovely/mail/README.txt
===================================================================
--- lovely.mail/trunk/src/lovely/mail/README.txt	2009-08-06 07:48:07 UTC (rev 102502)
+++ lovely.mail/trunk/src/lovely/mail/README.txt	2009-08-06 08:18:15 UTC (rev 102503)
@@ -1,5 +1,6 @@
-Lovely.Mail and Mail Testing
-============================
+==============================
+ Lovely.Mail and Mail Testing
+==============================
 
 This package mainly provides a simple way to test the mail delivery using the
 current configuration. There is no need to change the mailing configuration
@@ -117,9 +118,10 @@
    'Content-Transfer-Encoding: base64',
    'Content-Disposition: attachment; filename="f1.txt"',
    '',
-   'SSBhbSB0aGUgY29udGVudCBvZiBmaWxlIDE=',
+   'SS...',
    '--===============...==--']
 
+
   >>> f1.seek(0)
   >>> sendmail('subject', ('ich', 'me at gmail.org'), [('du','you at gmail.org',)],
   ...          'my mail body', attachments=[(f1, 'f1.txt', ('text','plain'))])
@@ -145,12 +147,12 @@
    '',
    'my mail body',
    '--===============...==',
-   'Content-Type: text/plain',
+   'Content-Type: text/plain; charset="us-ascii"',
    'MIME-Version: 1.0',
-   'Content-Transfer-Encoding: base64',
+   'Content-Transfer-Encoding: 7bit',
    'Content-Disposition: attachment; filename="f1.txt"',
    '',
-   'SSBhbSB0aGUgY29udGVudCBvZiBmaWxlIDE=',
+   'I am the content of file 1',
    '--===============...==--']
 
 And clean up.

Modified: lovely.mail/trunk/src/lovely/mail/__init__.py
===================================================================
--- lovely.mail/trunk/src/lovely/mail/__init__.py	2009-08-06 07:48:07 UTC (rev 102502)
+++ lovely.mail/trunk/src/lovely/mail/__init__.py	2009-08-06 08:18:15 UTC (rev 102503)
@@ -19,7 +19,8 @@
 from zope import component
 
 from zope.sendmail.interfaces import IMailDelivery
-
+from email.mime.audio import MIMEAudio
+from email.mime.image import MIMEImage
 from email.MIMEText import MIMEText
 from email.MIMEMultipart import MIMEMultipart
 from email.MIMEBase import MIMEBase
@@ -53,12 +54,23 @@
         message['Reply-To'] = replyTo
     message['To'] = ', '.join(recipients)
     message['Date'] = datetime.now().strftime('%a, %d %b %Y %H:%M:%S +0000')
+
+
     for f, name, mimetype in attachments:
         if mimetype is None:
             mimetype = ('application', 'octet-stream')
-        part = MIMEBase(*mimetype)
-        part.set_payload( f.read() )
-        Encoders.encode_base64(part)
+        maintype, subtype = mimetype
+        if maintype == 'text':
+            # XXX: encoding?
+            part = MIMEText(f.read(), _subtype=subtype)
+        elif maintype == 'image':
+            part = MIMEImage(f.read(), _subtype=subtype)
+        elif maintype == 'audio':
+            part = MIMEAudio(f.read(), _subtype=subtype)
+        else:
+            part = MIMEBase(maintype, subtype)
+            part.set_payload(f.read())
+            Encoders.encode_base64(part)
         part.add_header('Content-Disposition', 'attachment; filename="%s"' % name)
         message.attach(part)
     mailer = component.getUtility(IMailDelivery, name='lovely-mail-delivery')



More information about the Checkins mailing list