VirtualMailManager/Account.py
author Pascal Volk <neverseen@users.sourceforge.net>
Sat, 03 Apr 2010 02:14:13 +0000
branchv0.6.x
changeset 235 9d3405ed08e5
parent 228 a7b000ca4ac9
child 236 084331dd1e4c
permissions -rw-r--r--
VMM/Transport: Renamed attribute/property {,_}id to {,_}tid.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     1
# -*- coding: UTF-8 -*-
162
0ac9ef587769 Updated copyright notices to include the year 2010.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 156
diff changeset
     2
# Copyright (c) 2007 - 2010, Pascal Volk
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     3
# See COPYING for distribution information.
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     4
3
a9b44e04bf01 * VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 0
diff changeset
     5
"""Virtual Mail Manager's Account class to manage e-mail accounts."""
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
     6
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 162
diff changeset
     7
import VirtualMailManager.constants.ERROR as ERR
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 162
diff changeset
     8
from VirtualMailManager.Domain import Domain
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 162
diff changeset
     9
from VirtualMailManager.EmailAddress import EmailAddress
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    10
from VirtualMailManager.errors import AccountError as AccE
228
a7b000ca4ac9 VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 227
diff changeset
    11
from VirtualMailManager.maillocation import MailLocation, known_format
185
6e1ef32fbd82 VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 162
diff changeset
    12
from VirtualMailManager.Transport import Transport
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    13
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    14
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    15
_ = lambda msg: msg
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    16
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    17
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
    18
class Account(object):
3
a9b44e04bf01 * VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents: 0
diff changeset
    19
    """Class to manage e-mail accounts."""
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    20
    __slots__ = ('_addr', '_base', '_gid', '_mid', '_passwd', '_tid', '_uid',
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    21
                 '_dbh')
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    22
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    23
    def __init__(self, dbh, address, password=None):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    24
        self._dbh = dbh
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    25
        self._base = None
76
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
    26
        if isinstance(address, EmailAddress):
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
    27
            self._addr = address
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
    28
        else:
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
    29
            raise TypeError("Argument 'address' is not an EmailAddress")
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    30
        self._uid = 0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    31
        self._gid = 0
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    32
        self._mid = 0
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    33
        self._tid = 0
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    34
        self._passwd = password
24
48ea255e8a85 * 'vmm.cfg.5'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 20
diff changeset
    35
        self._setAddr()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    36
        self._exists()
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    37
        from VirtualMailManager.Handler import Handler
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    38
        if self._uid < 1 and Handler.aliasExists(self._dbh, self._addr):
156
a849843115e9 Added comments for the Translation Project. Updated PO template.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 155
diff changeset
    39
            # TP: Hm, what quotation marks should be used?
a849843115e9 Added comments for the Translation Project. Updated PO template.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 155
diff changeset
    40
            # If you are unsure have a look at:
a849843115e9 Added comments for the Translation Project. Updated PO template.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 155
diff changeset
    41
            # http://en.wikipedia.org/wiki/Quotation_mark,_non-English_usage
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    42
            raise AccE(_(u"There is already an alias with the address “%s”.") %
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    43
                       self._addr, ERR.ALIAS_EXISTS)
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    44
        if self._uid < 1 and Handler.relocatedExists(self._dbh, self._addr):
76
14c0a092d7d2 * 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 66
diff changeset
    45
            raise AccE(
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    46
              _(u"There is already a relocated user with the address “%s”.") %
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    47
                       self._addr, ERR.RELOCATED_EXISTS)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    48
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    49
    def _exists(self):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    50
        dbc = self._dbh.cursor()
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    51
        dbc.execute(
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    52
            "SELECT uid, mid, tid FROM users WHERE gid=%s AND local_part=%s",
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    53
                    self._gid, self._addr.localpart)
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    54
        result = dbc.fetchone()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    55
        dbc.close()
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    56
        if result is not None:
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    57
            self._uid, self._mid, self._tid = result
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    58
            return True
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    59
        else:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    60
            return False
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    61
24
48ea255e8a85 * 'vmm.cfg.5'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 20
diff changeset
    62
    def _setAddr(self):
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    63
        dom = Domain(self._dbh, self._addr.domainname)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    64
        self._gid = dom.getID()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    65
        if self._gid == 0:
216
0c8c053b451c Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 185
diff changeset
    66
            raise AccE(_(u"The domain “%s” doesn't exist.") %
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
    67
                       self._addr.domainname, ERR.NO_SUCH_DOMAIN)
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    68
        self._base = dom.getDir()
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    69
        self._tid = dom.getTransportID()
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    70
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    71
    def _setID(self):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    72
        dbc = self._dbh.cursor()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    73
        dbc.execute("SELECT nextval('users_uid')")
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    74
        self._uid = dbc.fetchone()[0]
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    75
        dbc.close()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    76
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
    77
    def _prepare(self, maillocation):
228
a7b000ca4ac9 VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 227
diff changeset
    78
        if not known_format(maillocation):                                  
a7b000ca4ac9 VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 227
diff changeset
    79
            raise AccE(_(u'Unknown mail_location mailbox format: %r') %
227
87db9f1f95ea VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 225
diff changeset
    80
                       maillocation, ERR.UNKNOWN_MAILLOCATION_NAME)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    81
        self._setID()
228
a7b000ca4ac9 VMM/maillocation: MailLocation.__init__(): take a 'format' name,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 227
diff changeset
    82
        self._mid = MailLocation(format=maillocation).mid
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    83
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
    84
    def _switchState(self, state, dcvers, service):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    85
        if not isinstance(state, bool):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    86
            return False
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
    87
        if not service in (None, 'all', 'imap', 'pop3', 'sieve', 'smtp'):
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
    88
            raise AccE(_(u"Unknown service “%s”.") % service,
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 48
diff changeset
    89
                    ERR.UNKNOWN_SERVICE)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
    90
        if self._uid < 1:
155
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 145
diff changeset
    91
            raise AccE(_(u"The account “%s” doesn't exist.") % self._addr,
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 48
diff changeset
    92
                    ERR.NO_SUCH_ACCOUNT)
134
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
    93
        if dcvers > 11:
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
    94
            sieve_col = 'sieve'
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
    95
        else:
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
    96
            sieve_col = 'managesieve'
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
    97
        if service in ('smtp', 'pop3', 'imap'):
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
    98
            sql = 'UPDATE users SET %s = %s WHERE uid = %d' % (service, state,
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
    99
                    self._uid)
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   100
        elif service == 'sieve':
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   101
            sql = 'UPDATE users SET %s = %s WHERE uid = %d' % (sieve_col,
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   102
                    state, self._uid)
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   103
        else:
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   104
            sql = 'UPDATE users SET smtp = %(s)s, pop3 = %(s)s, imap = %(s)s,\
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   105
 %(col)s = %(s)s WHERE uid = %(uid)d' % {
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   106
                's': state, 'col': sieve_col, 'uid': self._uid}
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   107
        dbc = self._dbh.cursor()
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   108
        dbc.execute(sql)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   109
        if dbc.rowcount > 0:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   110
            self._dbh.commit()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   111
        dbc.close()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   112
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   113
    def __aliaseCount(self):
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   114
        dbc = self._dbh.cursor()
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   115
        q = "SELECT COUNT(destination) FROM alias WHERE destination = '%s'"\
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   116
            % self._addr
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   117
        dbc.execute(q)
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   118
        a_count = dbc.fetchone()[0]
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   119
        dbc.close()
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   120
        return a_count
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   121
38
c44ea4526546 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   122
    def setPassword(self, password):
c44ea4526546 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   123
        self._passwd = password
c44ea4526546 * 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 34
diff changeset
   124
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   125
    def getUID(self):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   126
        return self._uid
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   127
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   128
    def getGID(self):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   129
        return self._gid
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   130
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   131
    def getDir(self, directory):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   132
        if directory == 'domain':
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   133
            return '%s' % self._base
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   134
        elif directory == 'home':
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   135
            return '%s/%i' % (self._base, self._uid)
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   136
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   137
    def enable(self, dcvers, service=None):
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   138
        self._switchState(True, dcvers, service)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   139
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   140
    def disable(self, dcvers, service=None):
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   141
        self._switchState(False, dcvers, service)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   142
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   143
    def save(self, maillocation, dcvers, smtp, pop3, imap, sieve):
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   144
        if self._uid < 1:
134
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   145
            if dcvers > 11:
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   146
                sieve_col = 'sieve'
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   147
            else:
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   148
                sieve_col = 'managesieve'
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
   149
            self._prepare(maillocation)
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   150
            sql = "INSERT INTO users (local_part, passwd, uid, gid, mid, tid,\
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   151
 smtp, pop3, imap, %s) VALUES ('%s', '%s', %d, %d, %d, %d, %s, %s, %s, %s)" % (
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   152
                sieve_col, self._addr.localpart, self._passwd, self._uid,
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   153
                self._gid, self._mid, self._tid, smtp, pop3, imap, sieve)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   154
            dbc = self._dbh.cursor()
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   155
            dbc.execute(sql)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   156
            self._dbh.commit()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   157
            dbc.close()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   158
        else:
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   159
            raise AccE(_(u'The account “%s” already exists.') % self._addr,
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 48
diff changeset
   160
                    ERR.ACCOUNT_EXISTS)
128
cf8116625866 Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 121
diff changeset
   161
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   162
    def modify(self, what, value):
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   163
        if self._uid == 0:
155
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 145
diff changeset
   164
            raise AccE(_(u"The account “%s” doesn't exist.") % self._addr,
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 48
diff changeset
   165
                    ERR.NO_SUCH_ACCOUNT)
17
fe9be0081e5f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 9
diff changeset
   166
        if what not in ['name', 'password', 'transport']:
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   167
            return False
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   168
        dbc = self._dbh.cursor()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   169
        if what == 'password':
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   170
            dbc.execute('UPDATE users SET passwd = %s WHERE uid = %s',
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   171
                    value, self._uid)
17
fe9be0081e5f * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 9
diff changeset
   172
        elif what == 'transport':
235
9d3405ed08e5 VMM/Transport: Renamed attribute/property {,_}id to {,_}tid.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 228
diff changeset
   173
            self._tid = Transport(self._dbh, transport=value).tid
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   174
            dbc.execute('UPDATE users SET tid = %s WHERE uid = %s',
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   175
                    self._tid, self._uid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   176
        else:
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   177
            dbc.execute('UPDATE users SET name = %s WHERE uid = %s',
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   178
                    value, self._uid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   179
        if dbc.rowcount > 0:
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   180
            self._dbh.commit()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   181
        dbc.close()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   182
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   183
    def getInfo(self, dcvers):
134
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   184
        if dcvers > 11:
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   185
            sieve_col = 'sieve'
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   186
        else:
6ca3d22e5dd0 Fixed a Python2.4.4 SyntaxError
Pascal Volk <neverseen@users.sourceforge.net>
parents: 133
diff changeset
   187
            sieve_col = 'managesieve'
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   188
        sql = 'SELECT name, uid, gid, mid, tid, smtp, pop3, imap, %s\
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   189
 FROM users WHERE uid = %d' % (sieve_col, self._uid)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   190
        dbc = self._dbh.cursor()
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   191
        dbc.execute(sql)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   192
        info = dbc.fetchone()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   193
        dbc.close()
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   194
        if info is None:
155
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 145
diff changeset
   195
            raise AccE(_(u"The account “%s” doesn't exist.") % self._addr,
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 48
diff changeset
   196
                    ERR.NO_SUCH_ACCOUNT)
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   197
        else:
227
87db9f1f95ea VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 225
diff changeset
   198
            keys = ['name', 'uid', 'gid', 'mid', 'transport', 'smtp',
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   199
                    'pop3', 'imap', sieve_col]
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   200
            info = dict(zip(keys, info))
115
21f264a88ab2 Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents: 114
diff changeset
   201
            for service in ('smtp', 'pop3', 'imap', sieve_col):
20
55146c78b3fb * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 19
diff changeset
   202
                if bool(info[service]):
156
a849843115e9 Added comments for the Translation Project. Updated PO template.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 155
diff changeset
   203
                    # TP: A service (pop3/imap/…) is enabled/usable for a user
41
fbcb7e314510 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   204
                    info[service] = _('enabled')
20
55146c78b3fb * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 19
diff changeset
   205
                else:
156
a849843115e9 Added comments for the Translation Project. Updated PO template.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 155
diff changeset
   206
                    # TP: A service (pop3/imap) isn't enabled/usable for a user
41
fbcb7e314510 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 38
diff changeset
   207
                    info[service] = _('disabled')
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   208
            info['address'] = self._addr
227
87db9f1f95ea VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 225
diff changeset
   209
            info['home'] = '%s/%s' % (self._base, info['uid'])
87db9f1f95ea VMM/Account: Adjusted to changes in maillocation.MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 225
diff changeset
   210
            info['mail_location'] = MailLocation(mid=info['mid']).mail_location
9
e3d3dbeb5b84 * 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 8
diff changeset
   211
            info['transport'] = Transport(self._dbh,
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   212
                                          tid=info['transport']).transport
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   213
            return info
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   214
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   215
    def getAliases(self):
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   216
        dbc = self._dbh.cursor()
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   217
        dbc.execute("SELECT address ||'@'|| domainname FROM alias, domain_name\
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   218
 WHERE destination = %s AND domain_name.gid = alias.gid\
145
ead2a7e9f8be Sort alias addresses in Account.getAliases() / vmm userinfo.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 144
diff changeset
   219
 AND domain_name.is_primary ORDER BY address", str(self._addr))
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   220
        addresses = dbc.fetchall()
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   221
        dbc.close()
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   222
        aliases = []
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   223
        if len(addresses) > 0:
144
4c6aa6c29dd7 Small optimizations in Account.getAliases() and Alias.getInfo().
Pascal Volk <neverseen@users.sourceforge.net>
parents: 138
diff changeset
   224
            aliases = [alias[0] for alias in addresses]
90
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   225
        return aliases
1734eb5101c6 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 82
diff changeset
   226
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   227
    def delete(self, delalias):
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   228
        if self._uid < 1:
155
eb866ebb9f2e Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents: 145
diff changeset
   229
            raise AccE(_(u"The account “%s” doesn't exist.") % self._addr,
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   230
                    ERR.NO_SUCH_ACCOUNT)
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   231
        dbc = self._dbh.cursor()
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   232
        if delalias == 'delalias':
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   233
            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
   234
            u_rc = dbc.rowcount
5506433db9a3 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   235
            # 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
   236
            # as for this account.
114
e671210b04b8 Fixed a libpq.OperationalError in Account.delete()
Pascal Volk <neverseen@users.sourceforge.net>
parents: 113
diff changeset
   237
            dbc.execute("DELETE FROM alias WHERE destination = %s",
e671210b04b8 Fixed a libpq.OperationalError in Account.delete()
Pascal Volk <neverseen@users.sourceforge.net>
parents: 113
diff changeset
   238
                    str(self._addr))
65
5506433db9a3 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 55
diff changeset
   239
            if u_rc > 0 or dbc.rowcount > 0:
0
bb0aa2102206 Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff changeset
   240
                self._dbh.commit()
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   241
        else: # check first for aliases
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   242
            a_count = self.__aliaseCount()
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   243
            if a_count == 0:
121
7ccc05774118 Converted to new-style class, added __slots__, updated queries.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 115
diff changeset
   244
                dbc.execute('DELETE FROM users WHERE uid = %s', self._uid)
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   245
                if dbc.rowcount > 0:
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   246
                    self._dbh.commit()
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   247
            else:
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   248
                dbc.close()
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   249
                raise AccE(
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   250
                  _(u"There are %(count)d aliases with the destination address\
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   251
%(address)s”.") % {'count': a_count, 'address': self._addr},
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   252
                  ERR.ALIAS_PRESENT)
66
995d538a6eb5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 65
diff changeset
   253
        dbc.close()
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   254
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   255
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   256
def getAccountByID(uid, dbh):
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   257
    try:
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   258
        uid = long(uid)
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   259
    except ValueError:
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 48
diff changeset
   260
        raise AccE(_(u'uid must be an int/long.'), ERR.INVALID_AGUMENT)
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   261
    if uid < 1:
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 48
diff changeset
   262
        raise AccE(_(u'uid must be greater than 0.'), ERR.INVALID_AGUMENT)
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   263
    dbc = dbh.cursor()
43
92a6132940f5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 41
diff changeset
   264
    dbc.execute("SELECT local_part||'@'|| domain_name.domainname AS address,\
92a6132940f5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 41
diff changeset
   265
 uid, users.gid FROM users LEFT JOIN domain_name ON (domain_name.gid \
92a6132940f5 * 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 41
diff changeset
   266
 = users.gid AND is_primary) WHERE uid = %s;", uid)
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   267
    info = dbc.fetchone()
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   268
    dbc.close()
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   269
    if info is None:
133
2d5c4745efec Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 128
diff changeset
   270
        raise AccE(_(u"There is no account with the UID “%d”.") % uid,
55
15c873f94ba6 * 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 48
diff changeset
   271
                ERR.NO_SUCH_ACCOUNT)
19
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   272
    keys = ['address', 'uid', 'gid']
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   273
    info = dict(zip(keys, info))
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   274
    return info
bf9a03c476fc * 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents: 17
diff changeset
   275
225
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   276
a51809f7940b VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents: 216
diff changeset
   277
del _