38 def __init__(self, dbh, domain): |
38 def __init__(self, dbh, domain): |
39 self._domain = domain |
39 self._domain = domain |
40 self._dbh = dbh |
40 self._dbh = dbh |
41 self._gid = get_gid(self._dbh, self.domain) |
41 self._gid = get_gid(self._dbh, self.domain) |
42 if not self._gid: |
42 if not self._gid: |
43 raise AErr(_(u"The domain '%s' does not exist.") % |
43 raise AErr(_("The domain '%s' does not exist.") % |
44 self.domain, NO_SUCH_DOMAIN) |
44 self.domain, NO_SUCH_DOMAIN) |
45 self._dests = [] |
45 self._dests = [] |
46 |
46 |
47 self._load_dests() |
47 self._load_dests() |
48 |
48 |
57 dbc.close() |
57 dbc.close() |
58 |
58 |
59 def _check_expansion(self, count_new): |
59 def _check_expansion(self, count_new): |
60 """Checks the current expansion limit of the alias.""" |
60 """Checks the current expansion limit of the alias.""" |
61 postconf = Postconf(cfg_dget('bin.postconf')) |
61 postconf = Postconf(cfg_dget('bin.postconf')) |
62 limit = long(postconf.read('virtual_alias_expansion_limit')) |
62 limit = int(postconf.read('virtual_alias_expansion_limit')) |
63 dcount = len(self._dests) |
63 dcount = len(self._dests) |
64 failed = False |
64 failed = False |
65 if dcount == limit or dcount + count_new > limit: |
65 if dcount == limit or dcount + count_new > limit: |
66 failed = True |
66 failed = True |
67 errmsg = _( |
67 errmsg = _( |
68 u"""Cannot add %(count_new)i new destination(s) to catch-all alias for |
68 """Cannot add %(count_new)i new destination(s) to catch-all alias for |
69 domain '%(domain)s'. Currently this alias expands into %(count)i/%(limit)i |
69 domain '%(domain)s'. Currently this alias expands into %(count)i/%(limit)i |
70 recipients. %(count_new)i additional destination(s) will render this alias |
70 recipients. %(count_new)i additional destination(s) will render this alias |
71 unusable. |
71 unusable. |
72 Hint: Increase Postfix' virtual_alias_expansion_limit""") |
72 Hint: Increase Postfix' virtual_alias_expansion_limit""") |
73 elif dcount > limit: |
73 elif dcount > limit: |
74 failed = True |
74 failed = True |
75 errmsg = _( |
75 errmsg = _( |
76 u"""Cannot add %(count_new)i new destination(s) to catch-all alias for domain |
76 """Cannot add %(count_new)i new destination(s) to catch-all alias for domain |
77 '%(domain)s'. This alias already exceeds its expansion limit \ |
77 '%(domain)s'. This alias already exceeds its expansion limit \ |
78 (%(count)i/%(limit)i). |
78 (%(count)i/%(limit)i). |
79 So its unusable, all messages addressed to this alias will be bounced. |
79 So its unusable, all messages addressed to this alias will be bounced. |
80 Hint: Delete some destination addresses.""") |
80 Hint: Delete some destination addresses.""") |
81 if failed: |
81 if failed: |
145 assert destinations and \ |
145 assert destinations and \ |
146 all(isinstance(dest, EmailAddress) for dest in destinations) |
146 all(isinstance(dest, EmailAddress) for dest in destinations) |
147 if not warnings is None: |
147 if not warnings is None: |
148 assert isinstance(warnings, list) |
148 assert isinstance(warnings, list) |
149 if not self._dests: |
149 if not self._dests: |
150 raise AErr(_(u"There are no catch-all aliases defined for " |
150 raise AErr(_("There are no catch-all aliases defined for " |
151 u"domain '%s'.") % self._domain, NO_SUCH_ALIAS) |
151 "domain '%s'.") % self._domain, NO_SUCH_ALIAS) |
152 unknown = destinations.difference(set(self._dests)) |
152 unknown = destinations.difference(set(self._dests)) |
153 if unknown: |
153 if unknown: |
154 destinations.intersection_update(set(self._dests)) |
154 destinations.intersection_update(set(self._dests)) |
155 if not warnings is None: |
155 if not warnings is None: |
156 warnings.extend(unknown) |
156 warnings.extend(unknown) |
157 if not destinations: |
157 if not destinations: |
158 raise AErr(_(u"No suitable destinations left to remove from the " |
158 raise AErr(_("No suitable destinations left to remove from the " |
159 u"catch-all alias of domain '%s'.") % self._domain, |
159 "catch-all alias of domain '%s'.") % self._domain, |
160 NO_SUCH_ALIAS) |
160 NO_SUCH_ALIAS) |
161 self._delete(destinations) |
161 self._delete(destinations) |
162 for destination in destinations: |
162 for destination in destinations: |
163 self._dests.remove(destination) |
163 self._dests.remove(destination) |
164 |
164 |
165 def get_destinations(self): |
165 def get_destinations(self): |
166 """Returns an iterator for all destinations of the catchall alias.""" |
166 """Returns an iterator for all destinations of the catchall alias.""" |
167 if not self._dests: |
167 if not self._dests: |
168 raise AErr(_(u"There are no catch-all aliases defined for " |
168 raise AErr(_("There are no catch-all aliases defined for " |
169 u"domain '%s'.") % self._domain, NO_SUCH_ALIAS) |
169 "domain '%s'.") % self._domain, NO_SUCH_ALIAS) |
170 return iter(self._dests) |
170 return iter(self._dests) |
171 |
171 |
172 def delete(self): |
172 def delete(self): |
173 """Deletes all catchall destinations for the domain.""" |
173 """Deletes all catchall destinations for the domain.""" |
174 if not self._dests: |
174 if not self._dests: |
175 raise AErr(_(u"There are no catch-all aliases defined for " |
175 raise AErr(_("There are no catch-all aliases defined for " |
176 u"domain '%s'.") % self._domain, NO_SUCH_ALIAS) |
176 "domain '%s'.") % self._domain, NO_SUCH_ALIAS) |
177 self._delete() |
177 self._delete() |
178 del self._dests[:] |
178 del self._dests[:] |
179 |
179 |
180 del _, cfg_dget |
180 del _, cfg_dget |