VirtualMailManager/Account.py
author Pascal Volk <neverseen@users.sourceforge.net>
Thu, 15 Apr 2010 20:21:18 +0000
branchv0.6.x
changeset 250 73cd082cd724
parent 246 481280686789
child 252 af555e6967c8
permissions -rw-r--r--
VMM/{Account,Alias,Relocated}: added a address property to the classes Account, Alias and Relocated.
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: 156
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
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
     5
"""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
     6
    VirtualMailManager.Account
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     7
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
     8
    Virtual Mail Manager's Account class to manage e-mail accounts.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
     9
"""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    10
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 162
diff changeset
    11
from VirtualMailManager.Domain import Domain
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 162
diff changeset
    12
from VirtualMailManager.EmailAddress import EmailAddress
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    13
from VirtualMailManager.Transport import Transport
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    14
from VirtualMailManager.constants.ERROR import \
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    15
     ACCOUNT_EXISTS, ACCOUNT_MISSING_PASSWORD, ALIAS_EXISTS, ALIAS_PRESENT, \
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    16
     INVALID_AGUMENT, NO_SUCH_ACCOUNT, NO_SUCH_DOMAIN, RELOCATED_EXISTS, \
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    17
     UNKNOWN_MAILLOCATION_NAME, UNKNOWN_SERVICE
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    18
from VirtualMailManager.errors import AccountError as AErr
228
a7b000ca4ac9 VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 227
diff changeset
    19
from VirtualMailManager.maillocation import MailLocation, known_format
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    20
from VirtualMailManager.pycompat import all
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    21
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    22
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    23
_ = lambda msg: msg
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    24
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    25
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
    26
class Account(object):
3
a9b44e04bf01 * VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 0
diff changeset
    27
    """Class to manage e-mail accounts."""
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    28
    __slots__ = ('_addr', '_domain', '_mid', '_new', '_passwd', '_tid', '_uid',
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    29
                 '_dbh')
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    30
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    31
    def __init__(self, dbh, address):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    32
        """Creates a new Account instance.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    33
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    34
        When an account with the given *address* could be found in the
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    35
        database all relevant data will be loaded.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    36
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    37
        Arguments:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    38
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    39
        `dbh` : pyPgSQL.PgSQL.Connection
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    40
          A database connection for the database access.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    41
        `address` : basestring
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    42
          The e-mail address of the (new) Account.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    43
        """
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    44
        if not isinstance(address, EmailAddress):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    45
            raise TypeError("Argument 'address' is not an EmailAddress")
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    46
        self._addr = address
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    47
        self._dbh = dbh
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    48
        self._domain = Domain(self._dbh, self._addr.domainname)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    49
        if not self._domain.gid:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    50
            raise AErr(_(u"The domain '%s' doesn't exist.") %
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    51
                       self._addr.domainname, NO_SUCH_DOMAIN)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    52
        self._uid = 0
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    53
        self._mid = 0
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    54
        self._tid = 0
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    55
        self._passwd = None
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    56
        self._new = True
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    57
        self._load()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    58
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    59
    def _load(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    60
        """Load 'uid', 'mid' and 'tid' from the database and set _new to
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    61
        `False` - if the user could be found. """
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    62
        dbc = self._dbh.cursor()
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    63
        dbc.execute(
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    64
            "SELECT uid, mid, tid FROM users WHERE gid=%s AND local_part=%s",
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    65
                    self._domain.gid, self._addr.localpart)
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    66
        result = dbc.fetchone()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    67
        dbc.close()
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    68
        if result:
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    69
            self._uid, self._mid, self._tid = result
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    70
            self._new = False
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    71
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    72
    def _set_uid(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    73
        """Set the unique ID for the new Account."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    74
        assert self._uid == 0
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    75
        dbc = self._dbh.cursor()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    76
        dbc.execute("SELECT nextval('users_uid')")
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    77
        self._uid = dbc.fetchone()[0]
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    78
        dbc.close()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    79
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    80
    def _prepare(self, maillocation):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    81
        """Check and set different attributes - before we store the
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    82
        information in the database."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    83
        if not known_format(maillocation):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    84
            raise AErr(_(u'Unknown mail_location mailbox format: %r') %
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    85
                       maillocation, UNKNOWN_MAILLOCATION_NAME)
228
a7b000ca4ac9 VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 227
diff changeset
    86
        self._mid = MailLocation(format=maillocation).mid
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    87
        if not self._tid:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    88
            self._tid = self._domain.tid
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    89
        self._set_uid()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    90
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    91
    def _switch_state(self, state, dcvers, service):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    92
        """Switch the state of the Account's services on or off. See
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    93
        Account.enable()/Account.disable() for more information."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    94
        self._chk_state()
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    95
        if service not in (None, 'all', 'imap', 'pop3', 'sieve', 'smtp'):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    96
            raise AErr(_(u"Unknown service: '%s'.") % service, UNKNOWN_SERVICE)
134
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
    97
        if dcvers > 11:
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
    98
            sieve_col = 'sieve'
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
    99
        else:
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   100
            sieve_col = 'managesieve'
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   101
        if service in ('smtp', 'pop3', 'imap'):
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   102
            sql = 'UPDATE users SET %s = %s WHERE uid = %d' % (service, state,
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   103
                                                               self._uid)
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   104
        elif service == 'sieve':
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   105
            sql = 'UPDATE users SET %s = %s WHERE uid = %d' % (sieve_col,
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   106
                                                               state,
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   107
                                                               self._uid)
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   108
        else:
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   109
            sql = 'UPDATE users SET smtp = %(s)s, pop3 = %(s)s, imap = %(s)s,\
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   110
 %(col)s = %(s)s WHERE uid = %(uid)d' % \
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   111
                {'s': state, 'col': sieve_col, 'uid': self._uid}
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   112
        dbc = self._dbh.cursor()
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   113
        dbc.execute(sql)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   114
        if dbc.rowcount > 0:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   115
            self._dbh.commit()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   116
        dbc.close()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   117
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   118
    def _count_aliases(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   119
        """Count all alias addresses where the destination address is the
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   120
        address of the Account."""
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   121
        dbc = self._dbh.cursor()
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   122
        sql = "SELECT COUNT(destination) FROM alias WHERE destination = '%s'"\
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   123
                % self._addr
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   124
        dbc.execute(sql)
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   125
        a_count = dbc.fetchone()[0]
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   126
        dbc.close()
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   127
        return a_count
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   128
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   129
    def _chk_state(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   130
        """Raise an AccountError if the Account is new - not yet saved in the
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   131
        database."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   132
        if self._new:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   133
            raise AErr(_(u"The account '%s' doesn't exist.") % self._addr,
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   134
                       NO_SUCH_ACCOUNT)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   135
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   136
    @property
250
73cd082cd724 VMM/{Account,Alias,Relocated}: added a address property to the classes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 246
diff changeset
   137
    def address(self):
73cd082cd724 VMM/{Account,Alias,Relocated}: added a address property to the classes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 246
diff changeset
   138
        """The Account's EmailAddress instance."""
73cd082cd724 VMM/{Account,Alias,Relocated}: added a address property to the classes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 246
diff changeset
   139
        return self._addr
73cd082cd724 VMM/{Account,Alias,Relocated}: added a address property to the classes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 246
diff changeset
   140
73cd082cd724 VMM/{Account,Alias,Relocated}: added a address property to the classes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 246
diff changeset
   141
    @property
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   142
    def domain_directory(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   143
        """The directory of the domain the Account belongs to."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   144
        return self._domain.directory
38
c44ea4526546 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   145
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   146
    @property
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   147
    def gid(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   148
        """The Account's group ID."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   149
        return self._domain.gid
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   150
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   151
    @property
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   152
    def home(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   153
        """The Account's home directory."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   154
        return '%s/%s' % (self._domain.directory, self._uid)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   155
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   156
    @property
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   157
    def uid(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   158
        """The Account's unique ID."""
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   159
        return self._uid
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   160
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   161
    def set_password(self, password):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   162
        """Set a password for the new Account.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   163
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   164
        If you want to update the password of an existing Account use
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   165
        Account.modify().
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   166
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   167
        Argument:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   168
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   169
        `password` : basestring
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   170
          The hashed password for the new Account."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   171
        self._passwd = password
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   172
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   173
    def set_transport(self, transport):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   174
        """Set the transport for the new Account.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   175
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   176
        If you want to update the transport of an existing Account use
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   177
        Account.modify().
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   178
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   179
        Argument:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   180
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   181
        `transport` : basestring
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   182
          The string representation of the transport, e.g.: 'dovecot:'
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   183
        """
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   184
        self._tid = Transport(self._dbh, transport=transport).tid
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   185
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   186
    def enable(self, dcvers, service=None):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   187
        """Enable a/all service/s for the Account.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   188
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   189
        Possible values for the *service* are: 'imap', 'pop3', 'sieve' and
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   190
        'smtp'. When all services should be enabled, use 'all' or the
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   191
        default value `None`.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   192
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   193
        Arguments:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   194
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   195
        `dcvers` : int
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   196
          The concatenated major and minor version number from
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   197
          `dovecot --version`.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   198
        `service` : basestring
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   199
          The name of a service ('imap', 'pop3', 'smtp', 'sieve'), 'all'
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   200
          or `None`.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   201
        """
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   202
        self._switch_state(True, dcvers, service)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   203
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   204
    def disable(self, dcvers, service=None):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   205
        """Disable a/all service/s for the Account.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   206
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   207
        For more information see: Account.enable()."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   208
        self._switch_state(False, dcvers, service)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   209
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   210
    def save(self, maillocation, dcvers, smtp, pop3, imap, sieve):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   211
        """Save the new Account in the database.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   212
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   213
        Arguments:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   214
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   215
        `maillocation` : basestring
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   216
          The mailbox format of the mail_location: 'maildir', 'mbox',
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   217
          'dbox' or 'mdbox'.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   218
        `dcvers` : int
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   219
          The concatenated major and minor version number from
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   220
          `dovecot --version`.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   221
        `smtp, pop3, imap, sieve` : bool
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   222
          Indicates if the user of the Account should be able to use this
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   223
          services.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   224
        """
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   225
        if not self._new:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   226
            raise AErr(_(u"The account '%s' already exists.") % self._addr,
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   227
                       ACCOUNT_EXISTS)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   228
        if not self._passwd:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   229
            raise AErr(_(u"No password set for '%s'.") % self._addr,
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   230
                       ACCOUNT_MISSING_PASSWORD)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   231
        assert all(isinstance(service, bool) for service in (smtp, pop3, imap,
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   232
                                                             sieve))
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   233
        if dcvers > 11:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   234
            sieve_col = 'sieve'
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   235
        else:
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   236
            sieve_col = 'managesieve'
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   237
        self._prepare(maillocation)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   238
        sql = "INSERT INTO users (local_part, passwd, uid, gid, mid, tid,\
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   239
 smtp, pop3, imap, %s) VALUES ('%s', '%s', %d, %d, %d, %d, %s, %s, %s, %s)" % (
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   240
            sieve_col, self._addr.localpart, self._passwd, self._uid,
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   241
            self._domain.gid, self._mid, self._tid, smtp, pop3, imap, sieve)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   242
        dbc = self._dbh.cursor()
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   243
        dbc.execute(sql)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   244
        self._dbh.commit()
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   245
        dbc.close()
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   246
        self._new = False
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   247
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   248
    def modify(self, field, value):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   249
        """Update the Account's *field* to the new *value*.
128
cf8116625866 Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 121
diff changeset
   250
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   251
        Possible values for *filed* are: 'name', 'password' and
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   252
        'transport'.  *value* is the *field*'s new value.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   253
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   254
        Arguments:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   255
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   256
        `field` : basestring
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   257
          The attribute name: 'name', 'password' or 'transport'
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   258
        `value` : basestring
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   259
          The new value of the attribute. The password is expected as a
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   260
          hashed password string.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   261
        """
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   262
        if field not in ('name', 'password', 'transport'):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   263
            raise AErr(_(u"Unknown field: '%s'") % field, INVALID_AGUMENT)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   264
        self._chk_state()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   265
        dbc = self._dbh.cursor()
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   266
        if field == 'password':
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   267
            dbc.execute('UPDATE users SET passwd = %s WHERE uid = %s',
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   268
                        value, self._uid)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   269
        elif field == 'transport':
235
9d3405ed08e5 VMM/Transport: Renamed attribute/property {,_}id to {,_}tid.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 228
diff changeset
   270
            self._tid = Transport(self._dbh, transport=value).tid
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   271
            dbc.execute('UPDATE users SET tid = %s WHERE uid = %s',
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   272
                        self._tid, self._uid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   273
        else:
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   274
            dbc.execute('UPDATE users SET name = %s WHERE uid = %s',
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   275
                        value, self._uid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   276
        if dbc.rowcount > 0:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   277
            self._dbh.commit()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   278
        dbc.close()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   279
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   280
    def get_info(self, dcvers):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   281
        """Returns a dict with some information about the Account.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   282
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   283
        The keys of the dict are: 'address', 'gid', 'home', 'imap'
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   284
        'mail_location', 'name', 'pop3', 'sieve', 'smtp', transport' and
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   285
        'uid'.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   286
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   287
        Argument:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   288
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   289
        `dcvers` : int
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   290
          The concatenated major and minor version number from
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   291
          `dovecot --version`.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   292
        """
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   293
        self._chk_state()
134
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   294
        if dcvers > 11:
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   295
            sieve_col = 'sieve'
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   296
        else:
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   297
            sieve_col = 'managesieve'
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   298
        sql = 'SELECT name, uid, gid, mid, tid, smtp, pop3, imap, %s\
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   299
 FROM users WHERE uid = %d' % (sieve_col, self._uid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   300
        dbc = self._dbh.cursor()
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   301
        dbc.execute(sql)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   302
        info = dbc.fetchone()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   303
        dbc.close()
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   304
        if info:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   305
            keys = ('name', 'uid', 'gid', 'mid', 'transport', 'smtp',
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   306
                    'pop3', 'imap', sieve_col)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   307
            info = dict(zip(keys, info))
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   308
            for service in ('smtp', 'pop3', 'imap', sieve_col):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   309
                if info[service]:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   310
                    # TP: A service (pop3/imap) is enabled/usable for a user
41
fbcb7e314510 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   311
                    info[service] = _('enabled')
20
55146c78b3fb * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 19
diff changeset
   312
                else:
156
a849843115e9 Added comments for the Translation Project. Updated PO template.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 155
diff changeset
   313
                    # TP: A service (pop3/imap) isn't enabled/usable for a user
41
fbcb7e314510 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   314
                    info[service] = _('disabled')
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   315
            info['address'] = self._addr
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   316
            info['home'] = '%s/%s' % (self._domain.directory, info['uid'])
227
87db9f1f95ea VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 225
diff changeset
   317
            info['mail_location'] = MailLocation(mid=info['mid']).mail_location
246
481280686789 VMM/Account: Account.get_info() use the domain's transport, if tid matches.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 245
diff changeset
   318
            if info['transport'] == self._domain.transport.tid:
481280686789 VMM/Account: Account.get_info() use the domain's transport, if tid matches.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 245
diff changeset
   319
                info['transport'] = self._domain.transport.transport
481280686789 VMM/Account: Account.get_info() use the domain's transport, if tid matches.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 245
diff changeset
   320
            else:
481280686789 VMM/Account: Account.get_info() use the domain's transport, if tid matches.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 245
diff changeset
   321
                info['transport'] = Transport(self._dbh,
481280686789 VMM/Account: Account.get_info() use the domain's transport, if tid matches.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 245
diff changeset
   322
                                              tid=info['transport']).transport
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   323
            del info['mid']
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   324
            return info
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   325
        # nearly impossible‽
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   326
        raise AErr(_(u"Couldn't fetch information for account: '%s'") \
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   327
                   % self._addr, NO_SUCH_ACCOUNT)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   328
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   329
    def get_aliases(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   330
        """Return a list with all alias e-mail addresses, whose destination
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   331
        is the address of the Account."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   332
        self._chk_state()
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   333
        dbc = self._dbh.cursor()
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   334
        dbc.execute("SELECT address ||'@'|| domainname FROM alias, domain_name\
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   335
 WHERE destination = %s AND domain_name.gid = alias.gid\
145
ead2a7e9f8be Sort alias addresses in Account.getAliases() / vmm userinfo.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 144
diff changeset
   336
 AND domain_name.is_primary ORDER BY address", str(self._addr))
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   337
        addresses = dbc.fetchall()
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   338
        dbc.close()
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   339
        aliases = []
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   340
        if addresses:
144
4c6aa6c29dd7 Small optimizations in Account.getAliases() and Alias.getInfo().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 138
diff changeset
   341
            aliases = [alias[0] for alias in addresses]
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   342
        return aliases
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   343
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   344
    def delete(self, delalias):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   345
        """Delete the Account from the database.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   346
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   347
        Argument:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   348
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   349
        `delalias` : basestring
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   350
          if the values of delalias is 'delalias', all aliases, which
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   351
          points to the Account, will be also deleted."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   352
        self._chk_state()
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   353
        dbc = self._dbh.cursor()
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   354
        if delalias == 'delalias':
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   355
            dbc.execute('DELETE FROM users WHERE uid= %s', self._uid)
65
5506433db9a3 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   356
            # delete also all aliases where the destination address is the same
5506433db9a3 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   357
            # as for this account.
114
e671210b04b8 Fixed a libpq.OperationalError in Account.delete()
Pascal Volk <neverseen@users.sourceforge.net>
parents: 113
diff changeset
   358
            dbc.execute("DELETE FROM alias WHERE destination = %s",
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   359
                        str(self._addr))
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   360
            self._dbh.commit()
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   361
        else:  # check first for aliases
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   362
            a_count = self._count_aliases()
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   363
            if a_count == 0:
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   364
                dbc.execute('DELETE FROM users WHERE uid = %s', self._uid)
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   365
                self._dbh.commit()
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   366
            else:
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   367
                dbc.close()
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   368
                raise AErr(_(u"There are %(count)d aliases with the \
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   369
destination address '%(address)s'.") % \
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   370
                           {'count': a_count, 'address': self._addr},
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   371
                           ALIAS_PRESENT)
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   372
        dbc.close()
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   373
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   374
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   375
def getAccountByID(uid, dbh):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   376
    """Search an Account by its UID.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   377
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   378
    Argument:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   379
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   380
    `uid` : long
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   381
      The Account unique ID.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   382
    `dbh` : pyPgSQL.PgSQL.Connection
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   383
      a database connection for the database access.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   384
    """
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   385
    try:
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   386
        uid = long(uid)
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   387
    except ValueError:
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   388
        raise AErr(_(u'UID must be an int/long.'), INVALID_AGUMENT)
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   389
    if uid < 1:
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   390
        raise AErr(_(u'UID must be greater than 0.'), INVALID_AGUMENT)
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   391
    dbc = dbh.cursor()
43
92a6132940f5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 41
diff changeset
   392
    dbc.execute("SELECT local_part||'@'|| domain_name.domainname AS address,\
92a6132940f5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 41
diff changeset
   393
 uid, users.gid FROM users LEFT JOIN domain_name ON (domain_name.gid \
92a6132940f5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 41
diff changeset
   394
 = users.gid AND is_primary) WHERE uid = %s;", uid)
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   395
    info = dbc.fetchone()
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   396
    dbc.close()
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   397
    if not info:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   398
        raise AErr(_(u"There is no account with the UID '%d'.") % uid,
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   399
                   NO_SUCH_ACCOUNT)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   400
    info = dict(zip(('address', 'uid', 'gid'), info))
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   401
    return info
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   402
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   403
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   404
del _