[Erp5-report] r34364 nicolas - /erp5/trunk/products/ERP5/Document/EmailDocument.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Apr 8 11:31:23 CEST 2010


Author: nicolas
Date: Thu Apr  8 11:31:22 2010
New Revision: 34364

URL: http://svn.erp5.org?rev=34364&view=rev
Log:
Return safe html content.
  * call convert and use conversion cache feature.
  * add index parameter in convert just for generate unique cache key per attachment
  * small cosmetics refactoring (sorry).


Modified:
    erp5/trunk/products/ERP5/Document/EmailDocument.py

Modified: erp5/trunk/products/ERP5/Document/EmailDocument.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/EmailDocument.py?rev=34364&r1=34363&r2=34364&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/EmailDocument.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/EmailDocument.py [utf8] Thu Apr  8 11:31:22 2010
@@ -252,8 +252,7 @@
     """
     Returns the decoded data of an attachment.
     """
-    i = 0
-    for part in self._getMessage().walk():
+    for i, part in enumerate(self._getMessage().walk()):
       if index == i:
         # This part should be handled in skin script
         # but it was a bit easier to access items here
@@ -262,11 +261,11 @@
           RESPONSE = REQUEST.RESPONSE
           RESPONSE.setHeader('Accept-Ranges', 'bytes')
           if kw.has_key('Content-Type'):
-            RESPONSE.setHeader('Content-Type', kw['Content-Type'])
             content_type = kw['Content-Type']
+            RESPONSE.setHeader('Content-Type', content_type)
           elif kw.has_key('Content-type'):
-            RESPONSE.setHeader('Content-Type', kw['Content-type'])
             content_type = kw['Content-type']
+            RESPONSE.setHeader('Content-Type', content_type)
           else:
             content_type = None
           if kw.has_key('Content-Disposition'):
@@ -280,12 +279,22 @@
             file_name = re.findall(file_name_regexp, content_type, re.MULTILINE)
           if content_disposition:
             if not file_name:
-              file_name = re.findall(file_name_regexp, content_disposition, re.MULTILINE)
+              file_name = re.findall(file_name_regexp,
+                                     content_disposition,
+                                     re.MULTILINE)
           if file_name:
             file_name = file_name[0]
-            RESPONSE.setHeader('Content-disposition', 'attachment; filename="%s"' % file_name)
-        return part.get_payload(decode=1)
-      i += 1
+            RESPONSE.setHeader('Content-disposition',
+                               'attachment; filename="%s"' % file_name)
+        if 'text/html' in content_type:
+          # Strip out html content in safe mode.
+          mime, content = self.convert(format='html',
+                                       text_content=part.get_payload(decode=1),
+                                       index=index) # add index to generate
+                                       # a unique cache key per attachment
+        else:
+          content = part.get_payload(decode=1)
+        return content
     return KeyError, "No attachment with index %s" % index
 
   # Helper methods which override header property sheet
@@ -448,7 +457,8 @@
         part_encoding = part.get_content_charset()
         part_html = part.get_payload(decode=1)
         # Invoke Document class HTML stripper
-        html_result = self._safeHTML(part_html, charset=part_encoding)
+        html_result = self.convert(format='html', text_content=part_html,
+                                   charset=part_encoding)
     if html_result:
       # Give priority to HTML
       text_result = html_result




More information about the Erp5-report mailing list