diff --git a/wallace/__init__.py b/wallace/__init__.py --- a/wallace/__init__.py +++ b/wallace/__init__.py @@ -92,7 +92,10 @@ lastrun = int(time.time()) time.sleep(60) - except (SystemExit, KeyboardInterrupt), e: + except KeyboardInterrupt: + log.info("Terminating heartbeat process") + break + except SystemExit: log.info("Terminating heartbeat process") break @@ -108,74 +111,74 @@ daemon_group = conf.add_cli_parser_option_group(_("Daemon Options")) daemon_group.add_option( - "--fork", - dest = "fork_mode", - action = "store_true", - default = False, - help = _("Fork to the background.") - ) + "--fork", + dest = "fork_mode", + action = "store_true", + default = False, + help = _("Fork to the background.") + ) daemon_group.add_option( - "-b", "--bind", - dest = "wallace_bind_address", - action = "store", - default = "localhost", - help = _("Bind address for Wallace.") - ) + "-b", "--bind", + dest = "wallace_bind_address", + action = "store", + default = "localhost", + help = _("Bind address for Wallace.") + ) daemon_group.add_option( - "-g", - "--group", - dest = "process_groupname", - action = "store", - default = "kolab", - help = _("Run as group GROUPNAME"), - metavar = "GROUPNAME" - ) + "-g", + "--group", + dest = "process_groupname", + action = "store", + default = "kolab", + help = _("Run as group GROUPNAME"), + metavar = "GROUPNAME" + ) daemon_group.add_option( - "--threads", - dest = "max_threads", - action = "store", - default = 4, - type = int, - help = _("Number of threads to use.") - ) + "--threads", + dest = "max_threads", + action = "store", + default = 4, + type = int, + help = _("Number of threads to use.") + ) daemon_group.add_option( - "-p", "--pid-file", - dest = "pidfile", - action = "store", - default = "/var/run/wallaced/wallaced.pid", - help = _("Path to the PID file to use.") - ) + "-p", "--pid-file", + dest = "pidfile", + action = "store", + default = "/var/run/wallaced/wallaced.pid", + help = _("Path to the PID file to use.") + ) daemon_group.add_option( - "--port", - dest = "wallace_port", - action = "store", - default = 10026, - type = int, - help = _("Port that Wallace is supposed to use.") - ) + "--port", + dest = "wallace_port", + action = "store", + default = 10026, + type = int, + help = _("Port that Wallace is supposed to use.") + ) daemon_group.add_option( - "-u", - "--user", - dest = "process_username", - action = "store", - default = "kolab", - help = _("Run as user USERNAME"), - metavar = "USERNAME" - ) + "-u", + "--user", + dest = "process_username", + action = "store", + default = "kolab", + help = _("Run as user USERNAME"), + metavar = "USERNAME" + ) conf.finalize_conf() utils.ensure_directory( - os.path.dirname(conf.pidfile), - conf.process_username, - conf.process_groupname - ) + os.path.dirname(conf.pidfile), + conf.process_username, + conf.process_groupname + ) import modules modules.__init__() @@ -203,7 +206,7 @@ s.bind((conf.wallace_bind_address, conf.wallace_port)) bound = True - except Exception, e: + except Exception: log.warning( _("Could not bind to socket on port %d on bind " + \ "address %s") % ( @@ -216,7 +219,7 @@ try: s.shutdown(socket.SHUT_RDWR) shutdown = True - except Exception, e: + except Exception: log.warning(_("Could not shut down socket")) time.sleep(1) @@ -293,7 +296,7 @@ channel = SMTPChannel(self, connection, address) asyncore.loop() - except Exception, errmsg: + except Exception: traceback.print_exc() s.shutdown(1) s.close() @@ -301,10 +304,10 @@ # shut down hearbeat process self.heartbeat.terminate() - def data_header(self, mailfrom, rcpttos): + def data_header(self, mailfrom, rcptto): COMMASPACE = ', ' return "X-Kolab-From: " + mailfrom + "\r\n" + \ - "X-Kolab-To: " + COMMASPACE.join(rcpttos) + "\r\n" + "X-Kolab-To: " + rcptto + "\r\n" def process_message(self, peer, mailfrom, rcpttos, data): """ @@ -312,18 +315,19 @@ and not ever block. """ - header = self.data_header(mailfrom, rcpttos) + for rcptto in rcpttos: + header = self.data_header(mailfrom, rcptto) - (fp, filename) = tempfile.mkstemp(dir="/var/spool/pykolab/wallace/") + (fp, filename) = tempfile.mkstemp(dir="/var/spool/pykolab/wallace/") - # @TODO: and add line separator (\n or \r\n?) - # we should make sure there's only one line separator between - # kolab headers and the original message (data) - os.write(fp, header); - os.write(fp, data) - os.close(fp) + # @TODO: and add line separator (\n or \r\n?) + # we should make sure there's only one line separator between + # kolab headers and the original message (data) + os.write(fp, header) + os.write(fp, data) + os.close(fp) - self.pool.apply_async(pickup_message, (filename, (self.modules))) + self.pool.apply_async(pickup_message, (filename, (self.modules))) self.current_connections -= 1 @@ -353,7 +357,7 @@ try: (ruid, euid, suid) = os.getresuid() (rgid, egid, sgid) = os.getresgid() - except AttributeError, errmsg: + except AttributeError: ruid = os.getuid() rgid = os.getgid() @@ -458,17 +462,17 @@ self.write_pid() self.do_wallace() - except SystemExit, e: + except SystemExit: exitcode = e except KeyboardInterrupt: exitcode = 1 log.info(_("Interrupted by user")) - except AttributeError, e: + except AttributeError: exitcode = 1 traceback.print_exc() print >> sys.stderr, _("Traceback occurred, please report a bug at https://issues.kolab.org") - except TypeError, e: + except TypeError: exitcode = 1 traceback.print_exc() log.error(_("Type Error: %s") % e)