author | Pascal Volk <neverseen@users.sourceforge.net> |
Sat, 24 Apr 2010 02:49:45 +0000 | |
branch | v0.6.x |
changeset 262 | 6eea85d8b91d |
parent 228 | a7b000ca4ac9 |
child 264 | 04fea4d8b900 |
permissions | -rw-r--r-- |
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 |
|
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
16 |
__all__ = ('MailLocation', 'known_format', |
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
17 |
'MAILDIR_ID', 'MBOX_ID', 'MDBOX_ID', 'SDBOX_ID') |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
18 |
|
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
19 |
MAILDIR_ID = 0x1 |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
20 |
MBOX_ID = 0x2 |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
21 |
MDBOX_ID = 0x3 |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
22 |
SDBOX_ID = 0x4 |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
23 |
MAILDIR_NAME = 'Maildir' |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
24 |
MBOX_NAME = 'mail' |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
25 |
MDBOX_NAME = 'mdbox' |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
26 |
SDBOX_NAME = 'dbox' |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
27 |
|
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
28 |
_storage = { |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
29 |
MAILDIR_ID: dict(dovecot_version=10, postfix=True, prefix='maildir:', |
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
30 |
directory=MAILDIR_NAME, mid=MAILDIR_ID), |
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
31 |
MBOX_ID: dict(dovecot_version=10, postfix=True, prefix='mbox:', |
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
32 |
directory=MBOX_NAME, mid=MBOX_ID), |
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
33 |
MDBOX_ID: dict(dovecot_version=20, postfix=False, prefix='mdbox:', |
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
34 |
directory=MDBOX_NAME, mid=MDBOX_ID), |
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
35 |
SDBOX_ID: dict(dovecot_version=12, postfix=False, prefix='dbox:', |
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
36 |
directory=SDBOX_NAME, mid=SDBOX_ID), |
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
37 |
} |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
38 |
|
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
39 |
_format_id = { |
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
40 |
'maildir': MAILDIR_ID, |
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
41 |
'mbox': MBOX_ID, |
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
42 |
'mdbox': MDBOX_ID, |
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
43 |
'dbox': SDBOX_ID, |
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
44 |
} |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
45 |
|
69
0c124160a991
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
46 |
|
122
30abf0abf8f8
Converted to new-style class, added __slots__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
47 |
class MailLocation(object): |
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
48 |
"""A small class for mail_location relevant information.""" |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
49 |
__slots__ = ('_info') |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
50 |
|
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
51 |
def __init__(self, mid=None, format=None): |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
52 |
"""Creates a new MailLocation instance. |
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
53 |
|
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
54 |
Either a mid or the format must be specified. |
122
30abf0abf8f8
Converted to new-style class, added __slots__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
55 |
|
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
56 |
Keyword arguments: |
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
57 |
mid -- the id of a mail_location (int) |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
58 |
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
|
59 |
`MDBOX_ID` and `SDBOX_ID` |
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
60 |
format -- the mailbox format of the mail_location. One out of: |
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
61 |
``maildir``, ``mbox``, ``dbox`` and ``mdbox``. |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
62 |
""" |
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
63 |
assert any((mid, format)) |
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
64 |
if mid: |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
65 |
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
|
66 |
self._info = _storage[mid] |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
67 |
else: |
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
68 |
assert isinstance(format, basestring) and \ |
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
69 |
format.lower() in _format_id |
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
70 |
self._info = _storage[_format_id[format.lower()]] |
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
71 |
|
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
72 |
def __str__(self): |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
73 |
return '%(prefix)s~/%(directory)s' % self._info |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
74 |
|
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
75 |
@property |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
76 |
def directory(self): |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
77 |
"""The mail_location's directory name.""" |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
78 |
return self._info['directory'] |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
79 |
|
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
80 |
@property |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
81 |
def dovecot_version(self): |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
82 |
"""The required Dovecot version (concatenated major and minor |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
83 |
parts) for this mailbox format.""" |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
84 |
return self._info['dovecot_version'] |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
85 |
|
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
86 |
@property |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
87 |
def postfix(self): |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
88 |
"""`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
|
89 |
return self._info['postfix'] |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
90 |
|
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
91 |
@property |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
92 |
def prefix(self): |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
93 |
"""The prefix of the mail_location.""" |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
94 |
return self._info['prefix'] |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
95 |
|
226
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
96 |
@property |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
97 |
def mail_location(self): |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
98 |
"""The mail_location, e.g. ``maildir:~/Maildir``""" |
311eee429f67
VMM/maillocation: rewrote MailLocation class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
99 |
return self.__str__() |
227
87db9f1f95ea
VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
226
diff
changeset
|
100 |
|
87db9f1f95ea
VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
226
diff
changeset
|
101 |
@property |
87db9f1f95ea
VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
226
diff
changeset
|
102 |
def mid(self): |
87db9f1f95ea
VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
226
diff
changeset
|
103 |
"""The mail_location's unique ID.""" |
228
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
104 |
return self._info['mid'] |
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
105 |
|
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
106 |
|
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
107 |
def known_format(format): |
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
108 |
"""Checks if the mailbox *format* is known, returns bool.""" |
a7b000ca4ac9
VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
227
diff
changeset
|
109 |
return format.lower() in _format_id |