|
|
finally: | finally: |
os.umask(omask) | os.umask(omask) |
desc = part.get('content-description', _('not available')) | desc = part.get('content-description', _('not available')) |
filename = part.get_filename(_('not available')) |
try: |
|
filename = part.get_filename(_('not available')) |
|
except ValueError: |
|
# Hack to deal with filename containing ' character. |
|
filename = _('not available') |
del part['content-type'] | del part['content-type'] |
del part['content-transfer-encoding'] | del part['content-transfer-encoding'] |
part.set_payload(_("""\ | part.set_payload(_("""\ |
|
|
# e.g. image/jpg (should be image/jpeg). For now we just store such | # e.g. image/jpg (should be image/jpeg). For now we just store such |
# things as application/octet-streams since that seems the safest. | # things as application/octet-streams since that seems the safest. |
ctype = msg.get_content_type() | ctype = msg.get_content_type() |
fnext = os.path.splitext(msg.get_filename(''))[1] |
try: |
ext = guess_extension(ctype, fnext) |
fnext = os.path.splitext(msg.get_filename(''))[1] |
|
except ValueError: |
|
# Catch the case when msg.get_filename('') fails with a |
|
# ValueError: need more than 2 values to unpack |
|
# File "/usr/lib/python2.4/email/Utils.py", line 222, in decode_rfc2231 |
|
# charset, language, s = parts |
|
ext = '' |
|
else: |
|
ext = guess_extension(ctype, fnext) |
if not ext: | if not ext: |
# We don't know what it is, so assume it's just a shapeless | # We don't know what it is, so assume it's just a shapeless |
# application/octet-stream, unless the Content-Type: is | # application/octet-stream, unless the Content-Type: is |
|
|
try: | try: |
# Now base the filename on what's in the attachment, uniquifying it if | # Now base the filename on what's in the attachment, uniquifying it if |
# necessary. | # necessary. |
filename = msg.get_filename() |
try: |
|
filename = msg.get_filename() |
|
except ValueError: |
|
# Another case of catching filenames that contain a ' character. |
|
filename = '' |
if not filename: | if not filename: |
filebase = 'attachment' | filebase = 'attachment' |
else: | else: |