Beispiel #1
0
	def run(self):

		with Connection.Connection(self.socket, self.name, self.debug) as conn:
			while conn.get_message():

				answer = self.default_answer

				if conn["sender"] != "" and conn["recipient"] != "":
					if self.debug:
						logging.debug("Mail from {0} to {1} with SASL: {2}".format(conn["sender"], conn["recipient"], conn["sasl_username"]))
					for flt in self.flts:
						with self._mutex:
							try:
								flt_answer = flt.check(conn)
							except:
								logging.error("Error in checking policy {0}. Traceback: \n{1}\n".format(flt, traceback.format_exc()))
						if flt_answer:
							break

					if flt_answer:
						answer = flt_answer

					if self.debug:
						logging.debug("Answer for mail {0} to {1} was: {2}".format(conn["sender"], conn["recipient"], answer))

				if conn["request"] == "smtpd_access_policy":
					conn.answer(answer)
				try:
					PySQLPool.cleanupPool()
				except:
					logging.warn('Error in cleaning SQL pool. Traceback: \n{0}\n'.format(traceback.format_exc()))
		if self.debug:
			stop_time = time.time()
			logging.debug("Process named {0} started {1}, stopped {2}. Working {3} seconds.".format(self.name, time.strftime("%d.%m.%y - %H:%M:%S", time.localtime(self.start_time)), time.strftime("%d.%m.%y - %H:%M:%S", time.localtime(stop_time)), (stop_time - self.start_time)))