26 MDBOX_NAME = 'mdbox' |
25 MDBOX_NAME = 'mdbox' |
27 SDBOX_NAME = 'dbox' |
26 SDBOX_NAME = 'dbox' |
28 |
27 |
29 _storage = { |
28 _storage = { |
30 MAILDIR_ID: dict(dovecot_version=10, postfix=True, prefix='maildir:', |
29 MAILDIR_ID: dict(dovecot_version=10, postfix=True, prefix='maildir:', |
31 directory=MAILDIR_NAME), |
30 directory=MAILDIR_NAME, mid=MAILDIR_ID), |
32 MBOX_ID: dict(dovecot_version=10, postfix=True, prefix='mbox:', |
31 MBOX_ID: dict(dovecot_version=10, postfix=True, prefix='mbox:', |
33 directory=MBOX_NAME), |
32 directory=MBOX_NAME, mid=MBOX_ID), |
34 MDBOX_ID: dict(dovecot_version=20, postfix=False, prefix='mdbox:', |
33 MDBOX_ID: dict(dovecot_version=20, postfix=False, prefix='mdbox:', |
35 directory=MDBOX_NAME), |
34 directory=MDBOX_NAME, mid=MDBOX_ID), |
36 SDBOX_ID: dict(dovecot_version=12, postfix=False, prefix='dbox:', |
35 SDBOX_ID: dict(dovecot_version=12, postfix=False, prefix='dbox:', |
37 directory=SDBOX_NAME), |
36 directory=SDBOX_NAME, mid=SDBOX_ID), |
38 } |
37 } |
39 |
38 |
40 _type_id = { |
39 _format_id = { |
41 'maildir': MAILDIR_ID, |
40 'maildir': MAILDIR_ID, |
42 MBOX_NAME: MBOX_ID, |
41 'mbox': MBOX_ID, |
43 MDBOX_NAME: MDBOX_ID, |
42 'mdbox': MDBOX_ID, |
44 SDBOX_NAME: SDBOX_ID, |
43 'dbox': SDBOX_ID, |
45 } |
44 } |
46 |
45 |
47 |
46 |
48 class MailLocation(object): |
47 class MailLocation(object): |
49 """A small class for mail_location relevant information.""" |
48 """A small class for mail_location relevant information.""" |
50 __slots__ = ('_info') |
49 __slots__ = ('_info') |
51 |
50 |
52 def __init__(self, mid=None, type_=None): |
51 def __init__(self, mid=None, format=None): |
53 """Creates a new MailLocation instance. |
52 """Creates a new MailLocation instance. |
54 |
53 |
55 Either mid or type_ must be specified. |
54 Either a mid or the format must be specified. |
56 |
55 |
57 Keyword arguments: |
56 Keyword arguments: |
58 mid -- the id of a mail_location (int) |
57 mid -- the id of a mail_location (int) |
59 one of the maillocation constants: `MAILDIR_ID`, `MBOX_ID`, |
58 one of the maillocation constants: `MAILDIR_ID`, `MBOX_ID`, |
60 `MDBOX_ID` and `SDBOX_ID` |
59 `MDBOX_ID` and `SDBOX_ID` |
61 type_ -- the type/mailbox format of the mail_location (str) |
60 format -- the mailbox format of the mail_location. One out of: |
62 one of the maillocation constants: `MAILDIR_NAME`, `MBOX_NAME`, |
61 ``maildir``, ``mbox``, ``dbox`` and ``mdbox``. |
63 `MDBOX_NAME` and `SDBOX_NAME` |
|
64 """ |
62 """ |
65 assert any((mid, type_)) |
63 assert any((mid, format)) |
66 if mid: |
64 if mid: |
67 assert isinstance(mid, (int, long)) and mid in _storage |
65 assert isinstance(mid, (int, long)) and mid in _storage |
68 self._info = _storage[mid] |
66 self._info = _storage[mid] |
69 else: |
67 else: |
70 assert isinstance(type_, basestring) and type_.lower() in _type_id |
68 assert isinstance(format, basestring) and \ |
71 self._info = _storage[_type_id[type_.lower()]] |
69 format.lower() in _format_id |
|
70 self._info = _storage[_format_id[format.lower()]] |
72 |
71 |
73 def __str__(self): |
72 def __str__(self): |
74 return '%(prefix)s~/%(directory)s' % self._info |
73 return '%(prefix)s~/%(directory)s' % self._info |
75 |
74 |
76 @property |
75 @property |