Index: email/message.py =================================================================== --- email/message.py (revision 65356) +++ email/message.py (working copy) @@ -24,6 +24,7 @@ # simple. It isn't strictly RFC 2045 (section 5.1) compliant, but it catches # most headers found in the wild. We may eventually need a full fledged # parser eventually. +# [see: _fast_paramre_name] paramre = re.compile(r'\s*;\s*') # Regular expression that matches `special' characters in parameters, the # existance of which force quoting of the parameter value. @@ -82,6 +83,18 @@ else: return utils.unquote(value) +def _fast_paramre_name(txt): + """ paramre has exponential bad behavior for strings with large amounts + of whitespace (issue2676). This function performs the same + operation that paramre was used for but linearly. + paramre is still included in the module for backwards compatibility. + """ + semi_ind = txt.find(';') + if semi_ind >= 0: + ctype = txt[:semi_ind] + else: + ctype = txt + return ctype.strip().lower() class Message: @@ -443,7 +456,7 @@ if value is missing: # This should have no parameters return self.get_default_type() - ctype = paramre.split(value)[0].lower().strip() + ctype = _fast_paramre_name(value) # RFC 2045, section 5.2 says if its invalid, use text/plain if ctype.count('/') != 1: return 'text/plain'