mirror of
https://github.com/simple-login/app.git
synced 2025-11-11 18:30:49 +08:00
Stop replies if the aliases are trashed
This commit is contained in:
parent
06fc808bba
commit
b0de3aa7b7
2 changed files with 65 additions and 1 deletions
|
|
@ -33,7 +33,6 @@ It should contain the following info:
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import email
|
import email
|
||||||
import time
|
|
||||||
import uuid
|
import uuid
|
||||||
from email import encoders
|
from email import encoders
|
||||||
from email.encoders import encode_noop
|
from email.encoders import encode_noop
|
||||||
|
|
@ -47,6 +46,7 @@ from typing import List, Tuple, Optional
|
||||||
|
|
||||||
import newrelic.agent
|
import newrelic.agent
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
|
import time
|
||||||
from aiosmtpd.controller import Controller
|
from aiosmtpd.controller import Controller
|
||||||
from aiosmtpd.smtp import Envelope
|
from aiosmtpd.smtp import Envelope
|
||||||
from email_validator import validate_email, EmailNotValidError
|
from email_validator import validate_email, EmailNotValidError
|
||||||
|
|
@ -1059,6 +1059,11 @@ def handle_reply(envelope, msg: Message, rcpt_to: str) -> (bool, str):
|
||||||
return False, status.E502
|
return False, status.E502
|
||||||
|
|
||||||
alias = contact.alias
|
alias = contact.alias
|
||||||
|
|
||||||
|
if alias.is_trashed():
|
||||||
|
LOG.d("%s is trashed, do not forward", alias)
|
||||||
|
return False, status.E502
|
||||||
|
|
||||||
alias_address: str = contact.alias.email
|
alias_address: str = contact.alias.email
|
||||||
alias_domain = get_email_domain_part(alias_address)
|
alias_domain = get_email_domain_part(alias_address)
|
||||||
|
|
||||||
|
|
|
||||||
59
tests/handler/test_trashed_alias.py
Normal file
59
tests/handler/test_trashed_alias.py
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
import random
|
||||||
|
|
||||||
|
import arrow
|
||||||
|
from aiosmtpd.smtp import Envelope
|
||||||
|
|
||||||
|
import email_handler
|
||||||
|
from app.email import status
|
||||||
|
from app.mail_sender import mail_sender
|
||||||
|
from app.models import Alias, BlockBehaviourEnum, Contact
|
||||||
|
from tests.utils import create_new_user, load_eml_file, random_email
|
||||||
|
|
||||||
|
|
||||||
|
@mail_sender.store_emails_test_decorator
|
||||||
|
def test_trash_on_forward():
|
||||||
|
user = create_new_user()
|
||||||
|
user.block_behaviour = BlockBehaviourEnum.return_5xx
|
||||||
|
alias = Alias.create_new_random(user)
|
||||||
|
alias.delete_on = arrow.utcnow().shift(days=1)
|
||||||
|
envelope = Envelope()
|
||||||
|
envelope.mail_from = "env.somewhere"
|
||||||
|
envelope.rcpt_tos = [alias.email]
|
||||||
|
original_sender_address = random_email()
|
||||||
|
msg = load_eml_file(
|
||||||
|
"replacement_on_forward_phase.eml",
|
||||||
|
{
|
||||||
|
"sender_address": original_sender_address,
|
||||||
|
"recipient_address": alias.email,
|
||||||
|
"cc_address": random_email(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
result = email_handler.MailHandler()._handle(envelope, msg)
|
||||||
|
assert result == status.E502
|
||||||
|
|
||||||
|
|
||||||
|
@mail_sender.store_emails_test_decorator
|
||||||
|
def test_trash_on_reply():
|
||||||
|
user = create_new_user()
|
||||||
|
user.block_behaviour = BlockBehaviourEnum.return_5xx
|
||||||
|
alias = Alias.create_new_random(user)
|
||||||
|
alias.delete_on = arrow.utcnow().shift(days=1)
|
||||||
|
contact = Contact.create(
|
||||||
|
user_id=alias.user.id,
|
||||||
|
alias_id=alias.id,
|
||||||
|
website_email=f"contact{random.random()}@mailbox.lan",
|
||||||
|
reply_email=f"re-{random.random()}@sl.lan",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
|
envelope = Envelope()
|
||||||
|
envelope.mail_from = "env.somewhere"
|
||||||
|
envelope.rcpt_tos = [contact.reply_email]
|
||||||
|
msg = load_eml_file(
|
||||||
|
"replacement_on_reply_phase.eml",
|
||||||
|
{
|
||||||
|
"contact_reply_email": contact.reply_email,
|
||||||
|
"other_contact_reply_email": random_email(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
result = email_handler.MailHandler()._handle(envelope, msg)
|
||||||
|
assert result == status.E502
|
||||||
Loading…
Add table
Reference in a new issue