author | martin f. krafft <madduck@madduck.net> |
Sat, 14 Apr 2012 22:53:21 +0200 | |
branch | v0.6.x |
changeset 543 | 1b3bdce0bf87 |
parent 513 | 557c4703986c |
child 608 | 0ed93eb8b364 |
permissions | -rw-r--r-- |
504
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
1 |
# -*- coding: UTF-8 -*- |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
2 |
# Copyright (c) 2012 martin f. krafft |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
3 |
# See COPYING for distribution information. |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
4 |
""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
5 |
VirtualMailManager.catchall |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
6 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
7 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
8 |
Virtual Mail Manager's CatchallAlias class to manage domain catch-all |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
9 |
aliases. |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
10 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
11 |
This is heavily based on (more or less a copy of) the Alias class, because |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
12 |
fundamentally, catchall aliases are aliases, but without a localpart. |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
13 |
While Alias could potentially derive from CatchallAlias to reuse some of |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
14 |
the functionality, it's probably not worth it. I found no sensible way to |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
15 |
derive CatchallAlias from Alias, or at least none that would harness the |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
16 |
powers of polymorphism. |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
17 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
18 |
Yet, we reuse the AliasError exception class, which makes sense. |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
19 |
""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
20 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
21 |
from VirtualMailManager.domain import get_gid |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
22 |
from VirtualMailManager.emailaddress import \ |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
23 |
EmailAddress, DestinationEmailAddress as DestAddr |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
24 |
from VirtualMailManager.errors import AliasError as AErr |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
25 |
from VirtualMailManager.ext.postconf import Postconf |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
26 |
from VirtualMailManager.pycompat import all |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
27 |
from VirtualMailManager.constants import \ |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
28 |
ALIAS_EXCEEDS_EXPANSION_LIMIT, NO_SUCH_ALIAS, NO_SUCH_DOMAIN |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
29 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
30 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
31 |
_ = lambda msg: msg |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
32 |
cfg_dget = lambda option: None |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
33 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
34 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
35 |
class CatchallAlias(object): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
36 |
"""Class to manage domain catch-all aliases.""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
37 |
__slots__ = ('_domain', '_dests', '_gid', '_dbh') |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
38 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
39 |
def __init__(self, dbh, domain): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
40 |
self._domain = domain |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
41 |
self._dbh = dbh |
507
2aae58cddfa9
Correct syntax errors
martin f. krafft <madduck@madduck.net>
parents:
504
diff
changeset
|
42 |
self._gid = get_gid(self._dbh, self.domain) |
504
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
43 |
if not self._gid: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
44 |
raise AErr(_(u"The domain '%s' does not exist.") % |
513 | 45 |
self.domain, NO_SUCH_DOMAIN) |
504
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
46 |
self._dests = [] |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
47 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
48 |
self._load_dests() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
49 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
50 |
def _load_dests(self): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
51 |
"""Loads all known destination addresses into the _dests list.""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
52 |
dbc = self._dbh.cursor() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
53 |
dbc.execute('SELECT destination FROM catchall WHERE gid = %s', |
507
2aae58cddfa9
Correct syntax errors
martin f. krafft <madduck@madduck.net>
parents:
504
diff
changeset
|
54 |
(self._gid,)) |
504
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
55 |
dests = dbc.fetchall() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
56 |
if dbc.rowcount > 0: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
57 |
self._dests.extend(DestAddr(dest[0], self._dbh) for dest in dests) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
58 |
dbc.close() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
59 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
60 |
def _check_expansion(self, count_new): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
61 |
"""Checks the current expansion limit of the alias.""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
62 |
postconf = Postconf(cfg_dget('bin.postconf')) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
63 |
limit = long(postconf.read('virtual_alias_expansion_limit')) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
64 |
dcount = len(self._dests) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
65 |
failed = False |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
66 |
if dcount == limit or dcount + count_new > limit: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
67 |
failed = True |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
68 |
errmsg = _( |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
69 |
u"""Cannot add %(count_new)i new destination(s) to catchall alias for |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
70 |
domain '%(domain)s'. Currently this alias expands into %(count)i/%(limit)i |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
71 |
recipients. %(count_new)i additional destination(s) will render this alias |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
72 |
unusable. |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
73 |
Hint: Increase Postfix' virtual_alias_expansion_limit""") |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
74 |
elif dcount > limit: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
75 |
failed = True |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
76 |
errmsg = _( |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
77 |
u"""Cannot add %(count_new)i new destination(s) to catchall alias for |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
78 |
domain '%(domain)s'. This alias already exceeds its expansion limit (%(count)i/%(limit)i). |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
79 |
So its unusable, all messages addressed to this alias will be bounced. |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
80 |
Hint: Delete some destination addresses.""") |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
81 |
if failed: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
82 |
raise AErr(errmsg % {'domain': self._domain, 'count': dcount, |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
83 |
'limit': limit, 'count_new': count_new}, |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
84 |
ALIAS_EXCEEDS_EXPANSION_LIMIT) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
85 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
86 |
def _delete(self, destination=None): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
87 |
"""Deletes a destination from the catchall alias, if ``destination`` |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
88 |
is not ``None``. If ``destination`` is None, the catchall alias with |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
89 |
all its destination addresses will be deleted. |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
90 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
91 |
""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
92 |
dbc = self._dbh.cursor() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
93 |
if not destination: |
509
1a9247e9763f
Correct syntax errors
martin f. krafft <madduck@madduck.net>
parents:
507
diff
changeset
|
94 |
dbc.execute('DELETE FROM catchall WHERE gid = %s', (self._gid,)) |
504
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
95 |
else: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
96 |
dbc.execute('DELETE FROM catchall WHERE gid = %s ' |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
97 |
'AND destination = %s', (self._gid, str(destination))) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
98 |
if dbc.rowcount > 0: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
99 |
self._dbh.commit() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
100 |
dbc.close() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
101 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
102 |
def __len__(self): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
103 |
"""Returns the number of destinations of the catchall alias.""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
104 |
return len(self._dests) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
105 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
106 |
@property |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
107 |
def domain(self): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
108 |
"""The Alias' domain.""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
109 |
return self._domain |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
110 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
111 |
def add_destinations(self, destinations, warnings=None): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
112 |
"""Adds the `EmailAddress`es from *destinations* list to the |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
113 |
destinations of the catchall alias. |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
114 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
115 |
Destinations, that are already assigned to the alias, will be |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
116 |
removed from *destinations*. When done, this method will return |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
117 |
a set with all destinations, that were saved in the database. |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
118 |
""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
119 |
destinations = set(destinations) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
120 |
assert destinations and \ |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
121 |
all(isinstance(dest, EmailAddress) for dest in destinations) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
122 |
if not warnings is None: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
123 |
assert isinstance(warnings, list) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
124 |
duplicates = destinations.intersection(set(self._dests)) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
125 |
if duplicates: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
126 |
destinations.difference_update(set(self._dests)) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
127 |
if not warnings is None: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
128 |
warnings.extend(duplicates) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
129 |
if not destinations: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
130 |
return destinations |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
131 |
self._check_expansion(len(destinations)) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
132 |
dbc = self._dbh.cursor() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
133 |
dbc.executemany("INSERT INTO catchall (gid, destination) " |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
134 |
"VALUES (%d, %%s)" % self._gid, |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
135 |
((str(destination),) for destination in destinations)) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
136 |
self._dbh.commit() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
137 |
dbc.close() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
138 |
self._dests.extend(destinations) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
139 |
return destinations |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
140 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
141 |
def del_destination(self, destination): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
142 |
"""Deletes the specified ``destination`` address from the catchall |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
143 |
alias.""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
144 |
assert isinstance(destination, EmailAddress) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
145 |
if not self._dests: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
146 |
raise AErr(_(u"There are no catchall aliases defined for " |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
147 |
u"domain '%s'.") % self._domain, NO_SUCH_ALIAS) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
148 |
if not destination in self._dests: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
149 |
raise AErr(_(u"The address '%(addr)s' is not a destination of " |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
150 |
u"the catchall alias for domain '%(domain)s'.") |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
151 |
% {'addr': destination, 'domain': self._domain}, |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
152 |
NO_SUCH_ALIAS) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
153 |
self._delete(destination) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
154 |
self._dests.remove(destination) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
155 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
156 |
def get_destinations(self): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
157 |
"""Returns an iterator for all destinations of the catchall alias.""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
158 |
if not self._dests: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
159 |
raise AErr(_(u"There are no catchall aliases defined for " |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
160 |
u"domain '%s'.") % self._domain, NO_SUCH_ALIAS) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
161 |
return iter(self._dests) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
162 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
163 |
def delete(self): |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
164 |
"""Deletes all catchall destinations for the domain.""" |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
165 |
if not self._dests: |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
166 |
raise AErr(_(u"There are no catchall aliases defined for " |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
167 |
u"domain '%s'.") % self._domain, NO_SUCH_ALIAS) |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
168 |
self._delete() |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
169 |
del self._dests[:] |
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
170 |
|
f180ead60568
First version of a CatchallAlias class
martin f. krafft <madduck@madduck.net>
parents:
diff
changeset
|
171 |
del _, cfg_dget |