VirtualMailManager/maillocation.py
author Pascal Volk <neverseen@users.sourceforge.net>
Tue, 02 Mar 2010 19:24:36 +0000
branchv0.6.x
changeset 227 87db9f1f95ea
parent 226 311eee429f67
child 228 a7b000ca4ac9
permissions -rw-r--r--
VMM/Account: Adjusted to changes in maillocation.MailLocation. VMM/maillocation: Class MailLocation added missing property `mid`. Added new error to VMM/constants/ERROR and doc/source/vmm_constants_error
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     1
# -*- coding: UTF-8 -*-
162
0ac9ef587769 Updated copyright notices to include the year 2010.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 138
diff changeset
     2
# Copyright (c) 2008 - 2010, Pascal Volk
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     3
# See COPYING for distribution information.
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     4
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
     5
"""
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
     6
    VirtualMailManager.maillocation
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
     7
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
     8
    Virtual Mail Manager's maillocation module to handle Dovecot's
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
     9
    mail_location setting for accounts.
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    10
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    11
"""
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    12
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    13
from VirtualMailManager.pycompat import any
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    14
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    15
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    16
__all__ = ('MailLocation',
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    17
           'MAILDIR_ID', 'MBOX_ID', 'MDBOX_ID', 'SDBOX_ID',
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    18
           'MAILDIR_NAME', 'MBOX_NAME', 'MDBOX_NAME', 'SDBOX_NAME')
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 162
diff changeset
    19
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    20
MAILDIR_ID = 0x1
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    21
MBOX_ID = 0x2
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    22
MDBOX_ID = 0x3
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    23
SDBOX_ID = 0x4
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    24
MAILDIR_NAME = 'Maildir'
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    25
MBOX_NAME = 'mail'
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    26
MDBOX_NAME = 'mdbox'
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    27
SDBOX_NAME = 'dbox'
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    28
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    29
_storage = {
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    30
    MAILDIR_ID: dict(dovecot_version=10, postfix=True, prefix='maildir:',
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    31
                     directory=MAILDIR_NAME),
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    32
    MBOX_ID: dict(dovecot_version=10, postfix=True, prefix='mbox:',
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    33
                  directory=MBOX_NAME),
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    34
    MDBOX_ID: dict(dovecot_version=20, postfix=False, prefix='mdbox:',
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    35
                   directory=MDBOX_NAME),
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    36
    SDBOX_ID: dict(dovecot_version=12, postfix=False, prefix='dbox:',
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    37
                   directory=SDBOX_NAME),
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    38
}
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    39
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    40
_type_id = {
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    41
    'maildir': MAILDIR_ID,
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    42
    MBOX_NAME: MBOX_ID,
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    43
    MDBOX_NAME: MDBOX_ID,
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    44
    SDBOX_NAME: SDBOX_ID,
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    45
}
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    46
69
0c124160a991 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 48
diff changeset
    47
122
30abf0abf8f8 Converted to new-style class, added __slots__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    48
class MailLocation(object):
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    49
    """A small class for mail_location relevant information."""
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    50
    __slots__ = ('_info')
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    51
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    52
    def __init__(self, mid=None, type_=None):
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    53
        """Creates a new MailLocation instance.
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    54
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    55
        Either mid or type_ must be specified.
122
30abf0abf8f8 Converted to new-style class, added __slots__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
    56
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    57
        Keyword arguments:
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    58
        mid -- the id of a mail_location (int)
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    59
          one of the maillocation constants: `MAILDIR_ID`, `MBOX_ID`,
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    60
          `MDBOX_ID` and `SDBOX_ID`
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    61
        type_ -- the type/mailbox format of the mail_location (str)
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    62
          one of the maillocation constants: `MAILDIR_NAME`, `MBOX_NAME`,
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    63
          `MDBOX_NAME` and `SDBOX_NAME`
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    64
        """
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    65
        assert any((mid, type_))
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    66
        if mid:
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    67
            assert isinstance(mid, (int, long)) and mid in _storage
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    68
            self._info = _storage[mid]
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    69
        else:
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    70
            assert isinstance(type_, basestring) and type_.lower() in _type_id
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    71
            self._info = _storage[_type_id[type_.lower()]]
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    72
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    73
    def __str__(self):
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    74
        return '%(prefix)s~/%(directory)s' % self._info
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    75
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    76
    @property
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    77
    def directory(self):
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    78
        """The mail_location's directory name."""
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    79
        return self._info['directory']
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    80
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    81
    @property
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    82
    def dovecot_version(self):
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    83
        """The required Dovecot version (concatenated major and minor
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    84
        parts) for this mailbox format."""
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    85
        return self._info['dovecot_version']
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    86
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    87
    @property
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    88
    def postfix(self):
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    89
        """`True` if Postfix supports this mailbox format, else `False`."""
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    90
        return self._info['postfix']
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    91
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    92
    @property
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    93
    def prefix(self):
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    94
        """The prefix of the mail_location."""
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    95
        return self._info['prefix']
8
7e3ce56f49e6 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    96
226
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    97
    @property
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    98
    def mail_location(self):
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    99
        """The mail_location, e.g. ``maildir:~/Maildir``"""
311eee429f67 VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   100
        return self.__str__()
227
87db9f1f95ea VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 226
diff changeset
   101
87db9f1f95ea VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 226
diff changeset
   102
    @property
87db9f1f95ea VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 226
diff changeset
   103
    def mid(self):
87db9f1f95ea VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 226
diff changeset
   104
        """The mail_location's unique ID."""
87db9f1f95ea VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 226
diff changeset
   105
        return _type_id[self._info['directory'].lower()]