Changeset 16:cd4170142d87 in mailjam for mailjam


Ignore:
Timestamp:
May 22, 2012, 9:31:15 AM (12 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

Renamed the project to Mailjam

Location:
mailjam
Files:
18 moved

Legend:

Unmodified
Added
Removed
  • mailjam/__init__.py

    r4 r16  
    11# -*- coding: utf-8 -*-
    22
    3 from models import Member, MailingList
    4 from storage import JsonStorage
     3from mailjam.models import Member, MailingList
     4from mailjam.storage import JsonStorage
  • mailjam/config.py

    r15 r16  
    22
    33"""
    4 The postman project - config.py
     4The mailjam project - config.py
    55
    66This file is released under the BSD license, see LICENSE for
     
    1717    def __init__(self, configfile=None):
    1818        self.configfile = configfile
    19         self.default_paths = ['/usr/local/etc/postman', '/usr/local/etc',
    20                               '/etc/postman', '/etc',
     19        self.default_paths = ['/usr/local/etc/mailjam', '/usr/local/etc',
     20                              '/etc/mailjam', '/etc',
    2121                              os.path.join(os.path.dirname(__file__),'../conf')]
    2222        self.config = {}
     
    2828        of an attribute for easier subclassing
    2929        """
    30         return 'postman.conf'
     30        return 'mailjam.conf'
    3131
    3232    @property
     
    8787    @property
    8888    def default_filename(self):
    89         return 'postman-mta.conf'
     89        return 'mailjam-mta.conf'
    9090
    9191    @property
  • mailjam/daemon.py

    r15 r16  
    44from SimpleXMLRPCServer import SimpleXMLRPCServer, list_public_methods
    55
    6 from postman import config
    7 from postman.models import Member, MailingList
    8 from postman.storage import JsonStorage as Storage
    9 
    10 
    11 class Postman():
     6from mailjam import config
     7from mailjam.models import Member, MailingList
     8from mailjam.storage import JsonStorage as Storage
     9
     10
     11class Mailjam():
    1212
    1313    def __init__(self, configfile=None):
     
    3333        if self.mailings:
    3434            # Save the config file from where we can reload information about
    35             # the mailing lists managed by this postman instance
     35            # the mailing lists managed by this mailjam instance
    3636            self.dbs['mailings'].write(self.mailings_addresses)
    3737            # Save each mailing list data into its separated persistence file
     
    6464        Delete all stored data from disk (useful for testing).
    6565        DANGER: Calling this method will remove all data from disk, leaving the
    66         postman instance with no persistence data, if the postman process die,
     66        mailjam instance with no persistence data, if the mailjam process die,
    6767        before another .save() call is made, all data will be lost.
    6868        """
     
    7676    def add_mailing_list(self, info={}):
    7777        """
    78         Add a new mailing list to this postman instance. expects one parameter,
     78        Add a new mailing list to this mailjam instance. expects one parameter,
    7979        info, which is a dictionary that should contain, at least, the
    8080        following keys:
     
    9696        if info['address'] in self.mailings_addresses:
    9797            raise IndexError(info['address'],
    98                              ' has been already added to postman')
     98                             ' has been already added to mailjam')
    9999
    100100        mailing = MailingList(info['name'], info['address'],
     
    109109        """
    110110        Add a new member for the mailing list represented by list_addr (a string
    111         containing the email address of any mailing list managed by this postman
     111        containing the email address of any mailing list managed by this mailjam
    112112        instance). member_addr is a string representing the email address of the
    113113        new member
     
    130130
    131131
    132 class PostmanXMLRPC():
     132class MailjamXMLRPC():
    133133    """
    134134    This class is a wrapper we will use to limit the methods that will be
     
    159159class MailingListXMLRPC():
    160160    def __init__(self):
    161         self.postman = Postman()
    162         self.postman.load()
     161        self.mailjam = Mailjam()
     162        self.mailjam.load()
    163163    def add(self, info={}):
    164         self.postman.add_mailing_list(info)
     164        self.mailjam.add_mailing_list(info)
    165165    def addresses(self):
    166         return self.postman.mailings_addresses   
     166        return self.mailjam.mailings_addresses   
    167167
    168168
    169169class MemberXMLRPC():
    170170    def __init__(self):
    171         self.postman = Postman()
    172         self.postman.load()
     171        self.mailjam = Mailjam()
     172        self.mailjam.load()
    173173    def add(self, member_addr=None, list_addr=None):
    174         self.postman.add_mailing_member(member_addr, list_addr)
     174        self.mailjam.add_mailing_member(member_addr, list_addr)
    175175    def list(self, mailing):
    176         if mailing in self.postman.mailings_addresses:
    177             return self.postman.mailings[mailing].members_addresses()
    178 
    179 
    180 class PostmanDaemon():
     176        if mailing in self.mailjam.mailings_addresses:
     177            return self.mailjam.mailings[mailing].members_addresses()
     178
     179
     180class MailjamDaemon():
    181181    def __init__(self, configfile=None):
    182182        self.config = config.get_config_parameters('xmlrpc_server', configfile)
     
    211211        """
    212212        Check if there is an initialized server (initialize it if there is none)
    213         and then register all the Postman public methods to be served through
     213        and then register all the Mailjam public methods to be served through
    214214        the xml-rpc link
    215215
     
    221221        msg = 'Registering public methods'
    222222        logging.info(msg)
    223         root = PostmanXMLRPC()
     223        root = MailjamXMLRPC()
    224224        root.lists = MailingListXMLRPC()
    225225        root.members = MemberXMLRPC()
  • mailjam/models.py

    r11 r16  
    22
    33"""
    4 The postman project - models.py
     4The mailjam project - models.py
    55
    66This file is released under the BSD license, see LICENSE for
     
    109109    def info(self):
    110110        """
    111         Returns a dict we can use to add this mailing list to a postman
     111        Returns a dict we can use to add this mailing list to a mailjam
    112112        instance
    113113        """
  • mailjam/mta.py

    r15 r16  
    22
    33"""
    4 The postman project - mta.py
     4The mailjam project - mta.py
    55
    66This file is released under the BSD license, see LICENSE for
     
    1313import os, sys, email, smtplib, xmlrpclib
    1414from datetime import datetime
    15 from postman.models import MailingList
    16 from postman.config import MTAClientConfig
    17 from postman.tools import validate_email_address
     15from mailjam.models import MailingList
     16from mailjam.config import MTAClientConfig
     17from mailjam.tools import validate_email_address
    1818
    1919class MTAClient():
  • mailjam/storage.py

    r11 r16  
    22
    33"""
    4 The postman project - storage.py
     4The mailjam project - storage.py
    55
    66This file is released under the BSD license, see LICENSE for
  • mailjam/tests/__init__.py

    r15 r16  
    22
    33"""
    4 The postman project - tests module
     4The mailjam project - tests module
    55
    66This file is released under the BSD license, see LICENSE for
  • mailjam/tests/daemon.py

    r11 r16  
    22
    33"""
    4 The postman project - daemon.py
     4The mailjam project - daemon.py
    55
    66This file is released under the BSD license, see LICENSE for
     
    1515from unittest import TestCase
    1616
    17 from postman.daemon import Postman, PostmanXMLRPC, PostmanDaemon
    18 from postman.models import Member, MailingList
    19 from postman.storage import JsonStorage as Storage
    20 
    21 
    22 class TestPostman(TestCase):
    23     """
    24     postman.daemon.Postman tests.
    25 
    26     Remember to call the .clear() method of postman after each test, so
     17from mailjam.daemon import Mailjam, MailjamXMLRPC, MailjamDaemon
     18from mailjam.models import Member, MailingList
     19from mailjam.storage import JsonStorage as Storage
     20
     21
     22class TestMailjam(TestCase):
     23    """
     24    mailjam.daemon.Mailjam tests.
     25
     26    Remember to call the .clear() method of mailjam after each test, so
    2727    the temp storage files are deleted
    2828    """
    2929    def setUp(self):
    30         self.configfile = os.path.join(os.path.dirname(__file__), 'postman.conf')
     30        self.configfile = os.path.join(os.path.dirname(__file__), 'mailjam.conf')
    3131        self.mailing_list = MailingList('test_list', 'test_list@example.com',
    3232                                        members={}, configfile=self.configfile)
     
    3434
    3535    def test___init__(self):
    36         postman = Postman(configfile=self.configfile)
    37         self.assertIsInstance(postman, Postman)
    38         self.assertEqual(postman.mailings, {})
    39         self.assertEqual(postman.mailings_addresses, [])
    40         self.assertIsInstance(postman.dbs, dict)
    41         self.assertTrue('mailings' in postman.dbs.keys())
    42         self.assertTrue('members' in postman.dbs.keys())
    43         self.assertIsInstance(postman.dbs['mailings'], Storage)
    44         self.assertIsInstance(postman.dbs['members'], Storage)
     36        mailjam = Mailjam(configfile=self.configfile)
     37        self.assertIsInstance(mailjam, Mailjam)
     38        self.assertEqual(mailjam.mailings, {})
     39        self.assertEqual(mailjam.mailings_addresses, [])
     40        self.assertIsInstance(mailjam.dbs, dict)
     41        self.assertTrue('mailings' in mailjam.dbs.keys())
     42        self.assertTrue('members' in mailjam.dbs.keys())
     43        self.assertIsInstance(mailjam.dbs['mailings'], Storage)
     44        self.assertIsInstance(mailjam.dbs['members'], Storage)
    4545
    4646    def test_save(self):
    47         postman = Postman(configfile=self.configfile)
    48         self.assertFalse(postman.save())
    49         postman.add_mailing_list(self.mailing_list.info())
    50         self.assertTrue(postman.save())
     47        mailjam = Mailjam(configfile=self.configfile)
     48        self.assertFalse(mailjam.save())
     49        mailjam.add_mailing_list(self.mailing_list.info())
     50        self.assertTrue(mailjam.save())
    5151        # FIXME: We have to test here that the generated json file
    5252        # contains the data it should contain
    5353
    5454        # Clear the files created by the tests
    55         postman.clear()
     55        mailjam.clear()
    5656
    5757    def test_load(self):
    58         postman = Postman(configfile=self.configfile)
    59         self.assertFalse(postman.mailings)
    60         self.assertFalse(postman.mailings_addresses)
    61         self.assertFalse(postman.load())
    62         postman.add_mailing_list(self.mailing_list.info())
    63         self.assertTrue(postman.load())
    64 
    65         # Check that another postman instance is able to load the saved data
    66         postman_load = Postman(configfile=self.configfile)
    67         self.assertFalse(postman_load.mailings)
    68         self.assertFalse(postman_load.mailings_addresses)
    69         postman_load.load()
    70         self.assertTrue(postman_load.mailings)
    71         self.assertIsInstance(postman_load.mailings, dict)
    72         self.assertTrue(postman_load.mailings_addresses)
    73         self.assertIsInstance(postman_load.mailings_addresses, list)       
    74 
    75         # Clear the files created by the tests
    76         postman.clear()
     58        mailjam = Mailjam(configfile=self.configfile)
     59        self.assertFalse(mailjam.mailings)
     60        self.assertFalse(mailjam.mailings_addresses)
     61        self.assertFalse(mailjam.load())
     62        mailjam.add_mailing_list(self.mailing_list.info())
     63        self.assertTrue(mailjam.load())
     64
     65        # Check that another mailjam instance is able to load the saved data
     66        mailjam_load = Mailjam(configfile=self.configfile)
     67        self.assertFalse(mailjam_load.mailings)
     68        self.assertFalse(mailjam_load.mailings_addresses)
     69        mailjam_load.load()
     70        self.assertTrue(mailjam_load.mailings)
     71        self.assertIsInstance(mailjam_load.mailings, dict)
     72        self.assertTrue(mailjam_load.mailings_addresses)
     73        self.assertIsInstance(mailjam_load.mailings_addresses, list)       
     74
     75        # Clear the files created by the tests
     76        mailjam.clear()
    7777
    7878    def test_clear(self):
    79         postman = Postman(configfile=self.configfile)
    80         self.assertFalse(postman.clear())
    81         postman.add_mailing_list(self.mailing_list.info())
    82         self.assertTrue(postman.clear())
     79        mailjam = Mailjam(configfile=self.configfile)
     80        self.assertFalse(mailjam.clear())
     81        mailjam.add_mailing_list(self.mailing_list.info())
     82        self.assertTrue(mailjam.clear())
    8383
    8484    def test_add_mailing_list(self):
    85         postman = Postman(configfile=self.configfile)
     85        mailjam = Mailjam(configfile=self.configfile)
    8686        with self.assertRaises(TypeError):
    8787            # test improper info values
    88             postman.add_mailing_list(['a list', 'is an', 'invalid parameter'])
    89             postman.add_mailing_list(self.mailing_list)
     88            mailjam.add_mailing_list(['a list', 'is an', 'invalid parameter'])
     89            mailjam.add_mailing_list(self.mailing_list)
    9090        with self.assertRaises(ValueError):
    9191            #test incomplete/missing info values
    92             postman.add_mailing_list()
    93             postman.add_mailing_list({'name': 'missing info'})
    94             postman.add_mailing_list({'address': 'missing info'})
    95             postman.add_mailing_list({'name': 'missing info',
     92            mailjam.add_mailing_list()
     93            mailjam.add_mailing_list({'name': 'missing info'})
     94            mailjam.add_mailing_list({'address': 'missing info'})
     95            mailjam.add_mailing_list({'name': 'missing info',
    9696                                      'address': 'missing info'})
    9797        # test mailing lists can be added
    98         self.assertTrue(postman.add_mailing_list(self.mailing_list.info()))
    99         self.assertTrue(postman.mailings)
    100         self.assertIsInstance(postman.mailings, dict)
    101         self.assertTrue(postman.mailings_addresses)
    102         self.assertIsInstance(postman.mailings_addresses, list)
     98        self.assertTrue(mailjam.add_mailing_list(self.mailing_list.info()))
     99        self.assertTrue(mailjam.mailings)
     100        self.assertIsInstance(mailjam.mailings, dict)
     101        self.assertTrue(mailjam.mailings_addresses)
     102        self.assertIsInstance(mailjam.mailings_addresses, list)
    103103        with self.assertRaises(IndexError):
    104104            # test what happens when the mailing has been already added
    105             postman.add_mailing_list(self.mailing_list.info())
    106 
    107         # Clear the files created by the tests
    108         postman.clear()
     105            mailjam.add_mailing_list(self.mailing_list.info())
     106
     107        # Clear the files created by the tests
     108        mailjam.clear()
    109109
    110110    def test_add_mailing_member(self):
    111         postman = Postman(configfile=self.configfile)
    112         postman.add_mailing_list(self.mailing_list.info())
     111        mailjam = Mailjam(configfile=self.configfile)
     112        mailjam.add_mailing_list(self.mailing_list.info())
    113113        with self.assertRaises(ValueError):
    114114            # test what happens if we call the method without proper
    115115            # parameters
    116             postman.add_mailing_member()
    117             postman.add_mailing_member(None, None)
    118             postman.add_mailing_member(None, 'test_list@example.net')
    119             postman.add_mailing_member('test@example.net', None)
    120             postman.add_mailing_member('test@example', 'test_list@example.net')
     116            mailjam.add_mailing_member()
     117            mailjam.add_mailing_member(None, None)
     118            mailjam.add_mailing_member(None, 'test_list@example.net')
     119            mailjam.add_mailing_member('test@example.net', None)
     120            mailjam.add_mailing_member('test@example', 'test_list@example.net')
    121121        with self.assertRaises(IndexError):
    122122            # test if we try to add a member to a non-existing mailing list
    123             postman.add_mailing_member('test@example.net',
     123            mailjam.add_mailing_member('test@example.net',
    124124                                       'test_list_b@example.net')
    125125        # Test adding a member
    126         self.assertTrue(postman.add_mailing_member('test@example.net',
     126        self.assertTrue(mailjam.add_mailing_member('test@example.net',
    127127                                                   self.mailing_list.address))
    128128        # Test trying to re-add that user
    129         self.assertFalse(postman.add_mailing_member('test@example.net',
     129        self.assertFalse(mailjam.add_mailing_member('test@example.net',
    130130                                                    self.mailing_list.address))
    131131
    132132        # Clear the files created by the tests
    133         postman.clear()
    134 
    135 
    136 class TestPostmanDaemon(TestCase):
    137     """
    138     postman.daemon.PostmanDaemon tests.
    139 
    140     Remember to call the .clear() method of postman after each test, so
     133        mailjam.clear()
     134
     135
     136class TestMailjamDaemon(TestCase):
     137    """
     138    mailjam.daemon.MailjamDaemon tests.
     139
     140    Remember to call the .clear() method of mailjam after each test, so
    141141    the temp storage files are deleted
    142142    """
    143143    def setUp(self):
    144144        self.configfile = os.path.join(os.path.dirname(__file__),
    145                                        'postman.conf')
     145                                       'mailjam.conf')
    146146        self.mailing_list = MailingList('test_xmlrpc',
    147147                                        'test_xmlrpc@example.com', members={},
     
    150150
    151151    def test___init__(self):
    152         daemon = PostmanDaemon(self.configfile)
    153         self.assertIsInstance(daemon, PostmanDaemon)
     152        daemon = MailjamDaemon(self.configfile)
     153        self.assertIsInstance(daemon, MailjamDaemon)
    154154        self.assertFalse(daemon.ready_to_serve)
    155155        # FIXME: More tests should be added here once the configuration
     
    157157
    158158    def test_create_server(self):
    159         daemon = PostmanDaemon(self.configfile)
     159        daemon = MailjamDaemon(self.configfile)
    160160        daemon.port = 9001
    161161        self.assertTrue(daemon.create_server())
     
    164164       
    165165    def test_add_methods(self):
    166         daemon = PostmanDaemon(self.configfile)
     166        daemon = MailjamDaemon(self.configfile)
    167167        daemon.port = 9002
    168168        self.assertTrue(daemon.add_methods())
    169169        self.assertTrue(daemon.ready_to_serve)
    170170
    171         daemon = PostmanDaemon(self.configfile)
     171        daemon = MailjamDaemon(self.configfile)
    172172        daemon.port = 9003       
    173173        daemon.create_server()
     
    176176       
    177177    def test_run(self):
    178         daemon = PostmanDaemon(self.configfile)
     178        daemon = MailjamDaemon(self.configfile)
    179179        daemon.port = 9004
    180180        # start the daemon in another process, so we can start communicating
     
    193193        # available public methods contains the list of methods we have
    194194        # defined in our base XMLRPC class
    195         set_class_methods = set(PostmanXMLRPC()._listMethods())
     195        set_class_methods = set(MailjamXMLRPC()._listMethods())
    196196        set_xmlrpc_methods = set(client.system.listMethods())
    197197        self.assertTrue(set_class_methods.issubset(set_xmlrpc_methods))
  • mailjam/tests/mailjam-mta.conf

    r15 r16  
    11#
    2 # postman-mta.conf - Postman MTA client configuration file
     2# mailjam-mta.conf - Mailjam MTA client configuration file
    33#
    44
     
    1111[archive]
    1212persistent = true
    13 path = /tmp/postman-tests/mta/archive
     13path = /tmp/mailjam-tests/mta/archive
  • mailjam/tests/mailjam.conf

    r13 r16  
    11#
    2 # postman.conf - Postman configuration file
     2# mailjam.conf - Mailjam configuration file
    33#
    44# IMPORTANT: This config file should be used only
     
    99port = 9876
    1010ssl = false
    11 ssl_key = /usr/local/etc/postman/ssl/postman.key
    12 ssl_crt = /usr/local/etc/postman/ssl/postman.crt
    13 logfile = /tmp/postman-tests/xmlrpc_server.log
     11ssl_key = /usr/local/etc/mailjam/ssl/mailjam.key
     12ssl_crt = /usr/local/etc/mailjam/ssl/mailjam.crt
     13logfile = /tmp/mailjam-tests/xmlrpc_server.log
    1414
    1515[storage]
    1616backend = json
    17 path = /tmp/postman-tests/storage
     17path = /tmp/mailjam-tests/storage
    1818lists_db = %(path)s/mailings.%(backend)s
    1919members_db = %(path)s/members.%(backend)s
     
    2222enabled = true
    2323backend = json
    24 path = /tmp/postman-tests/archives
     24path = /tmp/mailjam-tests/archives
    2525
    2626[mailing_lists]
  • mailjam/tests/models.py

    r10 r16  
    33import os
    44from unittest import TestCase
    5 from postman.models import Member, MailingList
     5from mailjam.models import Member, MailingList
    66
    77
     
    1919class TestMailingList(TestCase):
    2020    def setUp(self):
    21         configfile = os.path.join(os.path.dirname(__file__), 'postman.conf')
     21        configfile = os.path.join(os.path.dirname(__file__), 'mailjam.conf')
    2222        self.mailing_list = MailingList('test_list', 'test_list@example.com',
    2323                                        members={}, configfile=configfile)
  • mailjam/tests/mta.py

    r15 r16  
    33import os, sys, multiprocessing, time
    44from unittest import TestCase
    5 from postman.mta import MTAClient
    6 from postman.daemon import PostmanDaemon
    7 from postman.models import Member, MailingList
     5from mailjam.mta import MTAClient
     6from mailjam.daemon import MailjamDaemon
     7from mailjam.models import Member, MailingList
    88
    99
     
    1111    """
    1212    FIXME: These are dummy tests, they cover almost nothing from the
    13     real postman mta client (yet)
     13    real mailjam mta client (yet)
    1414    """
    1515    def setUp(self):
    1616        self.mta_configfile = os.path.join(os.path.dirname(__file__),
    17                                            'postman-mta.conf')
     17                                           'mailjam-mta.conf')
    1818        self.configfile = os.path.join(os.path.dirname(__file__),
    19                                        'postman.conf')
     19                                       'mailjam.conf')
    2020        self.mailing_list = MailingList('test_list', 'test_list@example.com',
    2121                                        members={}, configfile=self.configfile)
     
    2828
    2929    def test___init__(self):
    30         # in order to start mta client instances, we need to have a postman
     30        # in order to start mta client instances, we need to have a mailjam
    3131        # daemon running on the background
    3232        # This should be added to the setUp() method, but then it would be
    3333        # more difficult to terminate the process after all the methods
    3434        # were called
    35         daemon = PostmanDaemon(self.configfile)
     35        daemon = MailjamDaemon(self.configfile)
    3636        daemon.port = 9100
    3737        p = multiprocessing.Process(target=daemon.run)
     
    5454
    5555    def test_get_raw_email(self):
    56         # in order to start mta client instances, we need to have a postman
     56        # in order to start mta client instances, we need to have a mailjam
    5757        # daemon running on the background
    5858        # This should be added to the setUp() method, but then it would be
    5959        # more difficult to terminate the process after all the methods
    6060        # were called
    61         daemon = PostmanDaemon(self.configfile)
     61        daemon = MailjamDaemon(self.configfile)
    6262        daemon.port = 9100
    6363        p = multiprocessing.Process(target=daemon.run)
     
    8888    #    sys_stdin = sys.stdin
    8989    #    sys.stdin = open(self.raw_email_file, 'r')
    90     #    self.mta.save_raw_email.filename = '/tmp/postman-test-mta-save-raw-email'
     90    #    self.mta.save_raw_email.filename = '/tmp/mailjam-test-mta-save-raw-email'
    9191   
    9292       
  • mailjam/tools.py

    r11 r16  
    22
    33"""
    4 The postman project - tools.py
     4The mailjam project - tools.py
    55
    66This file is released under the BSD license, see LICENSE for
Note: See TracChangeset for help on using the changeset viewer.