From a9a44c378ad6e11fbabbd44c2c9d31db67849010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Fri, 10 Jun 2022 15:44:59 +0200 Subject: [PATCH] Do not report complaints for deleted aliases (#1067) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Do not report complaints for deleted aliases * revert reorder Co-authored-by: Adrià Casajús --- app/handler/provider_complaint.py | 18 +++++++++++++----- app/models.py | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) 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):