+

MantisSMTPServer : create add_attachment_to_issue() methode to replace code in add_note_to_issue_from_msg()

Benjamin Renard [2012-04-20 15:39:28]
MantisSMTPServer : create add_attachment_to_issue() methode to replace code in add_note_to_issue_from_msg()
Filename
src/usr/share/mantis-smtp/MantisSMTPServer.py
diff --git a/src/usr/share/mantis-smtp/MantisSMTPServer.py b/src/usr/share/mantis-smtp/MantisSMTPServer.py
index fe2c73c..af49387 100755
--- a/src/usr/share/mantis-smtp/MantisSMTPServer.py
+++ b/src/usr/share/mantis-smtp/MantisSMTPServer.py
@@ -138,34 +138,26 @@ class MantisSMTPServer(smtpd.SMTPServer):
 			self.start_ws()

 		issue_id=msg.get_issue_id_from_subject()
+		try:
+			note_id = self.ws.add_note_to_issue(issue_id,msg.get_text())
+			if note_id:
+				logging.info('Note add to issue %s with id %s' % (issue_id,note_id))
+				self.add_attachment_to_issue(issue_id,msg)
+				return issue_id
+			else:
+				logging.error('Error adding issue')

-		note_id = self.ws.add_note_to_issue(issue_id,msg.get_text())
-		if note_id:
-			logging.info('Note add to issue %s with id %s' % (issue_id,note_id))
-
-			for attachment in msg.get_attachments():
-				try:
-					logging.info('Add attachment to issue %s : %s' % (issue_id,attachment['filename']))
-					self.ws.add_attachment_to_issue(issue_id,attachment)
-				except MantisWS.MantisWSError, e:
-					if e.type == 'duplicate_attachment_filename':
-						logging.error('Duplicate filename %s in issue %s. Warning sender by mail.' % (attachment['filename'],issue_id))
-						MantisMail.send(
-							self._options['mail_from'],
-							msg.mailfrom,
-							'[Mantis] Duplicate filename %s in issue %s' % (attachment['filename'],issue_id),
-							"Your file %s attach in your email '%s' can't be attached to Mantis issue %s because a file with the same name is currently attached to this issue." % (attachment['filename'],msg.subject(),issue_id),
-							smtp_host=self._options['smtp_host'],
-							smtp_port=self._options['smtp_port']
-						)
-
-				except:
-					logging.error('Error adding attachment %s to issue %s' % (attachment['filename'],issue_id))
-#
+	def add_attachment_to_issue(self,issue_id,msg):
+		for attachment in msg.get_attachments():
+			try:
+				logging.info('Add attachment to issue %s : %s' % (issue_id,attachment['filename']))
+				self.ws.add_attachment_to_issue(issue_id,attachment)
+			except MantisWS.MantisWSError, e:
+				logging.error('MantisWS error adding attachment %s to issue %s : %s.' % (attachment['filename'],issue_id, e))
+
+			except Exception, e:
+				logging.error('Unknown error adding attachment %s to issue %s : %s. Warning sender by mail.' % (attachment['filename'],issue_id,e))

-			return issue_id
-		else:
-			logging.error('Error during add issue')

 	def save_msg(self,peer, mailfrom, rcpttos, data):
 		if self._options['save_dir']:
ViewGit