+

MantisWS : rename duplicated file on error

Benjamin Renard [2012-04-20 15:32:11]
MantisWS : rename duplicated file on error
Filename
src/usr/share/mantis-smtp/MantisWS.py
diff --git a/src/usr/share/mantis-smtp/MantisWS.py b/src/usr/share/mantis-smtp/MantisWS.py
index 25fd313..999b229 100755
--- a/src/usr/share/mantis-smtp/MantisWS.py
+++ b/src/usr/share/mantis-smtp/MantisWS.py
@@ -5,6 +5,7 @@ import logging
 import re
 import MantisMail
 import base64
+import time

 class MantisWS(object):

@@ -79,8 +80,16 @@ class MantisWS(object):
 			logging.error('Problem adding attachment %s to issue %s' % (attachment['filename'],issue_id))
 			err=str(e)
 			if re.search('Duplicate filename',err):
-				raise MantisWSError('duplicate_attachment_filename','Duplicate attachment filename %s in issue %s' % (attachment['filename'],issue_id))
-		except:
+				newname="%s-%s" % (time.time(),attachment['filename'])
+				logging.info('Duplicate attachment filename %s in issue %s. Rename it to %s and add again.' % (attachment['filename'],issue_id,newname))
+				attachment['filename']=newname
+				try:
+					self.add_attachment_to_issue(issue_id,attachment)
+				except Exception, e:
+					raise MantisWSError('general_attachment','Problem adding attachment %s to issue %s' % (attachment['filename'],issue_id))
+			else:
+				raise MantisWSError('general_attachment','Problem adding attachment %s to issue %s' % (attachment['filename'],issue_id))
+		except Exception, e:
 			logging.error('Problem adding attachment %s to issue %s' % (attachment['filename'],issue_id))
 			raise MantisWSError('general_attachment','Problem adding attachment %s to issue %s' % (attachment['filename'],issue_id))
 			return None
ViewGit