Index: /trunk/debian/changelog
===================================================================
--- /trunk/debian/changelog	(revision 295)
+++ /trunk/debian/changelog	(revision 296)
@@ -33,4 +33,11 @@
    Authors:  otto at bergerdata dot de and Bas van der Vlies
 
+ * FIxed an error when files where added with characters that needed to be 
+   escaped. Both email2trac and trac escaped the filenames. We removed the 
+   code from email2trac an let trac handle the escaping, closes #149
+
+   Reported by: hju att jochenkuhl dot de
+   Fixed by: Bas van der Vlies
+   
  -- Bas van der Vlies <bas@sara.nl>  Thu, 22 Oct 2009 17:47:50 +0200
 
Index: /trunk/email2trac.py.in
===================================================================
--- /trunk/email2trac.py.in	(revision 295)
+++ /trunk/email2trac.py.in	(revision 296)
@@ -143,9 +143,4 @@
 			os.umask(int(parameters['umask'], 8))
 
-		if parameters.has_key('quote_attachment_filenames'):
-			self.QUOTE_ATTACHMENT_FILENAMES = int(parameters['quote_attachment_filenames'])
-		else:
-			self.QUOTE_ATTACHMENT_FILENAMES = 1
-
 		if parameters.has_key('debug'):
 			self.DEBUG = int(parameters['debug'])
@@ -800,7 +795,15 @@
 		if self.EMAIL_HEADER > 0:
 			head = self.email_header_txt(msg)
-			
+
+					
 		message_parts = self.get_message_parts(msg)
+		if self.DEBUG:
+			print 'TD: self.get_message_parts ',
+			print message_parts
+
 		message_parts = self.unique_attachment_names(message_parts)
+		if self.DEBUG:
+			print 'TD: self.unique_attachment_names',
+			print message_parts
 		
 		if self.EMAIL_HEADER > 0:
@@ -1191,9 +1194,13 @@
 		
 	def unique_attachment_names(self, message_parts):
+		"""
+		"""
 		renamed_parts = []
 		attachment_names = set()
+
 		for part in message_parts:
 			
-			# If not an attachment, leave it alone
+			## If not an attachment, leave it alone
+			#
 			if not isinstance(part, tuple):
 				renamed_parts.append(part)
@@ -1201,10 +1208,8 @@
 				
 			(filename, part) = part
-			# Decode the filename
-			if filename:
-				filename = self.email_to_unicode(filename)			
-
-			# If no name, use a default one
-			else:
+
+			## If no filename, use a default one
+			#
+			if not filename:
 				filename = 'untitled-part'
 
@@ -1219,32 +1224,29 @@
 				filename = '%s%s' % (filename, ext)
 
-			# Discard relative paths in attachment names
-			filename = filename.replace('\\', '/').replace(':', '/') 
-			filename = os.path.basename(filename)
-
+# We now use the attachment insert function
+#
+			## Discard relative paths in attachment names
+			#
+			#filename = filename.replace('\\', '/').replace(':', '/') 
+			#filename = os.path.basename(filename)
+			#
 			# We try to normalize the filename to utf-8 NFC if we can.
 			# Files uploaded from OS X might be in NFD.
 			# Check python version and then try it
 			#
-			if sys.version_info[0] > 2 or (sys.version_info[0] == 2 and sys.version_info[1] >= 3):
-				try:
-					filename = unicodedata.normalize('NFC', unicode(filename, 'utf-8')).encode('utf-8')  
-				except TypeError:
-					pass
-					
-			if self.QUOTE_ATTACHMENT_FILENAMES:
-				try:
-					filename = urllib.quote(filename)
-				except KeyError, detail:
-					filename = urllib.quote(filename.encode('utf-8'))
+			#if sys.version_info[0] > 2 or (sys.version_info[0] == 2 and sys.version_info[1] >= 3):
+			#	try:
+			#		filename = unicodedata.normalize('NFC', unicode(filename, 'utf-8')).encode('utf-8')  
+			#	except TypeError:
+			#		pass
 
 			# Make the filename unique for this ticket
 			num = 0
 			unique_filename = filename
-			filename, ext = os.path.splitext(filename)
+			dummy_filename, ext = os.path.splitext(filename)
 
 			while unique_filename in attachment_names or self.attachment_exists(unique_filename):
 				num += 1
-				unique_filename = "%s-%s%s" % (filename, num, ext)
+				unique_filename = "%s-%s%s" % (dummy_filename, num, ext)
 				
 			if self.DEBUG:
@@ -1254,5 +1256,5 @@
 
 			renamed_parts.append((filename, unique_filename, part))
-		
+	
 		return renamed_parts
 			
@@ -1418,4 +1420,5 @@
 
 			att.insert(filename, fd, file_size)
+
 			#except  util.TracError, detail:
 			#	print detail
