author | Pascal Volk <user@localhost.localdomain.org> |
Sun, 21 Nov 2021 21:27:53 +0000 | |
branch | v0.7.x |
changeset 759 | 2a23083e2ea3 |
parent 721 | 2f25d1cf8502 |
permissions | -rw-r--r-- |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
1 |
# -*- coding: UTF-8 -*- |
703
58815c004a61
Updated copyright notices to include the year 2014.
Pascal Volk <user@localhost.localdomain.org>
parents:
675
diff
changeset
|
2 |
# Copyright (c) 2010 - 2014, Pascal Volk |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
3 |
# See COPYING for distribution information. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
4 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
5 |
VirtualMailManager.mailbox |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
6 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
7 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
8 |
VirtualMailManager's mailbox classes for the Maildir, single dbox |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
9 |
(sdbox) and multi dbox (mdbox) mailbox formats. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
10 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
11 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
12 |
import os |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
13 |
import re |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
14 |
from binascii import a2b_base64, b2a_base64 |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
15 |
from subprocess import Popen, PIPE |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
16 |
|
660
0bce7e1d1349
VMM/mailbox: Decode error messages from doveadm.
Pascal Volk <user@localhost.localdomain.org>
parents:
653
diff
changeset
|
17 |
from VirtualMailManager import ENCODING |
320
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
18 |
from VirtualMailManager.account import Account |
326
8f8d9c4c8332
VMM/common: Replaced function is_dir() by lisdir().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
323
diff
changeset
|
19 |
from VirtualMailManager.common import lisdir |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
20 |
from VirtualMailManager.errors import VMMError |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
309
diff
changeset
|
21 |
from VirtualMailManager.constants import VMM_ERROR |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
22 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
23 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
24 |
__all__ = ('new', 'Maildir', 'SingleDbox', 'MultiDbox', |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
25 |
'utf8_to_mutf7', 'mutf7_to_utf8') |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
26 |
|
386
b7854259ad74
VMM/mailbox: Added missing dummy translator (_) and comment for
Pascal Volk <neverseen@users.sourceforge.net>
parents:
377
diff
changeset
|
27 |
_ = lambda msg: msg |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
28 |
cfg_dget = lambda option: None |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
29 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
30 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
31 |
def _mbase64_encode(inp, dest): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
32 |
if inp: |
653
cf07e4468934
VMM: Post-2to3 fixes.
Pascal Volk <user@localhost.localdomain.org>
parents:
643
diff
changeset
|
33 |
mb64 = b2a_base64(''.join(inp).encode('utf-16be')).decode() |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
34 |
dest.append('&%s-' % mb64.rstrip('\n=').replace('/', ',')) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
35 |
del inp[:] |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
36 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
37 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
38 |
def _mbase64_to_unicode(mb64): |
653
cf07e4468934
VMM: Post-2to3 fixes.
Pascal Volk <user@localhost.localdomain.org>
parents:
643
diff
changeset
|
39 |
return str(a2b_base64(mb64.replace(',', '/').encode() + b'==='), |
cf07e4468934
VMM: Post-2to3 fixes.
Pascal Volk <user@localhost.localdomain.org>
parents:
643
diff
changeset
|
40 |
'utf-16be') |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
41 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
42 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
43 |
def utf8_to_mutf7(src): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
44 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
45 |
Converts the international mailbox name `src` into a modified |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
46 |
version version of the UTF-7 encoding. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
47 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
48 |
ret = [] |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
49 |
tmp = [] |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
50 |
for c in src: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
51 |
ordc = ord(c) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
52 |
if 0x20 <= ordc <= 0x25 or 0x27 <= ordc <= 0x7E: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
53 |
_mbase64_encode(tmp, ret) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
54 |
ret.append(c) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
55 |
elif ordc == 0x26: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
56 |
_mbase64_encode(tmp, ret) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
57 |
ret.append('&-') |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
58 |
else: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
59 |
tmp.append(c) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
60 |
_mbase64_encode(tmp, ret) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
61 |
return ''.join(ret) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
62 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
63 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
64 |
def mutf7_to_utf8(src): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
65 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
66 |
Converts the mailbox name `src` from modified UTF-7 encoding to UTF-8. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
67 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
68 |
ret = [] |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
69 |
tmp = [] |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
70 |
for c in src: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
71 |
if c == '&' and not tmp: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
72 |
tmp.append(c) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
73 |
elif c == '-' and tmp: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
74 |
if len(tmp) is 1: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
75 |
ret.append('&') |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
76 |
else: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
77 |
ret.append(_mbase64_to_unicode(''.join(tmp[1:]))) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
78 |
tmp = [] |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
79 |
elif tmp: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
80 |
tmp.append(c) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
81 |
else: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
82 |
ret.append(c) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
83 |
if tmp: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
84 |
ret.append(_mbase64_to_unicode(''.join(tmp[1:]))) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
85 |
return ''.join(ret) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
86 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
87 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
88 |
class Mailbox(object): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
89 |
"""Base class of all mailbox classes.""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
90 |
__slots__ = ('_boxes', '_root', '_sep', '_user') |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
642
diff
changeset
|
91 |
FILE_MODE = 0o600 |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
92 |
_ctrl_chr_re = re.compile('[\x00-\x1F\x7F-\x9F]') |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
93 |
_box_name_re = re.compile('^[\x20-\x25\x27-\x7E]+$') |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
94 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
95 |
def __init__(self, account): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
96 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
97 |
Creates a new mailbox instance. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
98 |
Use one of the `Maildir`, `SingleDbox` or `MultiDbox` classes. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
99 |
""" |
326
8f8d9c4c8332
VMM/common: Replaced function is_dir() by lisdir().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
323
diff
changeset
|
100 |
assert isinstance(account, Account) and lisdir(account.home) |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
101 |
self._user = account |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
102 |
self._boxes = [] |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
103 |
self._root = self._user.mail_location.directory |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
104 |
self._sep = '/' |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
105 |
os.chdir(self._user.home) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
106 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
107 |
def _add_boxes(self, mailboxes, subscribe): |
386
b7854259ad74
VMM/mailbox: Added missing dummy translator (_) and comment for
Pascal Volk <neverseen@users.sourceforge.net>
parents:
377
diff
changeset
|
108 |
"""Create all mailboxes from the `mailboxes` list. |
b7854259ad74
VMM/mailbox: Added missing dummy translator (_) and comment for
Pascal Volk <neverseen@users.sourceforge.net>
parents:
377
diff
changeset
|
109 |
If `subscribe` is *True*, the mailboxes will be listed in the |
b7854259ad74
VMM/mailbox: Added missing dummy translator (_) and comment for
Pascal Volk <neverseen@users.sourceforge.net>
parents:
377
diff
changeset
|
110 |
subscriptions file.""" |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
111 |
raise NotImplementedError |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
112 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
113 |
def _validate_box_name(self, name, good, bad): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
114 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
115 |
Validates the mailboxes name `name`. When the name is valid, it |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
116 |
will be added to the `good` set. Invalid mailbox names will be |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
117 |
appended to the `bad` list. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
118 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
119 |
name = name.strip() |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
120 |
if not name: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
121 |
return |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
122 |
if self.__class__._ctrl_chr_re.search(name): # no control chars |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
123 |
bad.append(name) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
124 |
return |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
125 |
if name[0] in (self._sep, '~'): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
126 |
bad.append(name) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
127 |
return |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
128 |
if self._sep == '/': |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
129 |
if '//' in name or '/./' in name or '/../' in name or \ |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
130 |
name.startswith('../'): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
131 |
bad.append(name) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
132 |
return |
415
c7a963e6cf6e
VMM/mailbox: Use the correct mailbox hierarchy separator in
Pascal Volk <neverseen@users.sourceforge.net>
parents:
386
diff
changeset
|
133 |
elif '/' in name or '..' in name: |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
134 |
bad.append(name) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
135 |
return |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
136 |
if not self.__class__._box_name_re.match(name): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
137 |
tmp = utf8_to_mutf7(name) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
138 |
if name == mutf7_to_utf8(tmp): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
139 |
if self._user.mail_location.mbformat == 'maildir': |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
140 |
good.add(tmp) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
141 |
else: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
142 |
good.add(name) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
143 |
return |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
144 |
else: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
145 |
bad.append(name) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
146 |
return |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
147 |
good.add(name) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
148 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
149 |
def add_boxes(self, mailboxes, subscribe): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
150 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
151 |
Create all mailboxes from the `mailboxes` list in the user's |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
152 |
mail directory. When `subscribe` is ``True`` all created mailboxes |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
153 |
will be listed in the subscriptions file. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
154 |
Returns a list of invalid mailbox names, if any. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
155 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
156 |
assert isinstance(mailboxes, list) and isinstance(subscribe, bool) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
157 |
good = set() |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
158 |
bad = [] |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
159 |
for box in mailboxes: |
415
c7a963e6cf6e
VMM/mailbox: Use the correct mailbox hierarchy separator in
Pascal Volk <neverseen@users.sourceforge.net>
parents:
386
diff
changeset
|
160 |
if self._sep == '/': |
c7a963e6cf6e
VMM/mailbox: Use the correct mailbox hierarchy separator in
Pascal Volk <neverseen@users.sourceforge.net>
parents:
386
diff
changeset
|
161 |
box = box.replace('.', self._sep) |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
162 |
self._validate_box_name(box, good, bad) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
163 |
self._add_boxes(good, subscribe) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
164 |
return bad |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
165 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
166 |
def create(self): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
167 |
"""Create the INBOX in the user's mail directory.""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
168 |
raise NotImplementedError |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
169 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
170 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
171 |
class Maildir(Mailbox): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
172 |
"""Class for Maildir++ mailboxes.""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
173 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
174 |
__slots__ = ('_subdirs') |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
175 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
176 |
def __init__(self, account): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
177 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
178 |
Create a new Maildir++ instance. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
179 |
Call the instance's create() method, in order to create the INBOX. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
180 |
For additional mailboxes use the add_boxes() method. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
181 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
182 |
super(self.__class__, self).__init__(account) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
183 |
self._sep = '.' |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
184 |
self._subdirs = ('cur', 'new', 'tmp') |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
185 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
186 |
def _create_maildirfolder_file(self, path): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
187 |
"""Mark the Maildir++ folder as Maildir folder.""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
188 |
maildirfolder_file = os.path.join(self._sep + path, 'maildirfolder') |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
189 |
os.close(os.open(maildirfolder_file, os.O_CREAT | os.O_WRONLY, |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
190 |
self.__class__.FILE_MODE)) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
191 |
os.chown(maildirfolder_file, self._user.uid, self._user.gid) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
192 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
193 |
def _make_maildir(self, path): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
194 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
195 |
Create Maildir++ folders with the cur, new and tmp subdirectories. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
196 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
197 |
mode = cfg_dget('account.directory_mode') |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
198 |
uid = self._user.uid |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
199 |
gid = self._user.gid |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
200 |
os.mkdir(path, mode) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
201 |
os.chown(path, uid, gid) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
202 |
for subdir in self._subdirs: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
203 |
dir_ = os.path.join(path, subdir) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
204 |
os.mkdir(dir_, mode) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
205 |
os.chown(dir_, uid, gid) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
206 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
207 |
def _subscribe_boxes(self): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
208 |
"""Writes all created mailboxes to the subscriptions file.""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
209 |
if not self._boxes: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
210 |
return |
642
4cd9d0a9f42f
Use the with statement for file operations.
Pascal Volk <user@localhost.localdomain.org>
parents:
568
diff
changeset
|
211 |
with open('subscriptions', 'w') as subscriptions: |
4cd9d0a9f42f
Use the with statement for file operations.
Pascal Volk <user@localhost.localdomain.org>
parents:
568
diff
changeset
|
212 |
subscriptions.write('\n'.join(self._boxes)) |
4cd9d0a9f42f
Use the with statement for file operations.
Pascal Volk <user@localhost.localdomain.org>
parents:
568
diff
changeset
|
213 |
subscriptions.write('\n') |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
214 |
os.chown('subscriptions', self._user.uid, self._user.gid) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
215 |
os.chmod('subscriptions', self.__class__.FILE_MODE) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
216 |
del self._boxes[:] |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
217 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
218 |
def _add_boxes(self, mailboxes, subscribe): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
219 |
for mailbox in mailboxes: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
220 |
self._make_maildir(self._sep + mailbox) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
221 |
self._create_maildirfolder_file(mailbox) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
222 |
self._boxes.append(mailbox) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
223 |
if subscribe: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
224 |
self._subscribe_boxes() |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
225 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
226 |
def create(self): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
227 |
"""Creates a Maildir++ INBOX.""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
228 |
self._make_maildir(self._root) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
229 |
os.chdir(self._root) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
230 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
231 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
232 |
class SingleDbox(Mailbox): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
233 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
234 |
Class for (single) dbox mailboxes. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
235 |
See http://wiki.dovecot.org/MailboxFormat/dbox for details. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
236 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
237 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
238 |
__slots__ = () |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
239 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
240 |
def __init__(self, account): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
241 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
242 |
Create a new dbox instance. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
243 |
Call the instance's create() method, in order to create the INBOX. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
244 |
For additional mailboxes use the add_boxes() method. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
245 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
246 |
assert cfg_dget('misc.dovecot_version') >= \ |
721
2f25d1cf8502
VMM/mailbox: s/dovecotpw/doveadm/g
Pascal Volk <user@localhost.localdomain.org>
parents:
711
diff
changeset
|
247 |
account.mail_location.dovecot_version |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
248 |
super(SingleDbox, self).__init__(account) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
249 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
250 |
def _doveadm_create(self, mailboxes, subscribe): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
251 |
"""Wrap around Dovecot's doveadm""" |
721
2f25d1cf8502
VMM/mailbox: s/dovecotpw/doveadm/g
Pascal Volk <user@localhost.localdomain.org>
parents:
711
diff
changeset
|
252 |
cmd_args = [cfg_dget('bin.doveadm'), 'mailbox', 'create', '-u', |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
253 |
str(self._user.address)] |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
254 |
if subscribe: |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
255 |
cmd_args.append('-s') |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
256 |
cmd_args.extend(mailboxes) |
422
33a45e4c80c4
VMM: Deleted a few unused variables.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
415
diff
changeset
|
257 |
process = Popen(cmd_args, stderr=PIPE) |
33a45e4c80c4
VMM: Deleted a few unused variables.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
415
diff
changeset
|
258 |
stderr = process.communicate()[1] |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
259 |
if process.returncode: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
642
diff
changeset
|
260 |
e_msg = _('Failed to create mailboxes: %r\n') % mailboxes |
660
0bce7e1d1349
VMM/mailbox: Decode error messages from doveadm.
Pascal Volk <user@localhost.localdomain.org>
parents:
653
diff
changeset
|
261 |
raise VMMError(e_msg + stderr.strip().decode(ENCODING), VMM_ERROR) |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
262 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
263 |
def create(self): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
264 |
"""Create a dbox INBOX""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
265 |
os.mkdir(self._root, cfg_dget('account.directory_mode')) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
266 |
os.chown(self._root, self._user.uid, self._user.gid) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
267 |
self._doveadm_create(('INBOX',), False) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
268 |
os.chdir(self._root) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
269 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
270 |
def _add_boxes(self, mailboxes, subscribe): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
271 |
self._doveadm_create(mailboxes, subscribe) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
272 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
273 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
274 |
class MultiDbox(SingleDbox): |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
275 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
276 |
Class for multi dbox mailboxes. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
277 |
See http://wiki.dovecot.org/MailboxFormat/dbox#Multi-dbox for details. |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
278 |
""" |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
279 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
280 |
__slots__ = () |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
281 |
|
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
282 |
|
322
94bd10e237e5
VMM/…: More PEP-8 fixes; eliminated __names.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
283 |
def new(account): |
94bd10e237e5
VMM/…: More PEP-8 fixes; eliminated __names.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
284 |
"""Create a new Mailbox instance for the given Account.""" |
94bd10e237e5
VMM/…: More PEP-8 fixes; eliminated __names.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
285 |
mbfmt = account.mail_location.mbformat |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
286 |
if mbfmt == 'maildir': |
322
94bd10e237e5
VMM/…: More PEP-8 fixes; eliminated __names.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
287 |
return Maildir(account) |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
288 |
elif mbfmt == 'mdbox': |
322
94bd10e237e5
VMM/…: More PEP-8 fixes; eliminated __names.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
289 |
return MultiDbox(account) |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
290 |
elif mbfmt == 'sdbox': |
322
94bd10e237e5
VMM/…: More PEP-8 fixes; eliminated __names.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
291 |
return SingleDbox(account) |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
292 |
raise ValueError('unsupported mailbox format: %r' % mbfmt) |
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
293 |
|
386
b7854259ad74
VMM/mailbox: Added missing dummy translator (_) and comment for
Pascal Volk <neverseen@users.sourceforge.net>
parents:
377
diff
changeset
|
294 |
del _, cfg_dget |