mirror of
https://github.com/Kozea/Radicale.git
synced 2025-08-01 18:18:31 +00:00
add support for hook option "dryrun"
This commit is contained in:
parent
fe175df9a2
commit
6de7b3b8c9
1 changed files with 13 additions and 2 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue