git » sea » commit acca81a

Detect broken file names and do not use them

author Alberto Bertogli
2010-05-09 00:43:00 UTC
committer Alberto Bertogli
2010-05-09 00:43:00 UTC
parent a74898f3cdc89f6663015118487010d95c8f42a4

Detect broken file names and do not use them

Some MUAs (don't know which one) emit broken attachment names when attempting
to encode non-ascii characters.

This patch detects those attempts and makes sea use our onw name generator
instead of the provided file name.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

sea +3 -1

diff --git a/sea b/sea
index 12dbf48..22d14ea 100755
--- a/sea
+++ b/sea
@@ -50,7 +50,9 @@ def main(infd, basepath):
 			os.mkdir(outpath)
 
 		fname = part.get_filename('')
-		if not fname:
+		# "=?" tells us that the name is broken (an attempt to encode
+		# it that went wrong), so just assign a name ourselves
+		if not fname or "=?" in fname:
 			ext = mimetypes.guess_extension(
 					part.get_content_type() )
 			fname = 'att-%d.%s' % (count, ext)