author | Pascal Volk <neverseen@users.sourceforge.net> |
Wed, 10 Feb 2010 07:38:19 +0000 | |
branch | v0.6.x |
changeset 197 | d2712e8c724e |
parent 196 | 65a3163bd113 |
child 198 | 02d467e4fbab |
permissions | -rw-r--r-- |
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:
155
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 |
|
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
5 |
""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
6 |
VirtualMailManager.Alias |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
7 |
|
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
8 |
Virtual Mail Manager's Alias class to manage e-mail aliases. |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
9 |
""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
10 |
|
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
11 |
from VirtualMailManager.Domain import Domain |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
12 |
from VirtualMailManager.EmailAddress import EmailAddress |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
13 |
from VirtualMailManager.Exceptions import VMMAliasException as VMMAE |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
14 |
from VirtualMailManager.constants.ERROR import ALIAS_ADDR_DEST_IDENTICAL, \ |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
15 |
ALIAS_EXCEEDS_EXPANSION_LIMIT, ALIAS_EXISTS, NO_SUCH_ALIAS, NO_SUCH_DOMAIN |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
16 |
|
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
17 |
|
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
18 |
_ = lambda msg: msg |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
19 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
20 |
|
122
30abf0abf8f8
Converted to new-style class, added __slots__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
21 |
class Alias(object): |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
22 |
"""Class to manage e-mail aliases.""" |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
23 |
__slots__ = ('_addr', '_dests', '_gid', '_dbh') |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
24 |
|
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
25 |
def __init__(self, dbh, address): |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
26 |
if isinstance(address, EmailAddress): |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
27 |
self._addr = address |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
28 |
else: |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
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._dbh = dbh |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
31 |
self._gid = 0 |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
32 |
self._dests = [] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
33 |
|
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
34 |
self.__set_gid() |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
35 |
self.__load_dests() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
36 |
|
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
37 |
def __set_gid(self): |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
38 |
"""Sets the alias' _gid based on its _addr.domainname.""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
39 |
dom = Domain(self._dbh, self._addr.domainname) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
40 |
self._gid = dom.getID() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
41 |
if self._gid == 0: |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
42 |
raise VMMAE(_(u"The domain “%s” doesn't exist.") % |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
43 |
self._addr.domainname, NO_SUCH_DOMAIN) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
44 |
|
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
45 |
def __load_dests(self): |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
46 |
"""Loads all known destination addresses into the _dests list.""" |
88
b3debcfea7bc
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
47 |
dbc = self._dbh.cursor() |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
48 |
dbc.execute( |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
49 |
'SELECT destination FROM alias WHERE gid=%s AND address=%s', |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
50 |
self._gid, self._addr.localpart) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
51 |
dests = iter(dbc.fetchall()) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
52 |
if dbc.rowcount > 0: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
53 |
dest_add = self._dests.append |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
54 |
for dest in dests: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
55 |
dest_add(EmailAddress(dest[0])) |
88
b3debcfea7bc
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
56 |
dbc.close() |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
57 |
|
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
58 |
def __check_expansion(self, limit): |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
59 |
"""Checks the current expansion limit of the alias.""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
60 |
dcount = len(self._dests) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
61 |
failed = False |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
62 |
if dcount == limit: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
63 |
failed = True |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
64 |
errmsg = _( |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
65 |
u"""Can't add new destination to alias “%(address)s”. |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
66 |
Currently this alias expands into %(count)i/%(limit)i recipients. |
89
752d3b57ebb6
small fixes/updates
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
67 |
One more destination will render this alias unusable. |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
68 |
Hint: Increase Postfix' virtual_alias_expansion_limit""") |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
69 |
elif dcount > limit: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
70 |
failed = True |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
71 |
errmsg = _( |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
72 |
u"""Can't add new destination to alias “%(address)s”. |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
73 |
This alias already exceeds it's expansion limit (%(count)i/%(limit)i). |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
74 |
So its unusable, all messages addressed to this alias will be bounced. |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
75 |
Hint: Delete some destination addresses.""") |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
76 |
if failed: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
77 |
raise VMMAE(errmsg % {'address': self._addr, 'count': dcount, |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
78 |
'limit': limit}, |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
79 |
ALIAS_EXCEEDS_EXPANSION_LIMIT) |
88
b3debcfea7bc
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
82
diff
changeset
|
80 |
|
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
81 |
def __delete(self, destination=None): |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
82 |
"""Deletes a destination from the alias, if ``destination`` is not |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
83 |
``None``. If ``destination`` is None, the alias with all it's |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
84 |
destination addresses will be deleted.""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
85 |
dbc = self._dbh.cursor() |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
86 |
if destination is None: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
87 |
dbc.execute("DELETE FROM alias WHERE gid=%s AND address=%s", |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
88 |
self._gid, self._addr.localpart) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
89 |
else: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
90 |
dbc.execute("DELETE FROM alias WHERE gid=%s AND address=%s AND \ |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
91 |
destination=%s", |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
92 |
self._gid, self._addr.localpart, str(destination)) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
93 |
if dbc.rowcount > 0: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
94 |
self._dbh.commit() |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
95 |
dbc.close() |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
96 |
|
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
97 |
def __len__(self): |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
98 |
"""Returns the number of destinations of the alias.""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
99 |
return len(self._dests) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
100 |
|
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
101 |
def addDestination(self, destination, expansion_limit): |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
102 |
"""Adds the ``destination`` `EmailAddress` to the alias.""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
103 |
if not isinstance(destination, EmailAddress): |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
104 |
raise TypeError("Argument 'destination' is not an EmailAddress") |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
105 |
if self._addr == destination: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
106 |
raise VMMAE(_(u"Address and destination are identical."), |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
107 |
ALIAS_ADDR_DEST_IDENTICAL) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
108 |
if not destination in self._dests: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
109 |
self.__check_expansion(expansion_limit) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
110 |
dbc = self._dbh.cursor() |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
111 |
dbc.execute('INSERT INTO alias (gid, address, destination) \ |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
112 |
VALUES (%s, %s, %s)', |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
113 |
self._gid, self._addr.localpart, str(destination)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
114 |
self._dbh.commit() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
115 |
dbc.close() |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
116 |
self._dests.append(destination) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
117 |
else: |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
118 |
raise VMMAE(_( |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
119 |
u'The alias “%(a)s” has already the destination “%(d)s”.') % |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
120 |
{'a': self._addr, 'd': destination}, ALIAS_EXISTS) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
121 |
|
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
122 |
def delDestination(self, destination): |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
123 |
"""Deletes the specified ``destination`` address from the alias.""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
124 |
if not isinstance(destination, EmailAddress): |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
125 |
raise TypeError("Argument 'destination' is not an EmailAddress") |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
126 |
if not self._dests: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
127 |
raise VMMAE(_(u"The alias “%s” doesn't exist.") % self._addr, |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
128 |
NO_SUCH_ALIAS) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
129 |
if not destination in self._dests: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
130 |
raise VMMAE(_(u"The address “%(d)s” isn't a destination of \ |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
131 |
the alias “%(a)s”.") % |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
132 |
{'a': self._addr, 'd': destination}, NO_SUCH_ALIAS) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
133 |
self.__delete(destination) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
134 |
self._dests.remove(destination) |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
135 |
|
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
136 |
def getDestinations(self): |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
137 |
"""Returns an iterator for all destinations of the alias.""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
138 |
if self._dests: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
139 |
return iter(self._dests) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
140 |
else: |
155
eb866ebb9f2e
Fixed some grammar errors and typos. (Reported by Clytie Siddall)
Pascal Volk <neverseen@users.sourceforge.net>
parents:
147
diff
changeset
|
141 |
raise VMMAE(_(u"The alias “%s” doesn't exist.") % self._addr, |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
142 |
NO_SUCH_ALIAS) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
143 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
144 |
def delete(self): |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
145 |
"""Deletes the alias with all it's destinations.""" |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
146 |
if self._dests: |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
147 |
self.__delete() |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
148 |
del self._dests[:] |
12
44161dbb1518
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
149 |
else: |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
150 |
raise VMMAE(_(u"The alias “%s” doesn't exist.") % self._addr, |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
151 |
NO_SUCH_ALIAS) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
152 |
|
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
153 |
|
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
154 |
del _ |