equal
deleted
inserted
replaced
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 from VirtualMailManager.Exceptions import VMMRelocatedException as VMMRE |
13 from VirtualMailManager.errors import RelocatedError as RErr |
14 from VirtualMailManager.constants.ERROR import \ |
14 from VirtualMailManager.constants.ERROR import \ |
15 NO_SUCH_RELOCATED, RELOCATED_ADDR_DEST_IDENTICAL, RELOCATED_EXISTS |
15 NO_SUCH_RELOCATED, RELOCATED_ADDR_DEST_IDENTICAL, RELOCATED_EXISTS |
16 |
16 |
17 |
17 |
18 _ = lambda msg: msg |
18 _ = lambda msg: msg |
55 def set_destination(self, destination): |
55 def set_destination(self, destination): |
56 """Sets/updates the new address of the relocated user.""" |
56 """Sets/updates the new address of the relocated user.""" |
57 update = False |
57 update = False |
58 assert isinstance(destination, EmailAddress) |
58 assert isinstance(destination, EmailAddress) |
59 if self._addr == destination: |
59 if self._addr == destination: |
60 raise VMMRE(_(u'Address and destination are identical.'), |
60 raise RErr(_(u'Address and destination are identical.'), |
61 RELOCATED_ADDR_DEST_IDENTICAL) |
61 RELOCATED_ADDR_DEST_IDENTICAL) |
62 if self._dest: |
62 if self._dest: |
63 if self._dest == destination: |
63 if self._dest == destination: |
64 raise VMMRE(_(u'The relocated user %r already exists.') % |
64 raise RErr(_(u'The relocated user %r already exists.') % |
65 self._addr, RELOCATED_EXISTS) |
65 self._addr, RELOCATED_EXISTS) |
66 else: |
66 else: |
67 self._dest = destination |
67 self._dest = destination |
68 update = True |
68 update = True |
69 else: |
69 else: |
70 self._dest = destination |
70 self._dest = destination |
81 dbc.close() |
81 dbc.close() |
82 |
82 |
83 def get_info(self): |
83 def get_info(self): |
84 """Returns the address to which mails should be sent.""" |
84 """Returns the address to which mails should be sent.""" |
85 if not self._dest: |
85 if not self._dest: |
86 raise VMMRE(_(u"The relocated user %r doesn't exist.") % |
86 raise RErr(_(u"The relocated user %r doesn't exist.") % |
87 self._addr, NO_SUCH_RELOCATED) |
87 self._addr, NO_SUCH_RELOCATED) |
88 return self._dest |
88 return self._dest |
89 |
89 |
90 def delete(self): |
90 def delete(self): |
91 """Deletes the relocated entry from the database.""" |
91 """Deletes the relocated entry from the database.""" |
92 if not self._dest: |
92 if not self._dest: |
93 raise VMMRE(_(u"The relocated user %r doesn't exist.") % |
93 raise RErr(_(u"The relocated user %r doesn't exist.") % self._addr, |
94 self._addr, NO_SUCH_RELOCATED) |
94 NO_SUCH_RELOCATED) |
95 dbc = self._dbh.cursor() |
95 dbc = self._dbh.cursor() |
96 dbc.execute("DELETE FROM relocated WHERE gid = %s AND address = %s", |
96 dbc.execute("DELETE FROM relocated WHERE gid = %s AND address = %s", |
97 self._gid, self._addr.localpart) |
97 self._gid, self._addr.localpart) |
98 if dbc.rowcount > 0: |
98 if dbc.rowcount > 0: |
99 self._dbh.commit() |
99 self._dbh.commit() |