Skip to content

Commit

Permalink
Decode enclosure filename properly (bug 1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
papagr authored and thp committed Sep 14, 2012
1 parent ea597c0 commit 6ec076f
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/gpodder/download.py
Expand Up @@ -63,25 +63,17 @@ def get_header_param(headers, param, header_name):
Returns None if the filename cannot be retrieved.
"""
value = None
try:
headers_string = ['%s:%s'%(k,v) for k,v in headers.items()]
msg = email.message_from_string('\n'.join(headers_string))
if header_name in msg:
value = msg.get_param(param, header=header_name)
if value is None:
return None
decoded_list = decode_header(value)
value = []
for part, encoding in decoded_list:
if encoding:
value.append(part.decode(encoding))
else:
value.append(unicode(part))
return u''.join(value)
raw_value = msg.get_param(param, header=header_name)
value = email.utils.collapse_rfc2231_value(raw_value)
except Exception, e:
logger.error('Cannot get %s from %s', param, header_name, exc_info=True)

return None
return value

class ContentRange(object):
# Based on:
Expand Down

0 comments on commit 6ec076f

Please sign in to comment.