equal
deleted
inserted
replaced
9 """ |
9 """ |
10 |
10 |
11 from VirtualMailManager.Domain import get_gid |
11 from VirtualMailManager.Domain import get_gid |
12 from VirtualMailManager.EmailAddress import EmailAddress |
12 from VirtualMailManager.EmailAddress import EmailAddress |
13 from VirtualMailManager.errors import AliasError as AErr |
13 from VirtualMailManager.errors import AliasError as AErr |
|
14 from VirtualMailManager.ext.Postconf import Postconf |
14 from VirtualMailManager.pycompat import all |
15 from VirtualMailManager.pycompat import all |
15 from VirtualMailManager.constants.ERROR import \ |
16 from VirtualMailManager.constants.ERROR import \ |
16 ALIAS_EXCEEDS_EXPANSION_LIMIT, NO_SUCH_ALIAS, NO_SUCH_DOMAIN |
17 ALIAS_EXCEEDS_EXPANSION_LIMIT, NO_SUCH_ALIAS, NO_SUCH_DOMAIN |
17 |
18 |
18 |
19 |
19 _ = lambda msg: msg |
20 _ = lambda msg: msg |
|
21 cfg_dget = lambda option: None |
20 |
22 |
21 |
23 |
22 class Alias(object): |
24 class Alias(object): |
23 """Class to manage e-mail aliases.""" |
25 """Class to manage e-mail aliases.""" |
24 __slots__ = ('_addr', '_dests', '_gid', '_dbh') |
26 __slots__ = ('_addr', '_dests', '_gid', '_dbh') |
44 dests = iter(dbc.fetchall()) |
46 dests = iter(dbc.fetchall()) |
45 if dbc.rowcount > 0: |
47 if dbc.rowcount > 0: |
46 self._dests.extend(EmailAddress(dest[0]) for dest in dests) |
48 self._dests.extend(EmailAddress(dest[0]) for dest in dests) |
47 dbc.close() |
49 dbc.close() |
48 |
50 |
49 def __check_expansion(self, count_new, limit): |
51 def __check_expansion(self, count_new): |
50 """Checks the current expansion limit of the alias.""" |
52 """Checks the current expansion limit of the alias.""" |
|
53 postconf = Postconf(cfg_dget('bin.postconf')) |
|
54 limit = long(postconf.read('virtual_alias_expansion_limit')) |
51 dcount = len(self._dests) |
55 dcount = len(self._dests) |
52 failed = False |
56 failed = False |
53 if dcount == limit or dcount + count_new > limit: |
57 if dcount == limit or dcount + count_new > limit: |
54 failed = True |
58 failed = True |
55 errmsg = _( |
59 errmsg = _( |
94 @property |
98 @property |
95 def address(self): |
99 def address(self): |
96 """The Alias' EmailAddress instance.""" |
100 """The Alias' EmailAddress instance.""" |
97 return self._addr |
101 return self._addr |
98 |
102 |
99 def add_destinations(self, destinations, expansion_limit, warnings=None): |
103 def add_destinations(self, destinations, warnings=None): |
100 """Adds the `EmailAddress`es from *destinations* list to the |
104 """Adds the `EmailAddress`es from *destinations* list to the |
101 destinations of the alias. |
105 destinations of the alias. |
102 |
106 |
103 Destinations, that are already assigned to the alias, will be |
107 Destinations, that are already assigned to the alias, will be |
104 removed from *destinations*. When done, this method will return |
108 removed from *destinations*. When done, this method will return |
118 destinations.difference_update(set(self._dests)) |
122 destinations.difference_update(set(self._dests)) |
119 if not warnings is None: |
123 if not warnings is None: |
120 warnings.extend(duplicates) |
124 warnings.extend(duplicates) |
121 if not destinations: |
125 if not destinations: |
122 return destinations |
126 return destinations |
123 self.__check_expansion(len(destinations), expansion_limit) |
127 self.__check_expansion(len(destinations)) |
124 dbc = self._dbh.cursor() |
128 dbc = self._dbh.cursor() |
125 dbc.executemany("INSERT INTO alias VALUES (%d, '%s', %%s)" % |
129 dbc.executemany("INSERT INTO alias VALUES (%d, '%s', %%s)" % |
126 (self._gid, self._addr.localpart), |
130 (self._gid, self._addr.localpart), |
127 (str(destination) for destination in destinations)) |
131 (str(destination) for destination in destinations)) |
128 self._dbh.commit() |
132 self._dbh.commit() |
158 NO_SUCH_ALIAS) |
162 NO_SUCH_ALIAS) |
159 self.__delete() |
163 self.__delete() |
160 del self._dests[:] |
164 del self._dests[:] |
161 |
165 |
162 |
166 |
163 del _ |
167 del _, cfg_dget |