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