mirror of
https://github.com/simple-login/app.git
synced 2025-02-24 15:53:22 +08:00
fix Mailbox.delete: use alias_utils.delete_alias
This commit is contained in:
parent
b4eb110971
commit
6bc0c5ada4
1 changed files with 15 additions and 17 deletions
|
@ -1509,23 +1509,21 @@ class Mailbox(db.Model, ModelMixin):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete(cls, obj_id):
|
def delete(cls, obj_id):
|
||||||
# Put all aliases belonging to this mailbox to global trash
|
mailbox: Mailbox = cls.get(obj_id)
|
||||||
try:
|
user = mailbox.user
|
||||||
for alias in Alias.query.filter_by(mailbox_id=obj_id):
|
|
||||||
# special handling for alias that has several mailboxes and has mailbox_id=obj_id
|
# Put all aliases belonging to this mailbox to global or domain trash
|
||||||
if len(alias.mailboxes) > 1:
|
for alias in Alias.query.filter_by(mailbox_id=obj_id):
|
||||||
# use the first mailbox found in alias._mailboxes
|
# special handling for alias that has several mailboxes and has mailbox_id=obj_id
|
||||||
first_mb = alias._mailboxes[0]
|
if len(alias.mailboxes) > 1:
|
||||||
alias.mailbox_id = first_mb.id
|
# use the first mailbox found in alias._mailboxes
|
||||||
alias._mailboxes.remove(first_mb)
|
first_mb = alias._mailboxes[0]
|
||||||
else:
|
alias.mailbox_id = first_mb.id
|
||||||
# only put aliases that have mailbox as a single mailbox into trash
|
alias._mailboxes.remove(first_mb)
|
||||||
DeletedAlias.create(email=alias.email)
|
else:
|
||||||
db.session.commit()
|
# only put aliases that have mailbox as a single mailbox into trash
|
||||||
# this can happen when a previously deleted alias is re-created via catch-all or directory feature
|
alias_utils.delete_alias(alias, user)
|
||||||
except IntegrityError:
|
db.session.commit()
|
||||||
LOG.exception("Some aliases have been added before to DeletedAlias")
|
|
||||||
db.session.rollback()
|
|
||||||
|
|
||||||
cls.query.filter(cls.id == obj_id).delete()
|
cls.query.filter(cls.id == obj_id).delete()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
Loading…
Reference in a new issue