VirtualMailManager/Handler.py
author Pascal Volk <neverseen@users.sourceforge.net>
Fri, 05 Feb 2010 20:16:44 +0000
branchv0.6.x
changeset 186 18757fd45e60
parent 185 VirtualMailManager/cli/handler.py@6e1ef32fbd82
child 187 38b9a9859749
permissions -rw-r--r--
moved VMM/cli/handler to VMM/Handler
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
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    21
from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net
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 import ENCODING, ace2idna, exec_ok, read_pass
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    25
from VirtualMailManager.Account import Account
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    26
from VirtualMailManager.Alias import Alias
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    27
from VirtualMailManager.AliasDomain import AliasDomain
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    28
from VirtualMailManager.Config import Config as Cfg
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    29
from VirtualMailManager.Domain import Domain
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
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    31
from VirtualMailManager.Exceptions import *
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
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    33
from VirtualMailManager.ext.Postconf import Postconf
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    34
16
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
    35
SALTCHARS = './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
35
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
    36
RE_DOMAIN_SRCH = """^[a-z0-9-\.]+$"""
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    37
RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]"""
68
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
    38
RE_MBOX_NAMES = """^[\x20-\x25\x27-\x7E]*$"""
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    39
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    40
class Handler(object):
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    41
    """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
    42
    VirtualMailManager"""
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    43
    # TODO: accept a LazyConfig object as argument
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
    44
    __slots__ = ('__Cfg', '__cfgFileName', '__dbh', '__scheme', '__warnings',
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
    45
                 '_postconf')
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    46
    def __init__(self):
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
    47
        """Creates a new Handler instance.
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    48
        Throws a VMMNotRootException if your uid is greater 0.
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    49
        """
94
0d303d15549e * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 90
diff changeset
    50
        self.__cfgFileName = ''
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    51
        self.__warnings = []
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    52
        self.__Cfg = None
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    53
        self.__dbh = None
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    54
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    55
        if os.geteuid():
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
    56
            raise VMMNotRootException(_(u"You are not root.\n\tGood bye!\n"),
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
    57
                ERR.CONF_NOPERM)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    58
        if self.__chkCfgFile():
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    59
            self.__Cfg = Cfg(self.__cfgFileName)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    60
            self.__Cfg.load()
182
84811fcc3c69 VMM/VMM: Allow version/help subcommands even with missing configuration options.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 180
diff changeset
    61
        if not os.sys.argv[1] in ('cf','configure','h','help','v','version'):
2
9b39f828aa8a * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 0
diff changeset
    62
            self.__Cfg.check()
175
b241272eb1bd VMM/VMM: allow configure subcommand also with missing settings.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 174
diff changeset
    63
            self.__chkenv()
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
    64
            self.__scheme = self.__Cfg.dget('misc.password_scheme')
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
    65
            self._postconf = Postconf(self.__Cfg.dget('bin.postconf'))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    66
94
0d303d15549e * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 90
diff changeset
    67
    def __findCfgFile(self):
0d303d15549e * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 90
diff changeset
    68
        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
    69
            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
    70
            if os.path.isfile(tmp):
014335f38962 Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
    71
                self.__cfgFileName = tmp
94
0d303d15549e * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 90
diff changeset
    72
                break
0d303d15549e * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 90
diff changeset
    73
        if not len(self.__cfgFileName):
0d303d15549e * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 90
diff changeset
    74
            raise VMMException(
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
    75
                _(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
    76
                ERR.CONF_NOFILE)
0d303d15549e * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 90
diff changeset
    77
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    78
    def __chkCfgFile(self):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    79
        """Checks the configuration file, returns bool"""
94
0d303d15549e * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 90
diff changeset
    80
        self.__findCfgFile()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    81
        fstat = os.stat(self.__cfgFileName)
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
    82
        fmode = int(oct(fstat.st_mode & 0777))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    83
        if fmode % 100 and fstat.st_uid != fstat.st_gid \
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    84
        or fmode % 10 and fstat.st_uid == fstat.st_gid:
128
cf8116625866 Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 119
diff changeset
    85
            raise VMMPermException(_(
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
    86
                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
    87
`chmod 0600 %(file)s` would be great.') % {'file':
cf8116625866 Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 119
diff changeset
    88
                self.__cfgFileName, 'perms': fmode}, ERR.CONF_WRONGPERM)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    89
        else:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    90
            return True
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    91
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    92
    def __chkenv(self):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    93
        """"""
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
    94
        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
    95
        if not os.path.exists(basedir):
28
87da30d30fde * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 24
diff changeset
    96
            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
    97
            os.makedirs(basedir, 0771)
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
    98
            os.chown(basedir, 0, self.__Cfg.dget('misc.gid_mail'))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    99
            os.umask(old_umask)
168
fd496561acc6 vmm.cfg: a few re-renamed configuration options.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 166
diff changeset
   100
        elif not os.path.isdir(basedir):
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   101
            raise VMMException(_(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
   102
(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
   103
                                 basedir, ERR.NO_SUCH_DIRECTORY)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   104
        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
   105
            try:
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   106
                exec_ok(val)
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   107
            except VMMException, e:
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   108
                code = e.code()
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   109
                if code is ERR.NO_SUCH_BINARY:
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   110
                    raise VMMException(_(u'“%(binary)s” doesn\'t exist.\n\
51
f5ca21303871 * Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 50
diff changeset
   111
(vmm.cfg: section "bin", option "%(option)s")') %{'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
   112
                                       ERR.NO_SUCH_BINARY)
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   113
                elif code is ERR.NOT_EXECUTABLE:
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   114
                    raise VMMException(_(u'“%(binary)s” is not executable.\n\
51
f5ca21303871 * Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 50
diff changeset
   115
(vmm.cfg: section "bin", option "%(option)s")') %{'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
   116
                                       ERR.NOT_EXECUTABLE)
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   117
                else:
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   118
                    raise
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   119
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   120
    def __dbConnect(self):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   121
        """Creates a pyPgSQL.PgSQL.connection instance."""
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   122
        if self.__dbh is None or (isinstance(self.__dbh, PgSQL.Connection) and
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   123
                                  not self.__dbh._isOpen):
83
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   124
            try:
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   125
                self.__dbh = PgSQL.connect(
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   126
                        database=self.__Cfg.dget('database.name'),
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   127
                        user=self.__Cfg.pget('database.user'),
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   128
                        host=self.__Cfg.dget('database.host'),
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   129
                        password=self.__Cfg.pget('database.pass'),
83
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   130
                        client_encoding='utf8', unicode_results=True)
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   131
                dbc = self.__dbh.cursor()
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   132
                dbc.execute("SET NAMES 'UTF8'")
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   133
                dbc.close()
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   134
            except PgSQL.libpq.DatabaseError, e:
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   135
                raise VMMException(str(e), ERR.DATABASE_ERROR)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   136
76
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   137
    def _exists(dbh, query):
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   138
        dbc = dbh.cursor()
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   139
        dbc.execute(query)
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   140
        gid = dbc.fetchone()
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   141
        dbc.close()
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   142
        if gid is None:
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   143
            return False
52
c152d7714802 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 51
diff changeset
   144
        else:
76
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   145
            return True
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   146
    _exists = staticmethod(_exists)
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   147
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   148
    def accountExists(dbh, address):
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   149
        sql = "SELECT gid FROM users WHERE gid = (SELECT gid FROM domain_name\
109
766299a8639d VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
   150
 WHERE domainname = '%s') AND local_part = '%s'" % (address._domainname,
766299a8639d VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
   151
            address._localpart)
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   152
        return Handler._exists(dbh, sql)
76
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   153
    accountExists = staticmethod(accountExists)
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   154
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   155
    def aliasExists(dbh, address):
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   156
        sql = "SELECT DISTINCT gid FROM alias WHERE gid = (SELECT gid FROM\
109
766299a8639d VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
   157
 domain_name WHERE domainname = '%s') AND address = '%s'" %\
766299a8639d VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
   158
            (address._domainname, address._localpart)
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   159
        return Handler._exists(dbh, sql)
76
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   160
    aliasExists = staticmethod(aliasExists)
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   161
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   162
    def relocatedExists(dbh, address):
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   163
        sql = "SELECT gid FROM relocated WHERE gid = (SELECT gid FROM\
109
766299a8639d VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
   164
 domain_name WHERE domainname = '%s') AND address = '%s'" %\
766299a8639d VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 102
diff changeset
   165
            (address._domainname, address._localpart)
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   166
        return Handler._exists(dbh, sql)
76
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   167
    relocatedExists = staticmethod(relocatedExists)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   168
38
c44ea4526546 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 35
diff changeset
   169
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   170
    def __getAccount(self, address, password=None):
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   171
        self.__dbConnect()
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   172
        address = EmailAddress(address)
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   173
        if not password is None:
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   174
            password = self.__pwhash(password)
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   175
        return Account(self.__dbh, address, password)
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   176
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   177
    def __getAlias(self, address, destination=None):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   178
        self.__dbConnect()
76
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   179
        address = EmailAddress(address)
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   180
        if destination is not None:
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 70
diff changeset
   181
            destination = EmailAddress(destination)
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
   182
        return Alias(self.__dbh, address, destination)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   183
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   184
    def __getRelocated(self,address, destination=None):
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   185
        self.__dbConnect()
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   186
        address = EmailAddress(address)
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   187
        if destination is not None:
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   188
            destination = EmailAddress(destination)
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   189
        return Relocated(self.__dbh, address, destination)
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   190
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   191
    def __getDomain(self, domainname, transport=None):
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
   192
        if transport is None:
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   193
            transport = self.__Cfg.dget('misc.transport')
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   194
        self.__dbConnect()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   195
        return Domain(self.__dbh, domainname,
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   196
                self.__Cfg.dget('misc.base_directory'), transport)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   197
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   198
    def __getDiskUsage(self, directory):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   199
        """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
   200
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   201
        Keyword arguments:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   202
        directory -- the directory to summarize recursively disk usage for
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   203
        """
40
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   204
        if self.__isdir(directory):
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   205
            return Popen([self.__Cfg.dget('bin.du'), "-hs", directory],
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   206
                stdout=PIPE).communicate()[0].split('\t')[0]
40
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   207
        else:
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   208
            return 0
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   209
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   210
    def __isdir(self, directory):
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   211
        isdir = os.path.isdir(directory)
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   212
        if not isdir:
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   213
            self.__warnings.append(_('No such directory: %s') % directory)
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   214
        return isdir
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   215
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   216
    def __makedir(self, directory, mode=None, uid=None, gid=None):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   217
        if mode is None:
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   218
            mode = self.__Cfg.dget('account.directory_mode')
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   219
        if uid is None:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   220
            uid = 0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   221
        if gid is None:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   222
            gid = 0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   223
        os.makedirs(directory, mode)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   224
        os.chown(directory, uid, gid)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   225
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   226
    def __domDirMake(self, domdir, gid):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   227
        os.umask(0006)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   228
        oldpwd = os.getcwd()
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   229
        basedir = self.__Cfg.dget('misc.base_directory')
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   230
        domdirdirs = domdir.replace(basedir+'/', '').split('/')
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   231
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   232
        os.chdir(basedir)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   233
        if not os.path.isdir(domdirdirs[0]):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   234
            self.__makedir(domdirdirs[0], 489, 0,
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   235
                           self.__Cfg.dget('misc.gid_mail'))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   236
        os.chdir(domdirdirs[0])
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   237
        os.umask(0007)
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   238
        self.__makedir(domdirdirs[1], self.__Cfg.dget('domain.directory_mode'),
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   239
                       0, gid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   240
        os.chdir(oldpwd)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   241
68
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   242
    def __subscribeFL(self, folderlist, uid, gid):
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   243
        fname = os.path.join(self.__Cfg.dget('maildir.name'), 'subscriptions')
68
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   244
        sf = file(fname, 'w')
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   245
        for f in folderlist:
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   246
            sf.write(f+'\n')
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   247
        sf.flush()
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   248
        sf.close()
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   249
        os.chown(fname, uid, gid)
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   250
        os.chmod(fname, 384)
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   251
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   252
    def __mailDirMake(self, domdir, uid, gid):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   253
        """Creates maildirs and maildir subfolders.
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   254
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   255
        Keyword arguments:
68
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   256
        domdir -- the path to the domain directory
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   257
        uid -- user id from the account
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   258
        gid -- group id from the account
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   259
        """
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   260
        os.umask(0007)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   261
        oldpwd = os.getcwd()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   262
        os.chdir(domdir)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   263
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   264
        maildir = self.__Cfg.dget('maildir.name')
68
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   265
        folders = [maildir]
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   266
        for folder in self.__Cfg.dget('maildir.folders').split(':'):
68
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   267
            folder = folder.strip()
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   268
            if len(folder) and not folder.count('..')\
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   269
            and re.match(RE_MBOX_NAMES, folder):
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   270
                folders.append('%s/.%s' % (maildir, folder))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   271
        subdirs = ['cur', 'new', 'tmp']
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   272
        mode = self.__Cfg.dget('account.directory_mode')
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   273
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   274
        self.__makedir('%s' % uid, mode, uid, gid)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   275
        os.chdir('%s' % uid)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   276
        for folder in folders:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   277
            self.__makedir(folder, mode, uid, gid)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   278
            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
   279
                self.__makedir(os.path.join(folder, subdir), mode, uid, gid)
68
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   280
        self.__subscribeFL([f.replace(maildir+'/.', '') for f in folders[1:]],
7ae95b9938c4 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
   281
                uid, gid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   282
        os.chdir(oldpwd)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   283
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   284
    def __userDirDelete(self, domdir, uid, gid):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   285
        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
   286
            userdir = '%s' % uid
f5ca21303871 * Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 50
diff changeset
   287
            if userdir.count('..') or domdir.count('..'):
f5ca21303871 * Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 50
diff changeset
   288
                raise VMMException(_(u'Found ".." in home directory path.'),
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   289
                    ERR.FOUND_DOTS_IN_PATH)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   290
            if os.path.isdir(domdir):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   291
                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
   292
                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
   293
                    mdstat = os.stat(userdir)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   294
                    if (mdstat.st_uid, mdstat.st_gid) != (uid, gid):
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   295
                        raise VMMException(
155
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 143
diff changeset
   296
                         _(u'Detected owner/group mismatch in home directory.'),
51
f5ca21303871 * Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 50
diff changeset
   297
                         ERR.MAILDIR_PERM_MISMATCH)
f5ca21303871 * Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 50
diff changeset
   298
                    rmtree(userdir, ignore_errors=True)
40
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   299
                else:
51
f5ca21303871 * Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 50
diff changeset
   300
                    raise VMMException(_(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
   301
                        os.path.join(domdir, userdir), ERR.NO_SUCH_DIRECTORY)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   302
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   303
    def __domDirDelete(self, domdir, gid):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   304
        if gid > 0:
40
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   305
            if not self.__isdir(domdir):
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   306
                return
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   307
            basedir = self.__Cfg.dget('misc.base_directory')
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   308
            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
   309
            domdirparent = os.path.join(basedir, domdirdirs[0])
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   310
            if basedir.count('..') or domdir.count('..'):
155
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 143
diff changeset
   311
                raise VMMException(_(u'Found ".." in domain directory path.'),
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 143
diff changeset
   312
                        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
   313
            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
   314
                os.chdir(domdirparent)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   315
                if os.lstat(domdirdirs[1]).st_gid != gid:
155
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 143
diff changeset
   316
                    raise VMMException(_(
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 143
diff changeset
   317
                        u'Detected group mismatch in domain directory.'),
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   318
                        ERR.DOMAINDIR_GROUP_MISMATCH)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   319
                rmtree(domdirdirs[1], ignore_errors=True)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   320
16
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   321
    def __getSalt(self):
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   322
        from random import choice
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   323
        salt = None
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   324
        if self.__scheme == 'CRYPT':
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   325
            salt = '%s%s' % (choice(SALTCHARS), choice(SALTCHARS))
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   326
        elif self.__scheme in ['MD5', 'MD5-CRYPT']:
140
ffac064bd728 Code cleanup/optimization in VirtualMailManager's __getSalt().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 138
diff changeset
   327
            salt = '$1$%s$' % ''.join([choice(SALTCHARS) for x in xrange(8)])
16
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   328
        return salt
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   329
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   330
    def __pwCrypt(self, password):
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   331
        # for: CRYPT, MD5 and MD5-CRYPT
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   332
        from crypt import crypt
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   333
        return crypt(password, self.__getSalt())
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   334
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   335
    def __pwSHA1(self, password):
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   336
        # for: SHA/SHA1
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   337
        import sha
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   338
        from base64 import standard_b64encode
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   339
        sha1 = sha.new(password)
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   340
        return standard_b64encode(sha1.digest())
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   341
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   342
    def __pwMD5(self, password, emailaddress=None):
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   343
        import md5
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   344
        _md5 = md5.new(password)
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   345
        if self.__scheme == 'LDAP-MD5':
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   346
            from base64 import standard_b64encode
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   347
            return standard_b64encode(_md5.digest())
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   348
        elif self.__scheme == 'PLAIN-MD5':
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   349
            return _md5.hexdigest()
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   350
        elif self.__scheme == 'DIGEST-MD5' and emailaddress is not None:
70
a3663ad491bf * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 69
diff changeset
   351
            # use an empty realm - works better with usenames like user@dom
a3663ad491bf * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 69
diff changeset
   352
            _md5 = md5.new('%s::%s' % (emailaddress, password))
16
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   353
            return _md5.hexdigest()
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   354
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   355
    def __pwMD4(self, password):
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   356
        # for: PLAIN-MD4
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   357
        from Crypto.Hash import MD4
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   358
        _md4 = MD4.new(password)
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   359
        return _md4.hexdigest()
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   360
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   361
    def __pwhash(self, password, scheme=None, user=None):
16
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   362
        if scheme is not None:
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   363
            self.__scheme = scheme
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   364
        if self.__scheme in ['CRYPT', 'MD5', 'MD5-CRYPT']:
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   365
            return '{%s}%s' % (self.__scheme, self.__pwCrypt(password))
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   366
        elif self.__scheme in ['SHA', 'SHA1']:
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   367
            return '{%s}%s' % (self.__scheme, self.__pwSHA1(password))
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   368
        elif self.__scheme in ['PLAIN-MD5', 'LDAP-MD5', 'DIGEST-MD5']:
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   369
            return '{%s}%s' % (self.__scheme, self.__pwMD5(password, user))
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   370
        elif self.__scheme == 'MD4':
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   371
            return '{%s}%s' % (self.__scheme, self.__pwMD4(password))
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   372
        elif self.__scheme in ['SMD5', 'SSHA', 'CRAM-MD5', 'HMAC-MD5',
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   373
                'LANMAN', 'NTLM', 'RPA']:
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   374
            return Popen([self.__Cfg.dget('bin.dovecotpw'), '-s',
16
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   375
                self.__scheme,'-p',password],stdout=PIPE).communicate()[0][:-1]
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   376
        else:
3388b96fd3ed * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 14
diff changeset
   377
            return '{%s}%s' % (self.__scheme, password)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   378
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   379
    def hasWarnings(self):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   380
        """Checks if warnings are present, returns bool."""
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   381
        return bool(len(self.__warnings))
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   382
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   383
    def getWarnings(self):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   384
        """Returns a list with all available warnings."""
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   385
        return self.__warnings
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   386
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   387
    def cfgDget(self, option):
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   388
        return self.__Cfg.dget(option)
40
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   389
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   390
    def cfgPget(self, option):
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   391
        return self.__Cfg.pget(option)
40
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   392
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   393
    def cfgSet(self, option, value):
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   394
        return self.__Cfg.set(option, value)
40
ab0748a5da9a * 'vmm'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   395
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   396
    def configure(self, section=None):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   397
        """Starts interactive configuration.
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   398
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   399
        Configures in interactive mode options in the given section.
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   400
        If no section is given (default) all options from all sections
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   401
        will be prompted.
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   402
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   403
        Keyword arguments:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   404
        section -- the section to configure (default None):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   405
        """
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   406
        if section is None:
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   407
            self.__Cfg.configure(self.__Cfg.getsections())
180
f8279c90e99c VMM/Config: dropped option config.done
Pascal Volk <neverseen@users.sourceforge.net>
parents: 175
diff changeset
   408
        elif self.__Cfg.has_section(section):
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   409
            self.__Cfg.configure([section])
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   410
        else:
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   411
            raise VMMException(_(u"Invalid section: “%s”") % section,
175
b241272eb1bd VMM/VMM: allow configure subcommand also with missing settings.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 174
diff changeset
   412
                               ERR.INVALID_SECTION)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   413
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   414
    def domainAdd(self, domainname, transport=None):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   415
        dom = self.__getDomain(domainname, transport)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   416
        dom.save()
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   417
        self.__domDirMake(dom.getDir(), dom.getID())
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   418
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   419
    def domainTransport(self, domainname, transport, force=None):
18
c98e08791ee8 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   420
        if force is not None and force != 'force':
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   421
            raise VMMDomainException(_(u"Invalid argument: “%s”") % force,
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   422
                ERR.INVALID_OPTION)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   423
        dom = self.__getDomain(domainname, None)
18
c98e08791ee8 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   424
        if force is None:
c98e08791ee8 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   425
            dom.updateTransport(transport)
c98e08791ee8 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   426
        else:
c98e08791ee8 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   427
            dom.updateTransport(transport, force=True)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   428
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   429
    def domainDelete(self, domainname, force=None):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   430
        if not force is None and force not in ['deluser','delalias','delall']:
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   431
            raise VMMDomainException(_(u"Invalid argument: “%s”") % force,
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   432
                ERR.INVALID_OPTION)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   433
        dom = self.__getDomain(domainname)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   434
        gid = dom.getID()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   435
        domdir = dom.getDir()
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   436
        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
   437
            dom.delete(True, True)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   438
        elif force == 'deluser':
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   439
            dom.delete(delUser=True)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   440
        elif force == 'delalias':
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   441
            dom.delete(delAlias=True)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   442
        else:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   443
            dom.delete()
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   444
        if self.__Cfg.dget('domain.delete_directory'):
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   445
            self.__domDirDelete(domdir, gid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   446
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   447
    def domainInfo(self, domainname, details=None):
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   448
        if details not in [None, 'accounts', 'aliasdomains', 'aliases', 'full',
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   449
                'relocated', 'detailed']:
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   450
            raise VMMException(_(u'Invalid argument: “%s”') % details,
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 88
diff changeset
   451
                    ERR.INVALID_AGUMENT)
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   452
        if details == 'detailed':
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   453
            details = 'full'
132
fa22bd13b4d1 Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   454
            self.__warnings.append(_(u'\
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   455
The keyword “detailed” is deprecated and will be removed in a future release.\n\
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   456
   Please use the keyword “full” to get full details.'))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   457
        dom = self.__getDomain(domainname)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   458
        dominfo = dom.getInfo()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   459
        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
   460
            dominfo['domainname'] += ' (%s)' % ace2idna(dominfo['domainname'])
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   461
        if details is None:
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   462
            return dominfo
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   463
        elif details == 'accounts':
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   464
            return (dominfo, dom.getAccounts())
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   465
        elif details == 'aliasdomains':
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   466
            return (dominfo, dom.getAliaseNames())
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   467
        elif details == 'aliases':
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   468
            return (dominfo, dom.getAliases())
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   469
        elif details == 'relocated':
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   470
            return(dominfo, dom.getRelocated())
62
869de537a020 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   471
        else:
44
c9ab6900ede9 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 40
diff changeset
   472
            return (dominfo, dom.getAliaseNames(), dom.getAccounts(),
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   473
                    dom.getAliases(), dom.getRelocated())
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   474
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   475
    def aliasDomainAdd(self, aliasname, domainname):
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   476
        """Adds an alias domain to the domain.
53
5b50eb306d37 * 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 52
diff changeset
   477
45
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   478
        Keyword arguments:
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   479
        aliasname -- the name of the alias domain (str)
45
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   480
        domainname -- name of the target domain (str)
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   481
        """
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   482
        dom = self.__getDomain(domainname)
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   483
        aliasDom = AliasDomain(self.__dbh, aliasname, dom)
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   484
        aliasDom.save()
53
5b50eb306d37 * 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 52
diff changeset
   485
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   486
    def aliasDomainInfo(self, aliasname):
53
5b50eb306d37 * 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 52
diff changeset
   487
        self.__dbConnect()
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   488
        aliasDom = AliasDomain(self.__dbh, aliasname, None)
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   489
        return aliasDom.info()
45
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   490
78
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   491
    def aliasDomainSwitch(self, aliasname, domainname):
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   492
        """Modifies the target domain of an existing alias domain.
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   493
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   494
        Keyword arguments:
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   495
        aliasname -- the name of the alias domain (str)
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   496
        domainname -- name of the new target domain (str)
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   497
        """
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   498
        dom = self.__getDomain(domainname)
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   499
        aliasDom = AliasDomain(self.__dbh, aliasname, dom)
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   500
        aliasDom.switch()
8f1e501b1bb1 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 76
diff changeset
   501
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   502
    def aliasDomainDelete(self, aliasname):
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   503
        """Deletes the specified alias domain.
53
5b50eb306d37 * 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 52
diff changeset
   504
45
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   505
        Keyword arguments:
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   506
        aliasname -- the name of the alias domain (str)
45
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   507
        """
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   508
        self.__dbConnect()
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   509
        aliasDom = AliasDomain(self.__dbh, aliasname, None)
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 54
diff changeset
   510
        aliasDom.delete()
45
9e66138aad0b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 44
diff changeset
   511
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   512
    def domainList(self, pattern=None):
35
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   513
        from Domain import search
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   514
        like = False
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   515
        if pattern is not None:
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   516
            if pattern.startswith('%') or pattern.endswith('%'):
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   517
                like = True
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   518
                if pattern.startswith('%') and pattern.endswith('%'):
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   519
                    domain = pattern[1:-1]
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   520
                elif pattern.startswith('%'):
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   521
                    domain = pattern[1:]
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   522
                elif pattern.endswith('%'):
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   523
                    domain = pattern[:-1]
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   524
                if not re.match(RE_DOMAIN_SRCH, domain):
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   525
                    raise VMMException(
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   526
                    _(u"The pattern “%s” contains invalid characters.") %
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   527
                    pattern, ERR.DOMAIN_INVALID)
35
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   528
        self.__dbConnect()
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   529
        return search(self.__dbh, pattern=pattern, like=like)
22cc616aef61 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   530
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   531
    def userAdd(self, emailaddress, password):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   532
        acc = self.__getAccount(emailaddress, password)
38
c44ea4526546 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 35
diff changeset
   533
        if password is None:
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   534
            password = read_pass()
38
c44ea4526546 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 35
diff changeset
   535
            acc.setPassword(self.__pwhash(password))
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   536
        acc.save(self.__Cfg.dget('maildir.name'),
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   537
                 self.__Cfg.dget('misc.dovecot_version'),
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   538
                 self.__Cfg.dget('account.smtp'),
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   539
                 self.__Cfg.dget('account.pop3'),
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   540
                 self.__Cfg.dget('account.imap'),
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   541
                 self.__Cfg.dget('account.sieve'))
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   542
        self.__mailDirMake(acc.getDir('domain'), acc.getUID(), acc.getGID())
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   543
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   544
    def aliasAdd(self, aliasaddress, targetaddress):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   545
        alias = self.__getAlias(aliasaddress, targetaddress)
88
b3debcfea7bc * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 87
diff changeset
   546
        alias.save(long(self._postconf.read('virtual_alias_expansion_limit')))
83
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   547
        gid = self.__getDomain(alias._dest._domainname).getID()
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   548
        if gid > 0 and not Handler.accountExists(self.__dbh,
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   549
        alias._dest) and not Handler.aliasExists(self.__dbh,
84
c1363b84a24b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 83
diff changeset
   550
        alias._dest):
83
cc195af37de0 * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 80
diff changeset
   551
            self.__warnings.append(
155
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 143
diff changeset
   552
                _(u"The destination account/alias “%s” doesn't exist.")%\
84
c1363b84a24b * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 83
diff changeset
   553
                        alias._dest)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   554
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 62
diff changeset
   555
    def userDelete(self, emailaddress, force=None):
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 62
diff changeset
   556
        if force not in [None, 'delalias']:
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   557
            raise VMMException(_(u"Invalid argument: “%s”") % force,
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 62
diff changeset
   558
                    ERR.INVALID_AGUMENT)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   559
        acc = self.__getAccount(emailaddress)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   560
        uid = acc.getUID()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   561
        gid = acc.getGID()
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 62
diff changeset
   562
        acc.delete(force)
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   563
        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
   564
            try:
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   565
                self.__userDirDelete(acc.getDir('domain'), uid, gid)
48
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   566
            except VMMException, e:
0d5f58f8b8f5 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 47
diff changeset
   567
                if e.code() in [ERR.FOUND_DOTS_IN_PATH,
47
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   568
                        ERR.MAILDIR_PERM_MISMATCH, ERR.NO_SUCH_DIRECTORY]:
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   569
                    warning = _(u"""\
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   570
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
   571
    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
   572
%(directory)s
155
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 143
diff changeset
   573
    Reason: %(reason)s""") % {'directory': acc.getDir('home'),'reason': e.msg()}
47
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   574
                    self.__warnings.append(warning)
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   575
                else:
191d5a5adc4a * Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 45
diff changeset
   576
                    raise e
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   577
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   578
    def aliasInfo(self, aliasaddress):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   579
        alias = self.__getAlias(aliasaddress)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   580
        return alias.getInfo()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   581
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   582
    def aliasDelete(self, aliasaddress, targetaddress=None):
12
44161dbb1518 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 9
diff changeset
   583
        alias = self.__getAlias(aliasaddress, targetaddress)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   584
        alias.delete()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   585
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 88
diff changeset
   586
    def userInfo(self, emailaddress, details=None):
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   587
        if details not in (None, 'du', 'aliases', 'full'):
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   588
            raise VMMException(_(u'Invalid argument: “%s”') % details,
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   589
                               ERR.INVALID_AGUMENT)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   590
        acc = self.__getAccount(emailaddress)
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   591
        info = acc.getInfo(self.__Cfg.dget('misc.dovecot_version'))
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   592
        if self.__Cfg.dget('account.disk_usage') or details in ('du', 'full'):
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
   593
            info['disk usage'] = self.__getDiskUsage('%(maildir)s' % info)
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   594
            if details in (None, 'du'):
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 88
diff changeset
   595
                return info
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   596
        if details in ('aliases', 'full'):
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 88
diff changeset
   597
            return (info, acc.getAliases())
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   598
        return info
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   599
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   600
    def userByID(self, uid):
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   601
        from Handler.Account import getAccountByID
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 18
diff changeset
   602
        self.__dbConnect()
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 18
diff changeset
   603
        return getAccountByID(uid, self.__dbh)
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 18
diff changeset
   604
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   605
    def userPassword(self, emailaddress, password):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   606
        acc = self.__getAccount(emailaddress)
38
c44ea4526546 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 35
diff changeset
   607
        if acc.getUID() == 0:
155
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 143
diff changeset
   608
           raise VMMException(_(u"Account doesn't exist"), ERR.NO_SUCH_ACCOUNT)
38
c44ea4526546 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 35
diff changeset
   609
        if password is None:
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   610
            password = read_pass()
70
a3663ad491bf * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 69
diff changeset
   611
        acc.modify('password', self.__pwhash(password, user=emailaddress))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   612
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   613
    def userName(self, emailaddress, name):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   614
        acc = self.__getAccount(emailaddress)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   615
        acc.modify('name', name)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   616
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   617
    def userTransport(self, emailaddress, transport):
17
fe9be0081e5f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 16
diff changeset
   618
        acc = self.__getAccount(emailaddress)
fe9be0081e5f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 16
diff changeset
   619
        acc.modify('transport', transport)
fe9be0081e5f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 16
diff changeset
   620
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   621
    def userDisable(self, emailaddress, service=None):
132
fa22bd13b4d1 Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   622
        if service == 'managesieve':
fa22bd13b4d1 Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   623
            service = 'sieve'
fa22bd13b4d1 Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   624
            self.__warnings.append(_(u'\
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   625
The service name “managesieve” is deprecated and will be removed\n\
132
fa22bd13b4d1 Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   626
   in a future release.\n\
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   627
   Please use the service name “sieve” instead.'))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   628
        acc = self.__getAccount(emailaddress)
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   629
        acc.disable(self.__Cfg.dget('misc.dovecot_version'), service)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   630
54
1fc1f82c662f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 53
diff changeset
   631
    def userEnable(self, emailaddress, service=None):
132
fa22bd13b4d1 Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   632
        if service == 'managesieve':
fa22bd13b4d1 Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   633
            service = 'sieve'
fa22bd13b4d1 Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   634
            self.__warnings.append(_(u'\
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   635
The service name “managesieve” is deprecated and will be removed\n\
132
fa22bd13b4d1 Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   636
   in a future release.\n\
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 132
diff changeset
   637
   Please use the service name “sieve” instead.'))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   638
        acc = self.__getAccount(emailaddress)
174
974bafa59330 VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 168
diff changeset
   639
        acc.enable(self.__Cfg.dget('misc.dovecot_version'), service)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   640
80
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   641
    def relocatedAdd(self, emailaddress, targetaddress):
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   642
        relocated = self.__getRelocated(emailaddress, targetaddress)
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   643
        relocated.save()
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   644
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   645
    def relocatedInfo(self, emailaddress):
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   646
        relocated = self.__getRelocated(emailaddress)
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   647
        return relocated.getInfo()
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   648
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   649
    def relocatedDelete(self, emailaddress):
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   650
        relocated = self.__getRelocated(emailaddress)
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   651
        relocated.delete()
5dedc673524e * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 78
diff changeset
   652
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   653
    def __del__(self):
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 184
diff changeset
   654
        if isinstance(self.__dbh, PgSQL.Connection) and self.__dbh._isOpen:
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   655
            self.__dbh.close()