summaryrefslogtreecommitdiff
path: root/start_mx.py
diff options
context:
space:
mode:
authorTomas Touceda <chiiph@leap.se>2013-04-24 16:47:07 -0300
committerTomas Touceda <chiiph@leap.se>2013-05-07 14:01:10 -0300
commitb1c2e24fb08f69a10a4d91a84ec0e31d91991190 (patch)
treeef5f2127f85b737fe035b190f6b0a7db83d7c142 /start_mx.py
parentb322a390af83addcf9768ae59d31c31a3229b49d (diff)
Improve the rest and start everything from start_mx
Diffstat (limited to 'start_mx.py')
-rwxr-xr-xstart_mx.py42
1 files changed, 31 insertions, 11 deletions
diff --git a/start_mx.py b/start_mx.py
index c802852..067011f 100755
--- a/start_mx.py
+++ b/start_mx.py
@@ -21,16 +21,20 @@ import sys
import ConfigParser
import logging
+from functools import partial
+
try:
- from leap.mx import couchdbhelper
+ from leap.mx import couchdbhelper, mail_receiver
from leap.mx.alias_resolver import AliasResolverFactory
except ImportError, ie:
print "%s \nExiting... \n" % ie.message
+ raise
sys.exit(1)
try:
- from twisted.internet import reactor
+ from twisted.internet import reactor, inotify
from twisted.internet.endpoints import TCP4ServerEndpoint
+ from twisted.python import filepath
except ImportError, ie:
print "This software requires Twisted>=12.0.2, please see the README for"
print "help on using virtualenv and pip to obtain requirements."
@@ -83,11 +87,8 @@ if __name__ == "__main__":
config = ConfigParser.ConfigParser()
config.read(config_file)
- users_user = config.get("couchdb", "users_user")
- users_password = config.get("couchdb", "users_password")
-
- mail_user = config.get("couchdb", "mail_user")
- mail_password = config.get("couchdb", "mail_password")
+ user = config.get("couchdb", "user")
+ password = config.get("couchdb", "password")
server = config.get("couchdb", "server")
port = config.get("couchdb", "port")
@@ -95,12 +96,31 @@ if __name__ == "__main__":
cdb = couchdbhelper.ConnectedCouchDB(server,
port=port,
dbName="users",
- username=users_user,
- password=users_password)
+ username=user,
+ password=password)
+
+ # Mail receiver
+ wm = inotify.INotify(reactor)
+ wm.startReading()
+
+ mask = inotify.IN_CREATE
+
+ mail_couch_url_prefix = "http://%s:%s@%s:%s" % (user,
+ password,
+ server,
+ port)
+
+ incoming_partial = partial(mail_receiver._process_incoming_email, cdb, mail_couch_url_prefix)
+ for section in config.sections():
+ if section in ("couchdb"):
+ continue
+ to_watch = config.get(section, "path")
+ recursive = config.getboolean(section, "recursive")
+ logger.debug("Watching %s --- Recursive: %s" % (to_watch, recursive))
+ wm.watch(filepath.FilePath(to_watch), mask, callbacks=[incoming_partial], recursive=recursive)
- # TODO: use the couchdb for mail
- # TODO: make the listening ports configurable
+ # Alias map
alias_endpoint = TCP4ServerEndpoint(reactor, 4242)
alias_endpoint.listen(AliasResolverFactory(couchdb=cdb))