From 2da00964535f91d2d5d9d4b3182b2d393aa77e84 Mon Sep 17 00:00:00 2001
From: lilly
Date: Mon, 9 Feb 2026 14:33:22 +0100
Subject: [PATCH] only send email when a note actually has content
---
hedgedoc-expire.py | 40 +++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/hedgedoc-expire.py b/hedgedoc-expire.py
index fbcc805..a9738a1 100644
--- a/hedgedoc-expire.py
+++ b/hedgedoc-expire.py
@@ -215,28 +215,30 @@ class HedgedocExpire:
with db.prepare('DELETE FROM "Notes" WHERE "id" = $1') as delete_statement:
for note in self.notes_to_be_expired(db):
try:
- note_age = datetime.now(timezone.utc) - datetime.fromisoformat(note['updatedAt'])
- msg = MIMEMultipart()
- msg['From'] = self.email_sender.mail_from
- msg['To'] = self.email_from_email_or_profile(note)
- msg['Subject'] = f'Your HedgeDoc Note "{note["title"]}" has expired'
- msg.attach(MIMEText(dedent(f'''\
- You created the note titled "{note["title"]}" on {note["createdAt"]}.
- It was lasted updated {note['updatedAt']}, {humanize.naturaldelta(note_age)} ago. We expire all notes
- that have not been updated within {humanize.naturaldelta(self.config.note_age)}.
+
+ if len(note["content"]) > 0:
+ note_age = datetime.now(timezone.utc) - datetime.fromisoformat(note['updatedAt'])
+ msg = MIMEMultipart()
+ msg['From'] = self.email_sender.mail_from
+ msg['To'] = self.email_from_email_or_profile(note)
+ msg['Subject'] = f'Your HedgeDoc Note "{note["title"]}" has expired'
+ msg.attach(MIMEText(dedent(f'''\
+ You created the note titled "{note["title"]}" on {note["createdAt"]}.
+ It was lasted updated {note['updatedAt']}, {humanize.naturaldelta(note_age)} ago. We expire all notes
+ that have not been updated within {humanize.naturaldelta(self.config.note_age)}.
- Please find attached the contents of the latest revision of your note.
+ Please find attached the contents of the latest revision of your note.
- The admin team for {self.config.url}
+ The admin team for {self.config.url}
- '''), 'plain', 'utf-8'))
- md = MIMEText(note["content"], 'markdown', 'utf-8')
- filename = note['title'].encode('ascii', 'ignore').decode('utf-8')
- if len(filename) == 0:
- filename = 'note'
- md.add_header('Content-Disposition', f'attachment; filename={filename}.md')
- msg.attach(md)
- self.email_sender.send(msg)
+ '''), 'plain', 'utf-8'))
+ md = MIMEText(note["content"], 'markdown', 'utf-8')
+ filename = note['title'].encode('ascii', 'ignore').decode('utf-8')
+ if len(filename) == 0:
+ filename = 'note'
+ md.add_header('Content-Disposition', f'attachment; filename={filename}.md')
+ msg.attach(md)
+ self.email_sender.send(msg)
# email backup of the note sent, now we can delete it
delete_statement(note["id"])
--
2.51.2