author | Pascal Volk <neverseen@users.sourceforge.net> |
Wed, 28 Apr 2010 04:12:29 +0000 | |
branch | v0.6.x |
changeset 269 | 188ea8d6072f |
parent 266 | e14c345b44a1 |
child 270 | d3389645a91d |
permissions | -rw-r--r-- |
0
bb0aa2102206
Initial import @sf.net
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:
158
diff
changeset
|
2 |
# Copyright (c) 2007 - 2010, Pascal Volk |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
3 |
# See COPYING for distribution information. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
4 |
|
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
5 |
""" |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
6 |
VirtualMailManager.Handler |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
7 |
|
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
8 |
A wrapper class. It wraps round all other classes and does some |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
9 |
dependencies checks. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
10 |
|
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
11 |
Additionally it communicates with the PostgreSQL database, creates |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
12 |
or deletes directories of domains or users. |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
13 |
""" |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
14 |
|
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
15 |
import os |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
16 |
import re |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
17 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
18 |
from shutil import rmtree |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
19 |
from subprocess import Popen, PIPE |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
20 |
|
241
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
21 |
from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
22 |
|
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
23 |
import VirtualMailManager.constants.ERROR as ERR |
262
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
259
diff
changeset
|
24 |
from VirtualMailManager import ENCODING, set_configuration |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
25 |
from VirtualMailManager.Account import Account |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
26 |
from VirtualMailManager.Alias import Alias |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
27 |
from VirtualMailManager.AliasDomain import AliasDomain |
262
6eea85d8b91d
VMM: moved some non-init functions to the new common module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
259
diff
changeset
|
28 |
from VirtualMailManager.common import exec_ok |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
29 |
from VirtualMailManager.Config import Config as Cfg |
254
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
251
diff
changeset
|
30 |
from VirtualMailManager.Domain import Domain, ace2idna, get_gid |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
31 |
from VirtualMailManager.EmailAddress import EmailAddress |
251
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
32 |
from VirtualMailManager.errors import VMMError, AliasError, DomainError, \ |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
33 |
RelocatedError |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
34 |
from VirtualMailManager.Relocated import Relocated |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
35 |
from VirtualMailManager.Transport import Transport |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
36 |
from VirtualMailManager.ext.Postconf import Postconf |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
37 |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
38 |
|
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
39 |
SALTCHARS = './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
241
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
40 |
RE_DOMAIN_SEARCH = """^[a-z0-9-\.]+$""" |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
41 |
RE_MBOX_NAMES = """^[\x20-\x25\x27-\x7E]*$""" |
251
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
42 |
TYPE_ACCOUNT = 0x1 |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
43 |
TYPE_ALIAS = 0x2 |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
44 |
TYPE_RELOCATED = 0x4 |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
45 |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
46 |
|
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
47 |
class Handler(object): |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
48 |
"""Wrapper class to simplify the access on all the stuff from |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
49 |
VirtualMailManager""" |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
50 |
__slots__ = ('_Cfg', '_cfgFileName', '_dbh', '_scheme', '__warnings', |
174
974bafa59330
VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
168
diff
changeset
|
51 |
'_postconf') |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
52 |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
53 |
def __init__(self, skip_some_checks=False): |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
54 |
"""Creates a new Handler instance. |
188
cf1b5f22dbd2
VMM/Handler: __init__ accepts now a config_type ('default'||'cli').
Pascal Volk <neverseen@users.sourceforge.net>
parents:
187
diff
changeset
|
55 |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
56 |
``skip_some_checks`` : bool |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
57 |
When a derived class knows how to handle all checks this |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
58 |
argument may be ``True``. By default it is ``False`` and |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
59 |
all checks will be performed. |
188
cf1b5f22dbd2
VMM/Handler: __init__ accepts now a config_type ('default'||'cli').
Pascal Volk <neverseen@users.sourceforge.net>
parents:
187
diff
changeset
|
60 |
|
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
61 |
Throws a NotRootError if your uid is greater 0. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
62 |
""" |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
63 |
self._cfgFileName = '' |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
64 |
self.__warnings = [] |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
65 |
self._Cfg = None |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
66 |
self._dbh = None |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
67 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
68 |
if os.geteuid(): |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
69 |
raise NotRootError(_(u"You are not root.\n\tGood bye!\n"), |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
70 |
ERR.CONF_NOPERM) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
71 |
if self.__chkCfgFile(): |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
72 |
self._Cfg = Cfg(self._cfgFileName) |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
73 |
self._Cfg.load() |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
74 |
if not skip_some_checks: |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
75 |
self._Cfg.check() |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
76 |
self._chkenv() |
256
ae80282301a3
VMM: added 'Configuration' variable and set_configuration().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
255
diff
changeset
|
77 |
# will be moved to the new password module and Alias |
ae80282301a3
VMM: added 'Configuration' variable and set_configuration().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
255
diff
changeset
|
78 |
#self._scheme = self._Cfg.dget('misc.password_scheme') |
ae80282301a3
VMM: added 'Configuration' variable and set_configuration().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
255
diff
changeset
|
79 |
#self._postconf = Postconf(self._Cfg.dget('bin.postconf')) |
ae80282301a3
VMM: added 'Configuration' variable and set_configuration().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
255
diff
changeset
|
80 |
set_configuration(self._Cfg) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
81 |
|
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
82 |
def __findCfgFile(self): |
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
83 |
for path in ['/root', '/usr/local/etc', '/etc']: |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
84 |
tmp = os.path.join(path, 'vmm.cfg') |
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
85 |
if os.path.isfile(tmp): |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
86 |
self._cfgFileName = tmp |
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
87 |
break |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
88 |
if not len(self._cfgFileName): |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
89 |
raise VMMError( |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
90 |
_(u"No “vmm.cfg” found in: /root:/usr/local/etc:/etc"), |
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
91 |
ERR.CONF_NOFILE) |
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
92 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
93 |
def __chkCfgFile(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
94 |
"""Checks the configuration file, returns bool""" |
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
95 |
self.__findCfgFile() |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
96 |
fstat = os.stat(self._cfgFileName) |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
97 |
fmode = int(oct(fstat.st_mode & 0777)) |
187
38b9a9859749
VMM/{,cli/Cli}Config: Moved interactive stuff to new CliConfig class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
186
diff
changeset
|
98 |
if fmode % 100 and fstat.st_uid != fstat.st_gid or \ |
38b9a9859749
VMM/{,cli/Cli}Config: Moved interactive stuff to new CliConfig class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
186
diff
changeset
|
99 |
fmode % 10 and fstat.st_uid == fstat.st_gid: |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
100 |
raise PermissionError(_( |
187
38b9a9859749
VMM/{,cli/Cli}Config: Moved interactive stuff to new CliConfig class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
186
diff
changeset
|
101 |
u'fix permissions (%(perms)s) for “%(file)s”\n\ |
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
102 |
`chmod 0600 %(file)s` would be great.') % {'file': |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
103 |
self._cfgFileName, 'perms': fmode}, ERR.CONF_WRONGPERM) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
104 |
else: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
105 |
return True |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
106 |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
107 |
def _chkenv(self): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
108 |
"""""" |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
109 |
basedir = self._Cfg.dget('misc.base_directory') |
168
fd496561acc6
vmm.cfg: a few re-renamed configuration options.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
166
diff
changeset
|
110 |
if not os.path.exists(basedir): |
28
87da30d30fde
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
24
diff
changeset
|
111 |
old_umask = os.umask(0006) |
168
fd496561acc6
vmm.cfg: a few re-renamed configuration options.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
166
diff
changeset
|
112 |
os.makedirs(basedir, 0771) |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
113 |
os.chown(basedir, 0, self._Cfg.dget('misc.gid_mail')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
114 |
os.umask(old_umask) |
168
fd496561acc6
vmm.cfg: a few re-renamed configuration options.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
166
diff
changeset
|
115 |
elif not os.path.isdir(basedir): |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
116 |
raise VMMError(_(u'“%s” is not a directory.\n\ |
168
fd496561acc6
vmm.cfg: a few re-renamed configuration options.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
166
diff
changeset
|
117 |
(vmm.cfg: section "misc", option "base_directory")') % |
fd496561acc6
vmm.cfg: a few re-renamed configuration options.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
166
diff
changeset
|
118 |
basedir, ERR.NO_SUCH_DIRECTORY) |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
119 |
for opt, val in self._Cfg.items('bin'): |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
120 |
try: |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
121 |
exec_ok(val) |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
122 |
except VMMError, e: |
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
123 |
if e.code is ERR.NO_SUCH_BINARY: |
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
124 |
raise VMMError(_(u'“%(binary)s” doesn\'t exist.\n\ |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
125 |
(vmm.cfg: section "bin", option "%(option)s")') % |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
126 |
{'binary': val, 'option': opt}, |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
127 |
ERR.NO_SUCH_BINARY) |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
128 |
elif e.code is ERR.NOT_EXECUTABLE: |
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
129 |
raise VMMError(_(u'“%(binary)s” is not executable.\ |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
130 |
\n(vmm.cfg: section "bin", option "%(option)s")') % |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
131 |
{'binary': val, 'option': opt}, |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
132 |
ERR.NOT_EXECUTABLE) |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
133 |
else: |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
134 |
raise |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
135 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
136 |
def __dbConnect(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
137 |
"""Creates a pyPgSQL.PgSQL.connection instance.""" |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
138 |
if self._dbh is None or (isinstance(self._dbh, PgSQL.Connection) and |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
139 |
not self._dbh._isOpen): |
83
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
140 |
try: |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
141 |
self._dbh = PgSQL.connect( |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
142 |
database=self._Cfg.dget('database.name'), |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
143 |
user=self._Cfg.pget('database.user'), |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
144 |
host=self._Cfg.dget('database.host'), |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
145 |
password=self._Cfg.pget('database.pass'), |
83
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
146 |
client_encoding='utf8', unicode_results=True) |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
147 |
dbc = self._dbh.cursor() |
83
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
148 |
dbc.execute("SET NAMES 'UTF8'") |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
149 |
dbc.close() |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
150 |
except PgSQL.libpq.DatabaseError, e: |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
151 |
raise VMMError(str(e), ERR.DATABASE_ERROR) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
152 |
|
251
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
153 |
def _chk_other_address_types(self, address, exclude): |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
154 |
"""Checks if the EmailAddress *address* is known as `TYPE_ACCOUNT`, |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
155 |
`TYPE_ALIAS` or `TYPE_RELOCATED`, but not as the `TYPE_*` specified |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
156 |
by *exclude*. If the *address* is known as one of the `TYPE_*`s |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
157 |
the according `TYPE_*` constant will be returned. Otherwise 0 will |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
158 |
be returned.""" |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
159 |
assert exclude in (TYPE_ACCOUNT, TYPE_ALIAS, TYPE_RELOCATED) and \ |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
160 |
isinstance(address, EmailAddress) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
161 |
if exclude is not TYPE_ACCOUNT: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
162 |
account = Account(self._dbh, address) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
163 |
if account.uid > 0: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
164 |
return TYPE_ACCOUNT |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
165 |
if exclude is not TYPE_ALIAS: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
166 |
alias = Alias(self._dbh, address) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
167 |
if alias: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
168 |
return TYPE_ALIAS |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
169 |
if exclude is not TYPE_RELOCATED: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
170 |
relocated = Relocated(self._dbh, address) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
171 |
if relocated: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
172 |
return TYPE_RELOCATED |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
173 |
return 0 |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
174 |
|
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
175 |
def __getAccount(self, address, password=None): |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
176 |
address = EmailAddress(address) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
177 |
if not password is None: |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
178 |
password = self.__pwhash(password) |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
179 |
self.__dbConnect() |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
180 |
return Account(self._dbh, address, password) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
181 |
|
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
182 |
def __getAlias(self, address): |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
183 |
address = EmailAddress(address) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
184 |
self.__dbConnect() |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
185 |
return Alias(self._dbh, address) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
186 |
|
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
187 |
def __getRelocated(self, address): |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
188 |
address = EmailAddress(address) |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
189 |
self.__dbConnect() |
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
190 |
return Relocated(self._dbh, address) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
191 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
192 |
def __getDomain(self, domainname): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
193 |
self.__dbConnect() |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
194 |
return Domain(self._dbh, domainname) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
195 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
196 |
def __getDiskUsage(self, directory): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
197 |
"""Estimate file space usage for the given directory. |
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
198 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
199 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
200 |
directory -- the directory to summarize recursively disk usage for |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
201 |
""" |
40 | 202 |
if self.__isdir(directory): |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
203 |
return Popen([self._Cfg.dget('bin.du'), "-hs", directory], |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
204 |
stdout=PIPE).communicate()[0].split('\t')[0] |
40 | 205 |
else: |
206 |
return 0 |
|
207 |
||
208 |
def __isdir(self, directory): |
|
209 |
isdir = os.path.isdir(directory) |
|
210 |
if not isdir: |
|
211 |
self.__warnings.append(_('No such directory: %s') % directory) |
|
212 |
return isdir |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
213 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
214 |
def __makedir(self, directory, mode=None, uid=None, gid=None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
215 |
if mode is None: |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
216 |
mode = self._Cfg.dget('account.directory_mode') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
217 |
if uid is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
218 |
uid = 0 |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
219 |
if gid is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
220 |
gid = 0 |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
221 |
os.makedirs(directory, mode) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
222 |
os.chown(directory, uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
223 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
224 |
def __domDirMake(self, domdir, gid): |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
225 |
#TODO: clenaup! |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
226 |
os.umask(0006) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
227 |
oldpwd = os.getcwd() |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
228 |
basedir = self._Cfg.dget('misc.base_directory') |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
229 |
domdirdirs = domdir.replace(basedir + '/', '').split('/') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
230 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
231 |
os.chdir(basedir) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
232 |
if not os.path.isdir(domdirdirs[0]): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
233 |
self.__makedir(domdirdirs[0], 489, 0, |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
234 |
self._Cfg.dget('misc.gid_mail')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
235 |
os.chdir(domdirdirs[0]) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
236 |
os.umask(0007) |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
237 |
self.__makedir(domdirdirs[1], self._Cfg.dget('domain.directory_mode'), |
174
974bafa59330
VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
168
diff
changeset
|
238 |
0, gid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
239 |
os.chdir(oldpwd) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
240 |
|
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
241 |
def __subscribe(self, folderlist, uid, gid): |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
242 |
"""Creates a subscriptions file with the mailboxes from `folderlist`""" |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
243 |
fname = os.path.join(self._Cfg.dget('maildir.name'), 'subscriptions') |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
244 |
sf = open(fname, 'w') |
223
5c7b7cbb01cd
replaced some "for x in list …"
Pascal Volk <neverseen@users.sourceforge.net>
parents:
222
diff
changeset
|
245 |
sf.write('\n'.join(folderlist)) |
5c7b7cbb01cd
replaced some "for x in list …"
Pascal Volk <neverseen@users.sourceforge.net>
parents:
222
diff
changeset
|
246 |
sf.write('\n') |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
247 |
sf.flush() |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
248 |
sf.close() |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
249 |
os.chown(fname, uid, gid) |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
250 |
os.chmod(fname, 384) |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
251 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
252 |
def __mailDirMake(self, domdir, uid, gid): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
253 |
"""Creates maildirs and maildir subfolders. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
254 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
255 |
Keyword arguments: |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
256 |
domdir -- the path to the domain directory |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
257 |
uid -- user id from the account |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
258 |
gid -- group id from the account |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
259 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
260 |
os.umask(0007) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
261 |
oldpwd = os.getcwd() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
262 |
os.chdir(domdir) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
263 |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
264 |
maildir = self._Cfg.dget('maildir.name') |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
265 |
folders = [maildir] |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
266 |
append = folders.append |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
267 |
for folder in self._Cfg.dget('maildir.folders').split(':'): |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
268 |
folder = folder.strip() |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
269 |
if len(folder) and not folder.count('..'): |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
270 |
if re.match(RE_MBOX_NAMES, folder): |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
271 |
append('%s/.%s' % (maildir, folder)) |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
272 |
else: |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
273 |
self.__warnings.append(_('Skipped mailbox folder: %r') % |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
274 |
folder) |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
275 |
else: |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
276 |
self.__warnings.append(_('Skipped mailbox folder: %r') % |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
277 |
folder) |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
278 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
279 |
subdirs = ['cur', 'new', 'tmp'] |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
280 |
mode = self._Cfg.dget('account.directory_mode') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
281 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
282 |
self.__makedir('%s' % uid, mode, uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
283 |
os.chdir('%s' % uid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
284 |
for folder in folders: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
285 |
self.__makedir(folder, mode, uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
286 |
for subdir in subdirs: |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
287 |
self.__makedir(os.path.join(folder, subdir), mode, uid, gid) |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
288 |
self.__subscribe((f.replace(maildir + '/.', '') for f in folders[1:]), |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
289 |
uid, gid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
290 |
os.chdir(oldpwd) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
291 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
292 |
def __userDirDelete(self, domdir, uid, gid): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
293 |
if uid > 0 and gid > 0: |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
294 |
userdir = '%s' % uid |
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
295 |
if userdir.count('..') or domdir.count('..'): |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
296 |
raise VMMError(_(u'Found ".." in home directory path.'), |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
297 |
ERR.FOUND_DOTS_IN_PATH) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
298 |
if os.path.isdir(domdir): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
299 |
os.chdir(domdir) |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
300 |
if os.path.isdir(userdir): |
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
301 |
mdstat = os.stat(userdir) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
302 |
if (mdstat.st_uid, mdstat.st_gid) != (uid, gid): |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
303 |
raise VMMError(_( |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
304 |
u'Detected owner/group mismatch in home directory.'), |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
305 |
ERR.MAILDIR_PERM_MISMATCH) |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
306 |
rmtree(userdir, ignore_errors=True) |
40 | 307 |
else: |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
308 |
raise VMMError(_(u"No such directory: %s") % |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
309 |
os.path.join(domdir, userdir), ERR.NO_SUCH_DIRECTORY) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
310 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
311 |
def __domDirDelete(self, domdir, gid): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
312 |
if gid > 0: |
40 | 313 |
if not self.__isdir(domdir): |
314 |
return |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
315 |
basedir = self._Cfg.dget('misc.base_directory') |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
316 |
domdirdirs = domdir.replace(basedir + '/', '').split('/') |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
317 |
domdirparent = os.path.join(basedir, domdirdirs[0]) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
318 |
if basedir.count('..') or domdir.count('..'): |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
319 |
raise VMMError(_(u'Found ".." in domain directory path.'), |
155
eb866ebb9f2e
Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents:
143
diff
changeset
|
320 |
ERR.FOUND_DOTS_IN_PATH) |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
321 |
if os.path.isdir(domdirparent): |
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
322 |
os.chdir(domdirparent) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
323 |
if os.lstat(domdirdirs[1]).st_gid != gid: |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
324 |
raise VMMError(_( |
155
eb866ebb9f2e
Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents:
143
diff
changeset
|
325 |
u'Detected group mismatch in domain directory.'), |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
326 |
ERR.DOMAINDIR_GROUP_MISMATCH) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
327 |
rmtree(domdirdirs[1], ignore_errors=True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
328 |
|
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
329 |
def __getSalt(self): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
330 |
from random import choice |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
331 |
salt = None |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
332 |
if self._scheme == 'CRYPT': |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
333 |
salt = '%s%s' % (choice(SALTCHARS), choice(SALTCHARS)) |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
334 |
elif self._scheme in ['MD5', 'MD5-CRYPT']: |
140
ffac064bd728
Code cleanup/optimization in VirtualMailManager's __getSalt().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
335 |
salt = '$1$%s$' % ''.join([choice(SALTCHARS) for x in xrange(8)]) |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
336 |
return salt |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
337 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
338 |
def __pwCrypt(self, password): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
339 |
# for: CRYPT, MD5 and MD5-CRYPT |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
340 |
from crypt import crypt |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
341 |
return crypt(password, self.__getSalt()) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
342 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
343 |
def __pwSHA1(self, password): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
344 |
# for: SHA/SHA1 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
345 |
import sha |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
346 |
from base64 import standard_b64encode |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
347 |
sha1 = sha.new(password) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
348 |
return standard_b64encode(sha1.digest()) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
349 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
350 |
def __pwMD5(self, password, emailaddress=None): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
351 |
import md5 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
352 |
_md5 = md5.new(password) |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
353 |
if self._scheme == 'LDAP-MD5': |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
354 |
from base64 import standard_b64encode |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
355 |
return standard_b64encode(_md5.digest()) |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
356 |
elif self._scheme == 'PLAIN-MD5': |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
357 |
return _md5.hexdigest() |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
358 |
elif self._scheme == 'DIGEST-MD5' and emailaddress is not None: |
70
a3663ad491bf
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
69
diff
changeset
|
359 |
# use an empty realm - works better with usenames like user@dom |
a3663ad491bf
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
69
diff
changeset
|
360 |
_md5 = md5.new('%s::%s' % (emailaddress, password)) |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
361 |
return _md5.hexdigest() |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
362 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
363 |
def __pwMD4(self, password): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
364 |
# for: PLAIN-MD4 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
365 |
from Crypto.Hash import MD4 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
366 |
_md4 = MD4.new(password) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
367 |
return _md4.hexdigest() |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
368 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
369 |
def __pwhash(self, password, scheme=None, user=None): |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
370 |
if scheme is not None: |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
371 |
self._scheme = scheme |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
372 |
if self._scheme in ['CRYPT', 'MD5', 'MD5-CRYPT']: |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
373 |
return '{%s}%s' % (self._scheme, self.__pwCrypt(password)) |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
374 |
elif self._scheme in ['SHA', 'SHA1']: |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
375 |
return '{%s}%s' % (self._scheme, self.__pwSHA1(password)) |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
376 |
elif self._scheme in ['PLAIN-MD5', 'LDAP-MD5', 'DIGEST-MD5']: |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
377 |
return '{%s}%s' % (self._scheme, self.__pwMD5(password, user)) |
259
6c699837b4d4
merged changes from default(9bf8d97ced88)
Pascal Volk <neverseen@users.sourceforge.net>
diff
changeset
|
378 |
elif self._scheme == 'PLAIN-MD4': |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
379 |
return '{%s}%s' % (self._scheme, self.__pwMD4(password)) |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
380 |
elif self._scheme in ['SMD5', 'SSHA', 'CRAM-MD5', 'HMAC-MD5', |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
381 |
'LANMAN', 'NTLM', 'RPA']: |
233
55503d63ba30
merged changes from default(8c4df3dd2d2c)
Pascal Volk <neverseen@users.sourceforge.net>
diff
changeset
|
382 |
cmd_args = [self._Cfg.dget('bin.dovecotpw'), '-s', self._scheme, |
55503d63ba30
merged changes from default(8c4df3dd2d2c)
Pascal Volk <neverseen@users.sourceforge.net>
diff
changeset
|
383 |
'-p', password] |
266
e14c345b44a1
VMM/{Account,common,Handler}: Improved version_hex().
Tobias Berling <t-obi@users.sourceforge.net>
parents:
264
diff
changeset
|
384 |
if self._Cfg.dget('misc.dovecot_version') >= 0x20000a01: |
231
8c4df3dd2d2c
VMM: VirtualMailManager.__pwhash() added support for 'doveadm pw'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
385 |
cmd_args.insert(1, 'pw') |
8c4df3dd2d2c
VMM: VirtualMailManager.__pwhash() added support for 'doveadm pw'.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
386 |
return Popen(cmd_args, stdout=PIPE).communicate()[0][:-1] |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
387 |
else: |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
388 |
return '{%s}%s' % (self._scheme, password) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
389 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
390 |
def hasWarnings(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
391 |
"""Checks if warnings are present, returns bool.""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
392 |
return bool(len(self.__warnings)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
393 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
394 |
def getWarnings(self): |
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
395 |
"""Returns a list with all available warnings and resets all |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
396 |
warnings. |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
397 |
|
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
398 |
""" |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
399 |
ret_val = self.__warnings[:] |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
400 |
del self.__warnings[:] |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
401 |
return ret_val |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
402 |
|
255
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
403 |
def cfg_dget(self, option): |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
404 |
"""Get the configured value of the *option* (section.option). |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
405 |
When the option was not configured its default value will be |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
406 |
returned.""" |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
407 |
return self._Cfg.dget(option) |
40 | 408 |
|
255
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
409 |
def cfg_pget(self, option): |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
410 |
"""Get the configured value of the *option* (section.option).""" |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
411 |
return self._Cfg.pget(option) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
412 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
413 |
def domainAdd(self, domainname, transport=None): |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
414 |
dom = self.__getDomain(domainname) |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
415 |
if transport is None: |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
416 |
dom.set_transport(Transport(self._dbh, |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
417 |
transport=self._Cfg.dget('misc.transport'))) |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
418 |
else: |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
419 |
dom.set_transport(Transport(self._dbh, transport=transport)) |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
420 |
dom.set_directory(self._Cfg.dget('misc.base_directory')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
421 |
dom.save() |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
422 |
self.__domDirMake(dom.directory, dom.gid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
423 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
424 |
def domainTransport(self, domainname, transport, force=None): |
18
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
425 |
if force is not None and force != 'force': |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
426 |
raise DomainError(_(u"Invalid argument: “%s”") % force, |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
427 |
ERR.INVALID_OPTION) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
428 |
dom = self.__getDomain(domainname) |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
429 |
trsp = Transport(self._dbh, transport=transport) |
18
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
430 |
if force is None: |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
431 |
dom.update_transport(trsp) |
18
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
432 |
else: |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
433 |
dom.update_transport(trsp, force=True) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
434 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
435 |
def domainDelete(self, domainname, force=None): |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
436 |
if not force is None and force not in ['deluser', 'delalias', |
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
437 |
'delall']: |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
438 |
raise DomainError(_(u'Invalid argument: “%s”') % |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
439 |
force, ERR.INVALID_OPTION) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
440 |
dom = self.__getDomain(domainname) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
441 |
gid = dom.gid |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
442 |
domdir = dom.directory |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
443 |
if self._Cfg.dget('domain.force_deletion') or force == 'delall': |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
444 |
dom.delete(True, True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
445 |
elif force == 'deluser': |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
446 |
dom.delete(deluser=True) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
447 |
elif force == 'delalias': |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
448 |
dom.delete(delalias=True) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
449 |
else: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
450 |
dom.delete() |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
451 |
if self._Cfg.dget('domain.delete_directory'): |
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
452 |
self.__domDirDelete(domdir, gid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
453 |
|
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
454 |
def domainInfo(self, domainname, details=None): |
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
455 |
if details not in [None, 'accounts', 'aliasdomains', 'aliases', 'full', |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
456 |
'relocated']: |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
457 |
raise VMMError(_(u'Invalid argument: “%s”') % details, |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
458 |
ERR.INVALID_AGUMENT) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
459 |
dom = self.__getDomain(domainname) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
460 |
dominfo = dom.get_info() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
461 |
if dominfo['domainname'].startswith('xn--'): |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
462 |
dominfo['domainname'] += ' (%s)' % ace2idna(dominfo['domainname']) |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
463 |
if details is None: |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
464 |
return dominfo |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
465 |
elif details == 'accounts': |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
466 |
return (dominfo, dom.get_accounts()) |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
467 |
elif details == 'aliasdomains': |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
468 |
return (dominfo, dom.get_aliase_names()) |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
469 |
elif details == 'aliases': |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
470 |
return (dominfo, dom.get_aliases()) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
471 |
elif details == 'relocated': |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
472 |
return(dominfo, dom.get_relocated()) |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
473 |
else: |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
474 |
return (dominfo, dom.get_aliase_names(), dom.get_accounts(), |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
475 |
dom.get_aliases(), dom.get_relocated()) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
476 |
|
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
477 |
def aliasDomainAdd(self, aliasname, domainname): |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
478 |
"""Adds an alias domain to the domain. |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
479 |
|
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
480 |
Arguments: |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
481 |
|
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
482 |
`aliasname` : basestring |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
483 |
The name of the alias domain |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
484 |
`domainname` : basestring |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
485 |
The name of the target domain |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
486 |
""" |
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
487 |
dom = self.__getDomain(domainname) |
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
488 |
aliasDom = AliasDomain(self._dbh, aliasname) |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
489 |
aliasDom.set_destination(dom) |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
490 |
aliasDom.save() |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
491 |
|
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
492 |
def aliasDomainInfo(self, aliasname): |
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
493 |
"""Returns a dict (keys: "alias" and "domain") with the names of |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
494 |
the alias domain and its primary domain.""" |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
495 |
self.__dbConnect() |
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
496 |
aliasDom = AliasDomain(self._dbh, aliasname) |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
497 |
return aliasDom.info() |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
498 |
|
78
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
499 |
def aliasDomainSwitch(self, aliasname, domainname): |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
500 |
"""Modifies the target domain of an existing alias domain. |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
501 |
|
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
502 |
Arguments: |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
503 |
|
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
504 |
`aliasname` : basestring |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
505 |
The name of the alias domain |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
506 |
`domainname` : basestring |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
507 |
The name of the new target domain |
78
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
508 |
""" |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
509 |
dom = self.__getDomain(domainname) |
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
510 |
aliasDom = AliasDomain(self._dbh, aliasname) |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
511 |
aliasDom.set_destination(dom) |
78
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
512 |
aliasDom.switch() |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
513 |
|
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
514 |
def aliasDomainDelete(self, aliasname): |
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
515 |
"""Deletes the given alias domain. |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
516 |
|
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
517 |
Argument: |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
518 |
|
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
519 |
`aliasname` : basestring |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
520 |
The name of the alias domain |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
521 |
""" |
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
522 |
self.__dbConnect() |
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
523 |
aliasDom = AliasDomain(self._dbh, aliasname) |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
524 |
aliasDom.delete() |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
525 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
526 |
def domainList(self, pattern=None): |
241
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
527 |
from VirtualMailManager.Domain import search |
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
528 |
like = False |
241
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
529 |
if pattern and (pattern.startswith('%') or pattern.endswith('%')): |
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
530 |
like = True |
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
531 |
if not re.match(RE_DOMAIN_SEARCH, pattern.strip('%')): |
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
532 |
raise VMMError( |
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
533 |
_(u"The pattern '%s' contains invalid characters.") % |
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
534 |
pattern, ERR.DOMAIN_INVALID) |
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
535 |
self.__dbConnect() |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
536 |
return search(self._dbh, pattern=pattern, like=like) |
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
537 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
538 |
def userAdd(self, emailaddress, password): |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
539 |
if password is None or (isinstance(password, basestring) and |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
540 |
not len(password)): |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
541 |
raise ValueError('could not accept password: %r' % password) |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
542 |
acc = self.__getAccount(emailaddress, self.__pwhash(password)) |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
543 |
acc.save(self._Cfg.dget('maildir.name'), |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
544 |
self._Cfg.dget('misc.dovecot_version'), |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
545 |
self._Cfg.dget('account.smtp'), |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
546 |
self._Cfg.dget('account.pop3'), |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
547 |
self._Cfg.dget('account.imap'), |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
548 |
self._Cfg.dget('account.sieve')) |
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
549 |
self.__mailDirMake(acc.getDir('domain'), acc.getUID(), acc.getGID()) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
550 |
|
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
551 |
def aliasAdd(self, aliasaddress, *targetaddresses): |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
552 |
"""Creates a new `Alias` entry for the given *aliasaddress* with |
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
553 |
the given *targetaddresses*.""" |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
554 |
alias = self.__getAlias(aliasaddress) |
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
555 |
destinations = [EmailAddress(address) for address in targetaddresses] |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
556 |
warnings = [] |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
557 |
destinations = alias.add_destinations(destinations, |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
558 |
long(self._postconf.read('virtual_alias_expansion_limit')), |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
559 |
warnings) |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
560 |
if warnings: |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
561 |
self.__warnings.append(_('Ignored destination addresses:')) |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
562 |
self.__warnings.extend((' * %s' % w for w in warnings)) |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
563 |
for destination in destinations: |
222
d0c16e70a9fb
VMM/Domain: get_gid() return 0 instead of raising an Exception,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
221
diff
changeset
|
564 |
gid = get_gid(self._dbh, destination.domainname) |
d0c16e70a9fb
VMM/Domain: get_gid() return 0 instead of raising an Exception,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
221
diff
changeset
|
565 |
if gid and (not Handler.accountExists(self._dbh, destination) and |
d0c16e70a9fb
VMM/Domain: get_gid() return 0 instead of raising an Exception,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
221
diff
changeset
|
566 |
not Handler.aliasExists(self._dbh, destination)): |
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
567 |
self.__warnings.append( |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
568 |
_(u"The destination account/alias %r doesn't exist.") % |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
569 |
str(destination)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
570 |
|
66
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
62
diff
changeset
|
571 |
def userDelete(self, emailaddress, force=None): |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
62
diff
changeset
|
572 |
if force not in [None, 'delalias']: |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
573 |
raise VMMError(_(u"Invalid argument: “%s”") % force, |
66
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
62
diff
changeset
|
574 |
ERR.INVALID_AGUMENT) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
575 |
acc = self.__getAccount(emailaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
576 |
uid = acc.getUID() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
577 |
gid = acc.getGID() |
66
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
62
diff
changeset
|
578 |
acc.delete(force) |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
579 |
if self._Cfg.dget('account.delete_directory'): |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
580 |
try: |
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
581 |
self.__userDirDelete(acc.getDir('domain'), uid, gid) |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
582 |
except VMMError, e: |
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
583 |
if e.code in [ERR.FOUND_DOTS_IN_PATH, |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
584 |
ERR.MAILDIR_PERM_MISMATCH, ERR.NO_SUCH_DIRECTORY]: |
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
585 |
warning = _(u"""\ |
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
586 |
The account has been successfully deleted from the database. |
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
587 |
But an error occurred while deleting the following directory: |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
588 |
“%(directory)s” |
192
0854fb9f3bc5
VMM/Handler: fixed a SyntaxError. Oops
Pascal Volk <neverseen@users.sourceforge.net>
parents:
191
diff
changeset
|
589 |
Reason: %(reason)s""") % \ |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
590 |
{'directory': acc.getDir('home'), 'reason': e.msg} |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
591 |
self.__warnings.append(warning) |
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
592 |
else: |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
593 |
raise |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
594 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
595 |
def aliasInfo(self, aliasaddress): |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
596 |
"""Returns an iterator object for all destinations (`EmailAddress` |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
597 |
instances) for the `Alias` with the given *aliasaddress*.""" |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
598 |
alias = self.__getAlias(aliasaddress) |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
599 |
try: |
215
33f727efa7c4
PEP-8-ified the work of the last days.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
208
diff
changeset
|
600 |
return alias.get_destinations() |
251
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
601 |
except AliasError, err: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
602 |
if err.code == ERR.NO_SUCH_ALIAS: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
603 |
other = self._chk_other_address_types(alias.address, |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
604 |
TYPE_ALIAS) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
605 |
if other is TYPE_ACCOUNT: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
606 |
raise VMMError(_(u"There is already an account with the \ |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
607 |
address '%s'.") % |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
608 |
alias.address, ERR.ACCOUNT_EXISTS) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
609 |
elif other is TYPE_RELOCATED: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
610 |
raise VMMError(_(u"There is already a relocated user \ |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
611 |
with the address '%s'.") % |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
612 |
alias.address, ERR.RELOCATED_EXISTS) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
613 |
else: # unknown address |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
614 |
raise |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
615 |
else: # something other went wrong |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
616 |
raise |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
617 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
618 |
def aliasDelete(self, aliasaddress, targetaddress=None): |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
619 |
"""Deletes the `Alias` *aliasaddress* with all its destinations from |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
620 |
the database. If *targetaddress* is not ``None``, only this |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
621 |
destination will be removed from the alias.""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
622 |
alias = self.__getAlias(aliasaddress) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
623 |
if targetaddress is None: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
624 |
alias.delete() |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
625 |
else: |
215
33f727efa7c4
PEP-8-ified the work of the last days.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
208
diff
changeset
|
626 |
alias.del_destination(EmailAddress(targetaddress)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
627 |
|
90
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
628 |
def userInfo(self, emailaddress, details=None): |
174
974bafa59330
VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
168
diff
changeset
|
629 |
if details not in (None, 'du', 'aliases', 'full'): |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
630 |
raise VMMError(_(u'Invalid argument: “%s”') % details, |
174
974bafa59330
VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
168
diff
changeset
|
631 |
ERR.INVALID_AGUMENT) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
632 |
acc = self.__getAccount(emailaddress) |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
633 |
info = acc.getInfo(self._Cfg.dget('misc.dovecot_version')) |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
634 |
if self._Cfg.dget('account.disk_usage') or details in ('du', 'full'): |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
635 |
info['disk usage'] = self.__getDiskUsage('%(maildir)s' % info) |
174
974bafa59330
VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
168
diff
changeset
|
636 |
if details in (None, 'du'): |
90
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
637 |
return info |
174
974bafa59330
VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
168
diff
changeset
|
638 |
if details in ('aliases', 'full'): |
90
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
639 |
return (info, acc.getAliases()) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
640 |
return info |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
641 |
|
255
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
642 |
def user_by_uid(self, uid): |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
643 |
"""Search for an Account by its *uid*. |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
644 |
Returns a dict (address, uid and gid) if a user could be found.""" |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
645 |
from VirtualMailManager.Account import get_account_by_uid |
19
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
646 |
self.__dbConnect() |
255
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
647 |
return get_account_by_uid(uid, self._dbh) |
19
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
648 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
649 |
def userPassword(self, emailaddress, password): |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
650 |
if password is None or (isinstance(password, basestring) and |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
651 |
not len(password)): |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
652 |
raise ValueError('could not accept password: %r' % password) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
653 |
acc = self.__getAccount(emailaddress) |
38
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
654 |
if acc.getUID() == 0: |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
655 |
raise VMMError(_(u"Account doesn't exist"), |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
656 |
ERR.NO_SUCH_ACCOUNT) |
70
a3663ad491bf
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
69
diff
changeset
|
657 |
acc.modify('password', self.__pwhash(password, user=emailaddress)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
658 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
659 |
def userName(self, emailaddress, name): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
660 |
acc = self.__getAccount(emailaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
661 |
acc.modify('name', name) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
662 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
663 |
def userTransport(self, emailaddress, transport): |
17
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
664 |
acc = self.__getAccount(emailaddress) |
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
665 |
acc.modify('transport', transport) |
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
666 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
667 |
def userDisable(self, emailaddress, service=None): |
132
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
668 |
if service == 'managesieve': |
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
669 |
service = 'sieve' |
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
670 |
self.__warnings.append(_(u'\ |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
671 |
The service name “managesieve” is deprecated and will be removed\n\ |
132
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
672 |
in a future release.\n\ |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
673 |
Please use the service name “sieve” instead.')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
674 |
acc = self.__getAccount(emailaddress) |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
675 |
acc.disable(self._Cfg.dget('misc.dovecot_version'), service) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
676 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
677 |
def userEnable(self, emailaddress, service=None): |
132
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
678 |
if service == 'managesieve': |
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
679 |
service = 'sieve' |
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
680 |
self.__warnings.append(_(u'\ |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
681 |
The service name “managesieve” is deprecated and will be removed\n\ |
132
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
682 |
in a future release.\n\ |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
683 |
Please use the service name “sieve” instead.')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
684 |
acc = self.__getAccount(emailaddress) |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
685 |
acc.enable(self._Cfg.dget('misc.dovecot_version'), service) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
686 |
|
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
687 |
def relocatedAdd(self, emailaddress, targetaddress): |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
688 |
"""Creates a new `Relocated` entry in the database. If there is |
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
689 |
already a relocated user with the given *emailaddress*, only the |
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
690 |
*targetaddress* for the relocated user will be updated.""" |
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
691 |
relocated = self.__getRelocated(emailaddress) |
215
33f727efa7c4
PEP-8-ified the work of the last days.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
208
diff
changeset
|
692 |
relocated.set_destination(EmailAddress(targetaddress)) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
693 |
|
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
694 |
def relocatedInfo(self, emailaddress): |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
695 |
"""Returns the target address of the relocated user with the given |
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
696 |
*emailaddress*.""" |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
697 |
relocated = self.__getRelocated(emailaddress) |
251
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
698 |
try: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
699 |
return relocated.get_info() |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
700 |
except RelocatedError, err: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
701 |
if err.code == ERR.NO_SUCH_RELOCATED: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
702 |
other = self._chk_other_address_types(relocated.address, |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
703 |
TYPE_RELOCATED) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
704 |
if other is TYPE_ACCOUNT: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
705 |
raise VMMError(_(u"There is already an account with the \ |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
706 |
address '%s'.") % |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
707 |
relocated.address, ERR.ACCOUNT_EXISTS) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
708 |
elif other is TYPE_ALIAS: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
709 |
raise VMMError(_(u"There is already an alias with the \ |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
710 |
address '%s'.") % |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
711 |
relocated.address, ERR.ALIAS_EXISTS) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
712 |
else: # unknown address |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
713 |
raise |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
714 |
else: # something other went wrong |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
715 |
raise |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
716 |
|
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
717 |
def relocatedDelete(self, emailaddress): |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
718 |
"""Deletes the relocated user with the given *emailaddress* from |
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
719 |
the database.""" |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
720 |
relocated = self.__getRelocated(emailaddress) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
721 |
relocated.delete() |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
722 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
723 |
def __del__(self): |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
724 |
if isinstance(self._dbh, PgSQL.Connection) and self._dbh._isOpen: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
725 |
self._dbh.close() |