mirror of
https://github.com/simple-login/app.git
synced 2024-09-20 15:05:59 +08:00
Send a notification to the user when a message has been quarantined
This commit is contained in:
parent
5f831d593a
commit
1b2d504b3b
|
@ -581,6 +581,28 @@ def apply_dmarc_policy(alias: Alias, contact: Contact, msg: Message) -> Optional
|
||||||
blocked=True,
|
blocked=True,
|
||||||
commit=True,
|
commit=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
),
|
||||||
|
)
|
||||||
return status.E519
|
return status.E519
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
4
templates/notification/message-quarantine.html
Normal file
4
templates/notification/message-quarantine.html
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<div>
|
||||||
|
There is a new quarantined message for <b>{{ alias.email }}</b>. Please go to your <a href="/dashboard/refused_email" class="btn btn-primary">quarantined emails</a> to review it.
|
||||||
|
</div>
|
||||||
|
|
|
@ -4,7 +4,14 @@ from aiosmtpd.smtp import Envelope
|
||||||
|
|
||||||
import email_handler
|
import email_handler
|
||||||
from app.email import headers, status
|
from app.email import headers, status
|
||||||
from app.models import User, Alias, AuthorizedAddress, IgnoredEmail, EmailLog
|
from app.models import (
|
||||||
|
User,
|
||||||
|
Alias,
|
||||||
|
AuthorizedAddress,
|
||||||
|
IgnoredEmail,
|
||||||
|
EmailLog,
|
||||||
|
Notification,
|
||||||
|
)
|
||||||
from email_handler import (
|
from email_handler import (
|
||||||
get_mailbox_from_mail_from,
|
get_mailbox_from_mail_from,
|
||||||
should_ignore,
|
should_ignore,
|
||||||
|
@ -85,6 +92,9 @@ def test_dmarc_quarantine(flask_client):
|
||||||
email_log = email_logs[0]
|
email_log = email_logs[0]
|
||||||
assert email_log.blocked
|
assert email_log.blocked
|
||||||
assert email_log.refused_email_id
|
assert email_log.refused_email_id
|
||||||
|
notifications = Notification.filter_by(user_id=user.id).all()
|
||||||
|
assert len(notifications) == 1
|
||||||
|
assert f"{alias.email} has a new mail in quarantine" == notifications[0].title
|
||||||
|
|
||||||
|
|
||||||
def test_gmail_dmarc_softfail(flask_client):
|
def test_gmail_dmarc_softfail(flask_client):
|
||||||
|
|
Loading…
Reference in a new issue