Skip to content

Commit

Permalink
Fix: Use email directly for DomainDeletedAlias (#1273)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
acasajus and acasajus authored Sep 8, 2022
1 parent 753a28e commit 9c86e1a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions app/handler/provider_complaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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 (
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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()}",
Expand Down

0 comments on commit 9c86e1a

Please sign in to comment.