summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-05-04 13:36:34 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-05-04 13:36:34 +0100
commit4275f237a86d32880569c8cd65c15565dde6130f (patch)
tree3b4abd6fab269703d9f50fb82b0fa9a28040d42e
parent837bf4fe7a6d2b33feae8bf463c866b936766892 (diff)
downloadpykolab-4275f237a86d32880569c8cd65c15565dde6130f.tar.gz
Apply diff for #1627, #1631 (non-ascii characters cause wallace tracebacks)
-rw-r--r--wallace/__init__.py27
-rw-r--r--wallace/modules.py23
2 files changed, 40 insertions, 10 deletions
diff --git a/wallace/__init__.py b/wallace/__init__.py
index b22430d..2db963e 100644
--- a/wallace/__init__.py
+++ b/wallace/__init__.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
+# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com)
#
# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
#
@@ -63,6 +63,9 @@ def worker_process(*args, **kw):
class WallaceDaemon(object):
def __init__(self):
+ self.current_connections = 0
+ self.max_connections = 24
+
daemon_group = conf.add_cli_parser_option_group(_("Daemon Options"))
daemon_group.add_option(
@@ -215,21 +218,29 @@ class WallaceDaemon(object):
if stage.lower() == "defer":
continue
+ self.current_connections += 1
self.pool.apply_async(pickup_message, (filepath, (self.modules), {'module': module, 'stage': stage}))
+ self.current_connections -= 1
continue
+ self.current_connections += 1
self.pool.apply_async(pickup_message, (filepath, (self.modules)))
+ self.current_connections -= 1
try:
while 1:
+ while self.current_connections >= self.max_connections:
+ time.sleep(0.5)
+
pair = s.accept()
log.info(_("Accepted connection"))
if not pair == None:
+ self.current_connections += 1
connection, address = pair
- #print "Accepted connection from %r" % (address)
channel = SMTPChannel(self, connection, address)
asyncore.loop()
+
except Exception, errmsg:
traceback.print_exc()
s.shutdown(1)
@@ -247,7 +258,9 @@ class WallaceDaemon(object):
'from': mailfrom,
'to': rcpttos,
'data': data
- }
+ },
+ ensure_ascii=True,
+ indent=4
)
(fp, filename) = tempfile.mkstemp(dir="/var/spool/pykolab/wallace/")
@@ -256,6 +269,8 @@ class WallaceDaemon(object):
self.pool.apply_async(pickup_message, (filename, (self.modules)))
+ self.current_connections -= 1
+
return
def reload_config(self, *args, **kw):
@@ -368,8 +383,7 @@ class WallaceDaemon(object):
except AttributeError, e:
exitcode = 1
traceback.print_exc()
- print >> sys.stderr, _("Traceback occurred, please report a " + \
- "bug at http://bugzilla.kolabsys.com")
+ print >> sys.stderr, _("Traceback occurred, please report a bug at http://bugzilla.kolabsys.com")
except TypeError, e:
exitcode = 1
@@ -378,8 +392,7 @@ class WallaceDaemon(object):
except:
exitcode = 2
traceback.print_exc()
- print >> sys.stderr, _("Traceback occurred, please report a " + \
- "bug at http://bugzilla.kolabsys.com")
+ print >> sys.stderr, _("Traceback occurred, please report a bug at http://bugzilla.kolabsys.com")
sys.exit(exitcode)
diff --git a/wallace/modules.py b/wallace/modules.py
index a20d80e..d256bdb 100644
--- a/wallace/modules.py
+++ b/wallace/modules.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Copyright 2010-2012 Kolab Systems AG (http://www.kolabsys.com)
+# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com)
#
# Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen a kolabsys.com>
#
@@ -251,9 +251,21 @@ X-Wallace-Result: REJECT
def cb_action_ACCEPT(module, filepath):
log.info(_("Accepting message in %s (by module %s)") % (filepath, module))
- _message = json.load(open(filepath, 'r'))
+ try:
+ _message = json.load(open(filepath, 'r'))
+ log.debug(_(u"Message JSON loaded: %r") % (_message), level=9)
+ except Exception, errmsg:
+ log.error(_("Error loading message: %r") % (errmsg))
+ return
+
+ try:
+ message = message_from_string(str(_message['data']).replace('\x00',''))
+ except Exception, errmsg:
+ log.error(_("Error parsing message: %r") % (errmsg))
+ return
+
+ log.debug(_("Accepting message in: %r") %(filepath), level=8)
- message = message_from_string("%s" %(str(_message['data'])))
sender = _message['from']
recipients = _message['to']
@@ -266,6 +278,11 @@ def cb_action_ACCEPT(module, filepath):
smtp.sendmail(
sender,
recipients,
+ # - Make sure we do not send this as binary.
+ # - Second, strip NUL characters - I don't know where they
+ # come from (TODO)
+ # - Third, a character return is inserted somewhere. It
+ # divides the body from the headers - and we don't like (TODO)
message.as_string()
)