diff --git a/app/handler/provider_complaint.py b/app/handler/provider_complaint.py index 43475013..bf16b790 100644 --- a/app/handler/provider_complaint.py +++ b/app/handler/provider_complaint.py @@ -190,11 +190,11 @@ def handle_yahoo_complaint(message: Message) -> bool: def find_alias_with_address(address: str) -> Optional[Alias]: - return ( - Alias.get_by(email=address) - or DeletedAlias.get_by(email=address) - or DomainDeletedAlias.get_by(email=address) - ) + return Alias.get_by(email=address) or DomainDeletedAlias.get_by(email=address) + + +def is_deleted_alias(address: str) -> bool: + return DeletedAlias.get_by(email=address) is not None def handle_complaint(message: Message, origin: ProviderComplaintOrigin) -> bool: @@ -220,12 +220,20 @@ def handle_complaint(message: Message, origin: ProviderComplaintOrigin) -> bool: store_provider_complaint(alias, message) return True + if is_deleted_alias(msg_info.sender_address): + LOG.i(f"Complaint is for deleted alias. Do nothing") + return True + contact = Contact.get_by(reply_email=msg_info.sender_address) if contact: alias = contact.alias else: alias = find_alias_with_address(msg_info.rcpt_address) + if is_deleted_alias(msg_info.rcpt_address): + LOG.i(f"Complaint is for deleted alias. Do nothing") + return True + if not alias: LOG.e( f"Cannot find alias for address {msg_info.rcpt_address} or contact with reply {msg_info.sender_address}" diff --git a/app/models.py b/app/models.py index e9d909e2..9797c37d 100644 --- a/app/models.py +++ b/app/models.py @@ -2232,6 +2232,7 @@ class DomainDeletedAlias(Base, ModelMixin): user_id = sa.Column(sa.ForeignKey(User.id, ondelete="cascade"), nullable=False) domain = orm.relationship(CustomDomain) + user = orm.relationship(User, foreign_keys=[user_id]) @classmethod def create(cls, **kw):