Merge pull request #849 from acasajus/new/parse-rpamd-headers

Return 200 on fishy dmarc result
This commit is contained in:
Son Nguyen Kim 2022-03-22 17:36:45 +01:00 committed by GitHub
commit 3d30870395
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 26 deletions

View file

@ -20,6 +20,7 @@ E211 = "250 SL E211 Bounce Forward phase handled"
E212 = "250 SL E212 Bounce Reply phase handled"
E213 = "250 SL E213 Unknown email ignored"
E214 = "250 SL E214 Unauthorized for using reverse alias"
E215 = "250 SL E215 Handled dmarc policy"
# endregion

View file

@ -554,8 +554,15 @@ def apply_dmarc_policy(
DmarcCheckResult.soft_fail,
):
quarantine_dmarc_failed_email(alias, contact, envelope, msg)
add_quarantine_notification_for_alias(alias)
return status.E519
Notification.create(
user_id=alias.user_id,
title=f"{alias.email} has a new mail in quarantine",
message=Notification.render(
"notification/message-quarantine.html", alias=alias
),
commit=True,
)
return status.E215
return None
@ -592,30 +599,6 @@ def quarantine_dmarc_failed_email(alias, contact, envelope, msg):
)
def add_quarantine_notification_for_alias(alias: Alias):
notification_title = f"{alias.email} has a new mail in quarantine"
notifications = (
Notification.filter_by(user_id=alias.user_id)
.order_by(Notification.read, Notification.created_at.desc())
.limit(10)
.all()
) # load a record more to know whether there's more
already_notified = False
for notification in notifications:
if notification.title == notification_title:
already_notified = True
break
if not already_notified:
Notification.create(
user_id=alias.user_id,
title=notification_title,
message=Notification.render(
"notification/message-quarantine.html", alias=alias
),
commit=True,
)
def handle_forward(envelope, msg: Message, rcpt_to: str) -> List[Tuple[bool, str]]:
"""return an array of SMTP status (is_success, smtp_status)
is_success indicates whether an email has been delivered and