From 6de7b3b8c95540ca576c3989e9d80c0d2edbfcc4 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Tue, 22 Jul 2025 20:58:40 +0200 Subject: [PATCH] add support for hook option "dryrun" --- radicale/hook/email/__init__.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/radicale/hook/email/__init__.py b/radicale/hook/email/__init__.py index 33539ed5..75d043aa 100644 --- a/radicale/hook/email/__init__.py +++ b/radicale/hook/email/__init__.py @@ -610,6 +610,7 @@ class EmailConfig: password: str, from_email: str, send_mass_emails: bool, + dryrun: bool, added_template: MessageTemplate, removed_template: MessageTemplate): self.host = host @@ -620,6 +621,7 @@ class EmailConfig: self.password = password self.from_email = from_email self.send_mass_emails = send_mass_emails + self.dryrun = dryrun self.added_template = added_template self.removed_template = removed_template self.updated_template = added_template # Reuse added template for updated events @@ -630,7 +632,7 @@ class EmailConfig: Return a string representation of the EmailConfig. """ return f"EmailConfig(host={self.host}, port={self.port}, username={self.username}, " \ - f"from_email={self.from_email}, send_mass_emails={self.send_mass_emails})" + f"from_email={self.from_email}, send_mass_emails={self.send_mass_emails}, dryrun={self.dryrun})" def __repr__(self): return self.__str__() @@ -747,6 +749,10 @@ class EmailConfig: logger.warning("No valid email addresses found in attendees. Cannot send email.") return False + if self.dryrun is True: + logger.warning("Hook 'email': DRY-RUN _send_email / to_addresses=%r", to_addresses) + return True + # Add headers message = MIMEMultipart("mixed") message["From"] = self.from_email @@ -819,6 +825,7 @@ def _read_event(vobject_data: str) -> EmailEvent: class Hook(BaseHook): def __init__(self, configuration): super().__init__(configuration) + self.dryrun = self.configuration.get("hook", "dryrun") self.email_config = EmailConfig( host=self.configuration.get("hook", "smtp_server"), port=self.configuration.get("hook", "smtp_port"), @@ -828,6 +835,7 @@ class Hook(BaseHook): password=self.configuration.get("hook", "smtp_password"), from_email=self.configuration.get("hook", "from_email"), send_mass_emails=self.configuration.get("hook", "mass_email"), + dryrun=self.configuration.get("hook", "dryrun"), added_template=MessageTemplate( subject="You have been added to an event", body=self.configuration.get("hook", "added_template") @@ -858,7 +866,10 @@ class Hook(BaseHook): :type notification_item: HookNotificationItem :return: None """ - logger.debug("Received notification item: %s", notification_item) + if self.dryrun: + logger.warning("Hook 'email': DRY-RUN received notification_item: %r", vars(notification_item)) + else: + logger.debug("Received notification_item: %r", vars(notification_item)) try: notification_type = HookNotificationItemTypes(value=notification_item.type) except ValueError: