Index: bin/postman_server
===================================================================
--- bin/postman_server	(revision 6)
+++ bin/postman_server	(revision 6)
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+#
+# Run the Postman XML-RPC server
+
+from postman.daemon import PostmanDaemon
+
+if __name__ == '__main__':
+    daemon = PostmanDaemon()
+    daemon.run()
Index: postman/daemon.py
===================================================================
--- postman/daemon.py	(revision 5)
+++ postman/daemon.py	(revision 6)
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 
-import os
+import os, inspect, logging
+from SimpleXMLRPCServer import SimpleXMLRPCServer, list_public_methods
 
 from postman import config
@@ -36,6 +37,6 @@
         """
         if self.mailings:
-            # Save the config file from where we can reload information about the
-            # mailing lists managed by this postman instance
+            # Save the config file from where we can reload information about
+            # the mailing lists managed by this postman instance
             self.dbs['mailings'].write(self.mailings_addresses)
             # Save each mailing list data into its separated persistence file
@@ -132,9 +133,106 @@
             self.save()
         return added
-        
-
-
-
-
-
-
+
+
+class PostmanXMLRPC():
+    """
+    This class is a wrapper we will use to limit the methods that will be
+    published through the XMLRPC link. Only the methods from this class
+    will be available through that link.
+
+    As we use dotted names to separate xmlrpc-exported methods into different
+    namespaces, this class contains nothing, it will be used only for
+    method-registering purposes. The MailingListXMLRPC and MemberXMLRPC classes
+    contain the actual methods that are published.
+
+    More information on this approach here:
+
+    http://www.doughellmann.com/PyMOTW/SimpleXMLRPCServer/#exposing-methods-of-objects
+    """
+
+    def _listMethods(self):
+        return list_public_methods(self)
+
+    def _methodHelp(self, method):
+        f = getattr(self, method)
+        return inspect.getdoc(f)
+
+
+class MailingListXMLRPC():
+    def __init__(self):
+        self.postman = Postman()
+        self.postman.load()
+    def add(self, info={}):
+        self.postman.add_mailing_list(info)
+
+
+class MemberXMLRPC():
+    def __init__(self):
+        self.postman = Postman()
+        self.postman.load()
+    def add(self, member_addr=None, list_addr=None):
+        self.postman.add_mailing_member(member_addr, list_addr)
+                  
+
+class PostmanDaemon():
+    def __init__(self, configfile=None):
+        if not configfile:
+            # FIXME: This is not used right now, we are getting the stuff
+            # from postman.config, but we will move configurations to a
+            # external ini-style config file soon
+            configfile = os.path.join(os.path.dirname(__file__),
+                                      '../conf/postman.conf')
+        self.configfile = configfile
+
+        self.logfile = os.path.join(os.path.dirname(__file__), 'server.log')
+        logging.basicConfig(filename=self.logfile, level=logging.DEBUG)
+
+        self.server = None
+        self.ready_to_serve = False
+        
+    def create_server(self):
+        """
+        If there is no server initialized in self.server, create an instance
+        of SimpleXMLRPCServer in that attribute. If there is already a server
+        initialized there, simply return True
+        """
+        address='localhost'
+        port = 9000        
+        if not self.server:
+            msg = 'Creating XMLRPC server object on {}:{}'.format(address,port)
+            logging.info(msg)
+            self.server = SimpleXMLRPCServer((address, port), allow_none=True,
+                                             logRequests=True)
+            self.server.register_introspection_functions()
+        return True
+
+    def add_methods(self):
+        """
+        Check if there is an initialized server (initialize it if there is none)
+        and then register all the Postman public methods to be served through
+        the xml-rpc link
+
+        Once the methods are registered set self.ready_to_serve to True        
+        """
+        if not self.server:
+            # ensure there is an XMLRPC server initialized
+            self.create_server()
+        msg = 'Registering public methods'
+        logging.info(msg)
+        root = PostmanXMLRPC()
+        root.lists = MailingListXMLRPC()
+        root.members = MemberXMLRPC()
+        self.server.register_instance(root, allow_dotted_names=True)
+        self.ready_to_serve = True
+            
+    def run(self):
+        """
+        Run the xmlrpc daemon. If self.ready_to_serve is False, call
+        self.add_methods, which will initialize the server and will register all
+        the public methods into that server
+        """
+        if not self.ready_to_serve:
+            self.add_methods()
+        msg = 'Starting XMLRPC server on {}:{}'.format(address,port)
+        logging.info(msg)
+        self.server.serve_forever()
Index: postman/tests/daemon.py
===================================================================
--- postman/tests/daemon.py	(revision 5)
+++ postman/tests/daemon.py	(revision 6)
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
 
-import os
+import os, xmlrpclib
 from unittest import TestCase
 from postman.daemon import Postman
@@ -121,2 +121,18 @@
         # Clear the files created by the tests
         postman.clear()
+
+
+class TestPostmanDaemon(TestCase):
+    """
+    postman.daemon.PostmanDaemon tests.
+    
+    """
+    def setUp(self):
+        config = {'private': False, 'archive': '/tmp/postman-tests/archive',
+                  'storage': '/tmp/postman-tests/storage'}
+        self.mailing_list = MailingList('test_xmlrpc', 'test_xmlrpc@example.com',
+                                        members={}, config=config)
+        self.member =  Member('test@example.com')
+        # FIXME: Hardcoded url here, should be picked from a config file
+        
+        self.link = xmlrpclib.ServerProxy('http://localhost:9000')
