From 9c86e1a820e968bfb09d9616642de0c073d54839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Thu, 8 Sep 2022 14:54:32 +0200 Subject: [PATCH] Fix: Use email directly for DomainDeletedAlias (#1273) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: Use email directly for DomainDeletedAlias * Add handling for reply phase * Use the first mailbox of the domain for deleted domain aliase Co-authored-by: Adrià Casajús --- app/handler/provider_complaint.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/handler/provider_complaint.py b/app/handler/provider_complaint.py index bf16b790..64af81cc 100644 --- a/app/handler/provider_complaint.py +++ b/app/handler/provider_complaint.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from dataclasses import dataclass from io import BytesIO from mailbox import Message -from typing import Optional +from typing import Optional, Union from app import s3 from app.config import ( @@ -189,7 +189,7 @@ def handle_yahoo_complaint(message: Message) -> bool: return handle_complaint(message, ProviderComplaintYahoo()) -def find_alias_with_address(address: str) -> Optional[Alias]: +def find_alias_with_address(address: str) -> Optional[Union[Alias, DomainDeletedAlias]]: return Alias.get_by(email=address) or DomainDeletedAlias.get_by(email=address) @@ -245,16 +245,22 @@ def handle_complaint(message: Message, origin: ProviderComplaintOrigin) -> bool: def report_complaint_to_user_in_reply_phase( - alias: Alias, + alias: Union[Alias, DomainDeletedAlias], to_address: str, origin: ProviderComplaintOrigin, msg_info: OriginalMessageInformation, ): capitalized_name = origin.name().capitalize() + mailbox_email = msg_info.mailbox_address + if not mailbox_email: + if type(alias) is Alias: + mailbox_email = alias.mailbox.email + else: + mailbox_email = alias.domain.mailboxes[0].email send_email_with_rate_control( alias.user, f"{ALERT_COMPLAINT_REPLY_PHASE}_{origin.name()}", - msg_info.mailbox_address or alias.mailbox.email, + mailbox_email, f"Abuse report from {capitalized_name}", render( "transactional/provider-complaint-reply-phase.txt.jinja2", @@ -293,11 +299,19 @@ def report_complaint_to_user_in_transactional_phase( def report_complaint_to_user_in_forward_phase( - alias: Alias, origin: ProviderComplaintOrigin, msg_info: OriginalMessageInformation + alias: Union[Alias, DomainDeletedAlias], + origin: ProviderComplaintOrigin, + msg_info: OriginalMessageInformation, ): capitalized_name = origin.name().capitalize() user = alias.user - mailbox_email = msg_info.mailbox_address or alias.mailbox.email + + mailbox_email = msg_info.mailbox_address + if not mailbox_email: + if type(alias) is Alias: + mailbox_email = alias.mailbox.email + else: + mailbox_email = alias.domain.mailboxes[0].email send_email_with_rate_control( user, f"{ALERT_COMPLAINT_FORWARD_PHASE}_{origin.name()}",