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