VirtualMailManager/account.py
author Pascal Volk <user@localhost.localdomain.org>
Sat, 15 Sep 2012 17:31:34 +0000
changeset 613 7b3494f1a2ef
parent 611 8e9b0046bc8f
child 614 1ec3497a6733
permissions -rw-r--r--
VMM/account: Fixed account's transport check. Make sure that 'virtual:' isn't used as transport when the mailbox-format is set to mdbox or sdbox.
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 -*-
568
14abdd04ddf5 Updated copyright notices to include the year 2012.
Pascal Volk <user@localhost.localdomain.org>
parents: 561
diff changeset
     2
# Copyright (c) 2007 - 2012, Pascal Volk
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     3
# See COPYING for distribution information.
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
     4
"""
320
011066435e6f VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 316
diff changeset
     5
    VirtualMailManager.account
302
32b4a39b5640 VMM/maillocation: Reworked class MailLocation to match the new
Pascal Volk <neverseen@users.sourceforge.net>
parents: 293
diff changeset
     6
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
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
532
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
    11
from VirtualMailManager.common import version_str, \
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
    12
     format_domain_default
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 306
diff changeset
    13
from VirtualMailManager.constants import \
252
af555e6967c8 VMM/Account: renamed function getAccountByID -> get_account_by_uid.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 250
diff changeset
    14
     ACCOUNT_EXISTS, ACCOUNT_MISSING_PASSWORD, ALIAS_PRESENT, \
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 306
diff changeset
    15
     INVALID_ARGUMENT, INVALID_MAIL_LOCATION, NO_SUCH_ACCOUNT, \
451
2408a3cd4bea VMM/account: Removed unused import.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 444
diff changeset
    16
     NO_SUCH_DOMAIN, VMM_ERROR
442
abcd73f5e980 VMM/account: Sorted imports …
Pascal Volk <neverseen@users.sourceforge.net>
parents: 417
diff changeset
    17
from VirtualMailManager.domain import Domain
abcd73f5e980 VMM/account: Sorted imports …
Pascal Volk <neverseen@users.sourceforge.net>
parents: 417
diff changeset
    18
from VirtualMailManager.emailaddress import EmailAddress
404
0c52094447b0 VMM/{account,domain}: Added a versions check to the update_quotalimit
Pascal Volk <neverseen@users.sourceforge.net>
parents: 390
diff changeset
    19
from VirtualMailManager.errors import VMMError, AccountError as AErr
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
    20
from VirtualMailManager.maillocation import MailLocation
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
    21
from VirtualMailManager.password import pwhash
442
abcd73f5e980 VMM/account: Sorted imports …
Pascal Volk <neverseen@users.sourceforge.net>
parents: 417
diff changeset
    22
from VirtualMailManager.quotalimit import QuotaLimit
abcd73f5e980 VMM/account: Sorted imports …
Pascal Volk <neverseen@users.sourceforge.net>
parents: 417
diff changeset
    23
from VirtualMailManager.transport import Transport
444
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
    24
from VirtualMailManager.serviceset import ServiceSet
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    25
444
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
    26
__all__ = ('Account', 'get_account_by_uid')
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    27
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    28
_ = lambda msg: msg
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
    29
cfg_dget = lambda option: None
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    30
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    31
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
    32
class Account(object):
3
a9b44e04bf01 * VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 0
diff changeset
    33
    """Class to manage e-mail accounts."""
293
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    34
    __slots__ = ('_addr', '_dbh', '_domain', '_mail', '_new', '_passwd',
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
    35
                 '_qlimit', '_services', '_transport', '_note', '_uid')
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    36
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    37
    def __init__(self, dbh, address):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    38
        """Creates a new Account instance.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    39
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    40
        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
    41
        database all relevant data will be loaded.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    42
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    43
        Arguments:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    44
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    45
        `dbh` : pyPgSQL.PgSQL.Connection
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    46
          A database connection for the database access.
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
    47
        `address` : VirtualMailManager.EmailAddress.EmailAddress
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    48
          The e-mail address of the (new) Account.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    49
        """
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    50
        if not isinstance(address, EmailAddress):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    51
            raise TypeError("Argument 'address' is not an EmailAddress")
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    52
        self._addr = address
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    53
        self._dbh = dbh
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    54
        self._domain = Domain(self._dbh, self._addr.domainname)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    55
        if not self._domain.gid:
341
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 338
diff changeset
    56
            # TP: Hm, what “quotation marks” should be used?
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 338
diff changeset
    57
            # If you are unsure have a look at:
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 338
diff changeset
    58
            # http://en.wikipedia.org/wiki/Quotation_mark,_non-English_usage
417
8209da83e256 VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 404
diff changeset
    59
            raise AErr(_(u"The domain '%s' does not exist.") %
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    60
                       self._addr.domainname, NO_SUCH_DOMAIN)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    61
        self._uid = 0
293
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
    62
        self._mail = None
531
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
    63
        self._qlimit = None
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
    64
        self._services = None
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
    65
        self._transport = None
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
    66
        self._note = None
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    67
        self._passwd = None
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    68
        self._new = True
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    69
        self._load()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    70
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
    71
    def __nonzero__(self):
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
    72
        """Returns `True` if the Account is known, `False` if it's new."""
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
    73
        return not self._new
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
    74
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    75
    def _load(self):
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
    76
        """Load 'uid', 'mid', 'qid', 'ssid', 'tid' and 'note' from the
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
    77
        database and set _new to `False` - if the user could be found. """
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    78
        dbc = self._dbh.cursor()
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
    79
        dbc.execute('SELECT uid, mid, qid, ssid, tid, note FROM users '
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
    80
                    'WHERE gid = %s AND local_part = %s',
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
    81
                    (self._domain.gid, self._addr.localpart))
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    82
        result = dbc.fetchone()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    83
        dbc.close()
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
    84
        if result:
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
    85
            self._uid, _mid, _qid, _ssid, _tid, _note = result
531
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
    86
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
    87
            def load_helper(ctor, own, field, dbresult):
559
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 543
diff changeset
    88
                #  Py25: cur = None if own is None else getattr(own, field)
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 543
diff changeset
    89
                if own is None:
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 543
diff changeset
    90
                    cur = None
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 543
diff changeset
    91
                else:
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 543
diff changeset
    92
                    cur = getattr(own, field)
531
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
    93
                if cur != dbresult:
559
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 543
diff changeset
    94
                    kwargs = {field: dbresult}
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 543
diff changeset
    95
                    if dbresult is None:
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 543
diff changeset
    96
                        return dbresult
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 543
diff changeset
    97
                    else:
cc0f67f99780 VMM: The Python 2.4.x compatibility commit.
Pascal Volk <user@localhost.localdomain.org>
parents: 543
diff changeset
    98
                        return ctor(self._dbh, **kwargs)
531
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
    99
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   100
            self._qlimit = load_helper(QuotaLimit, self._qlimit, 'qid', _qid)
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   101
            self._services = load_helper(ServiceSet, self._services, 'ssid',
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   102
                                         _ssid)
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   103
            self._transport = load_helper(Transport, self._transport, 'tid',
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   104
                                          _tid)
306
504fd29b4712 VMM/Account: s/prefix/mbformat/ and pass the dbh to MailLocation.__init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 302
diff changeset
   105
            self._mail = MailLocation(self._dbh, mid=_mid)
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   106
            self._note = _note
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   107
            self._new = False
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   108
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   109
    def _set_uid(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   110
        """Set the unique ID for the new Account."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   111
        assert self._uid == 0
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   112
        dbc = self._dbh.cursor()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   113
        dbc.execute("SELECT nextval('users_uid')")
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   114
        self._uid = dbc.fetchone()[0]
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   115
        dbc.close()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   116
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
   117
    def _prepare(self, maillocation):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   118
        """Check and set different attributes - before we store the
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   119
        information in the database.
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   120
        """
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   121
        if maillocation.dovecot_version > cfg_dget('misc.dovecot_version'):
306
504fd29b4712 VMM/Account: s/prefix/mbformat/ and pass the dbh to MailLocation.__init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 302
diff changeset
   122
            raise AErr(_(u"The mailbox format '%(mbfmt)s' requires Dovecot "
417
8209da83e256 VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 404
diff changeset
   123
                         u">= v%(version)s.") % {
8209da83e256 VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 404
diff changeset
   124
                       'mbfmt': maillocation.mbformat,
306
504fd29b4712 VMM/Account: s/prefix/mbformat/ and pass the dbh to MailLocation.__init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 302
diff changeset
   125
                       'version': version_str(maillocation.dovecot_version)},
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   126
                       INVALID_MAIL_LOCATION)
613
7b3494f1a2ef VMM/account: Fixed account's transport check.
Pascal Volk <user@localhost.localdomain.org>
parents: 611
diff changeset
   127
        transport = self._transport or self._domain.transport
7b3494f1a2ef VMM/account: Fixed account's transport check.
Pascal Volk <user@localhost.localdomain.org>
parents: 611
diff changeset
   128
        if not maillocation.postfix and \
7b3494f1a2ef VMM/account: Fixed account's transport check.
Pascal Volk <user@localhost.localdomain.org>
parents: 611
diff changeset
   129
          transport.transport.lower() in ('virtual:', 'virtual'):
306
504fd29b4712 VMM/Account: s/prefix/mbformat/ and pass the dbh to MailLocation.__init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 302
diff changeset
   130
            raise AErr(_(u"Invalid transport '%(transport)s' for mailbox "
417
8209da83e256 VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 404
diff changeset
   131
                         u"format '%(mbfmt)s'.") %
613
7b3494f1a2ef VMM/account: Fixed account's transport check.
Pascal Volk <user@localhost.localdomain.org>
parents: 611
diff changeset
   132
                       {'transport': transport,
306
504fd29b4712 VMM/Account: s/prefix/mbformat/ and pass the dbh to MailLocation.__init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 302
diff changeset
   133
                        'mbfmt': maillocation.mbformat}, INVALID_MAIL_LOCATION)
293
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   134
        self._mail = maillocation
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   135
        self._set_uid()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   136
390
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   137
    def _update_tables(self, column, value):
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   138
        """Update various columns in the users table.
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   139
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   140
        Arguments:
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   141
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   142
        `column` : basestring
444
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   143
          Name of the table column. Currently: qid, ssid and tid
390
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   144
        `value` : long
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   145
          The referenced key
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   146
        """
444
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   147
        if column not in ('qid', 'ssid', 'tid'):
390
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   148
            raise ValueError('Unknown column: %r' % column)
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   149
        dbc = self._dbh.cursor()
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   150
        dbc.execute('UPDATE users SET %s = %%s WHERE uid = %%s' % column,
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   151
                    (value, self._uid))
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   152
        if dbc.rowcount > 0:
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   153
            self._dbh.commit()
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   154
        dbc.close()
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   155
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   156
    def _count_aliases(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   157
        """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
   158
        address of the Account."""
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   159
        dbc = self._dbh.cursor()
352
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   160
        dbc.execute('SELECT COUNT(destination) FROM alias WHERE destination '
374
ecdba68c7a2c VMM/account: Account._count_aliases() cast the EmailAddress to str,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 366
diff changeset
   161
                    '= %s', (str(self._addr),))
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   162
        a_count = dbc.fetchone()[0]
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   163
        dbc.close()
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   164
        return a_count
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   165
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   166
    def _chk_state(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   167
        """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
   168
        database."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   169
        if self._new:
417
8209da83e256 VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 404
diff changeset
   170
            raise AErr(_(u"The account '%s' does not exist.") % self._addr,
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   171
                       NO_SUCH_ACCOUNT)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   172
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   173
    @property
250
73cd082cd724 VMM/{Account,Alias,Relocated}: added a address property to the classes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 246
diff changeset
   174
    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
   175
        """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
   176
        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
   177
73cd082cd724 VMM/{Account,Alias,Relocated}: added a address property to the classes
Pascal Volk <neverseen@users.sourceforge.net>
parents: 246
diff changeset
   178
    @property
329
41789df75339 VMM/account: Replaced property domain_directory by domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   179
    def domain(self):
41789df75339 VMM/account: Replaced property domain_directory by domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   180
        """The Domain to which the Account belongs to."""
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   181
        if self._domain:
329
41789df75339 VMM/account: Replaced property domain_directory by domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 320
diff changeset
   182
            return self._domain
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   183
        return None
38
c44ea4526546 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   184
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   185
    @property
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   186
    def gid(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   187
        """The Account's group ID."""
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   188
        if self._domain:
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   189
            return self._domain.gid
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   190
        return None
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   191
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   192
    @property
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   193
    def home(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   194
        """The Account's home directory."""
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   195
        if not self._new:
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   196
            return '%s/%s' % (self._domain.directory, self._uid)
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   197
        return None
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   198
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   199
    @property
293
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   200
    def mail_location(self):
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   201
        """The Account's MailLocation."""
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   202
        return self._mail
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   203
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   204
    @property
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   205
    def note(self):
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   206
        """The Account's note."""
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   207
        return self._note
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   208
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   209
    @property
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   210
    def uid(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   211
        """The Account's unique ID."""
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   212
        return self._uid
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   213
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   214
    def set_password(self, password):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   215
        """Set a password for the new Account.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   216
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   217
        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
   218
        Account.modify().
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   219
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   220
        Argument:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   221
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   222
        `password` : basestring
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   223
          The password for the new Account.
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   224
        """
390
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   225
        if not self._new:
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   226
            raise AErr(_(u"The account '%s' already exists.") % self._addr,
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   227
                       ACCOUNT_EXISTS)
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   228
        if not isinstance(password, basestring) or not password:
341
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 338
diff changeset
   229
            raise AErr(_(u"Could not accept password: '%s'") % password,
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   230
                       ACCOUNT_MISSING_PASSWORD)
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   231
        self._passwd = password
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   232
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   233
    def set_note(self, note):
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   234
        """Set the account's (optional) note.
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   235
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   236
        Argument:
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   237
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   238
        `note` : basestring or None
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   239
          The note, or None to remove
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   240
        """
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   241
        assert note is None or isinstance(note, basestring)
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   242
        self._note = note
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   243
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   244
    def save(self):
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   245
        """Save the new Account in the database."""
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   246
        if not self._new:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   247
            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
   248
                       ACCOUNT_EXISTS)
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   249
        if not self._passwd:
417
8209da83e256 VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 404
diff changeset
   250
            raise AErr(_(u"No password set for account: '%s'") % self._addr,
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   251
                       ACCOUNT_MISSING_PASSWORD)
306
504fd29b4712 VMM/Account: s/prefix/mbformat/ and pass the dbh to MailLocation.__init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 302
diff changeset
   252
        self._prepare(MailLocation(self._dbh, mbfmt=cfg_dget('mailbox.format'),
504fd29b4712 VMM/Account: s/prefix/mbformat/ and pass the dbh to MailLocation.__init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 302
diff changeset
   253
                                   directory=cfg_dget('mailbox.root')))
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   254
        dbc = self._dbh.cursor()
561
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   255
        qid = ssid = tid = None
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   256
        if self._qlimit:
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   257
            qid = self._qlimit.qid
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   258
        if self._services:
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   259
            ssid = self._services.ssid
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   260
        if self._transport:
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   261
            tid = self._transport.tid
352
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   262
        dbc.execute('INSERT INTO users (local_part, passwd, uid, gid, mid, '
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   263
                    'qid, ssid, tid, note) '
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   264
                    'VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)',
352
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   265
                    (self._addr.localpart,
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   266
                     pwhash(self._passwd, user=self._addr), self._uid,
561
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   267
                     self._domain.gid, self._mail.mid, qid, ssid, tid,
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   268
#                     self._qlimit.qid if self._qlimit else None,
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   269
#                     self._services.ssid if self._services else None,
b0165b7af7a3 VMM: The Python 2.4.x compatibility commit - part III.
Pascal Volk <user@localhost.localdomain.org>
parents: 560
diff changeset
   270
#                     self._transport.tid if self._transport else None,
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   271
                     self._note))
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   272
        self._dbh.commit()
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   273
        dbc.close()
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   274
        self._new = False
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   275
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   276
    def modify(self, field, value):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   277
        """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
   278
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   279
        Possible values for *field* are: 'name', 'password', 'note'.
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   280
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   281
        Arguments:
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
        `field` : basestring
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   284
          The attribute name: 'name', 'password' or 'note'
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   285
        `value` : basestring
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   286
          The new value of the attribute.
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   287
        """
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   288
        if field not in ('name', 'password', 'note'):
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 306
diff changeset
   289
            raise AErr(_(u"Unknown field: '%s'") % field, INVALID_ARGUMENT)
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   290
        self._chk_state()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   291
        dbc = self._dbh.cursor()
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   292
        if field == 'password':
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   293
            dbc.execute('UPDATE users SET passwd = %s WHERE uid = %s',
352
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   294
                        (pwhash(value, user=self._addr), self._uid))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   295
        else:
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   296
            dbc.execute('UPDATE users SET %s = %%s WHERE uid = %%s' % field,
352
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   297
                        (value, self._uid))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   298
        if dbc.rowcount > 0:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   299
            self._dbh.commit()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   300
        dbc.close()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   301
390
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   302
    def update_quotalimit(self, quotalimit):
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   303
        """Update the user's quota limit.
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   304
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   305
        Arguments:
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   306
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   307
        `quotalimit` : VirtualMailManager.quotalimit.QuotaLimit
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   308
          the new quota limit of the domain.
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   309
        """
404
0c52094447b0 VMM/{account,domain}: Added a versions check to the update_quotalimit
Pascal Volk <neverseen@users.sourceforge.net>
parents: 390
diff changeset
   310
        if cfg_dget('misc.dovecot_version') < 0x10102f00:
0c52094447b0 VMM/{account,domain}: Added a versions check to the update_quotalimit
Pascal Volk <neverseen@users.sourceforge.net>
parents: 390
diff changeset
   311
            raise VMMError(_(u'PostgreSQL-based dictionary quota requires '
417
8209da83e256 VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 404
diff changeset
   312
                             u'Dovecot >= v1.1.2.'), VMM_ERROR)
390
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   313
        self._chk_state()
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   314
        if quotalimit == self._qlimit:
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   315
            return
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   316
        self._qlimit = quotalimit
531
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   317
        if quotalimit is not None:
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   318
            assert isinstance(quotalimit, QuotaLimit)
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   319
            quotalimit = quotalimit.qid
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   320
        self._update_tables('qid', quotalimit)
390
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   321
444
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   322
    def update_serviceset(self, serviceset):
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   323
        """Assign a different set of services to the Account.
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   324
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   325
        Argument:
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   326
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   327
        `serviceset` : VirtualMailManager.serviceset.ServiceSet
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   328
          the new service set.
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   329
        """
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   330
        self._chk_state()
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   331
        if serviceset == self._services:
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   332
            return
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   333
        self._services = serviceset
531
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   334
        if serviceset is not None:
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   335
            assert isinstance(serviceset, ServiceSet)
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   336
            serviceset = serviceset.ssid
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   337
        self._update_tables('ssid', serviceset)
444
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   338
390
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   339
    def update_transport(self, transport):
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   340
        """Sets a new transport for the Account.
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   341
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   342
        Arguments:
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   343
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   344
        `transport` : VirtualMailManager.transport.Transport
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   345
          the new transport
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   346
        """
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   347
        self._chk_state()
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   348
        if transport == self._transport:
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   349
            return
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   350
        self._transport = transport
531
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   351
        if transport is not None:
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   352
            assert isinstance(transport, Transport)
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   353
            if transport.transport.lower() in ('virtual', 'virtual:') and \
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   354
                not self._mail.postfix:
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   355
                raise AErr(_(u"Invalid transport '%(transport)s' for mailbox "
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   356
                             u"format '%(mbfmt)s'.") %
611
8e9b0046bc8f PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents: 568
diff changeset
   357
                           {'transport': transport,
8e9b0046bc8f PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents: 568
diff changeset
   358
                            'mbfmt': self._mail.mbformat},
531
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   359
                           INVALID_MAIL_LOCATION)
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   360
            transport = transport.tid
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   361
        self._update_tables('tid', transport)
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   362
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   363
    def _get_info_transport(self):
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   364
        if self._transport:
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   365
            return self._transport.transport
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   366
        return format_domain_default(self._domain.transport.transport)
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   367
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   368
    def _get_info_serviceset(self):
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   369
        if self._services:
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   370
            services = self._services.services
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   371
            fmt = lambda s: s
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   372
        else:
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   373
            services = self._domain.serviceset.services
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   374
            fmt = format_domain_default
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   375
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   376
        ret = {}
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   377
        for service, state in services.iteritems():
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   378
            # TP: A service (e.g. pop3 or imap) may be enabled/usable or
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   379
            # disabled/unusable for a user.
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   380
            ret[service] = fmt((_('disabled'), _('enabled'))[state])
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   381
        return ret
390
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   382
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   383
    def get_info(self):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   384
        """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
   385
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   386
        The keys of the dict are: 'address', 'gid', 'home', 'imap'
390
660b42391c8e VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents: 389
diff changeset
   387
        'mail_location', 'name', 'pop3', 'sieve', 'smtp', transport', 'uid',
532
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   388
        'uq_bytes', 'uq_messages', 'ql_bytes', 'ql_messages', and
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   389
        'ql_domaindefault'.
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   390
        """
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   391
        self._chk_state()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   392
        dbc = self._dbh.cursor()
444
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   393
        dbc.execute('SELECT name, CASE WHEN bytes IS NULL THEN 0 ELSE bytes '
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   394
                    'END, CASE WHEN messages IS NULL THEN 0 ELSE messages END '
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   395
                    'FROM users LEFT JOIN userquota USING (uid) WHERE '
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   396
                    'users.uid = %s', (self._uid,))
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   397
        info = dbc.fetchone()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   398
        dbc.close()
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   399
        if info:
444
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   400
            info = dict(zip(('name', 'uq_bytes', 'uq_messages'), info))
531
cf3eb03c1c4f Modify Account class to handle NULL references
martin f. krafft <madduck@madduck.net>
parents: 528
diff changeset
   401
            info.update(self._get_info_serviceset())
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   402
            info['address'] = self._addr
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   403
            info['gid'] = self._domain.gid
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   404
            info['home'] = '%s/%s' % (self._domain.directory, self._uid)
293
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   405
            info['mail_location'] = self._mail.mail_location
532
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   406
            if self._qlimit:
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   407
                info['ql_bytes'] = self._qlimit.bytes
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   408
                info['ql_messages'] = self._qlimit.messages
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   409
                info['ql_domaindefault'] = False
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   410
            else:
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   411
                info['ql_bytes'] = self._domain.quotalimit.bytes
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   412
                info['ql_messages'] = self._domain.quotalimit.messages
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   413
                info['ql_domaindefault'] = True
2bb40aaef94e Modify userinfo output to indicate when domain defaults are displayed
martin f. krafft <madduck@madduck.net>
parents: 531
diff changeset
   414
            info['transport'] = self._get_info_transport()
539
5806fb74130b Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents: 532
diff changeset
   415
            info['note'] = self._note
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   416
            info['uid'] = self._uid
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   417
            return info
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   418
        # nearly impossible‽
341
6709d0faf2f5 VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 338
diff changeset
   419
        raise AErr(_(u"Could not fetch information for account: '%s'") %
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 276
diff changeset
   420
                   self._addr, NO_SUCH_ACCOUNT)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   421
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   422
    def get_aliases(self):
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   423
        """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
   424
        is the address of the Account."""
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   425
        self._chk_state()
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   426
        dbc = self._dbh.cursor()
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 276
diff changeset
   427
        dbc.execute("SELECT address ||'@'|| domainname FROM alias, "
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 276
diff changeset
   428
                    "domain_name WHERE destination = %s AND domain_name.gid = "
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 276
diff changeset
   429
                    "alias.gid AND domain_name.is_primary ORDER BY address",
352
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   430
                    (str(self._addr),))
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   431
        addresses = dbc.fetchall()
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   432
        dbc.close()
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   433
        aliases = []
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   434
        if addresses:
144
4c6aa6c29dd7 Small optimizations in Account.getAliases() and Alias.getInfo().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 138
diff changeset
   435
            aliases = [alias[0] for alias in addresses]
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   436
        return aliases
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   437
333
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 329
diff changeset
   438
    def delete(self, force=False):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   439
        """Delete the Account from the database.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   440
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   441
        Argument:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   442
333
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 329
diff changeset
   443
        `force` : bool
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 329
diff changeset
   444
          if *force* is `True`, all aliases, which points to the Account,
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 329
diff changeset
   445
          will be also deleted.  If there are aliases and *force* is
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   446
          `False`, an AccountError will be raised.
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   447
        """
333
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 329
diff changeset
   448
        if not isinstance(force, bool):
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 329
diff changeset
   449
            raise TypeError('force must be a bool')
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   450
        self._chk_state()
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   451
        dbc = self._dbh.cursor()
333
1ed85e696748 VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 329
diff changeset
   452
        if force:
352
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   453
            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
   454
            # 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
   455
            # as for this account.
114
e671210b04b8 Fixed a libpq.OperationalError in Account.delete()
Pascal Volk <neverseen@users.sourceforge.net>
parents: 113
diff changeset
   456
            dbc.execute("DELETE FROM alias WHERE destination = %s",
352
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   457
                        (str(self._addr),))
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   458
            self._dbh.commit()
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   459
        else:  # check first for aliases
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   460
            a_count = self._count_aliases()
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   461
            if a_count > 0:
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   462
                dbc.close()
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 276
diff changeset
   463
                raise AErr(_(u"There are %(count)d aliases with the "
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 276
diff changeset
   464
                             u"destination address '%(address)s'.") %
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   465
                           {'count': a_count, 'address': self._addr},
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   466
                           ALIAS_PRESENT)
352
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   467
            dbc.execute('DELETE FROM users WHERE uid = %s', (self._uid,))
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   468
            self._dbh.commit()
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   469
        dbc.close()
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   470
        self._new = True
293
a77b67673aa6 VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 290
diff changeset
   471
        self._uid = 0
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   472
        self._addr = self._dbh = self._domain = self._passwd = None
444
95275b61ff8a VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 442
diff changeset
   473
        self._mail = self._qlimit = self._services = self._transport = None
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   474
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   475
252
af555e6967c8 VMM/Account: renamed function getAccountByID -> get_account_by_uid.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 250
diff changeset
   476
def get_account_by_uid(uid, dbh):
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   477
    """Search an Account by its UID.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   478
252
af555e6967c8 VMM/Account: renamed function getAccountByID -> get_account_by_uid.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 250
diff changeset
   479
    This function returns a dict (keys: 'address', 'gid' and 'uid'), if an
af555e6967c8 VMM/Account: renamed function getAccountByID -> get_account_by_uid.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 250
diff changeset
   480
    Account with the given *uid* exists.
af555e6967c8 VMM/Account: renamed function getAccountByID -> get_account_by_uid.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 250
diff changeset
   481
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   482
    Argument:
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   483
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   484
    `uid` : long
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   485
      The Account unique ID.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   486
    `dbh` : pyPgSQL.PgSQL.Connection
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   487
      a database connection for the database access.
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   488
    """
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   489
    try:
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   490
        uid = long(uid)
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   491
    except ValueError:
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 306
diff changeset
   492
        raise AErr(_(u'UID must be an int/long.'), INVALID_ARGUMENT)
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   493
    if uid < 1:
316
31d8931dc535 VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 306
diff changeset
   494
        raise AErr(_(u'UID must be greater than 0.'), INVALID_ARGUMENT)
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   495
    dbc = dbh.cursor()
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 276
diff changeset
   496
    dbc.execute("SELECT local_part||'@'|| domain_name.domainname AS address, "
543
1b3bdce0bf87 Include account note in getuser output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   497
                "uid, users.gid, note FROM users LEFT JOIN domain_name ON "
290
e2785e04f92e VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 276
diff changeset
   498
                "(domain_name.gid = users.gid AND is_primary) WHERE uid = %s",
352
22d115376e4d VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 341
diff changeset
   499
                (uid,))
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   500
    info = dbc.fetchone()
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   501
    dbc.close()
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   502
    if not info:
417
8209da83e256 VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 404
diff changeset
   503
        raise AErr(_(u"There is no account with the UID: '%d'") % uid,
245
f9a6b6701cf9 VMM/Account: reworked class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 236
diff changeset
   504
                   NO_SUCH_ACCOUNT)
543
1b3bdce0bf87 Include account note in getuser output
martin f. krafft <madduck@madduck.net>
parents: 539
diff changeset
   505
    info = dict(zip(('address', 'uid', 'gid', 'note'), info))
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   506
    return info
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   507
275
524f7ed5ad5b VMM/Account: some modifications and small improvements in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 266
diff changeset
   508
del _, cfg_dget