+

MantisSMTPServer : send email alert to sender on error adding his note

Benjamin Renard [2012-04-20 15:56:46]
MantisSMTPServer : send email alert to sender on error adding his note
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 57195b9..0b41a7d 100755
--- a/src/usr/share/mantis-smtp/MantisSMTPServer.py
+++ b/src/usr/share/mantis-smtp/MantisSMTPServer.py
@@ -152,7 +152,25 @@ class MantisSMTPServer(smtpd.SMTPServer):
 				self.add_attachment_to_issue(issue_id,msg)
 				return issue_id
 			else:
+				self.alert_sender(
+					msg,
+					u"[Mantis] Error occured adding your note to issue %s" % issue_id,
+					u"An error occured adding your note to issue %s. Your note has not been added.\n\nSubject : %s\n--\n%s" % (issue_id,msg.subject(),msg.get_text())
+				)
 				logging.error('Error adding issue')
+		except MantisWS.MantisWSError, e:
+			if e.type == 'unknown_issue_note_add':
+				subject = u"[Mantis] Issue %s does not exists. Can't add your note." % issue_id
+				content = u"Issue %s does not exists. Can't add your note :\n\nSubject : %s\n--\n%s" % (issue_id,msg.subject(),msg.get_text())
+
+			else:
+				subject = u"[Mantis] WS error occured adding your note to issue %s" % issue_id
+                                content = u"An WS error occured adding your note to issue %s. Your note has not been added.\n\nSubject : %s\n--\n%s" % (issue_id,msg.subject(),msg.get_text())
+			self.alert_sender(
+				msg,
+				subject,
+				content
+			)

 	def add_attachment_to_issue(self,issue_id,msg):
 		for attachment in msg.get_attachments():
ViewGit