--- Scrubber.py.orig 2006-06-13 22:05:53.000000000 +0300 +++ Scrubber.py 2006-06-13 22:04:24.000000000 +0300 @@ -266,7 +266,11 @@ finally: os.umask(omask) 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-transfer-encoding'] part.set_payload(_("""\ @@ -358,8 +362,16 @@ # e.g. image/jpg (should be image/jpeg). For now we just store such # things as application/octet-streams since that seems the safest. ctype = msg.get_content_type() - fnext = os.path.splitext(msg.get_filename(''))[1] - ext = guess_extension(ctype, fnext) + try: + 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: # We don't know what it is, so assume it's just a shapeless # application/octet-stream, unless the Content-Type: is @@ -377,7 +389,11 @@ try: # Now base the filename on what's in the attachment, uniquifying it if # 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: filebase = 'attachment' else: