diff --git a/email_handler.py b/email_handler.py index 2c026c74..bc645231 100644 --- a/email_handler.py +++ b/email_handler.py @@ -394,7 +394,7 @@ def replace_header_when_reply(msg: Message, alias: Alias, header: str): header, headers, ) - raise NonReverseAliasInReplyPhase + raise NonReverseAliasInReplyPhase(reply_email) # still keep this email in header # new_addrs.append(reply_email) else: @@ -582,7 +582,7 @@ def handle_forward(envelope, msg: Message, rcpt_to: str) -> List[Tuple[bool, str reply_to_contact = None if msg[headers.REPLY_TO]: reply_to = get_header_unicode(msg[headers.REPLY_TO]) - LOG.d("Create or get contact for from_header:%s", reply_to) + LOG.d("Create or get contact for reply_to_header:%s", reply_to) # ignore when reply-to = alias if reply_to == alias.email: LOG.i("Reply-to same as alias %s", alias) @@ -1078,8 +1078,23 @@ def handle_reply(envelope, msg: Message, rcpt_to: str) -> (bool, str): LOG.d("From header is %s", from_header) add_or_replace_header(msg, headers.FROM, from_header) - replace_header_when_reply(msg, alias, headers.TO) - replace_header_when_reply(msg, alias, headers.CC) + try: + replace_header_when_reply(msg, alias, headers.TO) + replace_header_when_reply(msg, alias, headers.CC) + except NonReverseAliasInReplyPhase as e: + LOG.w("non reverse-alias in reply %s %s %s", e, contact, alias) + send_email( + mailbox.email, + f"Email sent to {contact.email} contains non reverse-alias addresses", + render( + "transactional/non-reverse-alias-reply-phase.txt.jinja2", + destination=contact.email, + alias=alias.email, + subject=msg[headers.SUBJECT], + ), + ) + # user is informed and will retry + return True, status.E200 replace_original_message_id(alias, email_log, msg) diff --git a/templates/emails/transactional/non-reverse-alias-reply-phase.txt.jinja2 b/templates/emails/transactional/non-reverse-alias-reply-phase.txt.jinja2 new file mode 100644 index 00000000..1a578afe --- /dev/null +++ b/templates/emails/transactional/non-reverse-alias-reply-phase.txt.jinja2 @@ -0,0 +1,15 @@ +Hi + +Your email sent to {{ destination }} from {{ alias }} ({{ subject }}) contains an address which isn't a reverse-alias in the To: or Cc: field. + +This will reveal your real mailbox address. + +Please create a reverse alias for each recipient to make sure your mailbox stays hidden. + +More info about reverse-alias can be found on https://simplelogin.io/docs/getting-started/reverse-alias/ +and how to send an email from your alias on https://simplelogin.io/docs/getting-started/send-email/ + +Please let us know if you have any question. + +Best, +SimpleLogin team. \ No newline at end of file