107 self._localpart, self._gid) |
107 self._localpart, self._gid) |
108 if dbc.rowcount > 0: |
108 if dbc.rowcount > 0: |
109 self._dbh.commit() |
109 self._dbh.commit() |
110 dbc.close() |
110 dbc.close() |
111 |
111 |
|
112 def __aliaseCount(self): |
|
113 dbc = self._dbh.cursor() |
|
114 q = "SELECT COUNT(destination) FROM alias WHERE destination = '%s'"\ |
|
115 %self._addr |
|
116 dbc.execute(q) |
|
117 a_count = dbc.fetchone()[0] |
|
118 dbc.close() |
|
119 return a_count |
|
120 |
112 def setPassword(self, password): |
121 def setPassword(self, password): |
113 self._passwd = password |
122 self._passwd = password |
114 |
123 |
115 def getUID(self): |
124 def getUID(self): |
116 return self._uid |
125 return self._uid |
191 mid=info['maildir']).getMailLocation()) |
200 mid=info['maildir']).getMailLocation()) |
192 info['transport'] = Transport(self._dbh, |
201 info['transport'] = Transport(self._dbh, |
193 tid=info['transport']).getTransport() |
202 tid=info['transport']).getTransport() |
194 return info |
203 return info |
195 |
204 |
196 def delete(self): |
205 def delete(self, delalias): |
197 if self._uid > 0: |
206 if self._uid < 1: |
198 dbc = self._dbh.cursor() |
207 raise AccE(_(u"The account »%s« doesn't exists.") % self._addr, |
|
208 ERR.NO_SUCH_ACCOUNT) |
|
209 dbc = self._dbh.cursor() |
|
210 if delalias == 'delalias': |
199 dbc.execute("DELETE FROM users WHERE gid=%s AND local_part=%s", |
211 dbc.execute("DELETE FROM users WHERE gid=%s AND local_part=%s", |
200 self._gid, self._localpart) |
212 self._gid, self._localpart) |
201 u_rc = dbc.rowcount |
213 u_rc = dbc.rowcount |
202 # delete also all aliases where the destination address is the same |
214 # delete also all aliases where the destination address is the same |
203 # as for this account. |
215 # as for this account. |
204 dbc.execute("DELETE FROM alias WHERE destination = %s", self._addr) |
216 dbc.execute("DELETE FROM alias WHERE destination = %s", self._addr) |
205 if u_rc > 0 or dbc.rowcount > 0: |
217 if u_rc > 0 or dbc.rowcount > 0: |
206 self._dbh.commit() |
218 self._dbh.commit() |
207 dbc.close() |
219 else: # check first for aliases |
208 else: |
220 a_count = self.__aliaseCount() |
209 raise AccE(_(u"The account »%s« doesn't exists.") % self._addr, |
221 if a_count == 0: |
210 ERR.NO_SUCH_ACCOUNT) |
222 dbc.execute("DELETE FROM users WHERE gid=%s AND local_part=%s", |
211 |
223 self._gid, self._localpart) |
|
224 if dbc.rowcount > 0: |
|
225 self._dbh.commit() |
|
226 else: |
|
227 dbc.close() |
|
228 raise AccE( |
|
229 _(u"There are %(count)d aliases with the destination address\ |
|
230 »%(address)s«.") %{'count': a_count, 'address': self._addr}, ERR.ALIAS_PRESENT) |
|
231 dbc.close() |
212 |
232 |
213 def getAccountByID(uid, dbh): |
233 def getAccountByID(uid, dbh): |
214 try: |
234 try: |
215 uid = long(uid) |
235 uid = long(uid) |
216 except ValueError: |
236 except ValueError: |