Georg Graf wrote:
>
>There are 2 assumptions in email.Utils.decode_rfc2231 I do not
>understand.
>
>Assumption 1: The string passed either has zero single-quotes or
>more than 1.
>
>Assumption 2: If the string has two or more single-quotes the
>meaning of the parts is different. I dont know rfc2231, so what
>do I write. But still it seems funny to me.


See <http://www.faqs.org/rfcs/rfc2231.html>

The single quotes are delimiters for character-set and language fields
for extended-parameters.


>Fact is in this mail (generated by a recent thunderbird version)
>there is only one single quote in the filename and the function
>fails, see below.
>
>My fix would be to write "if len(parts) != 3", but I'm interested
>what you say (it fixes this specific problem, I'd say).

Yes it does, but it doesn't fix the general problem because there could
be two single-quote (') characters in a non extended parameter value.

The standard is clear that the single-quote (') character is not
allowed in extended-values, but I think it is OK in non extended
values. The issue in email.Utils is that decode_rfc2231 should only be
called for extended parameters of the form

  name*=charset'language'value

or

  name*0*=charset'language'value

I.e. only when the '=' is immediately preceded by '*'.

The attached patch.txt file contains a very lightly tested patch that I
think will fix the problem.

-- 
Mark Sapiro <[EMAIL PROTECTED]>       The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan

--- /lib/python2.4/email/Utils.py.orig  2006-05-18 04:42:34.001000000 -0700
+++ /lib/python2.4/email/Utils.py       2006-07-07 15:36:06.687500000 -0700
@@ -249,11 +249,16 @@
     new_params = []
     # maps parameter's name to a list of continuations
     rfc2231_params = {}
+    rfc2231_extended = {}
     # params is a sequence of 2-tuples containing (content_type, string value)
     name, value = params[0]
     new_params.append((name, value))
     # Cycle through each of the rest of the parameters.
     for name, value in params[1:]:
+        if name.endswith('*'):
+            rfc2231_extended_flag = True
+        else:
+            rfc2231_extended_flag = False
         value = unquote(value)
         mo = rfc2231_continuation.match(name)
         if mo:
@@ -262,6 +267,8 @@
                 num = int(num)
             rfc2231_param1 = rfc2231_params.setdefault(name, [])
             rfc2231_param1.append((num, value))
+            if rfc2231_extended_flag:
+                rfc2231_extended[name] = True
         else:
             new_params.append((name, '"%s"' % quote(value)))
     if rfc2231_params:
@@ -272,9 +279,14 @@
             # And now append all values in num order
             for num, continuation in continuations:
                 value.append(continuation)
-            charset, language, value = decode_rfc2231(EMPTYSTRING.join(value))
-            new_params.append(
-                (name, (charset, language, '"%s"' % quote(value))))
+            if rfc2231_extended.has_key(name):
+                charset, language, value = \
+                    decode_rfc2231(EMPTYSTRING.join(value))
+                new_params.append(
+                    (name, (charset, language, '"%s"' % quote(value))))
+            else:
+                new_params.append(
+                    (name, '"%s"' % quote(EMPTYSTRING.join(value))))
     return new_params
 
 def collapse_rfc2231_value(value, errors='replace',
_______________________________________________
Email-SIG mailing list
[email protected]
Your options: 
http://mail.python.org/mailman/options/email-sig/archive%40mail-archive.com

Reply via email to