I have a second suggestion to that same Message.get_filename() method.

It needs to understand filenames that come with text encodings.

The proposed patch is in the attached text file.

Thank you for your time...

Nando Florestan
===============
[skype]    nandoflorestan
[phone]  + 55 (11) 3675-3038
[mobile] + 55 (11) 9820-5451
[internet] http://oui.com.br/
[À Capela] http://acapela.com.br/
[location] São Paulo - SP - Brasil



Nando wrote:
Greetings, Mr. Barry Warsaw and all other Pythonistas,

How do you like this little patch?

$ svn diff
Index: message.py
===================================================================
--- message.py  (revision 60758)
+++ message.py  (working copy)
@@ -671,7 +671,10 @@
filename = self.get_param('filename', missing, 'content-disposition')
         if filename is missing:
filename = self.get_param('name', missing, 'content-disposition') + # nando: Some messages specify the file name of attachment this way:
         if filename is missing:
+            filename = self.get_param('name', missing, 'content-type')
+        if filename is missing:
             return failobj
         return utils.collapse_rfc2231_value(filename).strip()


This is the first time I collaborate this way, so if there is anything else I can do to help, let me know, cause I am sort of ignorant.

Index: message.py
===================================================================
--- message.py  (revision 60758)
+++ message.py  (working copy)
@@ -16,6 +16,7 @@
 import email.charset
 from email import utils
 from email import errors
+from email.header import decode_header
 
 SEMISPACE = '; '
 
@@ -671,8 +672,16 @@
         filename = self.get_param('filename', missing, 'content-disposition')
         if filename is missing:
             filename = self.get_param('name', missing, 'content-disposition')
+        # nando: Some messages specify the file name of attachment this way:
         if filename is missing:
+            filename = self.get_param('name', missing, 'content-type')
+        if filename is missing:
             return failobj
+        """The following line takes care of cases such as this:
+Content-Disposition: attachment;
+  filename="=?ISO-8859-1?Q?z=C7D-_Zoltan=5Fchunk=5F5.wmv?="
+        """
+        filename = decode_header(filename)[0][0]
         return utils.collapse_rfc2231_value(filename).strip()
 
     def get_boundary(self, failobj=None):
_______________________________________________
Email-SIG mailing list
[email protected]
Your options: 
http://mail.python.org/mailman/options/email-sig/archive%40mail-archive.com

Reply via email to