← Back to team overview

credativ team mailing list archive

[Bug 909913] Re: smtpclient attachment mimetype hardcoded

 

This works, and is backwards compatible:

=== modified file 'smtpclient/smtpclient.py'
--- smtpclient/smtpclient.py	2010-07-06 05:41:03 +0000
+++ smtpclient/smtpclient.py	2011-12-30 00:33:14 +0000
@@ -434,7 +434,13 @@
             
             #attach files from disc
             for file in attachments:
-                part = MIMEBase('application', "octet-stream")
+                maintype = 'application'
+                subtype = 'octet-stream'
+                if isinstance(file, dict):
+                    maintype = file.get('maintype', 'application')
+                    subtype = file.get('subtype', 'octet-stream')
+                    file = file.get('filename')
+                part = MIMEBase(maintype, subtype)
                 part.set_payload(open(file,"rb").read())
                 Encoders.encode_base64(part)
                 part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(file))

And, to be fair to Thunderbird, the latest version can open the octet-
streams. Deleting mimeTypes.rdf may have helped there.

-- 
You received this bug notification because you are a member of OpenERP
Framework Experts, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/909913

Title:
  smtpclient attachment mimetype hardcoded

Status in OpenERP Addons (modules):
  New

Bug description:
  OpenERP 6.0.3 on Ubuntu 10.04
  I am using smtpclient to send emails  with attached pdf reports generated by jasper_reports. The plan is to automatically send these reports by use of the scheduler. I successfully receive the emails with attached report but I cannot open the pdf in Thunderbird because the mimetype is set to application/octet-stream. This is hardcoded in smtpclient.
  The octet-stream opening problem is a well-known and long-standing 'feature' of Thunderbird, I don't know if other MUAs suffer from it too but ultimately the fault lies with the generating program as (I believe) the email RFCs require the mimetype to properly describe the attachment.
  At present you just pass a list of filenames as the attachment parameter to send_email(). I think it should be changed to allow a list of dicts something like this: [{'filename': '/tmp/file', 'maintype':'application', 'subtype': 'pdf'}, {...}] with application/octet-stream as the fallback.

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/909913/+subscriptions


References