diff options
| author | Dennis Fink | 2026-10-25 20:47:14 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-10-25 20:47:14 +0100 |
| commit | a231913ab273f427697f2d27d615b495f6e160bb (patch) | |
| tree | b9d84e3aab3555ec88c648f790f9c31d8a4266a6 /webmentions_ssg/tasks/receiver.py | |
| parent | ae25061b14f8ea713ec7695848421edf84e4f0fc (diff) | |
| download | webmentions-ssg-a231913ab273f427697f2d27d615b495f6e160bb.tar.gz webmentions-ssg-a231913ab273f427697f2d27d615b495f6e160bb.zip | |
feat(receiver): add email notifications for new webmentions
Send an email after a newly received Webmention is successfully
verified, with SMTP delivery configurable through Flask-Mail.
Avoid notifications for resubmissions and manual reverification, and
keep the persisted verification result unchanged if notification
enqueueing fails.
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/tasks/receiver.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/webmentions_ssg/tasks/receiver.py b/webmentions_ssg/tasks/receiver.py index c33f517..e99eea3 100644 --- a/webmentions_ssg/tasks/receiver.py +++ b/webmentions_ssg/tasks/receiver.py @@ -15,6 +15,7 @@ from .. import DATABASE as db from .. import HUEY as huey from ..models import ReceivedWebmention from ..url_security import AddressResolutionError, is_public_url +from .notifications import send_webmention_notification class VerificationError(Exception): @@ -218,7 +219,9 @@ def source_mentions_target(source_url: str, target_url: str) -> bool: @huey.task(retries=2, retry_delay=50) -def verify_webmention(webmention_uuid: uuid.UUID) -> None: +def verify_webmention( + webmention_uuid: uuid.UUID, send_notification: bool = True +) -> None: """ Verify a received webmention and store its verification status. @@ -226,6 +229,8 @@ def verify_webmention(webmention_uuid: uuid.UUID) -> None: retry the task. :param webmention_uuid: Identifier of the received webmention to verify. + :param send_notification: Whether to enqueue an email notification after + successful verification. :raises TemporaryFetchError: If fetching the source fails temporarily. :raises httpx.RequestError: If an HTTP request error occurs while fetching the source. @@ -267,3 +272,12 @@ def verify_webmention(webmention_uuid: uuid.UUID) -> None: webmention.failure_reason = "Source does not mention target" db.session.commit() + + if send_notification: + try: + send_webmention_notification(webmention_uuid) + except Exception: + # Notification delivery must not change the persisted verification status. + current_app.logger.exception( + "Could not enqueue webmention notification for %s", webmention_uuid + ) |
