7 |
7 |
8 Virtual Mail Manager's Relocated class to handle relocated users. |
8 Virtual Mail Manager's Relocated class to handle relocated users. |
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 DestinationEmailAddress |
13 from VirtualMailManager.errors import RelocatedError as RErr |
14 from VirtualMailManager.errors import RelocatedError as RErr |
14 from VirtualMailManager.constants import NO_SUCH_DOMAIN, \ |
15 from VirtualMailManager.constants import DOMAIN_INVALID, NO_SUCH_DOMAIN, \ |
15 NO_SUCH_RELOCATED, RELOCATED_ADDR_DEST_IDENTICAL, RELOCATED_EXISTS |
16 NO_SUCH_RELOCATED, RELOCATED_ADDR_DEST_IDENTICAL, RELOCATED_EXISTS |
16 |
17 |
17 |
18 |
18 _ = lambda msg: msg |
19 _ = lambda msg: msg |
19 |
20 |
54 dbc.execute('SELECT destination FROM relocated WHERE gid = %s AND ' |
55 dbc.execute('SELECT destination FROM relocated WHERE gid = %s AND ' |
55 'address = %s', (self._gid, self._addr.localpart)) |
56 'address = %s', (self._gid, self._addr.localpart)) |
56 destination = dbc.fetchone() |
57 destination = dbc.fetchone() |
57 dbc.close() |
58 dbc.close() |
58 if destination: |
59 if destination: |
59 self._dest = EmailAddress(destination[0]) |
60 destination = DestinationEmailAddress(destination[0], self._dbh) |
|
61 if destination.at_localhost: |
|
62 raise RErr(_(u"The destination address' domain name must not " |
|
63 u"be localhost."), DOMAIN_INVALID) |
|
64 self._dest = destination |
60 |
65 |
61 @property |
66 @property |
62 def address(self): |
67 def address(self): |
63 """The Relocated's EmailAddress instance.""" |
68 """The Relocated's EmailAddress instance.""" |
64 return self._addr |
69 return self._addr |
65 |
70 |
66 def set_destination(self, destination): |
71 def set_destination(self, destination): |
67 """Sets/updates the new address of the relocated user.""" |
72 """Sets/updates the new address of the relocated user.""" |
68 update = False |
73 update = False |
69 assert isinstance(destination, EmailAddress) |
74 assert isinstance(destination, DestinationEmailAddress) |
|
75 if destination.at_localhost: |
|
76 raise RErr(_(u"The destination address' domain name must not be " |
|
77 u"localhost."), DOMAIN_INVALID) |
70 if self._addr == destination: |
78 if self._addr == destination: |
71 raise RErr(_(u'Address and destination are identical.'), |
79 raise RErr(_(u'Address and destination are identical.'), |
72 RELOCATED_ADDR_DEST_IDENTICAL) |
80 RELOCATED_ADDR_DEST_IDENTICAL) |
73 if self._dest: |
81 if self._dest: |
74 if self._dest == destination: |
82 if self._dest == destination: |