author | Pascal Volk <neverseen@users.sourceforge.net> |
Tue, 18 Aug 2009 03:00:00 +0000 | |
changeset 115 | 21f264a88ab2 |
parent 114 | e671210b04b8 |
child 121 | 7ccc05774118 |
permissions | -rw-r--r-- |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
1 |
# -*- coding: UTF-8 -*- |
102
485d3f7d6981
Removed svn keywords, more POSIX compliant shell scripts
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
2 |
# Copyright (c) 2007 - 2009, VEB IT |
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 |
|
102
485d3f7d6981
Removed svn keywords, more POSIX compliant shell scripts
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
7 |
from constants.VERSION import * |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
8 |
|
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
9 |
from Exceptions import VMMAccountException as AccE |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
10 |
from Domain import Domain |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
11 |
from Transport import Transport |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
12 |
from MailLocation import MailLocation |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
13 |
from EmailAddress import EmailAddress |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
14 |
import VirtualMailManager as VMM |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
15 |
import constants.ERROR as ERR |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
16 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
17 |
class Account: |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
18 |
"""Class to manage e-mail accounts.""" |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
19 |
def __init__(self, dbh, address, password=None): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
20 |
self._dbh = dbh |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
21 |
self._base = None |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
22 |
if isinstance(address, EmailAddress): |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
23 |
self._addr = address |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
24 |
else: |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
25 |
raise TypeError("Argument 'address' is not an EmailAddress") |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
26 |
self._uid = 0 |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
27 |
self._gid = 0 |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
28 |
self._mid = 0 |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
29 |
self._tid = 0 |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
30 |
self._passwd = password |
24 | 31 |
self._setAddr() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
32 |
self._exists() |
82
6c85915f3815
„speedup commit“ ;-)
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
33 |
if self._uid < 1 and VMM.VirtualMailManager.aliasExists(self._dbh, |
6c85915f3815
„speedup commit“ ;-)
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
34 |
self._addr): |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
35 |
raise AccE(_(u"There is already an alias with the address »%s«.") %\ |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
36 |
self._addr, ERR.ALIAS_EXISTS) |
82
6c85915f3815
„speedup commit“ ;-)
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
37 |
if self._uid < 1 and VMM.VirtualMailManager.relocatedExists(self._dbh, |
6c85915f3815
„speedup commit“ ;-)
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
38 |
self._addr): |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
39 |
raise AccE( |
78
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
40 |
_(u"There is already a relocated user with the address »%s«.") %\ |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
41 |
self._addr, ERR.RELOCATED_EXISTS) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
42 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
43 |
def _exists(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
44 |
dbc = self._dbh.cursor() |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
45 |
dbc.execute("SELECT uid, mid, tid FROM users \ |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
46 |
WHERE gid=%s AND local_part=%s", |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
47 |
self._gid, self._addr._localpart) |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
48 |
result = dbc.fetchone() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
49 |
dbc.close() |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
50 |
if result is not None: |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
51 |
self._uid, self._mid, self._tid = result |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
52 |
return True |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
53 |
else: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
54 |
return False |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
55 |
|
24 | 56 |
def _setAddr(self): |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
57 |
dom = Domain(self._dbh, self._addr._domainname) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
58 |
self._gid = dom.getID() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
59 |
if self._gid == 0: |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
60 |
raise AccE(_(u"The domain »%s« doesn't exist yet.") %\ |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
61 |
self._addr._domainname, ERR.NO_SUCH_DOMAIN) |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
62 |
self._base = dom.getDir() |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
63 |
self._tid = dom.getTransportID() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
64 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
65 |
def _setID(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
66 |
dbc = self._dbh.cursor() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
67 |
dbc.execute("SELECT nextval('users_uid')") |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
68 |
self._uid = dbc.fetchone()[0] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
69 |
dbc.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
70 |
|
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
71 |
def _prepare(self, maillocation): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
72 |
self._setID() |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
73 |
self._mid = MailLocation(self._dbh, maillocation=maillocation).getID() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
74 |
|
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
75 |
def _switchState(self, state, dcvers, service): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
76 |
if not isinstance(state, bool): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
77 |
return False |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
78 |
if not service in (None, 'all', 'imap', 'pop3', 'sieve', 'smtp'): |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
79 |
raise AccE(_(u"Unknown service »%s«.") % service, |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
80 |
ERR.UNKNOWN_SERVICE) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
81 |
if self._uid < 1: |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
82 |
raise AccE(_(u"The account »%s« doesn't exists.") % self._addr, |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
83 |
ERR.NO_SUCH_ACCOUNT) |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
84 |
sieve_col = 'sieve' if dcvers > 11 else 'managesieve' |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
85 |
if service in ('smtp', 'pop3', 'imap'): |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
86 |
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
|
87 |
self._uid) |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
88 |
elif service == 'sieve': |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
89 |
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
|
90 |
state, self._uid) |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
91 |
else: |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
92 |
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
|
93 |
%(col)s = %(s)s WHERE uid = %(uid)d' % { |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
94 |
's': state, 'col': sieve_col, 'uid': self._uid} |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
95 |
dbc = self._dbh.cursor() |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
96 |
dbc.execute(sql) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
97 |
if dbc.rowcount > 0: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
98 |
self._dbh.commit() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
99 |
dbc.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
100 |
|
66
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
101 |
def __aliaseCount(self): |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
102 |
dbc = self._dbh.cursor() |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
103 |
q = "SELECT COUNT(destination) FROM alias WHERE destination = '%s'"\ |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
104 |
%self._addr |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
105 |
dbc.execute(q) |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
106 |
a_count = dbc.fetchone()[0] |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
107 |
dbc.close() |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
108 |
return a_count |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
109 |
|
38
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
110 |
def setPassword(self, password): |
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
111 |
self._passwd = password |
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
112 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
113 |
def getUID(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
114 |
return self._uid |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
115 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
116 |
def getGID(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
117 |
return self._gid |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
118 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
119 |
def getDir(self, directory): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
120 |
if directory == 'domain': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
121 |
return '%s' % self._base |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
122 |
elif directory == 'home': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
123 |
return '%s/%i' % (self._base, self._uid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
124 |
|
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
125 |
def enable(self, dcvers, service=None): |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
126 |
self._switchState(True, dcvers, service) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
127 |
|
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
128 |
def disable(self, dcvers, service=None): |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
129 |
self._switchState(False, dcvers, service) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
130 |
|
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
131 |
def save(self, maillocation, dcvers, smtp, pop3, imap, sieve): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
132 |
if self._uid < 1: |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
133 |
sieve_col = 'sieve' if dcvers > 11 else 'managesieve' |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
134 |
self._prepare(maillocation) |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
135 |
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
|
136 |
smtp, pop3, imap, %s) VALUES ('%s', '%s', %d, %d, %d, %d, %s, %s, %s, %s)" % ( |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
137 |
sieve_col, self._addr._localpart, self._passwd, self._uid, |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
138 |
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
|
139 |
dbc = self._dbh.cursor() |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
140 |
dbc.execute(sql) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
141 |
self._dbh.commit() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
142 |
dbc.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
143 |
else: |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
144 |
raise AccE(_(u'The account »%s« already exists.') % self._addr, |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
145 |
ERR.ACCOUNT_EXISTS) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
146 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
147 |
def modify(self, what, value): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
148 |
if self._uid == 0: |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
149 |
raise AccE(_(u"The account »%s« doesn't exists.") % self._addr, |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
150 |
ERR.NO_SUCH_ACCOUNT) |
17
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
151 |
if what not in ['name', 'password', 'transport']: |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
152 |
return False |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
153 |
dbc = self._dbh.cursor() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
154 |
if what == 'password': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
155 |
dbc.execute("UPDATE users SET passwd=%s WHERE local_part=%s AND\ |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
156 |
gid=%s", value, self._addr._localpart, self._gid) |
17
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
157 |
elif what == 'transport': |
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
158 |
self._tid = Transport(self._dbh, transport=value).getID() |
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
159 |
dbc.execute("UPDATE users SET tid=%s WHERE local_part=%s AND\ |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
160 |
gid=%s", self._tid, self._addr._localpart, self._gid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
161 |
else: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
162 |
dbc.execute("UPDATE users SET name=%s WHERE local_part=%s AND\ |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
163 |
gid=%s", value, self._addr._localpart, self._gid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
164 |
if dbc.rowcount > 0: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
165 |
self._dbh.commit() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
166 |
dbc.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
167 |
|
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
168 |
def getInfo(self, dcvers): |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
169 |
sieve_col = 'sieve' if dcvers > 11 else 'managesieve' |
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
170 |
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
|
171 |
FROM users WHERE uid = %d' % (sieve_col, self._uid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
172 |
dbc = self._dbh.cursor() |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
173 |
dbc.execute(sql) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
174 |
info = dbc.fetchone() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
175 |
dbc.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
176 |
if info is None: |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
177 |
raise AccE(_(u"The account »%s« doesn't exists.") % self._addr, |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
178 |
ERR.NO_SUCH_ACCOUNT) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
179 |
else: |
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
180 |
keys = ['name', 'uid', 'gid', 'maildir', 'transport', 'smtp', |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
181 |
'pop3', 'imap', sieve_col] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
182 |
info = dict(zip(keys, info)) |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
114
diff
changeset
|
183 |
for service in ('smtp', 'pop3', 'imap', sieve_col): |
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
184 |
if bool(info[service]): |
41
fbcb7e314510
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
38
diff
changeset
|
185 |
info[service] = _('enabled') |
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
186 |
else: |
41
fbcb7e314510
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
38
diff
changeset
|
187 |
info[service] = _('disabled') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
188 |
info['address'] = self._addr |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
189 |
info['maildir'] = '%s/%s/%s' % (self._base, info['uid'], |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
190 |
MailLocation(self._dbh, |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
191 |
mid=info['maildir']).getMailLocation()) |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
192 |
info['transport'] = Transport(self._dbh, |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
193 |
tid=info['transport']).getTransport() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
194 |
return info |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
195 |
|
90
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
196 |
def getAliases(self): |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
197 |
dbc = self._dbh.cursor() |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
198 |
dbc.execute("SELECT address ||'@'|| domainname FROM alias, domain_name\ |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
199 |
WHERE destination = %s AND domain_name.gid = alias.gid\ |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
200 |
AND domain_name.is_primary", str(self._addr)) |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
201 |
addresses = dbc.fetchall() |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
202 |
dbc.close() |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
203 |
aliases = [] |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
204 |
if len(addresses) > 0: |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
205 |
for alias in addresses: |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
206 |
aliases.append(alias[0]) |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
207 |
return aliases |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
208 |
|
66
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
209 |
def delete(self, delalias): |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
210 |
if self._uid < 1: |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
211 |
raise AccE(_(u"The account »%s« doesn't exists.") % self._addr, |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
212 |
ERR.NO_SUCH_ACCOUNT) |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
213 |
dbc = self._dbh.cursor() |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
214 |
if delalias == 'delalias': |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
215 |
dbc.execute("DELETE FROM users WHERE gid=%s AND local_part=%s", |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
216 |
self._gid, self._addr._localpart) |
65
5506433db9a3
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
217 |
u_rc = dbc.rowcount |
5506433db9a3
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
218 |
# 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
|
219 |
# as for this account. |
114
e671210b04b8
Fixed a libpq.OperationalError in Account.delete()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
113
diff
changeset
|
220 |
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
|
221 |
str(self._addr)) |
65
5506433db9a3
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
222 |
if u_rc > 0 or dbc.rowcount > 0: |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
223 |
self._dbh.commit() |
66
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
224 |
else: # check first for aliases |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
225 |
a_count = self.__aliaseCount() |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
226 |
if a_count == 0: |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
227 |
dbc.execute("DELETE FROM users WHERE gid=%s AND local_part=%s", |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
228 |
self._gid, self._addr._localpart) |
66
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
229 |
if dbc.rowcount > 0: |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
230 |
self._dbh.commit() |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
231 |
else: |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
232 |
dbc.close() |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
233 |
raise AccE( |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
234 |
_(u"There are %(count)d aliases with the destination address\ |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
235 |
»%(address)s«.") %{'count': a_count, 'address': self._addr}, ERR.ALIAS_PRESENT) |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
65
diff
changeset
|
236 |
dbc.close() |
19
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
237 |
|
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
238 |
def getAccountByID(uid, dbh): |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
239 |
try: |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
240 |
uid = long(uid) |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
241 |
except ValueError: |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
242 |
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
|
243 |
if uid < 1: |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
244 |
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
|
245 |
dbc = dbh.cursor() |
43
92a6132940f5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
41
diff
changeset
|
246 |
dbc.execute("SELECT local_part||'@'|| domain_name.domainname AS address,\ |
92a6132940f5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
41
diff
changeset
|
247 |
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
|
248 |
= users.gid AND is_primary) WHERE uid = %s;", uid) |
19
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
249 |
info = dbc.fetchone() |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
250 |
dbc.close() |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
251 |
if info is None: |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
252 |
raise AccE(_(u"There is no account with the UID »%d«.") % uid, |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
48
diff
changeset
|
253 |
ERR.NO_SUCH_ACCOUNT) |
19
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
254 |
keys = ['address', 'uid', 'gid'] |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
255 |
info = dict(zip(keys, info)) |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
256 |
return info |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
257 |