diff --git a/conf/jmc.conf b/conf/jmc.conf
new file mode 100644
index 0000000..55398a2
--- /dev/null
+++ b/conf/jmc.conf
@@ -0,0 +1,24 @@
+[jabber]
+server: localhost
+port: 5347
+secret: secret
+service_jid: jmc.localhost
+#supported language: en, fr (See src/jmc/lang.py to add more)
+language: en
+
+[db]
+#type: mysql
+type: sqlite
+#host: root@localhost
+host:
+name: /var/spool/jabber/jmc.db
+#url: %(type)%(host)%(name)?debug=1&debugThreading=1
+db_url: %(type)s://%(host)s%(name)s
+
+[component]
+pid_file: /var/run/jabber/jmc.pid
+
+[jmc]
+mail_default_encoding: iso-8859-1
+check_interval: 1
+
diff --git a/jmc.xml b/jmc.xml
deleted file mode 100644
index 55ea976..0000000
--- a/jmc.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
- 127.0.0.1
- 5347
- secret
- jmc.localhost
- 5
-
- fr
-
- Jabber Mail Component
- A Jabber mail server component
- http://people.happycoders.org/dax/jabber/jmc/
-
-
- DBM
- ./spool/jabber
- ./run/jabber/jmc.pid
-
- 1
- iso-8859-1
-
diff --git a/src/jmc.py b/src/jmc.py
index 692806b..f454d20 100755
--- a/src/jmc.py
+++ b/src/jmc.py
@@ -20,41 +20,15 @@
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
-import logging
import sys
-
reload(sys)
sys.setdefaultencoding('utf-8')
del sys.setdefaultencoding
-from sqlobject import *
-from pyxmpp.message import Message
+import jmc
+from jmc.runner import JMCRunner
-from jcl.model import account
-from jcl.model.account import Account, PresenceAccount
-
-from jmc.jabber.component import MailComponent
-from jmc.model.account import MailAccount, IMAPAccount, POP3Account
-
-DB_PATH = "/tmp/jmc.db"
-DB_URL = DB_PATH# + "?debug=1&debugThreading=1"
-
-logger = logging.getLogger()
-logger.addHandler(logging.StreamHandler())
-logger.setLevel(logging.DEBUG)
-
-account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
-Account.createTable(ifNotExists = True)
-PresenceAccount.createTable(ifNotExists = True)
-MailAccount.createTable(ifNotExists = True)
-IMAPAccount.createTable(ifNotExists = True)
-POP3Account.createTable(ifNotExists = True)
-del account.hub.threadConnection
-
-component = MailComponent("jmc.localhost", \
- "secret", \
- "127.0.0.1", \
- 5347, \
- "sqlite://" + DB_URL)
-component.run()
-logger.debug("JMC is exiting")
+if __name__ == "__main__":
+ runner = JMCRunner("Jabber Mail Component", jmc.version)
+ runner.configure()
+ runner.run()
diff --git a/src/jmc/runner.py b/src/jmc/runner.py
new file mode 100644
index 0000000..c103e9f
--- /dev/null
+++ b/src/jmc/runner.py
@@ -0,0 +1,63 @@
+##
+## runner.py
+## Login : David Rousselie
+## Started on Thu May 17 21:58:32 2007 David Rousselie
+## $Id$
+##
+## Copyright (C) 2007 David Rousselie
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+
+from jcl.runner import JCLRunner
+
+from jmc.model.account import MailAccount, IMAPAccount, POP3Account
+from jmc.jabber.component import MailComponent
+from jmc.lang import Lang
+
+class JMCRunner(JCLRunner):
+ def __init__(self, component_name, component_version):
+ JCLRunner.__init__(self, component_name, component_version)
+ # define new options
+ self.check_interval = 1
+ self.mail_default_encoding = "iso-8859-1"
+ self.options += [("i:", "check-interval=", "jmc", \
+ " INTERVAL\t\t\tInterval unit in minute between mail checks", \
+ lambda arg: setattr(self, "check_interval", int(arg))), \
+ ("e:", "mail-default-encoding=", "jmc", \
+ " ENCODING\t\tDefault encoding of the component", \
+ lambda arg: setattr(self, "mail_default_encoding", arg))]
+ # override JCL default
+ self.service_jid = "jmc.localhost"
+ self.db_url = "sqlite:///var/spool/jabber/jmc.db"
+ self.pid_file = "/var/run/jabber/jmc.pid"
+
+ def setup_db(self):
+ JCLRunner.setup_db(self)
+ MailAccount.createTable(ifNotExists = True)
+ IMAPAccount.createTable(ifNotExists = True)
+ POP3Account.createTable(ifNotExists = True)
+
+ def run(self):
+ def run_func():
+ component = MailComponent(jid = self.service_jid, \
+ secret = self.secret, \
+ server = self.server, \
+ port = self.port, \
+ db_connection_str = self.db_url, \
+ lang = Lang(self.language))
+ MailAccount.default_encoding = self.mail_default_encoding
+ component.check_interval = self.check_interval
+ component.run()
+ self._run(run_func)
diff --git a/src/jmc/tests/__init__.py b/src/jmc/tests/__init__.py
index a97a7a5..22ec1eb 100644
--- a/src/jmc/tests/__init__.py
+++ b/src/jmc/tests/__init__.py
@@ -3,13 +3,14 @@ __revision__ = ""
import unittest
-from jmc.tests import lang
+from jmc.tests import lang, runner
from jmc.jabber import tests as jabber
from jmc.model import tests as model
def suite():
suite = unittest.TestSuite()
suite.addTest(lang.suite())
+ suite.addTest(runner.suite())
suite.addTest(jabber.suite())
suite.addTest(model.suite())
return suite
diff --git a/src/jmc/tests/jmc.conf b/src/jmc/tests/jmc.conf
new file mode 100644
index 0000000..f05c78c
--- /dev/null
+++ b/src/jmc/tests/jmc.conf
@@ -0,0 +1,25 @@
+[jabber]
+server: test_localhost
+port: 42
+secret: test_secret
+service_jid: test_jmc.localhost
+#supported language: en, fr (See src/jmc/lang.py to add more)
+language: test_en
+
+[db]
+#type: mysql
+type: test_sqlite
+#host: root@localhost
+host: root@localhost
+name: /var/spool/jabber/test_jmc.db
+#url: %(type)%(host)%(name)?debug=1&debugThreading=1
+db_url: %(type)s://%(host)s%(name)s
+
+[component]
+pid_file: /var/run/jabber/test_jmc.pid
+
+[jmc]
+mail_default_encoding: test_iso-8859-1
+check_interval: 2
+
+
diff --git a/src/jmc/tests/runner.py b/src/jmc/tests/runner.py
new file mode 100644
index 0000000..6f818c4
--- /dev/null
+++ b/src/jmc/tests/runner.py
@@ -0,0 +1,150 @@
+##
+## runner.py
+## Login : David Rousselie
+## Started on Fri May 18 13:43:37 2007 David Rousselie
+## $Id$
+##
+## Copyright (C) 2007 David Rousselie
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+
+import unittest
+import sys
+import os
+
+from sqlobject import *
+
+from jcl.tests.runner import JCLRunner_TestCase
+
+from jcl.model import account
+from jcl.model.account import Account, PresenceAccount
+
+import jmc
+from jmc.runner import JMCRunner
+from jmc.model.account import MailAccount, IMAPAccount, POP3Account
+
+if sys.platform == "win32":
+ DB_PATH = "/c|/temp/test.db"
+else:
+ DB_PATH = "/tmp/test.db"
+DB_URL = "sqlite://" + DB_PATH# + "?debug=1&debugThreading=1"
+
+class JMCRunner_TestCase(JCLRunner_TestCase):
+ def setUp(self):
+ self.runner = JMCRunner("Jabber Mail Component", jmc.version)
+
+ def tearDown(self):
+ self.runner = None
+ sys.argv = [""]
+
+ def test_configure_default(self):
+ self.runner.configure()
+ self.assertEquals(self.runner.config_file, None)
+ self.assertEquals(self.runner.server, "localhost")
+ self.assertEquals(self.runner.port, 5347)
+ self.assertEquals(self.runner.secret, "secret")
+ self.assertEquals(self.runner.service_jid, "jmc.localhost")
+ self.assertEquals(self.runner.language, "en")
+ self.assertEquals(self.runner.db_url, "sqlite:///var/spool/jabber/jmc.db")
+ self.assertEquals(self.runner.pid_file, "/var/run/jabber/jmc.pid")
+ self.assertFalse(self.runner.debug)
+ self.assertEquals(self.runner.mail_default_encoding, "iso-8859-1")
+ self.assertEquals(self.runner.check_interval, 1)
+
+ def test_configure_configfile(self):
+ self.runner.config_file = "src/jmc/tests/jmc.conf"
+ self.runner.configure()
+ self.assertEquals(self.runner.server, "test_localhost")
+ self.assertEquals(self.runner.port, 42)
+ self.assertEquals(self.runner.secret, "test_secret")
+ self.assertEquals(self.runner.service_jid, "test_jmc.localhost")
+ self.assertEquals(self.runner.language, "test_en")
+ self.assertEquals(self.runner.db_url, "test_sqlite://root@localhost/var/spool/jabber/test_jmc.db")
+ self.assertEquals(self.runner.pid_file, "/var/run/jabber/test_jmc.pid")
+ self.assertFalse(self.runner.debug)
+ self.assertEquals(self.runner.mail_default_encoding, "test_iso-8859-1")
+ self.assertEquals(self.runner.check_interval, 2)
+
+ def test_configure_commandline_shortopt(self):
+ sys.argv = ["", "-c", "src/jmc/tests/jmc.conf", \
+ "-S", "test2_localhost", \
+ "-P", "43", \
+ "-s", "test2_secret", \
+ "-j", "test2_jmc.localhost", \
+ "-l", "test2_en", \
+ "-u", "sqlite:///tmp/test_jmc.db", \
+ "-p", "/tmp/test_jmc.pid", \
+ "-e", "test2_iso-8859-1", \
+ "-i", "3"]
+ self.runner.configure()
+ self.assertEquals(self.runner.server, "test2_localhost")
+ self.assertEquals(self.runner.port, 43)
+ self.assertEquals(self.runner.secret, "test2_secret")
+ self.assertEquals(self.runner.service_jid, "test2_jmc.localhost")
+ self.assertEquals(self.runner.language, "test2_en")
+ self.assertEquals(self.runner.db_url, "sqlite:///tmp/test_jmc.db")
+ self.assertEquals(self.runner.pid_file, "/tmp/test_jmc.pid")
+ self.assertFalse(self.runner.debug)
+ self.assertEquals(self.runner.mail_default_encoding, "test2_iso-8859-1")
+ self.assertEquals(self.runner.check_interval, 3)
+
+ def test_configure_commandline_longopt(self):
+ sys.argv = ["", "--config-file", "src/jmc/tests/jmc.conf", \
+ "--server", "test2_localhost", \
+ "--port", "43", \
+ "--secret", "test2_secret", \
+ "--service-jid", "test2_jmc.localhost", \
+ "--language", "test2_en", \
+ "--db-url", "sqlite:///tmp/test_jmc.db", \
+ "--pid-file", "/tmp/test_jmc.pid", \
+ "--mail-default-encoding", "test2_iso-8859-1", \
+ "--check-interval", "4"]
+ self.runner.configure()
+ self.assertEquals(self.runner.server, "test2_localhost")
+ self.assertEquals(self.runner.port, 43)
+ self.assertEquals(self.runner.secret, "test2_secret")
+ self.assertEquals(self.runner.service_jid, "test2_jmc.localhost")
+ self.assertEquals(self.runner.language, "test2_en")
+ self.assertEquals(self.runner.db_url, "sqlite:///tmp/test_jmc.db")
+ self.assertEquals(self.runner.pid_file, "/tmp/test_jmc.pid")
+ self.assertFalse(self.runner.debug)
+ self.assertEquals(self.runner.mail_default_encoding, "test2_iso-8859-1")
+ self.assertEquals(self.runner.check_interval, 4)
+
+ def test__run(self):
+ self.runner.pid_file = "/tmp/jmc.pid"
+ self.runner.db_url = DB_URL
+ def do_nothing():
+ pass
+ self.runner._run(do_nothing)
+ account.hub.threadConnection = connectionForURI(self.runner.db_url)
+ # dropTable should succeed because tables should exist
+ Account.dropTable()
+ PresenceAccount.dropTable()
+ MailAccount.dropTable()
+ IMAPAccount.dropTable()
+ POP3Account.dropTable()
+ del account.hub.threadConnection
+ os.unlink(DB_PATH)
+ self.assertFalse(os.access("/tmp/jmc.pid", os.F_OK))
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(JMCRunner_TestCase, 'test'))
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='suite')
+